var Request = new Object();
Request.send = function(url, method, callback, data, urlencoded) {
	var req;
	if(window.XMLHttpRequest){
		req = new XMLHttpRequest();
	}else if(window.ActiveXObject){
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	req.onreadystatechange = function() {
		if(req.readyState == 4){
			if (req.status < 400) {
				(method=="POST") ? callback(req) : callback(req,data);
			}else{
				//alert("服务器繁忙请稍后再试!");
			}
		}
	}
	if (method=="POST") {
		req.open("POST", url, true);
		if (urlencoded) req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(data);
	} else {
		req.open("GET", url, true);
		req.send(null);
	}
	return req;
}
Request.sendRawPOST = function(url, data, callback) {
	Request.send(url, "POST", callback, data, false);
}
Request.sendPOST = function(url, data, callback) {
	Request.send(url, "POST", callback, data, true);
}
Request.sendGET = function(url, callback, args) {
	return Request.send(url, "GET", callback, args);
}


function check(){ 
	var form1 = document.getElementById("loginForm");
	if (form1.email.value.length<2)
	{ 
		alert("请输入用户名或Email!")
		form1.email.focus()
		return false;
	}
	
	if (form1.userPass.value.length<4 || form1.userPass.value.length>20)
	{ 
		alert("请输入4-20位密码!")
		form1.userPass.value="";
		form1.userPass.focus()
		return false;
	}
	return true;
	 
} 

function checkLogin(){
	if(check()== true){				
		new Request.sendPOST('/isLogin.jsp?email='+loginForm.email.value+'&userPass='+loginForm.userPass.value,"",doLogin);
	}
}
	
function logout(){		
	new Request.sendPOST('/logout.jsp',"",doLogout);	
}
function logout11(){		
	new Request.sendPOST('/logout11.jsp',"",doLogout11);	
}
function doLogout(response){
	location.href='';	
	
}	
function doLogout11(response){
	location.href='http://zhekou.jinghua.cn';	
	
}	
function doLogin(response){

	var res = response.responseText;	
	if (res.indexOf("no")==-1){
		document.getElementById('userInfo').innerHTML = res;	
	}else{
		alert("服务器验证错误：用户名或密码有误！");
	}
}

var idx=1;
function showBox(winFileName,winWidth,winHeight,winTitle)
{  
	if(idx>1) closeBox();
	//className: alphacube,spread,darkX		
	var win = new Window({className: "alphacube", title:winTitle,top:10, right:20, width:winWidth, height:winHeight,resizable: true,closable: true,minimizable:true,maximizable:true, url: winFileName, showEffectOptions: {duration:1.5}}); 
	//win.getContent().innerHTML = winFileName; 
	//win.setDestroyOnClose(); 
	win.showCenter();
	win.setConstraint(false, {left:0, right:0, top: 30, bottom:10})
	win.toFront();
	idx++;
		
}
function showBoxBy(winFileName,winTop,winLeft,winWidth,winHeight,winTitle)
{  
	if(idx>1) closeBox();					
	var win = new Window({className: "alphacube", title:winTitle,left:winLeft,top:winTop, width:winWidth,height:winHeight,resizable: true,closable: true,minimizable:true,maximizable:true,url: winFileName, showEffectOptions: {duration:1.5}}); 
	win.show();
	win.setConstraint(true, {left:0, right:0, top: 30, bottom:10})
	win.toFront();
	idx++;
		
}

function closeBox(){
	Windows.closeAll()
}


function isLogin() {
var name='JhSSOSessionID';
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) {
		   if(c.substring(nameEQ.length,c.length).length>10){
		      return true;
		   }else{
		      return false;
		   }
		}
	}
   return false;
}
function login_WinBox(){
 showBoxBy('http://share.jinghua.cn/login.jsp','420','300','320','160','京华网-请登陆'); 
}
function login_WinBox_px(){
 showBoxBy('/template/1/login.jsp','420','300','320','160','京华网-请登陆'); 
}
function logout_px(){		
	new Request.sendPOST('/template/1/logout.jsp',"",doLogout);	
}
function login_baoming_WinBox(){
 showBoxBy('http://share.jinghua.cn/login_baoming.jsp','420','300','320','160','京华网-请登陆'); 
}


