var mailStatus = true;
var vmailStatus = true;
var pwdStatus = true;
var vpwdStatus = true;
var verifyCodeStatus = true;
var agreementStatus = true;
var checkOK = true;
var appPath = "";

$(document).ready(function() {
    renewVerifyImage();

    $("#ctl00_MainPlace_email").focus();

    $(".imgchange,.checkimg").click(function() {
        renewVerifyImage();
        return false;
    });

    $("#agreementLink").click(function() {
        window.open("RegisterRemark.html", '用户服务协议', 'height=155, width=580,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
        return false;
    });


    $("input").focus(function() {
        $(this).addClass("focus");
    })
    .blur(function() {
        $(this).removeClass("focus");
    });


    if ($("#ctl00_MainPlace_ipRegError").val() != "") {
        switch ($("#ctl00_MainPlace_ipRegError").val()) {
            case "附加码校验失败":
                $("#ctl00_MainPlace_checkimg").siblings("span").text("验证码输入有错").addClass("note error").removeClass("ok");
                break;
        }
    }
		/*
    $("#ctl00_MainPlace_email").focus(function() {
        $(this).next("span").addClass("note").removeClass("ok").removeClass("error").text("请填写有效的Email地址作为下次登录用户名。我们会给这个地址发送新拍卖和订单通知、优惠信息等");
    });
	  $("#ctl00_MainPlace_vemail").focus(function() {
        $(this).next("span").addClass("note").removeClass("ok").removeClass("error").text("两次输入的Email地址要一致");
    });

    $("#ctl00_MainPlace_psd").focus(function() {
        $(this).next("span").addClass("note").removeClass("ok").removeClass("error").text("密码必须是6-30位字符，请正确输入");
    });

    $("#ctl00_MainPlace_vpsd").focus(function() {
        $(this).next("span").addClass("note").removeClass("ok").removeClass("error").text("两次输入的密码要一致");
    });

    $("#ctl00_MainPlace_checkimg").focus(function() {
        $(this).siblings("span").addClass("note").removeClass("ok").removeClass("error").text("请输入六位验证码");
    });    
    
    $("#ctl00_MainPlace_email").blur(function() { CheckEmail($(this)); });

    $("#ctl00_MainPlace_vemail").blur(function() { CheckVEmail($(this)); });

    $("#ctl00_MainPlace_psd").blur(function() { CheckPwd($(this)); });

    $("#ctl00_MainPlace_vpsd").blur(function() { CheckVPwd($(this)) });

    $("#ctl00_MainPlace_checkimg").blur(function() { CheckVeryCode($(this)); });
    */
});

function CheckEmail(obj) {
    if ($(obj).val() != "") {
        if (!f_CheckEMail($(obj).val())) {
            $(obj).next("span").addClass("note error").removeClass("ok").text("请输入正确的Email地址");
            mailStatus = false;
        }
        else {
            $.post($("#appPath").val() + "UserUtils.axd", { mail: $(obj).val(), type: "mail" }, function(data) {
                if (data == "1") {
                    $(obj).next("span").addClass("ok").text("");
                    mailStatus = true;
                }
                else {
                    $(obj).next("span").html(data).addClass("note error").removeClass("ok");
                    mailStatus = false;
                }
            })
        }
        
    }
    else {
        $(obj).next("span").addClass("note error").removeClass("ok").text("请输入正确的Email地址");
        mailStatus = false;
    }
}


function CheckVEmail(obj) {
    if ($(obj).val() != "") {
        if ($(obj).val() != $("#ctl00_MainPlace_email").val()) {
            $(obj).next("span").text("两次输入的Email地址不一致").addClass("error").removeClass("ok");
            vmailStatus = false;
        }
        else {
            $(obj).next("span").addClass("ok").text("");
            vmailStatus = true;
        }
    }
    else {
        $(obj).next("span").addClass("note error").text("请再输一次你的Email地址").removeClass("ok"); 
        vmailStatus = false;
    }
}


function CheckPwd(obj) {
    if ($(obj).val() != "") {
        var reg = /^(\w|@|#|\$){6,30}/;
        if (!reg.test($("#ctl00_MainPlace_psd").val())) {
            $(obj).next("span").addClass("note error").removeClass("ok").text("密码必须是6-30位字符，请正确输入");
            pwdStatus = false;
        }
        else {
            $(obj).next("span").addClass("ok").text("");
            pwdStatus = true;
        }
    }
    else {
        $(obj).next("span").addClass("note error").removeClass("ok").text("密码必须是6-30位字符，请正确输入");
        pwdStatus = false;
    }
}



function CheckVPwd(obj) {
    if ($(obj).val() != "") {
        if ($(obj).val() != $("#ctl00_MainPlace_psd").val()) {
            $(obj).next("span").text("您两次输入的密码不一致，请重新输入").addClass("note error").removeClass("ok");
            vpwdStatus = false;
        }
        else {
            $(obj).next("span").addClass("note ok").text("");
            vpwdStatus = true;
        }
    } else {
        $(obj).next("span").addClass("note error").removeClass("ok").text("请再输一次你的密码");
        vpwdStatus = false;
    }
}


function CheckVeryCode(obj) {
    if ($(obj).val() != "") {
        if ($(obj).val().length == 6) {
            $.post($("#appPath").val() + "UserUtils.axd?seed=" + Math.round(Math.random() * 100000), { checkcode: $(obj).val(), type: "veryimg" }, function(data) {
                if (data == "1") {
                    $("#ctl00_MainPlace_checkimg").siblings("span").addClass("ok").text("");
                    verifyCodeStatus = true;
                }
                else {
                    $("#ctl00_MainPlace_checkimg").siblings("span").text("验证码输入有错").addClass("note error").removeClass("ok");
                    $("#ctl00_MainPlace_checkimg").text('');
                    verifyCodeStatus = false;
                }
            });

        }
        else {
            $(obj).siblings("span").addClass("note error").text("请输入六位验证码").removeClass("ok");
            $("#ctl00_MainPlace_checkimg").text('');
            verifyCodeStatus = false;
        }
    }
    else {
        $(obj).siblings("span").addClass("note error").text("请输入六位验证码");
        verifyCodeStatus = false;
    }
}


function CheckAgreement(obj) {
    if ($(obj).attr("checked")==true) {
        $(obj).siblings("span").removeClass("note error").text("")
        agreementStatus = true;
    }
    else {
        $(obj).siblings("span").addClass("note error").text("请先阅读并同意《麦网用户服务协议》");
        agreementStatus = false;
    }
}


function renewVerifyImage() {
    var img = $("#appPath").val() + "CaptchaSecurityImages.php?width=80&height=32&character=4";
    $(".checkimg").attr("src", img);
}


function CheckRegister() {   
    
    CheckEmail($("#ctl00_MainPlace_email"));

    CheckVEmail($("#ctl00_MainPlace_vemail"));

    CheckPwd($("#ctl00_MainPlace_psd"));

    CheckVPwd($("#ctl00_MainPlace_vpsd"));

    CheckVeryCode($("#ctl00_MainPlace_checkimg"));

    CheckAgreement($("#chkAgreement"));

    if (!mailStatus || !vmailStatus || !pwdStatus || !vpwdStatus || !verifyCodeStatus || !agreementStatus) {
        checkOK = false;
    }
    else {
        checkOK = true;
    }
    

    return checkOK;
    
    
}