﻿var boolyhm = false;
var boolmm = false;
var check = false;
$(document).ready(function(){
    $("#yhm").blur(function(){
       $("#Warning").html("");
       CheckUserName();
    }); 
    $("#mm").blur(function(){
        $("#Warning").html("");
        CheckPassWord();
        if(boolyhm && boolmm){
            CheckLogin();
        }
    });
    $("#btLogin").click(function(){
       CheckUserName();
       CheckPassWord();
       if(boolyhm && boolmm){
           CheckLogin();
       }
       return false;
    });
    
    $("#btReset").click(function(){
      this.form.reset();
      $("#vyhm").html("");
      $("#vmm").html("");
      $("#Warning").html("");
      return false;
    });
});

//用户名检测
function CheckUserName()
{      
       isNull = CheckNull("yhm","<img src='http://images.jxrsrc.com/waring.gif' /> 请输入会员名称！");
       if(!isNull){
            boolyhm = false;
       }
       else{
            CheckExist();
       }
}
//用户名检测--是否存在用户名
function CheckExist(){
     var exist;
     $.ajax({
           type: "post",
           url: "Ashx/PersonReg.ashx",
           async: false,
           data:"yhm="+$("#yhm").val()+"",
           beforeSend: function(XMLHttpRequest){
		        $("#vyhm").html("正在检测用户名...");
		        boolyhm = false;
           },
           success: function(data, textStatus){
              if(data =="0"){
                 $("#vyhm").html("<img src='http://images.jxrsrc.com/waring.gif' /> 对不起，该用户名不存在！");
                 boolyhm = false;
              }
              else if(data =="1"){
                 $("#vyhm").html("");
                 boolyhm = true;
              }else{
                 $("#vyhm").html(data);
                 boolyhm = false;
              }
           },
           error: function(){
                $("#vyhm").html("<img src='http://images.jxrsrc.com/waring.gif' /> 验证失败！");
		        boolyhm = false;
           }
    });
}
//密码检测
function CheckPassWord(){
       isNull = CheckNull("mm","<img src='http://images.jxrsrc.com/waring.gif' /> 请输入用户口令！");
       if(!isNull){
            boolmm = false;
       }else{
            boolmm = true;
       }
}
function CheckLogin(){$.ajax({type: "post",
           url: "Ashx/CheckLogin.ashx",
           async: false,
           data:"userName="+$.trim($("#yhm").val())+"&passWord="+$.trim($("#mm").val())+"",
           beforeSend: function(XMLHttpRequest){
		        $("#Warning").html("正在检测用户名和密码...");
		        check = false;
           },
           success: function(data, textStatus){
              if(data =="0"){
                 $("#Warning").html("<img src='http://images.jxrsrc.com/waring.gif' /> 对不起，密码错误！");
                 check = false;
              }
              else if(data =="1"){
                 $("#Warning").html("");
                 check = true;
                 returnPage("Main.aspx");
              }else{
                 $("#Warning").html(data);
                 check = false;
              }
           },
           error: function(){
                $("#Warning").html("<img src='http://images.jxrsrc.com/waring.gif' /> 验证失败！");
		        check = false;
           }
    });
}
