﻿

var useActiveX=function(){return (typeof ActiveXObject != "undefined");} 

var useDom=function(){return document.implementation && document.implementation.createDocument;}  

var useXmlHttp=function(){return (typeof XMLHttpRequest != "undefined");}  

var ARR_XMLHTTP_VERS = ["MSXML2.XmlHttp.6.0","MSXML2.XmlHttp.3.0"];
 
var ARR_DOM_VERS = ["MSXML2.DOMDocument.6.0","MSXML2.DOMDocument.3.0"]; 


function $(i){
	  if(!document.getElementById)return false;
	  if(typeof i==="string"){
	   	   if(document.getElementById && document.getElementById(i)) {
	   	   	   // W3C DOM
	           return document.getElementById(i);
         }
         else if (document.all && document.all(i)) {
         	   // MSIE 4 DOM
	           return document.all(i);
         }
         else if (document.layers && document.layers[i]) {
         	   // NN 4 DOM.. note: this won't find nested layers
	           return document.layers[i];
         } 
         else {
	           return false;
         }
	  }
	  else{return i;}
}


function createXMLHTTPRequest(){
	
	 if (useXmlHttp){ 
         return new XMLHttpRequest();
   } 
   else if (useActiveX) { 
         if (!XMLHTTP_VER) {
              for (var i=0; i < ARR_XMLHTTP_VERS.length; i++){
                  try {
                      new ActiveXObject(ARR_XMLHTTP_VERS[i]);
                      XMLHTTP_VER = ARR_XMLHTTP_VERS[i]; 
                      break;
                  } catch (oError) {}
              }
         }
         if (XMLHTTP_VER) {
             return new ActiveXObject(XMLHTTP_VER);
         } 
         else {
             throw new Error("无法创建XMLHttpRequest对象！");
         }
    } 
    else {
         throw new Error("您的浏览器不支持XMLHttpRequest对象！");
    }
}


function ajaxUpdater(tarObj,sMethod,URL,parameters){
    var oXmlHttp = createXMLHTTPRequest();
    	   
    oXmlHttp.open(sMethod, URL+parameters, true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
             if (oXmlHttp.status == 200) {
                  if($(tarObj)){
                       $(tarObj).innerHTML = oXmlHttp.responseText;
                  }
                  else{
                       return false;	
                  }          
             } 
             else {
                  throw new Error("有一个错误产生！");
             }
         }    
    }
    oXmlHttp.setRequestHeader("If-Modified-Since","0");        
    oXmlHttp.send(null); 
} 


function ajaxRequest(sMethod,URL,parameters,func){
    var oXmlHttp = createXMLHTTPRequest();
    	   
    oXmlHttp.open(sMethod, URL+parameters, true);
    oXmlHttp.onreadystatechange = function() {
         if (oXmlHttp.readyState == 4) {
              if (oXmlHttp.status == 200) {
                    return func(oXmlHttp);     
              } 
              else {
                    throw new Error("有一个错误产生！");
              }
         }    
    }
            
    oXmlHttp.send(null);   
} 


function tabsEvent(){
	  for(var i=0;i<arguments.length;i++){
         var tabs = $(arguments[i]);
         
	       if(!tabs || !document.getElementsByTagName) return false;
	           
	       var theList = tabs.getElementsByTagName("li"); 
	       var theLink = tabs.getElementsByTagName("a"); 
	           
	       for(var j=0;j<theList.length;j++){
	    	     var theTab = theList[j];
	    	     if(theTab.parentNode!=tabs) continue;
	    	         
	    	     var theA = theLink[j];
	    	   
	    	     theA.onclick = function(){
	    	         return false;	
	    	     }
	    	     
	    	    
	    	     theTab.onclick = function(){
	              var theClass = this.className;
	              if(theClass!="current" && theClass!="first"){
	    	     	       var objId = this.getAttribute("id").split("-")[1];
	    	     	       var tarObj = this.getAttribute("id").split("-")[0]; 
	                   var theURL = tarObj + "/" + tarObj + objId + ".htm"; 
	      	           ajaxInject($(tarObj),objId,tarObj,theURL);	
	      	           return false;
	      	       }
	           }
	       } 
	  }      
} 


function ajaxInject(ListName,tabId,tarObj,URL){
    if(!ListName || !document.getElementsByTagName) return false;
	  var Tabs = ListName;
	  var theLi = Tabs.getElementsByTagName("li");
	  for(var i=0;i<theLi.length;i++){
	  	  // 设置当前选中标签的样式
	      if(i==tabId){
	      	  if(i==0){
	      	  	 theLi[tabId].className = "first"; // 当选中第一项的样式
	      	  }
	    	    else{// 
	    	    	 theLi[tabId].className = "current"; // 选中其他项的样式
	    	    }	 
	    	    var msgBox = tarObj+"Cnt"; 
	    	    var loadstatustext="<div class='loading'><img src='img/loading.gif' alt='Загружаю...' /><i>Загружаю сожержание...</i></div>";	  
	          $(msgBox).innerHTML = loadstatustext; // 加载信息时的提示信息
	          var para = "?d=" + Math.random(); // URL后的参数，接Math.random()（一个随机数）,目的是处理ajax的缓存问题
	          var myAjax = ajaxUpdater(msgBox,"get",URL,para);
	      }
	      else{// 设置其他标签的样式
	          theLi[i].className = "";
	          if(tabId!=0){
	         	   theLi[tabId-1].className = "off"; // 当不是第一项时，隐藏选中项的前一项的分隔标签
	         	}  
	      }	
	  }
}        
//-->