var xmlHttp;

function GetId(id){
    return document.getElementById(id);
}
 
function CreateXMLHttpRequest(){
	if (window.ActiveXObject){
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else{
		xmlHttp = new XMLHttpRequest();
	}
}

function ajax_post(url,action,id,arg_str){
	//alert(url+action+id+arg_str);
	/* 影藏形态下无法获取offset属性 */
	GetId(id).style.display = "block";
	/* 获取屏幕中心位置 */
	GetId(id).style.top  = (document.body.clientHeight-GetId(id).offsetHeight)/2 + document.body.scrollTop;
	GetId(id).style.left = ((1-(GetId(id).offsetWidth)/document.body.clientWidth)/2)*document.body.clientWidth;
	CreateXMLHttpRequest();
	if(xmlHttp){
	
		xmlHttp.open('POST',url+'&action='+action,true); 		
		xmlHttp.onreadystatechange=function(){
		   if(xmlHttp.readyState==4){
			 if(xmlHttp.status==200){
				 GetId(id).innerHTML = xmlHttp.responseText;
				 DataTemp = xmlHttp.responseText;
			 }
			 else{
			 	 GetId(id).innerHTML='ERROR:'+xmlHttp.statusText;
			 }
		   }
		   else{
		       //GetId(id).innerHTML="<table style='border:0' width=100%><tr><td style='border:0' align=right><div style='width:110px;background-color:#313131;color:#f90;font-size:16px;font-weight:bolder;padding-right:10px;'><img src = '../images/Common/loading1.gif'>&nbsp;Loading...</div></td></tr></table>";    
		       	GetId(id).innerHTML="<table style='border:0' width=100% height=70%><tr><td style='border:0' align=center><div style='width:160px;background-color:#282828;color:#ffcc00;font:bold 16px tahoma;'><img src = 'http://images.mmosite.com/sro/images/db/loading1.gif'>&nbsp;Loading...</div></td></tr></table>";
		   }
	  	}		
	 }
	 else{
	 	GetId(id).innerHTML='Sorry,your explorer does not support XMLHttpRequest';
	 }	 
	 
	 xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
     xmlHttp.setRequestHeader("If-Modified-Since","0"); // delete cache 
	 var SendData = 'url='+url+'&action='+action+"&"+arg_str;
	 xmlHttp.send(SendData);
}



function getAjaxTip(url,action,id,arg_str,lstyle){
	divH = 0;
	divW = 0;
	DataHeight = 0;
	DataWidth  = 0;
	var ls = arguments[4]?arguments[4]:1;
	//alert(url+action+id+arg_str);
	//GetId(id).style.top = document.body.scrollTop;
    //GetId(id).style.display = "";
	CreateXMLHttpRequest();
	
	if(xmlHttp){	
		xmlHttp.open('POST',url+'&action='+action,true); 		
		xmlHttp.onreadystatechange=function(){
		   if(xmlHttp.readyState==4){
			 if(xmlHttp.status==200){
				 if(GetId(id).offsetHeight > 0){
					 GetId(id).innerHTML = xmlHttp.responseText;
					 DataTemp   = xmlHttp.responseText;
					 DataHeight = GetId(id).offsetHeight;
					 DataWidth  = GetId(id).offsetWidth;
					 //alert(DataHeight);
				 }else{
					 GetId(id).innerHTML = "Loading";
				 }
			 }
			 else{
			 	 GetId(id).innerHTML='ERROR:'+xmlHttp.statusText;
			 }
		   }
		   else{
			    if(ls == 1){
		       	GetId(id).innerHTML="<table style='border:0' width=100% height=70%><tr><td style='border:0' align=center><div style='width:160px;background-color:#313131;color:#f90;font-size:16px;font-weight:bolder;'><img src = 'http://images.mmosite.com/sro/images/db/loading1.gif'>&nbsp;Loading...</div></td></tr></table>";
				}else if(ls == 2){
					GetId(id).innerHTML = "Loading";
				}
		   }
	  	}		
	 }
	 else{
	 	GetId(id).innerHTML='Sorry,your explorer does not support XMLHttpRequest';
	 }	 
	 
	 xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
     xmlHttp.setRequestHeader("If-Modified-Since","0"); // delete cache 
	 var SendData = 'url='+url+'&action='+action+"&"+arg_str;
	 xmlHttp.send(SendData);
}

function ajaxGetUserInfo(url,action,id,arg_str){
	//alert(url+action+id+arg_str);
	GetId(id).style.top = document.body.scrollTop;
    GetId(id).style.display = "block";
	CreateXMLHttpRequest();
	
	if(xmlHttp){	
		xmlHttp.open('POST',url+'&action='+action,true); 		
		xmlHttp.onreadystatechange=function(){
		   if(xmlHttp.readyState==4){
			 if(xmlHttp.status==200){
				 GetId(id).innerHTML = xmlHttp.responseText;
				 DataTemp = xmlHttp.responseText;
			 }
			 else{
			 	 GetId(id).innerHTML='ERROR:'+xmlHttp.statusText;
			 }
		   }
		   else{
		       	GetId(id).innerHTML="<img src = 'http://images.mmosite.com/sro/images/db/loading1.gif'>";
		   }
	  	}		
	 }
	 else{
	 	GetId(id).innerHTML='Sorry,your explorer does not support XMLHttpRequest';
	 }	 
	 
	 xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
     xmlHttp.setRequestHeader("If-Modified-Since","0"); // delete cache
	 arg_str += "&windowurl="+escape(window.location.href);
	 var SendData = 'url='+url+'&action='+action+"&"+arg_str;
	 xmlHttp.send(SendData);
}

function ex(ajaxObj,url,action,id,arg){
	if (window.ActiveXObject){
		ajaxObj = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		ajaxObj = new XMLHttpRequest();
	}
	if(ajaxObj){
		ajaxObj.open('POST',url+'&action='+action,true); 	
		ajaxObj.onreadystatechange=function(){
		   if(ajaxObj.readyState==4){
			 if(ajaxObj.status==200){
				 GetId(id).innerHTML = ajaxObj.responseText;
			 }else{
			 	 GetId(id).innerHTML='ERROR'+ajaxObj.statusText;
			 }
		    }else{
		       GetId(id).innerHTML="loading";
		    }
	  	}		
	 }else{
	 	GetId(id).innerHTML='Sorry,your explorer does not support XMLHttpRequest';
	 }	 
	 
	 ajaxObj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
     ajaxObj.setRequestHeader("If-Modified-Since","0"); // delete cache
	 arg += "&windowurl="+escape(window.location.href);
	 var SendData = arg;
	 ajaxObj.send(SendData);
}
    window.onload = function(){
	
		var editDiv = document.getElementById("edit");
		if(editDiv){
			
			editDiv.onscroll = function(){
			
				mov = document.getElementById("movebar");
				mov.style.position = "relative";
				mov.style.top = editDiv.scrollTop+"px";
			}
		}
	}
function setCookie( name, value, expires, path, domain, secure ){
	
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	
	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ){
	
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}
