﻿var MouseDelayTime=200;//鼠标感应延迟
var waitInterval;
var Browser = new Object();
Browser.isMozilla = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined') && (typeof HTMLDocument!='undefined');
Browser.isIE = window.ActiveXObject ? true : false;
Browser.isFirefox = (navigator.userAgent.toLowerCase().indexOf("firefox")!=-1);
Browser.isOpera = (navigator.userAgent.toLowerCase().indexOf("opera")!=-1);

var etype=0;
var ajccache=new Object();
this.maxh=new Object();
var idn,tmpa,tmpat;
var aw="";
var rT; 

function SetCookie(name,value,expires){//写cookie
var exp=new Date();
exp.setTime(exp.getTime()+expires*60000);
document.cookie=name+"="+escape(value)+";expires="+exp.toGMTString();//+";domain=arkoo.com;path=/";
} 
function readcookie(name){//读取cookie
var oRegex=new RegExp(name+'=([^;]+)','i');
var oMatch=oRegex.exec(document.cookie);
if(oMatch&&oMatch.length>1)return unescape(oMatch[1]);
else return '';
}


function getObject(objectId) {
     if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	   return document.getElementById(objectId);
     } 
     else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	   return document.all(objectId);
     } 
     else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	   return document.layers[objectId];
     } 
     else {
	   return false;
    }
} 


function GXC(sTargetId,x,sWhere)
{
this.tagid = sTargetId;
this.xmlHttp;
this. requestType = sTargetId;
this.where =sWhere;
this.url = "/Tab/Tab_"+this.tagid+'_'+x+'.aspx';
}


GXC.prototype.GetXMLContent = function(){
   var url2=this.url;
   var xH=new Object();
   var tagid =this.tagid;
   var rqtp=new Object();

    if(ajccache[this.url]==null)
    {  
        var loadstatustext="<div class='loading'><img src='/images/loading.gif' /> Loading request content, please wait...</div>";
        rqtp[tagid]=tagid;
        this.CreateXMLHttpRequest();  
         
        var hdr=this.tagid;
        xH[tagid]=this.xmlHttp;
        //alert("etype:"+etype);
        if(etype==1)getObject(this.requestType+'_cnt').innerHTML = loadstatustext;
        

        xH[tagid].onreadystatechange = function()
        {   
            // only if xmlHttp shows "complete"
            if (xH[tagid].readyState == 4)
            {         
       
                // only http 200 to process
            
                if (window.location.href.indexOf("http")==-1 || xH[tagid].status == 200)
                {
               
                    var content = xH[tagid].responseText;
                    var dateStr=xH[tagid].getResponseHeader("Date");
                    var dStr = new Date(dateStr);
                    SetCookie('dStr',dStr,10000000);
                    //inject centent to tab-pane    
          
                    ShowContent(rqtp[tagid],content);
                   ajccache[url2]=content;
                }
            }
        }
          
        xH[tagid].open("GET", this.url, true);
        xH[tagid].setRequestHeader("If-Modified-Since","0");
        xH[tagid].send(null);
    }
    else
    {  
        ShowContent(this.requestType,ajccache[this.url]);
    }
}

GXC.prototype.CreateXMLHttpRequest = function (){
   // Initialize Mozilla XMLHttpRequest object
   if (window.XMLHttpRequest){
       this.xmlHttp = new XMLHttpRequest();
   } 
   // Initialize for IE/Windows ActiveX version
   else if (window.ActiveXObject) {
       try{
			this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
	   } 
       catch (e){
			try{
			this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){this.newsstring = "<div class='loading'>Loading rquest content fail, Please try it again latter...</div>";}
       }
   }
}

function ShowContent (requestType,content)
{
    //<![CDATA[
 var responsecont = getObject(requestType+'_cnt');
 responsecont.innerHTML = content;
     //]]>
}


function Switch_X(sTargetId,iItem,iEventType)
{
this.tagid=sTargetId;
this.etp = iEventType;
this.iItem = iItem;
}



Switch_X.prototype.ShowInfo = function()
{
    var lis=getObject(this.tagid+"_mn").getElementsByTagName('li');
    var wts=this.tagid+"_cnt";
    var wnf=this.tagid+"info";

    if(readcookie(this.tagid+"_cntd")=="none")
    {  
	    hiddenList(getObject(wts));
	    maxh[wts]=readcookie(tagid+"_cnth");
	    getObject("pdate").innerText=readcookie("dStr");
    }
    else
    {

	    if(parseInt(readcookie(wnf))>1)
	        TabContent(this.tagid,readcookie(wnf));//返回上次访问
	    else
	        TabContent(this.tagid,this.iItem);
	    if(this.etp==1)aw=this.tagid+readcookie(wnf);
    }
            
	for(var iy=0;iy<lis.length;iy++)
	{    
		with(lis[iy])
		{   
		    if(this.etp==0)
		    { 
		        lis[iy].onmouseover=function()
		        {		

			        rT=attributes.getNamedItem('id').value.substring(0, attributes.getNamedItem('id').value.length-1);
			        if(getObject(rT+'_cnt').style.display != "none"&&className!="") return;
			        idn=parseInt(attributes.getNamedItem('id').value.substring(attributes.getNamedItem('id').value.length-1, attributes.getNamedItem('id').value.length));
			        clearTimeout(waitInterval);
			        waitInterval=window.setTimeout("onmouseoverE();",MouseDelayTime);
			    }
		        lis[iy].onmouseout=function(){if(getObject(rT+'_cnt').style.display != "none"&&className!="") return;clearTimeout(waitInterval);}
		    } 
		    if(this.etp==1)
		    {

		        lis[iy].onmouseover=function(){getElementsByTagName('a')[0].blur();}
		        	
		        lis[iy].onclick=function()
		        { 
		              
			        idn=parseInt(attributes.getNamedItem('id').value.substring(attributes.getNamedItem('id').value.length-1, attributes.getNamedItem('id').value.length));			           
	
			        rT=attributes.getNamedItem('id').value.substring(0, attributes.getNamedItem('id').value.length-1);			          
			        if(getObject(rT+'_cnt').style.display != "none"&&(idn==1&&(this.className=="tabactive1")||aw==attributes.getNamedItem('id').value)) return true;
			       
			        if(getObject(rT+'_cnt').style.display == "none")
			        { 
				        displayList(rT+'_cnt');
				        SetCookie(rT+'_cntd','ture',10000000);
			        }
			               
			        etype=1;
			        TabContent(rT,idn);
			        SetCookie(rT+'info',idn,10000000);
			        aw=attributes.getNamedItem('id').value;
			        getElementsByTagName('a')[0].blur();
			        return false;
		        }
		    }
		}
	}
} 

function onmouseoverE(){
etype=0;
TabContent(rT,idn);
if(getObject(rT+'_cnt').style.display == 'none')
displayList(rT+'_cnt'); 
SetCookie(rT+'info',idn,10000000);
SetCookie(rT+'_cntd','ture',10000000);
}
function TabContent (tagid,x)
{
	var lim=getObject(tagid+"_mn").getElementsByTagName('li');
	var mnt=getObject(tagid+"_mn").getElementsByTagName('li').length;
	if(!mnt)mnt=4;
	for(var i=0;i<mnt;i++)
	{
		if(i == (x-1))
		{
			if(i==0)
			{
				lim[i].className="tabactive1";
			}
			else
			{
				lim[i].className="tabactive2";
				lim[i-1].getElementsByTagName('a')[0].style.background="url()";
			}
			lim[i].getElementsByTagName('a')[0].style.background="url(/images/tab_bgs.gif) right -60px no-repeat";
			try
			{ 
			    var gxc = new GXC(tagid,x,'?type=1&grade=2')
                gxc.GetXMLContent();
			    //this.getnews(tagid,x);
			}
			catch(e)
			{
			    alert(e);
			}
		}	
		else
		{
			lim[i].className="";
			lim[i].getElementsByTagName('a')[0].style.background="url(/images/tab_bgs.gif) right -88px no-repeat";		
		}
	}
	
	
}

function hiddenList(objid){
       var h = objid.offsetHeight;
		   var anim = function(){
			     h -= 50; // 每次递减50像素
			     if(h <= 5){
	             objid.style.display="none"; 
		           getObject('tab'+objid.attributes.getNamedItem('id').value).style.background="url(/images/tab_bgs.gif) -14px -114px no-repeat"; 
		           if(tt){alert('clear');window.clearInterval(tt);}
		       }
		       else{
		           objid.style.height = h + "px";
		       }
		   }
		     
		   var tt = window.setInterval(anim,2); 
}


function displayList (oid){    
	var h = 0;  
	var objid=getObject(oid);
	      if(isNaN(parseInt(maxh[oid]))) var max_h = 210; // 容器的最大高度
		else 
			var max_h = maxh[oid];
	      var anim = function(){			
				    h += 50; // 每次递增50像素
				    if(h >= max_h){ 
		            objid.style.height = max_h + "px";; 
		            getObject('tab'+objid.attributes.getNamedItem('id').value).style.background="url(/images/tab_bgs.gif) 5px -113px no-repeat"; // 让图片标签改变背景	       
		            if(tt){window.clearInterval(tt);} 
				    }
				    else{ 
                objid.style.display="block"; 
                objid.style.height = h + "px";
				    }
		    }
		   	
			  var tt = window.setInterval(anim,2);  	
}
