﻿var waitInterval;
var activeTab;
var MouseDelayTime = 150;//鼠标感应延迟300毫秒
var myEvent;//鼠标滑动对象
Tab = function(tabID,onCss,outCss,childTag)
{
	this.tabObj = $(tabID);
	this.onClassName = onCss;
	this.outClassName = outCss;
	this.innerHtml = new Array();
	this.contentObj = new Array();
	this.ajaxEndMethod = new Array();
	this.childTag = childTag;
};

Tab.prototype.onload = function()
{
	this.tabMObj = this.tabMObj ? this.tabMObj : clearNodeType3(this.tabObj.childNodes)[0];
	this.tabCObj = this.tabCObj ? this.tabCObj : clearNodeType3(this.tabObj.childNodes)[1];
	var MChilds = this.childTag ? getTags(this.tabObj,this.childTag) : getTags(getTags(this.tabMObj,"ul")[0],"li");
	var me = this;
	for(var i = 0; i < MChilds.length; i++)
	{
	    if(MChilds[i].innerHTML.trim().length>0)
	    {
	        //alert(MChilds[i].innerHTML);
		    var aObj = getTags(MChilds[i],"a")[0];
		    var MChildsChilds = clearNodeType3(MChilds[i].childNodes)
		    MChilds[i].style.cursor = "pointer";
		    MChilds[i].onmouseover = function(){
		        if(!(me.activeObj && me.activeObj == this))
		        {
		            if(me.activeObj == this) return;
			        myEvent = this;
			        activeTab = me;
			        clearTimeout(waitInterval);
			        waitInterval = window.setTimeout("activeTab.ontab(myEvent)",MouseDelayTime);
			    }
		    }
		    MChilds[i].onmouseout = function(){		    
		        if(me.activeObj == this) return;
		        clearTimeout(waitInterval);		    
		    }
		    if(aObj)aObj.onfocus = function(){this.blur();}
		}
	}
	this.ontab();
};
Tab.prototype.onclick = function()
{
	this.tabMObj = this.tabMObj ? this.tabMObj : clearNodeType3(this.tabObj.childNodes)[0];
	this.tabCObj = this.tabCObj ? this.tabCObj : clearNodeType3(this.tabObj.childNodes)[1];
	var MChilds = this.childTag ? getTags(this.tabObj,this.childTag) : getTags(getTags(this.tabMObj,"ul")[0],"li");
	var me = this;
	for(var i = 0; i < MChilds.length; i++)
	{
	    if(MChilds[i].innerHTML.trim().length>0)
	    {	        
		    var aObj = getTags(MChilds[i],"a")[0];
		    var MChildsChilds = clearNodeType3(MChilds[i].childNodes)
		    MChilds[i].style.cursor = "pointer";
		    MChilds[i].onclick = function(){
		        if(!(me.activeObj && me.activeObj == this))
		        {
		            if(me.activeObj == this) return;
			        myEvent = this;
			        activeTab = me;
			        clearTimeout(waitInterval);
			        waitInterval = window.setTimeout("activeTab.ontab(myEvent)",MouseDelayTime);
			    }
		    }
		    if(aObj)aObj.onfocus = function(){this.blur();}
		}
	}
	this.ontab();
};
Tab.prototype.ontab = function(e)
{
	var me = this;
	var top = (parseInt(me.tabCObj.offsetHeight) - 30)/2;
	var loadInfo = me.loadImg ? "<div style=\"margin:" + top + "px auto;padding:0px; text-align:center;\"><img src=\"" + me.loadImg + "\" border=\"0\" style=\"height:16px;line-height:16px;\"></div>" : "<div style=\"margin:" + top + "px auto;height:25px;line-height:25px; text-align:center;\">載入中．．．</div>";
	get_Ajax_CallBack = function(rs)
    {        
        if(rs.value != null)
	    {
	        var returnValue = rs.value;
	        var innerHtmlIndex = returnValue[0]
	        me.innerHtml[innerHtmlIndex] = returnValue[1].toString();
		    me.tabCObj.innerHTML = me.innerHtml[innerHtmlIndex];
		    if(me.ajaxEndMethod && me.ajaxEndMethod[innerHtmlIndex] && me.ajaxEndMethod[innerHtmlIndex].trim().length > 0){eval(me.ajaxEndMethod[innerHtmlIndex]);}	
	    }
	    else
	    {
	        me.tabCObj.innerHTML = loadInfo
	    }
    };

	var MChilds = this.childTag ? getTags(this.tabObj,this.childTag) : getTags(getTags(this.tabMObj,"ul")[0],"li");	
	var cObjChilds = clearNodeType3(this.tabCObj.childNodes);
	this.activeObj = e ? e : (this.activeObj ? this.activeObj : MChilds[0]);
	for(var i=0;i<MChilds.length;i++)
	{		
		if(MChilds[i] != this.activeObj)
		{  
			MChilds[i].className = MChilds[i].getAttribute("outClassName") ? MChilds[i].getAttribute("outClassName") : this.outClassName;
			var nObj = (MChilds[i].tagName.toLowerCase()=="a") ? MChilds[i] : getTags(MChilds[i],"a")[0];
			if(nObj && nObj.getAttribute("ahref")) {nObj.href = "JavaScript:void(0);";}
		}
		else
		{
		    var value = MChilds[i].value && MChilds[i].value>0 ? MChilds[i].value : i;
			var aObj = (MChilds[i].tagName.toLowerCase() == "a") ? MChilds[i] : getTags(MChilds[i],"a")[0];
			MChilds[i].className = MChilds[i].getAttribute("onClassName") ? MChilds[i].getAttribute("onClassName") : this.onClassName;
			if(aObj && aObj.getAttribute("ahref")) {aObj.href = aObj.getAttribute("ahref");}
			if(this.contentObj&&this.contentObj[i])
		    {
		        for(j=0;j<this.contentObj.length;j++)
		        {
		            if(j==i)
		                this.contentObj[j].style.display = "block";
		            else
		                this.contentObj[j].style.display = "none";
		        }
		    }
		    else
		    {			
			    if(this.ajaxMethod)
			    {
			        if(this.innerHtml && this.innerHtml[value] && this.innerHtml[value].trim().length > 0)
			        {
			            this.tabCObj.innerHTML = this.innerHtml[value].trim();
			            if(this.ajaxEndMethod && this.ajaxEndMethod[value] && this.ajaxEndMethod[value].trim().length > 0){eval(this.ajaxEndMethod[value]);}
			        }
			        else
			        {
			            this.tabCObj.innerHTML = loadInfo;			        
				        eval(this.ajaxMethod + "(value,get_Ajax_CallBack)");
				    }
			    }
			    else
			    {
			        this.tabCObj.innerHTML = this.innerHtml[value].trim();
			    }
			}
		}
	}
	try
	{	    
	    if(StranBody != null)
	    {
	        StranBody(this.tabObj);
	     }
	}
	catch(error)
    {}
	clearTimeout(waitInterval);		
};
function MailTo()
{
	window.location="/MailTo.aspx?url="+escape(window.location.href.toString())+"&title=" + ArticleTitle+"&content=" + ArticleContent;
}
function $(id){
  if (typeof(id) != "string" || id == "") return null;
  if (document.all) return document.all(id);
  if (document.getElementById) return document.getElementById(id);
  try {return eval(id);} catch(e){ return null;}
}
function clearNodeType3(objs)
{
	var newObjs=new Array();
	var j=0;
	for(var i=0;i<objs.length;i++)
	{
		if(objs[i].nodeType==1)
		{
			newObjs[j]=objs[i];
			j++;
		}
	}
	return newObjs;
}
function getIdTags(id,tagName)
{ 
	return $(id).getElementsByTagName(tagName);
}
function getTags(obj,tagName)
{ 
	return obj.getElementsByTagName(tagName);
}
String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
};
function linkPage(url)
{
	if(window.location.href)
	{
		window.location.href  =url;
	}
	else
	{
		window.location  =url;
	}
}