$(function () {
    $("#btn_search").click(function () {
        document.location.href = "agentuser.aspx?sUserName=" + $("#sUserName").val() + "&sMail=" + $("#sMail").val() + "&sUserGrade=" + $("#sUserGrade").val();
    });

    $("#cts div").css("float", "left");
    $("#UserName").blur(function () {
        var href = window.location.href;
        CommonGetAjax(5000, "/Common/ashx/global.ashx", { "Id": getUrlVar(href, "Id"), "UpAction": getUrlVar(href, "Action"), "Action": "Reg_CheckUserName", "UserName": $(this).val() }, $(".UserName"), "检测失败");
    });
    $("#Email").blur(function () {
        var href = window.location.href;
        CommonGetAjax(5000, "/Common/ashx/global.ashx", { "Id": getUrlVar(href, "Id"), "UpAction": getUrlVar(href, "Action"), "Action": "Reg_CheckMail", "Email": $(this).val() }, $(".Email"), "检测失败");
    });
    function ValidTemp() {
        var UserName = $("#UserName"),
                sName = $("#Name"),
                Tel = $("#Tel"),
                Mobile = $("#Mobile"),
                QQ = $("#QQ"),
                Email = $("#Email"),
                Zip = $("#Zip"),
                Address = $("#Address"),
                allFields = $([])
                .add(UserName)
                .add(sName)
                .add(Tel)
                .add(Mobile)
                .add(QQ)
                .add(Email)
                .add(Zip)
        ;
        var bValid = true;
        bValid = bValid && checkRegexp(UserName, Regex_UserName, "帐号名格式不正确");
        bValid = bValid && checkLength(sName, "持有者", 2, 50);
        if (Tel.val() != "") {
            bValid = bValid && checkRegexp(Tel, Regex_Tel, "电话号码格式不正确");
        }
        if (Mobile.val() != "") {
            bValid = bValid && checkRegexp(Mobile, Regex_Mobile, "手机号码格式不正确");
        }
        if (QQ.val().length > 0) {
            bValid = bValid && checkRegexp(QQ, Regex_QQ, "QQ格式不正确");
        }
        bValid = bValid && checkRegexp(Email, Regex_EMail, "Email格式不正确");
        if (Zip.val().length > 0) {
            bValid = bValid && checkRegexp(Zip, Regex_Zip, "邮政编码格式不正确");
        }
        return bValid;
    };
    $("form").submit(function () {
        if (!ValidTemp()) {
            $(this).find("button[type=submit]").removeClass("loading").removeAttr("disabled");
            return false;
        }
    });
});