﻿
var PreFix = "#ctl00_ContentPlaceHolder1_";

var txtFirstName = PreFix +"txtFirstName";
var txtLastName = PreFix + "txtLastName";
var txtMobile = PreFix + "txtMobile";
var txtEmail = PreFix + "txtEmail";
var txtPwd1 = PreFix + "txtPwd1";
var txtPwd2 = PreFix + "txtPwd2";
var txtValidateCode = PreFix + "txtValidateCode";   

$(document).ready(
    function (){
            $(txtFirstName).blur(function(){DoMessageForEmpty(txtFirstName,"divFirstName",varFirstName);}).focus(function(){DoMessageForEmpty(txtFirstName,"divFirstName",varFirstName);});
            $(txtLastName).blur(function(){DoMessageForEmpty(txtLastName,"divLastName",varLastName);}).focus(function(){DoMessageForEmpty(txtLastName,"divLastName",varLastName);});
            $(txtMobile).blur(function(){DoMessageForMobile();}).focus(function(){DoMessageForMobile();});
            $(txtEmail).blur(function(){DoMessageForEmail();}).focus(function(){DoMessageForEmail();});
            $(txtPwd1).blur(function(){DoMessageForEmpty(txtPwd1,"divPwd1",varPwd1);}).focus(function(){DoMessageForEmpty(txtPwd1,"divPwd1",varPwd1);});
            $(txtPwd2).blur(function(){DoMessageForPwd2();}).focus(function(){DoMessageForPwd2();});
            $(txtValidateCode).blur(function(){DoMessageForEmpty(txtValidateCode,"divValidateCode",varValidateCode);}).focus(function(){DoMessageForEmpty(txtValidateCode,"divValidateCode",varValidateCode);});
            
            //设定鼠标按下事件
            $(".signcontent").keydown(function(e){
                      var currKey=0,e=e||event;
　　      　          currKey=e.keyCode||e.which||e.charCode;
　　       　         if(currKey == 13)
　　       　         {
　　       　               if(ValidateForm())
                            {
                                RegistePostBack();
                            }
　　       　         }
            });
    }
);
//验证表单
function ValidateForm()
{ 
    if(!CheckText(txtFirstName,"divFirstName",varFirstName))
        return false; 
    else if(!CheckText(txtLastName,"divLastName",varLastName))
        return false; 
    else if(!CheckMobile())
        return false; 
    else if(!CheckRegisterEmail())
        return false; 
    else if(!CheckText(txtPwd1,"divPwd1",varPwd1))
        return false; 
    else if(!CheckPwd2())
        return false; 
    else if(!CheckText(txtValidateCode,"divValidateCode",varValidateCode))
        return false; 
        
    return true;
}
//检测文本框是否为空，并且操作相应的DIV提示
function CheckText(txt,divMsg,strMsg)
{
    if($.trim($(txt).val())=="")
    {
        $("#"+divMsg).html(strMsg).show();
        return false;
    }
    else
    {
        $("#"+divMsg).hide();
        return true;
    }
}
//文本框获得、失去焦点时是否显示消息
function DoMessageForEmpty(txt,divMsg,strMsg)
{
    if($.trim($(txt).val())=="")
    {
        $("#"+divMsg).html(strMsg).show();
    }
    else
    {
        $("#"+divMsg).hide();
    }
}
//判断密码框
function CheckPwd2()
{
    if($.trim($(txtPwd2).val())=="")
    {
        $("#divPwd2").html(varPwd2).show();
        return false;
    }
    else if($.trim($(txtPwd2).val()) != $.trim($(txtPwd1).val()))
    {
        $("#divPwd2").html(varPwdDifferent).show();
        return false;
    }
    else
    {
        $("#divPwd2").hide();
        return true;
    }
}
//判断密码框
function DoMessageForPwd2()
{
    if($.trim($(txtPwd2).val())=="")
    {
        $("#divPwd2").html(varPwd2).show();
    }
    else if($.trim($(txtPwd2).val()) != $.trim($(txtPwd1).val()))
    {
        $("#divPwd2").html(varPwdDifferent).show();
    }
    else
    {
        $("#divPwd2").hide();
    }
}
//验证邮箱地址
function CheckRegisterEmail()
{
    var reg = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    if($.trim($(txtEmail).val())=="")
    {
        $("#divEmail").html(varEmail).show();
        return false;
    }
    else if(!reg.exec($.trim($(txtEmail).val())))
    {
        $("#divEmail").html(varEmailFormat).show();
        return false;
    }
    else
    {
        $("#divEmail").hide();
        return true;
    }
}
//验证邮箱地址
function DoMessageForEmail()
{
    var reg = /\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    if($.trim($(txtEmail).val())=="")
    {
        $("#divEmail").html(varEmail).show();
    }
    else if(!reg.exec($.trim($(txtEmail).val())))
    {
        $("#divEmail").html(varEmailFormat).show();
    }
    else
    {
        $("#divEmail").hide();
    }
}
//验证手机号
function CheckMobile()
{
    var reg = /^\d{11}$/;
    if($.trim($(txtMobile).val())=="")
    {
        $("#divMobile").html(varMobile).show();
        return false;
    }
    else if(!reg.test($.trim($(txtMobile).val())))
    {
        $("#divMobile").html(varMobileFormat).show();
        return false;
    }
    else
    {
        $("#divMobile").hide();
        return true;
    }
}
//验证手机号
function DoMessageForMobile()
{
    var reg = /^\d{11}$/;
    if($.trim($(txtMobile).val())=="")
    {
        $("#divMobile").html(varMobile).show();
    }
    else if(!reg.exec($.trim($(txtMobile).val())))
    {
        $("#divMobile").html(varMobileFormat).show();
    }
    else
    {
        $("#divMobile").hide();
    }
}

