﻿var flag = 0;
var xml = null;
var l_type=1;
function jTrim(inputString) {
 if(typeof inputString != "string"){
	return inputString;
 }
 var retValue = inputString;
 var ch = retValue.substring(0,1);
 while(ch == " " || ch == "\r" || ch == "\n"){
	retValue = retValue.substring(1, retValue.length);
	ch = retValue.substring(0, 1);
 }
 ch = retValue.substring(retValue.length-1, retValue.length);
 while(ch == " " || ch == "\r" || ch == "\n"){
	retValue = retValue.substring(0, retValue.length-1);
	ch = retValue.substring(retValue.length-1, retValue.length);
 }
 while(retValue.indexOf("  ") != -1){
	retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
 }
 return retValue; 
}
function Login(){
 flag = 0;
 l_type=document.form_login.login_type.value;
 if(jTrim(document.form_login.username.value) == "")
	flag = 1;
 else if(jTrim(document.form_login.password.value) == "")
	flag = 2;
 else if (jTrim(document.form_login.CheckCode.value) == "")
   flag = 3;
 if(flag)
	ShowCheck();
 else{
	if(window.XMLHttpRequest){
		isIE = false;
		xml = new XMLHttpRequest();	}
	else if(window.ActiveXObject){
		isIE = true;
		xml = new ActiveXObject("Microsoft.XMLHTTP");}
	xml.onreadystatechange = getCheckLogin;
	try{
		//document.write("/UserCenter/logincheck.asp?login_type="+jTrim(document.form_login.login_type.value)+"&username="+jTrim(document.form_login.username.value)+"&password="+jTrim(document.form_login.password.value)+"&CheckCode="+jTrim(document.form_login.CheckCode.value)+"&nocache=" + Math.random())
		xml.open("GET", "/UserCenter/logincheck.asp?login_type="+jTrim(document.form_login.login_type.value)+"&username="+jTrim(document.form_login.username.value)+"&password="+jTrim(document.form_login.password.value)+"&CheckCode="+jTrim(document.form_login.CheckCode.value)+"&nocache=" + Math.random(), true);
		xml.send(null);	}
	catch(e){}
 }
}
function getCheckLogin(){
	//alert(xml.status);
 if(xml.readyState == 4)
	if(xml.status == 200){
		flag = xml.responseText;
		flag=flag.replace(/<meta http-equiv="Content-Type" content="text\/html; charset=utf-8" \/>/,"");
		flag=flag.replace(/<meta http-equiv="Content-Type" content="text\/html; charset=utf-8">/,"");
		//alert(flag);
		ShowCheck();
	}
}
function FrmKeyUp(){
 if(event.keyCode == 13)
	Login();
}
function ShowCheck(){
 //var obj = document.getElementById("username");
 //var obj2 = document.getElementById("password");
 //var obj3 = document.getElementById("CheckCode");
 var obj = document.getElementById("UserNameErr");
 var obj2 = document.getElementById("PassWordErr");
 var obj3 = document.getElementById("CheckCodeErr");
  obj.innerHTML = "";
 obj2.innerHTML = "";
 obj3.innerHTML = "";
 var t_title;
  if(l_type==1)
	 {
	   t_title="用户名";
	 }
	else if (l_type==2)
	 {
		t_title="手机号码"; 
	 }
	else if (l_type==3)
	 {
	   t_title="邮箱";  
	 }
 if(flag == 1)
   {
	 obj.innerHTML="请输入"+t_title;
   }
 else if(flag == 2)
   {
	obj2.innerHTML = "请填写密码";
	return false;
   }
 else if(flag ==3)
  {
	obj3.innerHTML = "请填写验证码";
  }
 else if(flag == 4)
  {
	obj.innerHTML =t_title+"不正确";
  }
 else if(flag == 5)
  {
	obj2.innerHTML = "密码错误";
	return false;
  }
   else if(flag == 6)
  {
	obj3.innerHTML = "验证码错误";
  }
 else
  {
    location.href='../UserCenter/UserCenterMain.asp';
  }
}