// BY CXD 2011-10-23 
// 2011-11-08 PositionDiv 支持超过了 正文全文高 的修正(IE6 IE7 OK，Chrome基本OK)
// 2011-10-23 ajax 加入
// 2011-05-12

/////////////////////////////////////////////////////////////////////AJAX
function createAjaxXMLRequestIE7(){
// 条件编译 window.XMLHttpRequest 在 IE6 就直接导致脚本问题. 暂停使用这个脚本
  
	// Microsoft 浏览器中，创建 XMLHttpRequest 对象。
	/*@cc_on @*/
	/*if (@_jscript_version >= 5)
	try {
	  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	//  alert("\Msxml2.XMLHTTP ok");
	} catch (tryOtherOldMicrosoft) {
	  try {
	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  
	//    alert("\Microsoft.XMLHTTP ok");
	  } catch (MicrosoftFailed) {
	    xmlHttp = false;
	  }
	}
	@end @*/	
	
	//Mozilla 、Firefox 、Safari、Opera 以及基本上所有以任何形式或方式支持 Ajax 的非 Microsoft 浏览器中，创建 XMLHttpRequest 对象。
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
	  xmlHttp = new XMLHttpRequest();
	//  alert("\XMLHttpRequest ok ");
	}


	if (!xmlHttp) alert("Error initializing XMLHttpRequest");
	else	alert("Ok initializing XMLHttpRequest");

}

function createAjaxXMLRequest(){

	// Microsoft 浏览器中，创建 XMLHttpRequest 对象。
	try {
	  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	//  alert("\Msxml2.XMLHTTP ok");
	} catch (tryOtherOldMicrosoft) {
	  try {
	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");  
	//    alert("\Microsoft.XMLHTTP ok");
	  } catch (MicrosoftFailed) {
	    xmlHttp = false;
	  }
	}
	
	//Mozilla 、Firefox 、Safari、Opera 以及基本上所有以任何形式或方式支持 Ajax 的非 Microsoft 浏览器中，创建 XMLHttpRequest 对象。
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
	  xmlHttp = new XMLHttpRequest();
	//  alert("\XMLHttpRequest ok ");
	}


	if (!xmlHttp) alert("Error initializing XMLHttpRequest");
//	else	alert("Ok initializing XMLHttpRequest");

}




/////////////////////////////////////////////////////////////////////用于多TAB切换的导航一次性切换，要求 objX 和 objnavX 名称
//用于正文显示，以TAB的形式显示
//要求 div 的id 从1开始, div 1保留给原始页面内容
//要求 名称格式为“ntes+数字” 和  “ntes+nav+数字”

var load2=true;
var load3=true;
var load4=true;

function contextTabShowDiv(obj,num,len)
{
  var iSetID="i"+obj+num;
  if ( num==2 && !load2){
     try{document.getElementById(iSetID).src="1.html"}catch(e){};
	 if(obj == 'ntes'){load2=true;}
  }else if ( num==3 && !load3){
     try{document.getElementById(iSetID).src="3.html"}catch(e){};
     if(obj == 'ntes'){load3=true;}
  }else if ( num==4 && !load4){
     try{document.getElementById(iSetID).src="4.asp"}catch(e){};
      if(obj == 'ntes'){load4=true;}
  }
  
  for(var id=1;id<=len;id++)
  {
    var setID=obj+id;
    var setnavID=obj+"nav"+id;
    if(id==num){
  	try{document.getElementById(setID).style.display="block"}catch(e){};
  	try{document.getElementById(setnavID).className="contextTabOn"}catch(e){};
    }else{
  	try{document.getElementById(setID).style.display="none"}catch(e){};
  	try{document.getElementById(setnavID).className="contextTabOff"}catch(e){};
    }
  }  
}



/////////////////////////////////////////////////////////////////////用于点击“展开、收缩”的用法
<!--  
var state = "none";  

function showhide(layer_ref) {  
    if (state == "block") {  
        state = "none";  
    }  
    else {  
        state = "block";  
    }  
    if (document.all) { //IS IE 4 or 5 (or 6 beta)  
        eval( "document.all." + layer_ref + ".style.display = state");  
    }  
    if (document.layers) { //IS NETSCAPE 4 or below  
        document.layers[layer_ref].display = state;  
    }  
    if (document.getElementById &&!document.all) {  
        hza = document.getElementById(layer_ref);  
        hza.style.display = state;  
    }  
} 
 
function showdiv(layer_ref) {  
//    alert(layer_ref);
    state = "block";  

    if (document.all) { //IS IE 4 or 5 (or 6 beta)  
        eval( "document.all." + layer_ref + ".style.display = state");  
    }  
    if (document.layers) { //IS NETSCAPE 4 or below  
        document.layers[layer_ref].display = state;  
    }  
    if (document.getElementById &&!document.all) {  
        hza = document.getElementById(layer_ref);  
        hza.style.display = state;  
    }  
} 
function hidediv(layer_ref) {  
    state = "none";  

    if (document.all) { //IS IE 4 or 5 (or 6 beta)  
        eval( "document.all." + layer_ref + ".style.display = state");  
    }  
    if (document.layers) { //IS NETSCAPE 4 or below  
        document.layers[layer_ref].display = state;  
    }  
    if (document.getElementById &&!document.all) {  
        hza = document.getElementById(layer_ref);  
        hza.style.display = state;  
    }  
} 

function ScreenInfo(){
var str = "";
str = str + "\n网页可见区域宽： document.body.clientWidth =" + document.body.clientWidth ;
str = str + "\n网页可见区域高： document.body.clientHeight=" + document.body.clientHeight ;
str = str + "\n网页可见区域宽： document.body.offsetWidth (包括边线的宽) =" + document.body.offsetWidth ;
str = str + "\n网页可见区域高： document.body.offsetHeight (包括边线的高)=" + document.body.offsetHeight ;
str = str + "\n网页正文全文宽： document.body.scrollWidth =" + document.body.scrollWidth ;
str = str + "\n网页正文全文高： document.body.scrollHeight=" + document.body.scrollHeight ;
str = str + "\n网页被卷去的高： document.body.scrollTop   =" + document.body.scrollTop ;
str = str + "\n网页被卷去的左： document.body.scrollLeft  =" + document.body.scrollLeft ;
str = str + "\n网页正文部分上： window.screenTop =" + window.screenTop ;
str = str + "\n网页正文部分左： window.screenLeft=" + window.screenLeft ;
str = str + "\n屏幕分辨率的高： window.screen.height=" + window.screen.height ;
str = str + "\n屏幕分辨率的宽： window.screen.width =" + window.screen.width ;
str = str + "\n屏幕可用工作区高度： window.screen.availHeight=" + window.screen.availHeight ;
str = str + "\n屏幕可用工作区宽度： window.screen.availWidth =" + window.screen.availWidth ;
str = str + "\nevent.clientY=" + event.clientY;
alert(str);
}

//浮动菜单定位，依据src 对 layer_ref 精确定位 
// 说明 PositionDiv 在 <div>里用的是 document.all      在标准元素例如<TD>里用的是 layer_ref.xxx

function  PositionDiv(src, layer_ref, offsetX)	// 2011-11-08 PositionDiv 支持超过了 正文全文高 的修正
{
   var leftPos; 
   var topPos, topPosTmp ;
   var parent ;
   parent = document.all(src).offsetParent;

   if (offsetX >0)   { leftPos =  parent.offsetLeft + document.all(src).offsetLeft + offsetX ; }
   else  	     { leftPos =  parent.offsetLeft + document.all(src).offsetLeft + document.all(src).offsetWidth/2; }
   //offsetY 默认“从parent 的中间位置开始”
   topPos  =  parent.offsetTop + document.all(src).offsetTop + document.all(src).offsetHeight/2;

//alert(document.all(layer_ref).offsetHeight);
   while(true)
   {
        parent = parent.offsetParent ;
//	alert(parent.tagName + " leftPos=" + leftPos + " topPos=" + topPos);
        if  ( "BODY"==parent.tagName)  break;

        leftPos += parent.offsetLeft ;
        topPos  += parent.offsetTop;
   }


	//如果 超过了 屏幕可用工作区高度，则 = 原高度 - （超过部分） = 原高度 - （鼠标位置 + 需要的高度 - 屏幕高度）
	if ( (event.clientY + document.all(layer_ref).offsetHeight) > window.screen.availHeight ) 
	{
		topPosTmp = event.clientY + document.all(layer_ref).offsetHeight - window.screen.availHeight;
		if (topPos >=topPosTmp) topPos -= topPosTmp ;
	}


	//如果 超过了 正文全文高，则 = 正文全文高 - 需要的高度
	if ( (topPos + document.all(layer_ref).offsetHeight)> document.body.scrollHeight) 
	{
		topPos = document.body.scrollHeight - document.all(layer_ref).offsetHeight;
//		ScreenInfo();
//		alert("over! topPos  =" + topPos  );
	}

   document.all(layer_ref).style.left = leftPos ;
   document.all(layer_ref).style.top = topPos ;   
//  layer_ref.style.left = leftPos;
//  layer_ref.style.top = topPos - 10;
}



//--> 



/////////////////////////////////////////////////////////////////////专门用于锁定、浮层解锁，要求层名固定
function   Locking01(){   
  document.all.LockedLayer01.style.display="block";   
  document.all.LockedLayer01.style.width=document.body.clientWidth;   
  document.all.LockedLayer01.style.height=10000;	//document.body.clientHeight;   
  document.all.LockedFloat01.style.display='block';   
}   
function   UnLock01(){   
  document.all.LockedLayer01.style.display='none';
  document.all.LockedFloat01.style.display='none';
}   



/////////////////////////////////////////////////////////////////////2011-05-12 Cookies 
//函数中的参数存有 cookie 的名称、值以及过期天数。首先将天数转换为有效的日期，然后，我们将 cookie 名称、值及其过期日期存入 document.cookie 对象。
function setCookie(c_name,value,expiredays)
{
  var exdate=new Date()
  exdate.setDate(exdate.getDate()+expiredays)
  document.cookie=c_name+ "=" +escape(value)+
  ((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}
//函数首先会检查 document.cookie 对象中是否存有 cookie。假如 document.cookie 对象存有某些 cookie，那么会继续检查我们指定的 cookie 是否已储存。如果找到了我们要的 cookie，就返回值，否则返回空字符串。
function getCookie(c_name)  
{
  if (document.cookie.length>0)
  {
    c_start=document.cookie.indexOf(c_name + "=")
    if (c_start!=-1)
    { 
      c_start=c_start + c_name.length+1 
      c_end=document.cookie.indexOf(";",c_start)
      if (c_end==-1) c_end=document.cookie.length
      return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
  return ""
}
//应用
function checkCookie()
{
  username=getCookie('username')
  if (username!=null && username!="")
  {alert('Welcome again '+username+'!')}
  else 
  {
    username=prompt('Please enter your name:',"")
    if (username!=null && username!="")
    {
      setCookie('username',username,365)
    }
  }
}

/////////////////////////////////////////////////////////////////////2011-05-12 固定位置 不随滚动条滚动 
function scroll(p){
	var d = document,dd = d.documentElement,db = d.body,w = window,o = d.getElementById(p.id),ie = /msie/i.test(navigator.userAgent),style;
	if(o){
		o.style.cssText +=";position:"+(p.f&&!ie?'fixed':'absolute')+";"+(p.l==undefined?'right:0;':'left:'+p.l+'px;')+(p.t!=undefined?'top:'+p.t+'px':'bottom:0');
		if(p.f&&ie){
		o.style.cssText +=';left:expression(body.scrollLeft + '+(p.l==undefined?db.clientWidth-o.offsetWidth:p.l)+' + "px");top:expression(body.scrollTop +'+(p.t==undefined?db.clientHeight-o.offsetHeight:p.t)+'+ "px" );'
		db.style.cssText +=";background-image:url(about:blank);background-attachment:fixed;"
		}else{
			if(!p.f){
				w.onresize = w.onscroll = function(){
			var timer,timer1;
			return function(){
			if(timer)
				clearTimeout(timer);
			timer = setTimeout(function(){
			timer1 = setInterval(function(){
			  var st = db.scrollTop,c;
			  c = st  - o.offsetTop + (p.t!=undefined?p.t:(w.innerHeight||db.clientHeight)-o.offsetHeight);
			  if(c!=0){
			   o.style.top = o.offsetTop + Math.ceil(Math.abs(c)/10)*(c<0?-1:1) + 'px';
			  }else{
			   clearInterval(timer1);  
			  }
			 },10)
			},100)//控制滚动的频率越大频率越慢
			}
			}()
			}
		}
	}  
}
