var flag = 0;
var xml = null;
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(){
 //alert('ds');
 with(document){
 flag = 0;
 if(jTrim(form1.UserName.value) == "")
	flag = 1;
 else if(jTrim(form1.PassWord.value) == "")
	flag = 2;
 else if(jTrim(form1.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{
		xml.open("GET", "loginCheck.asp?u="+escape(jTrim(form1.UserName.value))+"&p="+jTrim(form1.PassWord.value)+"&c="+jTrim(form1.CheckCode.value)+"&nocache=" + Math.random(), true);
		xml.send(null);	}
	catch(e){}
 }
}}
function getCheckLogin(){
	//alert (xml.responseText);
 if(xml.readyState == 4)
	if(xml.status == 200){
		flag = xml.responseText;
		ShowCheck();
	}
}
function FrmKeyUp(){
 if(event.keyCode == 13)
	Login();
}
function ShowCheck(){
	with(document){
	if (flag>=1&&flag<=8){
		document.getElementById("codeFlash").src='include/getcode.asp?t='+Math.random();
	}
	 if(flag == 1){
		alert("请填写用户名");
		form1.UserName.focus();}
	 else if(flag == 2){
		alert("请填写密码");
		form1.PassWord.focus();}
	 else if(flag == 3){
		alert("请填写附加码");
		form1.CheckCode.focus();}
	 else if(flag == 4){
		alert("用户名错误");
		form1.UserName.focus();}
	 else if(flag == 5){
		alert("密码错误");
		form1.PassWord.focus();}
	 else if(flag == 6){
		alert("附加码错误");
		form1.CheckCode.focus();}
	 else if(flag == 7){
		alert("用户名非法");
		form1.UserName.focus();}
	 else if(flag == 8){
		alert("该用户已经锁定！");
		form1.UserName.focus();}
/*	 else if(flag == 100){
		alert("您的测试时间已经过期，请联系我们的客户专员！");}*/
	 else
		location.href = "index.asp";
	}
}