﻿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;
    }
} 

var responsecont;
var xmlHttp;
var xH=new Object();
var rqtp=new Object();
var dateStr,dStr;
var requestType;
var etype=0;
var newsstring;
var ajccache=new Object();
var url;
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);


function CreateXMLHttpRequest(){
   // Initialize Mozilla XMLHttpRequest object
   if (window.XMLHttpRequest){
       xmlHttp = new XMLHttpRequest();
   } 
   // Initialize for IE/Windows ActiveX version
   else if (window.ActiveXObject) {
       try{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
	   } 
       catch (e){
			try{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){newsstring = "<div class='loading'>调用页面失败,请重新调用...</div>";}
       }
   }
}

function getnews(tagid,x){

//url =document.getElementById(tagid+x).childNodes[0].href
url ="/tabimgs/"+document.getElementById(tagid+x).childNodes[0].title
var url2="/tabimgs/"+url;
requestType = tagid;
if(ajccache[url]==null){
var loadstatustext="<div class='loading'><img src='tabimgs/loading.gif' /> 正在调用页面,请等待一会儿......</div>";
rqtp[tagid]=tagid;
CreateXMLHttpRequest();   
   xH[tagid]=xmlHttp;
   if(etype==1)getObject(requestType+'_cnt').innerHTML = loadstatustext;
   xH[tagid].onreadystatechange = function(){
   if (xH[tagid].readyState == 4){
      if (window.location.href.indexOf("http")==-1 || xH[tagid].status == 200){
         newsstring = xH[tagid].responseText;
            shownews(rqtp[tagid],newsstring);
            ajccache[url2]=newsstring;
      }
   }
}
   xH[tagid].open("GET", url, true);
   //xH[tagid].setRequestHeader("If-Modified-Since","0");
   xH[tagid].send(null);
}
else
{shownews(requestType,ajccache[url]);
	}
}
function shownews(requestType,newsstring){

    responsecont = getObject(requestType+'_cnt');
    responsecont.innerHTML = newsstring;
}
function TabNews(tagid,x){
		//fadeIn(tagid+"_cnt",0) 
	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(tabimgs/tab_bgs.gif) right -60px no-repeat";
			try{getnews(tagid,x);}catch(e){alert(e);}
		}	
		else{
			lim[i].className="";
			lim[i].getElementsByTagName('a')[0].style.background="url(tabimgs/tab_bgs.gif) right -88px no-repeat";		
		}
	}
}

var idn,tmpa,tmpat;
var aw="";
var rT;
function aet(tagid,etp){
var lis=getObject(tagid+"_mn").getElementsByTagName('li');
var wts=tagid+"_cnt";
var wnf=tagid+"info";

	TabNews(tagid,1);

	for(var iy=0;iy<lis.length;iy++){
		with(lis[iy]){
		if(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("etype=0;TabNews(rT,idn);if(getObject(rT+'_cnt').style.display == 'none')displayList(rT+'_cnt');",MouseDelayTime);
			}
		lis[iy].onmouseout=function(){if(getObject(rT+'_cnt').style.display != "none"&&className!="") return;
			clearTimeout(waitInterval);
			}
		} 
		if(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');

				}
			etype=1;
			TabNews(rT,idn);
			//SetCookie(rT+'info',idn,10000000);
			aw=attributes.getNamedItem('id').value;
			getElementsByTagName('a')[0].blur();
			return false;
			}}}
	}
} 
var maxh=new Object();
//显示内容框
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(tabimgs/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);  	
}

// 隐藏列表框
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(tabimgs/tab_bgs.gif) -14px -114px no-repeat"; 
		           if(tt){window.clearInterval(tt);}
		       }
		       else{
		           objid.style.height = h + "px";
		       }
		   }
		     
		   var tt = window.setInterval(anim,2); 
}

function showClassList(oid){
var objid=getObject(oid);
   if(objid.style.display == "none"){
	if(objid.getElementsByTagName("img").length==0)TabNews(oid.substring(0,oid.indexOf("_")),1);
       displayList(oid); // 显示内容框
	//SetCookie(oid+'d',"ture",10000000);
   }
   else{
      if(isNaN(parseInt(maxh[oid]))){
         if(Browser.isFirefox){
            maxh[oid]=objid.offsetHeight;
      }
      else{
         maxh[oid]=objid.offsetHeight; // 内容容器的初始高度
          }
      }
      hiddenList(objid); // 隐藏内容框 
	//SetCookie(oid+'d',"none",10000000);SetCookie(oid+'h',maxh[oid],10000000);
   }
}

