﻿$(function() {
    $("#txt_Email").focus();
    $('#txt_Pwd,#txt_ValidateCode').keypress(function(e) {
        if (e.which == '13') {
            var returnValue = chkLogin();

            if (returnValue == undefined) {
                __doPostBack('lbtn_Login', '');
            }
        }
    });
});

function chkLogin() {
    hideValidate();
    if ($("#txt_Email").val().length == 0) {
        $("#div_valEmail").html("请输入EMAIL地址!");
        $("#div_valEmail").show();
        $("#txt_Email").focus();
        return false;
    }
    else {
        var email = $.ajax({
            url: "customer.ashx?Param=checkvemailformat&email=" + $("#txt_Email").val(), async: false, cache: false
        }
		).responseText;
        if (email != "1") {
            $("#div_valEmail").html("EMAIL地址无效,请重新输入!");
            $("#div_valEmail").show();
            return false;
        }
    }

    if ($("#txt_Pwd").val().length == 0) {
        $("#div_valPwd").html("请输入密码!");
        $("#div_valPwd").show();
        $("#txt_Pwd").focus();
        return false;
    }
    if ($('#txt_ValidateCode').val().length == 0) {
        $('#div_valCode').html("请输入验证码!");
        $('#div_valCode').show();
        $('#txt_ValidateCode').focus();
        return false;
    }
    else {
        var code = $.ajax({
            url: "customer.ashx?Param=checkvalidatecode&code=" + $("#txt_ValidateCode").val(), async: false, cache: false
        }
	    ).responseText;
        if (code != "0") {
            $("#div_valCode").html("验证码无效,请重新输入!");
            $("#div_valCode").show();
            $('#txt_ValidateCode').focus();
            return false;
        }
    }
}
function hideValidate() {
    $("#div_valEmail").hide();
    $("#div_valPwd").hide();
    $("#div_valCode").hide();
}
