﻿function $(b_Control)
{
	return document.getElementById(b_Control);
}

/*Tab切换
-id：节点唯一标识
-index：初始索引（从0开始）
-eventType：事件类型（0-鼠标滑动，1-鼠标点击）
-showDelay：渐显时间
-isAuto：是否自动切换
-autoDelay：自动切换间间隔）*/
function HR_Tab(id, index, eventType, showDelay, isAuto, autoDelay)
{
	if(jQuery("#"+ id + " .tMenu .t").size() == jQuery("#"+ id + " .tBox").size())
	{
		var j;function slide(j){jQuery("#"+ id + " .tMenu .t").removeClass("current");jQuery("#"+ id + " .tMenu .t").eq(j).addClass("current");jQuery("#"+ id + " .tBox").hide();jQuery("#"+ id + " .tBox").eq(j).fadeIn(showDelay);}
		if(index < 0 || index > jQuery("#"+ id + " .tMenu .t").size() - 1){index = 0;}
		jQuery("#"+ id + " .tBox:not(:eq(" + index + "))").hide();
		jQuery("#"+ id + " .tMenu .t:eq(" + index + ")").addClass("current");
		jQuery("#"+ id + " .tMenu .t").each(function(i)
			{if(eventType == 0){jQuery(this).mouseover(function(){slide(i);});}else{jQuery(this).click(function(){slide(i);});}}
		);
		if(isAuto)
		{
			j = index-1; var timer = null;
			function autoPlay(){n = jQuery("#"+ id + " .tMenu .t").size()-1; j++;if(j > n){j = 0;}slide(j);timer = window.setTimeout(autoPlay, autoDelay);}
			function hookThumb()
			{jQuery("#"+ id + " .tMenu .t").hover(function(){if (timer){clearTimeout(timer);j = jQuery(this).prevAll().filter(".t").length;}},function (){timer = window.setTimeout(autoPlay, autoDelay);this.blur();return false;});jQuery("#"+ id + " .tBox").hover(function(){if (timer){clearTimeout(timer);j = jQuery(this).prevAll().filter(".tBox").length;}},function (){timer = window.setTimeout(autoPlay, autoDelay);this.blur();return false;});}autoPlay();hookThumb();
		}
	}
	else
	{
		alert("ID为[ " + id + " ]的tab个数有误！请检查");
	}
}

//文章搜索表单验证
function CheckArticleSearch()
{
	if ($("wd").value == "关键字")
	{
		alert("请输入文章搜索关键字！");		
		$("wd").value = ""
		$("wd").focus();
		return false;
	}
	if ($("wd").value == "")
	{
		alert("请输入文章搜索关键字！");
		$("wd").focus();
		return false;
	}
	if ($("wd").value.length < 2)
	{
		alert("关键字不少于两个字符！");
		$("wd").focus();
		return false;
	}
}

//Form之Input
function fEvent(sType,oInput){
switch (sType){
	case "focus" :
		oInput.isfocus = true;
		oInput.style.background = '#fdf6aa';
		oInput.style.color = '#353535';
	case "mouseover" :
		oInput.style.borderColor = '#ff9900';
		oInput.style.background = '#fdf6aa';
		oInput.style.color = '#353535';
			break;
	case "blur" :
		oInput.isfocus = false;
		oInput.style.background = '#fdf6aa';
		oInput.style.color = '#353535';
	case "mouseout" :
		if(!oInput.isfocus){
			oInput.style.borderColor='#8ee65b';
			oInput.style.background = '#FFF';
		}
		break;
	  }
}



// Tab切换
function Tab_Show(TitleBoxID,ContentBoxID,n,TitleTagType,ContentTagType)
{
	var m_n = document.getElementById(TitleBoxID).getElementsByTagName(TitleTagType);
	var c_n = document.getElementById(ContentBoxID).getElementsByTagName(ContentTagType);
	for(i=0;i<m_n.length;i++)
	{
		m_n[i].className=i==n?"on":"off";
		c_n[i].className=i==n?"dis":"undis";
	}
	//alert(m_n);
}

//显示回顶
function ShowTop()
{
	var S_Top = document.documentElement.scrollTop;
	var obj = document.getElementById("ShowTop");
	//alert(S_Top);
	if(S_Top > document.documentElement.clientHeight)
	{
		obj.style.display = "block";
	}
	else
	{
		obj.style.display = "none";
	}
}



//弹出高亮窗口
function ShowWindow(title, url, msg, w, h)
{
	var zHeight; //滚动滚动条时上面被遮的高度
	
	//隐藏滚动条
	function HideScroll()
	{
		var temp_h1 = document.body.clientHeight;
		var temp_h2 = document.documentElement.clientHeight;
		var isXhtml = (temp_h2<=temp_h1&&temp_h2!=0)?true:false; 
		var htmlbody = isXhtml?document.documentElement:document.body;
		htmlbody.style.overflow = "hidden";
	}
	
	//恢复滚动条
	function ShowScroll()
	{
		var temp_h1 = document.body.clientHeight;
		var temp_h2 = document.documentElement.clientHeight;
		var isXhtml = (temp_h2<=temp_h1&&temp_h2!=0)?true:false; 
		var htmlbody = isXhtml?document.documentElement:document.body;
		htmlbody.style.overflow = "auto";
	}

	var titleheight = "22px"; // 提示窗口标题高度 
	var bordercolor = "#9C0"; // 提示窗口的边框颜色 
	var titlecolor = "#FFFFFF"; // 提示窗口的标题文字颜色 
	var titlebgcolor = "#9C0"; // 提示窗口的标题背景色
	var bgcolor = "#f4f4f4"; // 提示内容的背景色
	
	var iWidth = document.documentElement.clientWidth; 
	var iHeight = document.documentElement.clientHeight; 
	//alert(iHeight + "--" + document.documentElement.scrollTop);
	var bgObj = document.createElement("div"); 
	bgObj.style.cssText = "position:absolute;left:0px;top:0px;width:"+iWidth+"px;height:"+Math.max(document.body.clientHeight, iHeight)+"px;filter:Alpha(Opacity=80);opacity:0.8;background-color:#000000;z-index:101;";
	document.body.appendChild(bgObj); 
	
	var msgObj=document.createElement("div");
	msgObj.style.cssText = "position:absolute;font:12px '宋体';top:"+((iHeight-h)/2+document.documentElement.scrollTop)+"px;left:"+(iWidth-w)/2+"px;width:"+w+"px;height:"+h+"px;text-align:center;border:1px solid "+bordercolor+";background-color:"+bgcolor+";padding:1px;line-height:2px;z-index:102;";
	document.body.appendChild(msgObj);
	
	var table = document.createElement("table");
	msgObj.appendChild(table);
	table.style.cssText = "margin:0px;border:0px;padding:0px;";
	table.cellSpacing = 0;
	var tr = table.insertRow(-1);
	var titleBar = tr.insertCell(-1);
	titleBar.style.cssText = "width:100%;height:"+titleheight+"px;text-align:left;padding:8px 2px;margin:0px;font:bold 12px '宋体';color:"+titlecolor+";border:0px solid " + bordercolor + ";cursor:auto;background-color:" + titlebgcolor;
	titleBar.style.paddingLeft = "10px";
	titleBar.innerHTML = title;
	
	var closeBtn = tr.insertCell(-1);
	closeBtn.style.cssText = "cursor:pointer; padding:2px;background-color:" + titlebgcolor;
	closeBtn.innerHTML = "<span style='font-size:20px; color:"+titlecolor+";'>×</span>";
	closeBtn.onclick = function()
	{
		document.body.removeChild(bgObj);
		document.body.removeChild(msgObj);
		ShowScroll();
	}
 
	var msgBox = table.insertRow(-1).insertCell(-1);
	msgBox.style.cssText = "font:12px '宋体';";
	msgBox.colSpan  = 2;
	if(url !="")
	{
		msgBox.innerHTML = "<iframe border='0' src='" + url + "' width='100%' height='" + (h-30) + "' scrollbars='no' frameBorder='0'></iframe>";
	}
	else
	{
		msgBox.innerHTML = msg;
	}
	// 获得事件Event对象，用于兼容IE和FireFox
	function getEvent() 
	{
		return window.event || arguments.callee.caller.arguments[0];
	}
	HideScroll();
}



function MarqueeTop()
{
	var speed=50; //数字越大速度越慢
	var tab=document.getElementById("demo");
	var tab1=document.getElementById("demo1");
	var tab2=document.getElementById("demo2");
	tab2.innerHTML=tab1.innerHTML; //克隆demo1为demo2
	function Marquee()
	{
		if(tab2.offsetTop-tab.scrollTop<=0)//当滚动至demo1与demo2交界时
		tab.scrollTop-=tab1.offsetHeight //demo跳到最顶端
		else
		{
			tab.scrollTop++
		}
	}
	var MyMar=setInterval(Marquee,speed);
	tab.onmouseover=function() {clearInterval(MyMar)};//鼠标移上时清除定时器达到滚动停止的目的
	tab.onmouseout=function() {MyMar=setInterval(Marquee,speed)};//鼠标移开时重设定时器
}
