﻿// JavaScript Document
/*-----------------------------------------------------------------------
	以下代码由乐清市亿新软件开发咨询有限公司(亿新科技)编写
	联系电话：0577-27802780   Http://www.eshion.cn/
    代码撰写：张洋
-----------------------------------------------------------------------*/


function check(){
	if(document.getElementById("textfield").value==""){
		alert("请输入您的用户名！");
		document.getElementById("textfield").focus();
		return false;
	}
	if(document.getElementById("textfield2").value==""){
		alert("请输入您的登录密码！");
		document.getElementById("textfield2").focus();
		return false;
	}
	document.getElementById("Submit").disabled = true;
	createBG();
	document.getElementById("loginstate").style.display="block";
	document.getElementById("loginstate").style.marginTop=document.documentElement.scrollTop.toString().replace("px","")-50+"px";
	startRequest();
	return false;
}

var xmlHttp;
function createXMLHttpRequest(){
   if(window.ActiveXObject) {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
   else if(window.XMLHttpRequest) {xmlHttp = new XMLHttpRequest();}
}

function startRequest(){
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("POST", "/common/loginAction.asp?now=" + (new Date().getTime()), true);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	if(document.getElementById("exps").checked){
		xmlHttp.send("textfield="+encodeURI(document.getElementById("textfield").value)+"&textfield2="+encodeURI(document.getElementById("textfield2").value)+"&exps="+document.getElementById("exps").value);
	}else{
		xmlHttp.send("textfield="+encodeURI(document.getElementById("textfield").value)+"&textfield2="+encodeURI(document.getElementById("textfield2").value));
	}
}

function handleStateChange(){
	if(xmlHttp.readyState == 4){
		if(xmlHttp.status == 200){
			if(xmlHttp.responseText=="OK!"){
				xmlHttp.abort();
				xmlHttp=null;
				startRequestFM();
			}else{
				document.getElementById("logintext").innerHTML=xmlHttp.responseText;
				xmlHttp.abort();
				xmlHttp=null;
			};			
		}else{
			xmlHttp.abort();
			xmlHttp=null;
			document.getElementById("logintext").innerHTML="系统错误：会员登录失败！";
		}	
	}else{
		document.getElementById("logintext").innerHTML='<img src="../images/web/logining.gif" align="absmiddle" />&nbsp;&nbsp;请稍候，正在登录中...';
	}	
}

//--------------------------------------------------------------------------------------
var xmlHttpFM;
var logonYN;
function createXMLHttpRequestFM(){
   if(window.ActiveXObject) { xmlHttpFM = new ActiveXObject("Microsoft.XMLHTTP");}
   else if(window.XMLHttpRequest) { xmlHttpFM = new XMLHttpRequest();}
}

function startRequestFM(){
	createXMLHttpRequestFM();
	xmlHttpFM.onreadystatechange = handleStateChangeFM;
	xmlHttpFM.open("POST", "/forum/login.aspx?agree=yes&now=" + (new Date().getTime()), true);
	xmlHttpFM.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	if(document.getElementById("exps").checked){
		xmlHttpFM.send("username="+encodeURI(document.getElementById("textfield").value)+"&password="+encodeURI(document.getElementById("textfield2").value)+"&expires="+document.getElementById("exps").value);
	}else{
		xmlHttpFM.send("username="+encodeURI(document.getElementById("textfield").value)+"&password="+encodeURI(document.getElementById("textfield2").value));	
	}
}

function handleStateChangeFM(){
	if(xmlHttpFM.readyState == 4){
		if(xmlHttpFM.status == 200){
			FMReturn=xmlHttpFM.responseText;
			if(FMReturn.indexOf("登录成功, 返回登录前页面")!=-1){
				logonYN="yes!";
				document.getElementById("logintext").innerHTML="<img src='../images/web/ok.gif' align='absmiddle' border='0' />&nbsp;&nbsp;<span style='color:#669900'>登录成功：3秒后自动跳转！<br /><a href='"+document.getElementById("refer").value+"' class='aOrg'>点击此处</a><span style='color:#484848'>或<a href='javascript:loginClose();' class='aOrg'>关闭窗口</a>直接跳转！</span></span>";	
				setTimeout(function(){location.href=document.getElementById("refer").value;},3000);
			}else{
				document.getElementById("logintext").innerHTML="论坛登录失败！";	
			}
			xmlHttpFM.abort(); xmlHttpFM=null;
		}else{
			xmlHttpFM.abort(); xmlHttpFM=null;
			document.getElementById("logintext").innerHTML="系统错误：论坛登录失败！";
		}	
	}else{
		document.getElementById("logintext").innerHTML='<img src="../images/web/logining.gif" align="absmiddle" />&nbsp;&nbsp;请稍候，正在登录中...';
	}	
}
//--------------------------------------------------------------------------------------

function createBG(){
	var sWidth,sHeight;
	sWidth=document.body.offsetWidth;	
	sHeight=document.body.offsetHeight;
	if(document.documentElement.clientHeight>document.body.offsetHeight){
		sHeight=document.documentElement.clientHeight;
	}
	
	var bgObj=document.createElement("div");
	bgObj.setAttribute('id','bgDiv');
	bgObj.style.position="absolute";
	bgObj.style.top="0";
	bgObj.style.background="#2D5754";
	if(browser.indexOf("Internet Explorer") != -1){	
		bgObj.style.filter="alpha(opacity=50)";
	}else{
		bgObj.style.opacity=0.5;
	}
	bgObj.style.left="0";
	bgObj.style.width=sWidth + "px";
	bgObj.style.height=sHeight + "px";
	bgObj.style.zIndex = "1000";
	document.body.appendChild(bgObj);
}


function loginClose(){
	var bgObj=document.getElementById("bgDiv");
	if(bgObj!=null){document.body.removeChild(bgObj)};
	
	if(xmlHttpFM!=null){xmlHttpFM.abort(); xmlHttpFM=null;}
	if(xmlHttp!=null){xmlHttp.abort(); xmlHttp=null;}
	
	var loginstate=document.getElementById("loginstate");
	loginstate.style.display="none";
	
	document.getElementById("textfield").value="";
	document.getElementById("textfield2").value="";
	document.getElementById("Submit").disabled = false;
	document.getElementById("textfield").focus();
	
	if(logonYN=="yes!"){
		logonYN=null;
		location.href=document.getElementById("refer").value;	
	}
}