//前台用户注册页脚本
$(function () {
    $("#UserName").blur(function () {//验证用户名是否存在
        CommonGetAjax(5000,"/Common/ashx/global.ashx", { "Id": "0", "UpAction": "Add", "Action": "Reg_CheckUserName", "UserName": $(this).val() }, $(".UserName"), "检测失败");
    });
    $("#Email").blur(function () {//验证EMAIL是否存在
        CommonGetAjax(5000,"/Common/ashx/global.ashx", { "Id": "0", "UpAction": "Add", "Action": "Reg_CheckMail", "Email": $(this).val() }, $(".Email"), "检测失败");
    });
    $.fn.password({
        passwordInput: 'password',
        checkInput: 'checkpassword',
        strengthInfoText: 'infoText',
        strengthInfoBar: 'infoBar',
        checkInfoText: "checkInfoText"
    });
    $("#password,#checkpassword").keyup(function () {
        $.checkPassword();
    });

    $("#regform tr").mouseover(function () {
        if (!$(this).find("td").is($(".ntit"))) {
            $(this).css("background-color", "#EEEFEF");
        }
    });
    $("#regform tr").mouseout(function () {
        if (!$(this).find("td").is($(".ntit"))) {
            $(this).css("background-color", "white");
        }
    });
    var UserName = $("#UserName"),
			password = $("#password"),
            checkpassword = $("#checkpassword"),
            sName = $("#Name"),
            Tel = $("#Tel"),
            Mobile = $("#Mobile"),
            QQ = $("#QQ"),
            Email = $("#Email"),
            ZIP = $("#ZIP"),
            CheckCode = $("#CheckCode"),
			allFields = $([])
            .add(UserName)
            .add(password)
            .add(checkpassword)
            .add(sName)
            .add(Tel)
            .add(Mobile)
            .add(QQ)
            .add(Email)
            .add(ZIP)
            .add(CheckCode)
            ;
    function ValidTemp() {
        var bValid = true;
                allFields.removeClass("ui-state-error");
                bValid = bValid && checkRegexp(UserName, Regex_UserName, "帐号名格式不正确");
                bValid = bValid && checkRegexp(Email, Regex_EMail, "Email格式不正确");
                bValid = bValid && checkLength(password, "密码", 6, 16);
                bValid = bValid && checkEquals("密码", password, checkpassword);
                bValid = bValid && checkLength(sName, "持有者", 2, 50);
                if (Tel.val().length > 0) {
                    bValid = bValid && checkRegexp(Tel, Regex_Tel, "电话号码格式不正确");
                }
                if (Mobile.val().length > 0) {
                    bValid = bValid && checkRegexp(Mobile, Regex_Mobile, "手机号码格式不正确");
                }
                if (Tel.val().length <= 0 && Mobile.val().length <= 0) {
                    bValid = bValid && false;
                    Tel.addClass("ui-state-error");
                    updateTips("电话和手机有一项为必填", Tel.attr("id"));
                } else {
                    $("." + Tel.attr("id")).html("<img src=\"/Common/Images/true.png\" />");
                }

                if (QQ.val().length > 0) {
                    bValid = bValid && checkRegexp(QQ, Regex_QQ, "QQ格式不正确");
                }
                if (ZIP.val().length > 0) {
                    bValid = bValid && checkRegexp(Zip, Regex_Zip, "邮政编码格式不正确");
                }
                bValid = bValid && checkLength(CheckCode, "验证码", 4, 4);

        if ($("#agreement").attr("checked") == undefined) {
            bValid = bValid && false;
            $(".agreementmsg").html("<img src=\"/Common/Images/false.png\" /> 请先阅读并同意注册条款").addClass("red");
        } else {
            bValid = bValid && true;
            $(".agreementmsg").html("<img src=\"/Common/Images/true.png\" />");
        }
        return bValid;
    };
    $("#subbtn").click(function () {
        return ValidTemp();
    });
    
});