var flag = 0;
var xml = null;
var xmlg = 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) == ""||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(){
 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 t_title;
  if(l_type==1)
	 {
	   t_title="用户名";
	 }
	else if (l_type==2)
	 {
		t_title="手机号码"; 
	 }
	else if (l_type==3)
	 {
	   t_title="邮箱";  
	 }
	 //刷新验证码
	if (flag!=0){
		document.getElementById("codeFlash").src='../include/getcode.asp?t='+Math.random();
	}
 if(flag == 1)
   {
	 alert("请输入"+t_title);
   }
 else if(flag == 2)
   {
	alert("请填写密码");
	return false;
   }
 else if(flag ==3)
  {
	alert("请填写附加码");
  }
 else if(flag == 4)
  {
	alert(t_title+"不正确");
  }
 else if(flag == 5)
  {
	alert("密码错误");
	return false;
  }
   else if(flag == 6)
  {
	alert("附加码错误");
  }
 else if(flag == 0)
  {
	  
    document.Rebook.action="../Flight/BookingI.asp";
	document.Rebook.submit();
  }
 else
  {
	alert('非法操作');  
  }
}

if (document.addEventListener)
document.addEventListener("keypress",Handler,true);
else
document.attachEvent("onkeypress",Handler);
function Handler(evt){
if (evt.keyCode == 13){
	if(jTrim(document.getElementById("mobile").value) != "")
	Login_orderregsiter();
	if(jTrim(document.form_login.username.value) != "" && jTrim(document.form_login.password.value) != "" && jTrim(document.form_login.CheckCode.value) != "")
	Login();
}
}

function Login_orderregsiter()
{
 flag = 0;
 if(jTrim(document.getElementById("mobile").value) == "")
    {
	flag = 1;
   }
 if(!IsValidMobile(jTrim(document.getElementById("mobile").value)))
  {
	flag = 1;
  }
 if(flag)
	ShowCheck_order();
 else{
	if(window.XMLHttpRequest){
		isIE = false;
		xmlg = new XMLHttpRequest();	}
	else if(window.ActiveXObject){
		isIE = true;
		xmlg = new ActiveXObject("Microsoft.XMLHTTP");}
	xmlg.onreadystatechange = getCheckLogin_order;
	try{
		//document.write("/UserCenter/orderregsiter.asp?mobile="+jTrim(document.getElementById("mobile").value)+"&nocache=" + Math.random());
		xmlg.open("GET", "/UserCenter/orderregsiter.asp?mobile="+jTrim(document.getElementById("mobile").value)+"&nocache=" + Math.random(), true);
		xmlg.send(null);	}
	catch(e){}
 } 
}

function getCheckLogin_order()
{	 
	if(xmlg.readyState == 4)
	{
		if(xmlg.status == 200)
		{   
			flag = xmlg.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">/,"");
			ShowCheck_order();
		}
     }
}

function ShowCheck_order()
{with(document){
if(flag == 1)
  {
	alert("请填写正确的手机号吗");
  }
 else if(flag == 0)
  { 
    Rebook.action="../Flight/BookingI.asp";
	Rebook.submit();
  }
 else
  {
	alert('非法操作');  
  }
}}

function IsValidMobile(s){
  if(s.length == 0)
    return false;
  var pattern = /^1[0-9]{10}$/;
  return pattern.test(s);
}