﻿
//获得当前日期 
function getDate_custom()
{
	var today = new Date();
	var week;
	var day = today.getDay();
	switch(day)
	{
		case 1:
			week = "星期一"
			break;
		case 2:
			week = "星期二";
			break;
		case 3:
			week = "星期三";
			break;
		case 4: 
			week = "星期四";
			break;
		case 5:
			week = "星期五";
			break;
		case 6: 
			week = "星期六";
			break;
		case 7:
			week = "星期天";	
			break;
	}
	//alert(week);
	//window.alert(day);
	var cur_time = today.toLocaleString();
	var p =  cur_time.indexOf('日');
	return  ouput  = cur_time.substr(0,p+1) + " " + week; 
}


//隔行变色 
function sort(ul_id){
	function hasClass(obj,className)
	{
		var reg = new RegExp('(^|)'+className+'( |$)'); 
	 	return reg.test(obj.className);
	}
	function addClass(obj,className)
	{
		if(!hasClass(obj,className))
		{
			obj.className += " " + className;
		}
	}
	var arr = document.getElementById(ul_id).getElementsByTagName("LI");
	
	//alert(arr);
	for(i = 0;i < arr.length;i+=2)
	{
		addClass(arr[i],"odd");
		addClass(arr[i+1],"even");
		//alert(i);
	}
}

//选项卡
function switchTab(identify,index,count)
{
	for(i=0;i<count;i++)
	{
		var CurTabObj = document.getElementById("Tab_"+identify+"_"+i);
		var CurListObj = document.getElementById("List_"+identify+"_"+i);
		if (i != index)
		{		
			fRemoveClass(CurTabObj , "upH2");
			fRemoveClass(CurListObj , "upBox");
		}
	}
	fAddClass(document.getElementById("Tab_"+identify+"_"+index),"upH2") ;
	fAddClass(document.getElementById("List_"+identify+"_"+index),"upBox") ;
}

function fAddClass(XEle, XClass) 
{
	if(!XClass) throw new Error("XClass 不能为空!");
	if(XEle.className!="") 
	{
		var Re = new RegExp("\\b"+XClass+"\\b\\s*", "");
		XEle.className = XEle.className.replace(Re, "");	
		var OldClassName = XEle.className.replace(/^\s+|\s+$/g,"");
		if (OldClassName == "" ) 
		{		 
			XEle.className = XClass;
		}
		else 
		{
			XEle.className = OldClassName + " " + XClass;
		}
	}
	else XEle.className = XClass;
}


function fRemoveClass(XEle, XClass)
{
	var OldClassName = XEle.className.replace(/^\s+|\s+$/g,"");
	if(OldClassName!="") 
	{
		var Re = new RegExp("\\b"+XClass+"\\b\\s*", "");  
 		XEle.className = OldClassName.replace(Re, "");
	}
}


//强制等高 
function $(obj)
{
	return document.getElementById(obj);
}

String.prototype.camelCase = function()
{
	return this.replace(/-\D/g,function(match)
	{
		return match.charAt(1).toUpperCase();
	});
}

String.prototype.hyphenate = function()
{
	return this.replace(/[A-Z]/g,function(match)
	{
		return ('-' + match.charAt(0).toLowerCase());
	});
}

var _getComputedStyle = function(property)
{
	if(this.currentStyle) return this.currentStyle[property.camelCase()];
	var computed = document.defaultView.getComputedStyle(this,null);
	return (computed) ? computed.getPropertyValue([property.hyphenate()]) : null;
}



function EqualHeight(obj,clear){
	function $(obj)
	{
		return document.getElementById(obj);
	}

	function $each(iterable,fn,fn_sub)
	{
		for(i = 0;i < iterable.length;i++)
		{
			fn.apply(null,[iterable,i]);
		}
	}

	function _nodeFix(obj)
	{
		var arr = new Array();
		var cl = new RegExp("\\b"+clear+"\\b\\s*","");
		for(i = 0;i < obj.childNodes.length;i++)
		{
			if(obj.childNodes[i] && obj.childNodes[i].nodeType == 1 && !(cl.test(obj.childNodes[i].className)))
			{
				arr.push(obj.childNodes[i]);
					
			}
		}
		return arr;
	}	

	function calc(h,obj)
	{
			
		try
		{
			 var _t = parseInt(_getComputedStyle.call(obj,"paddingTop"));
		}
		catch(e)
		{
			throw new Error("获取padding值时出现错误!!");
			alert(e);
		}

		var _b = parseInt(_getComputedStyle.call(obj,"paddingBottom"));
		return (h - (_t + _b))	;
	}
	//window.alert("断点-改变前");		
	var arr = _nodeFix($(obj)),_H = 0;

	$each(arr,function(arr,i)
	{	
		var _h = arr[i].offsetHeight;
		_H = (_h > _H ? _h : _H);
	});
	$each(arr,function(arr,j)
	{
		arr[j].style.height = calc(_H,arr[i]) + 'px';
	});
	
};



//网新的滚动代码 
function marquee(i, direction)
{
	var obj = document.getElementById("marquee" + i);
	var obj1 = document.getElementById("marquee" + i + "_1");
	var obj2 = document.getElementById("marquee" + i + "_2");

	if (direction == "up")
	{
		if (obj2.offsetTop - obj.scrollTop <= 0)
		{
			obj.scrollTop -= (obj1.offsetHeight + 20);
		}
		else
		{
			var tmp = obj.scrollTop;
			obj.scrollTop++;
			if (obj.scrollTop == tmp)
			{
				obj.scrollTop = 1;
			}
		}
	}
	else
	{
		if (obj2.offsetWidth - obj.scrollLeft <= 0)
		{
			obj.scrollLeft -= obj1.offsetWidth;
		}
		else
		{
			obj.scrollLeft++;
		}
	}
}

function marqueeStart(i, direction)
{
	var obj = document.getElementById("marquee" + i);
	var obj1 = document.getElementById("marquee" + i + "_1");
	var obj2 = document.getElementById("marquee" + i + "_2");

	obj2.innerHTML = obj1.innerHTML;
	var marqueeVar = window.setInterval("marquee("+ i +", '"+ direction +"')", 20);
	obj.onmouseover = function(){window.clearInterval(marqueeVar);}
	obj.onmouseout = function(){marqueeVar = window.setInterval("marquee("+ i +", '"+ direction +"')", 20);}
}
