﻿var count = 0;
$(document).ready(function () {
    $("#loading").hide()
});



function  input_onkeypress(event)  //回车事件
   {   
  if(event.keyCode==13){   
  CheckLogin();  
  }   
  } 


function CheckLogin() {
    $("#loading").hide();
    
    var txtCode = $("#txtCode");
    var txtName = $("#username");
    var txtPwd = $("#password");
    if(txtName.val()==""&&txtPwd.val()=="")
	{
	$("#showMes").show();
	$("#showMes").html("<font style='color:#600'>Please input your username and password.</font>");
	return;
	}
    if(txtName.val()=="")
	{
	$("#showMes").show();
	$("#showMes").html("<font style='color:#600'>Please input your username.</font>");
	return;
	}
    if(txtPwd.val()=="")
	{
	$("#showMes").show();
	$("#showMes").html("<font style='color:#600'>Please input your password.</font>");
	return;
	}
	$("#showMes").show();
	$("#showMes").html("&nbsp;");
	$("#loading").show();
    $.ajax({
        url: "../chk_login.asp?userName=" + txtName.val() + "&password=" + txtPwd.val(),
        type: "post",
        datatype: "text",
        success: function (returnValue) {
			
            if (returnValue == "true") {
                $("#popup").hide();
                $("#showMes").hide();
                $("#divLoginWindow").remove();
                $("#greybackground").remove();
                $("#showMes").hide();
				location.href="../main.html?"+Math.floor(Math.random()*99999)
            }
            else {
				
				//user
				if(returnValue=="-30000")
				{
				$("#showMes").html("<font style='color:#600'>The username entered is incorrect.</font>");	
				}
				
				//password				
				if(returnValue=="-30001")
				{
				$("#showMes").html("<font style='color:#600'>The password entered is incorrect.</font>");	
				}
				
			   if(returnValue=="-30002")
				{
				$("#showMes").html("<font style='color:#600'>Your account has been banned, Please contact admin.</font>");	
				}
				
                if(returnValue=="-30004")
				{
				$("#showMes").html("<font style='color:#600'>You have logined too many accounts.</font>");	
				}  
				
				if(returnValue=="false")
				{
				$("#showMes").html("<font style='color:#600'>Login failed, please try latter.</font>");	
				}  
				
                $("#loading").hide();
                $("#alogin").show();
                $("#showMes").show();
                
            }
        }
    })
}
