﻿function IsLoginCn(id,dir){
	var result;
	createXMLHttpRequest();
	AjaxRequest("../../Include/Ajax.aspx?action=check&cId="+id+"&aaa="+new Date().getTime(),null,null);
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			result = xmlHttp.responseText;
		}
	}
	// onkeypress=\"if(event.keyCode==13){LoginCn("+id+");return false;}\"
	var loginStr;
	if ((result == "") || (result == "0")){ //未登录
    	loginStr = "用户名：<input name=\"txtUser\" type=\"text\" id=\"txtUser\" size=\"15\" maxlength=\"50\" onkeypress=\"if(event.keyCode==13){LoginCn("+id+");return false;}\"/>\n"
        loginStr += "密码：<input name=\"txtPsw\" type=\"password\" id=\"txtPsw\" size=\"15\" maxlength=\"50\" onkeypress=\"if(event.keyCode==13){LoginCn("+id+");return false;}\"/>\n"
        loginStr += "验证码：<input name=\"txtCode\" type=\"text\" id=\"txtCode\" size=\"8\" maxlength=\"5\" onkeypress=\"if(event.keyCode==13){LoginCn("+id+");return false;}\"/>\n"
        loginStr += "<img src=\"../../Include/Code.aspx\" alt=\"点击刷新验证码\" height=\"20\" border=\"0\" align=\"absmiddle\" style=\"cursor: pointer;\" onclick=\"javascript:this.src='../../Include/Code.aspx?'+new Date().getTime()\" />\n"
      	loginStr += "<a href=\"javascript:void(null);\" onclick=\"return LoginCn("+id+");\"><img src=\"../../Images/Default/imgLogin.gif\" width=\"49\" height=\"19\" border=\"0\" align=\"absmiddle\" /></a>\n"
      loginStr += "<a href=\""+dir+"cn/Register.htm\"><img src=\"../../Images/Default/imgReg.gif\" width=\"49\" height=\"19\" border=\"0\" align=\"absmiddle\" /></a>\n"
      loginStr += "<a href=\"../../GetPassword.aspx?lang=cn&cId="+id+"\" target=\"_blank\"><font color=\"red\">忘记密码？</font></a>\n"
	}
	else{
		var loginStatus;
		loginStatus = result.split("|");
		loginStr = "<font color=\"blue\">欢迎登录："+loginStatus[1]+" ";
		if(loginStatus[2] == "1"){
			loginStr += "<a href=\"../../PersonalInfo.aspx?lang=cn&cId="+id+"\" title=\"个人信息\" style=\"color:red\">个人信息</a> <a href=\"javascript:LoginOut(0,"+id+");\" onclick=\"return confirm('确定退出登录吗？');\" style=\"color:red\">退出登录</a>";
		}
		else{
			loginStr += "<a href=\"../../ExhibitorInfo.aspx?lang=cn&cId="+id+"\" title=\"展商信息\" style=\"color:red\">展商信息</a> <a href=\"javascript:LoginOut(0,"+id+");\" onclick=\"return confirm('确定退出登录吗？');\" style=\"color:red\">退出登录</a></font>";
		}
	}
	$("loginLeft").innerHTML = loginStr;
}

function LoginCn(id){
    var status;
	var user = $("txtUser");
	var psw = $("txtPsw");
	var code = $("txtCode");
    if (CheckSpace(user.value)){
        alert("对不起，请填写用户名！");
        user.focus();
        return false;
    }
    if (CheckSpace(psw.value)){
        alert("对不起，请填写密码！");
        psw.focus();
        return false;
    }
    if (CheckSpace(code.value)){
        alert("对不起，请填写验证码！");
        code.focus();
        return false;
    }

	createXMLHttpRequest();
	AjaxRequest("../../Include/Ajax.aspx?action=login&user="+user.value+"&password="+psw.value+"&code="+code.value+"&cId="+id+"&aaa="+new Date().getTime(),null,null);
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			status = xmlHttp.responseText;
		}
	}
	switch (status){
		case "100":{
			alert("对不起，验证码错误！");
			code.value = "";
			code.focus();
			return false;
			break;
		}
		case "0":{
			alert("对不起，用户不存在！");
			user.value="";
			psw.value="";
			code.value = "";
			user.focus();
			return false;
			break;
		}
		case "1":{
			alert("对不起，密码不正确，请重新输入！");
			psw.value="";
			code.value = "";
			user.focus();
			return false;
			break;
		}
		case "2":{
			IsLoginCn(id);
			break;
		}
		default:{
			alert("页面错误！！");
			break;
		}
	}
}

function IsLoginEn(id,dir){
	var result;
	createXMLHttpRequest();
	AjaxRequest("../../Include/Ajax.aspx?action=check&cId="+id+"&aaa="+new Date().getTime(),null,null);
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			result = xmlHttp.responseText;
		}
	}
	// onkeypress=\"if(event.keyCode==13){LoginCn("+id+");return false;}\"
	var loginStr;
	if ((result == "") || (result == "0")){ //未登录
    	loginStr = "ID：<input name=\"txtUser\" type=\"text\" id=\"txtUser\" size=\"15\" maxlength=\"50\" onkeypress=\"if(event.keyCode==13){LoginEn("+id+");return false;}\"/>\n"
        loginStr += "Password：<input name=\"txtPsw\" type=\"password\" id=\"txtPsw\" size=\"15\" maxlength=\"50\" onkeypress=\"if(event.keyCode==13){LoginEn("+id+");return false;}\"/>\n"
        loginStr += "Code：<input name=\"txtCode\" type=\"text\" id=\"txtCode\" size=\"8\" maxlength=\"5\" onkeypress=\"if(event.keyCode==13){LoginEn("+id+");return false;}\"/>\n"
        loginStr += "<img src=\"../../Include/Code.aspx\" alt=\"Refresh\" height=\"20\" border=\"0\" align=\"absmiddle\" style=\"cursor: pointer;\" onclick=\"javascript:this.src='../../Include/Code.aspx?'+new Date().getTime()\" />\n"
      	loginStr += "<a href=\"javascript:void(null);\" onclick=\"return LoginEn("+id+");\"><img src=\"../../Images/Default/loginen.jpg\" width=\"49\" height=\"19\" border=\"0\" align=\"absmiddle\" /></a>\n"
      loginStr += "<a href=\""+dir+"en/Register.htm\"><img src=\"../../Images/Default/regen.jpg\" width=\"49\" height=\"19\" border=\"0\" align=\"absmiddle\" /></a>\n"
      loginStr += "<a href=\"../../GetPassword.aspx?lang=en&cId="+id+"\" target=\"_blank\"><font color=\"red\">Forgot password?</font></a>\n"
	}
	else{
		var loginStatus;
		loginStatus = result.split("|");
		loginStr = "<font color=\"blue\">Welcome : "+loginStatus[1]+" ";
		if(loginStatus[2] == "1"){
			loginStr += "<a href=\"../../PersonalInfo.aspx?lang=en&cId="+id+"\" title=\"Personal Infomation\" style=\"color:red\">Personal Infomation</a>&nbsp;&nbsp;&nbsp;<a href=\"javascript:LoginOut(1,"+id+");\" onclick=\"return confirm('Sure to exit?');\" style=\"color:red\">Exit</a>";
		}
		else{
			loginStr += "<a href=\"../../ExhibitorInfo.aspx?lang=en&cId="+id+"\" title=\"Exhibitor Information\" style=\"color:red\">Exhibitor Information</a>&nbsp;&nbsp;<a href=\"javascript:LoginOut(1,"+id+");\" onclick=\"return confirm('Sure to exit?');\" style=\"color:red\">Exit</a></font>";
		}
	}
	$("loginLeft").innerHTML = loginStr;
}

function LoginEn(id){
	var status;
	var user = $("txtUser");
	var psw = $("txtPsw");
	var code = $("txtCode");
    if (CheckSpace(user.value)){
        alert("Sorry,please fill in the ID!");
        user.focus();
        return false;
    }
    if (CheckSpace(psw.value)){
        alert("Sorry,please fill in the password!");
        psw.focus();
        return false;
    }
    if (CheckSpace(code.value)){
        alert("Sorry,please fill in the verification code!");
        code.focus();
        return false;
    }
	
	createXMLHttpRequest();
	AjaxRequest("../../Include/Ajax.aspx?action=login&user="+user.value+"&password="+psw.value+"&code="+code.value+"&cId="+id+"&aaa="+new Date().getTime(),null,null);
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			status = xmlHttp.responseText;
		}
	}
	switch (status){
		case "100":{
			alert("Sorry,Code error!");
			code.value = "";
			code.focus();
			return false;
			break;
		}
		case "0":{
			alert("Sorry,the ID does not exist!");
			user.value="";
			psw.value="";
			code.value = "";
			user.focus();
			return false;
			break;
		}
		case "1":{
			alert("Sorry,password is incorrect!");
			psw.value="";
			code.value = "";
			user.focus();
			return false;
			break;
		}
		case "2":{
			IsLoginEn(id);
			break;
		}
		default:{
			alert("Error！！");
			break;
		}
	}
}

function LoginOut(lang,id){
	createXMLHttpRequest();
	AjaxRequest("../../Include/Ajax.aspx?action=loginOut&cId="+id+"&aaa="+new Date().getTime(),null,null);
	if(lang == 0){
		IsLoginCn(id);
	}
	else{
		IsLoginEn(id);
	}
}
