﻿
//检测用户名是否合法
function CheckUserName(userName, divId, controlId, rowId) {
    userName = removeAllSpace(userName);
    if (userName.toString().length > 2) {
        $.ajax({
            type: 'POST',
            url: '/We7Controls/Register/CS/QueryAjax.ashx',
            data: 'name=Register.Simple.ascx&userName=' + escape(userName),
            cache: false,
            complete: function(msg, textStatus) {
                var data = msg.responseText.split("|");
                if (data[0] == "true") {
                    SetResult("right", data[1], divId, controlId, rowId);
                }
                else {
                    SetResult("error", data[1], divId, controlId, rowId);
                }
            }
        });
    }
    else {
        SetResult("error", "用户名不能少于3位", divId, controlId, rowId);
    }
}

//检测Email是否合法
function CheckEmail(email, divId, controlId, rowId) {
    email = removeAllSpace(email);
    if (email.toString().length > 0) {
        $.ajax({
            type: 'POST',
            url: '/We7Controls/Register/CS/QueryAjax.ashx',
            data: 'name=Register.Simple.ascx&email=' + escape(email),
            cache: false,
            complete: function(msg, textStatus) {
                var data = msg.responseText.split("|");
                if (data[0] == "true") {
                    SetResult("right", data[1], divId, controlId, rowId);
                }
                else {
                    SetResult("error", data[1], divId, controlId, rowId);
                }
            }
        });
    }
    else {
        SetResult("error", "电子邮箱不能为空", divId, controlId, rowId);
    }

}

//检测密码是否合法
function CheckPWD(pwd, divId, controlId, rowId) {
    pwd = removeAllSpace(pwd);
    var data = "";
    if (!(pwd.toString().length >= 6 && pwd.toString().length <= 16)) {
        data = "密码必须在6-16个字符内";
        SetResult("error", data, divId, controlId, rowId);
    }
    else {
        SetResult("right", "", divId, controlId, rowId);
    }
}


//检测确认密码是否合法
function CheckRePWD(pwdID, rePwd, divId, controlId, rowId) {
    var pwd = removeAllSpace($("#" + pwdID).val());
    rePwd = removeAllSpace(rePwd);
    var data = "";
    if (pwd != rePwd) {
        data = "密码不匹配";
        SetResult("error", data, divId, controlId, rowId);
    }
    else {
        SetResult("right", "", divId, controlId, rowId);
    }
}

//处理结果
function SetResult(type, text, divId, controlId, rowId) {

    var result = "";
    if (type == "error") {
        InitStyle(divId, controlId, rowId);
        result = "<table width='100%' style='line-height:19px;' align='left'><tr><td width='20px' valign='top' align='left'><img src='/Admin/images/error.jpg'/></td><td  valign='top'>" + text + "</td></tr><table>";
        if ($("#" + controlId).val() != "") {
            $("#" + divId).html("");
            $("#" + divId).html(result);
            $("#" + divId).addClass("error");
            $("#" + controlId).addClass("error");
        }
        $("#" + controlId).attr("validate", "false");
    }
    else if (type == "right") {
        InitStyle(divId, controlId, rowId);
        result = "<img  width='20px' src='/Admin/images/right.jpg'/>";
        //<table width='100%' style='line-height:19px;' align='left'><tr><td width='20px' valign='top' align='left'>图片</td><td valign='top'>" + text + "</td></tr><table> 
        $("#" + divId).html("");
        $("#" + divId).html(result);
        $("#" + divId).addClass("allRight");
        $("#" + controlId).attr("validate", "true");
    }
    else if (type == "init") {
        InitStyle(divId, controlId, rowId);
        result = "<table width='100%' style='line-height:19px;' align='left'><tr><td width='20px' valign='top' align='left'><img src='/Admin/images/init.jpg'/></td><td  valign='top'>" + text + "</td></tr><table>";
        $("#" + divId).html("");
        $("#" + divId).html(result);
        $("#" + divId).addClass("initDiv");
        $("#" + rowId).addClass("initRow");
        //        alert(controlId);
        //        alert($("#" + controlId).attr("class"));
    }
    else if (type == "initValidateCode") {
        $("#" + divId).html("");
        $("#" + rowId).addClass("initRow");
    }
    else if (type == "errorValidateCode") {
        $("#" + rowId).removeClass("initRow");
        if ($("#" + controlId).val() != "") {
            $("#" + divId).html("<img src='/Admin/images/error.jpg'/>");
        }
        $("#" + controlId).attr("validate", "false");
    }
    else if (type == "rightValidateCode") {
        $("#" + rowId).removeClass("initRow");
        $("#" + divId).html("<img src='/Admin/images/right.jpg'/>");
        $("#" + controlId).attr("validate", "true");
    }
}



//判断最后提交按钮是否可用
function CheckValidate(emailId, userNameId, pwdId, rePwdId, btnId, validateId) {
    alert($("#" + validateId).attr("validate"));
    if ($("#" + emailId).attr("validate") == "true" && $("#" + userNameId).attr("validate") == "true" && $("#" + pwdId).attr("validate") == "true" && $("#" + rePwdId).attr("validate") == "true" && $("#" + validateId).attr("validate") == "true") {
        $("#" + btnId).removeAttr('disabled');
    }
    else {

        $("#" + btnId).attr("disabled", 'disabled');
    }
}

//出现该项目的填写帮助
function InitControlHelp(text, divId, controlId, rowId) {
    SetResult("init", text, divId, controlId, rowId);
}



//去除该项目的填写帮助
function InitStyle(divId, controlId, rowId) {
    var initText = "";
    $("#" + divId).html(initText);
    $("#" + divId).removeClass("initDiv");
    $("#" + rowId).removeClass("initRow");

    $("#" + divId).removeClass("error");
    $("#" + controlId).removeClass("error");

    $("#" + divId).removeClass("allRight");
    $("#" + controlId).removeClass("allRight");
}

///去除所有空格
function removeAllSpace(str) {
    return str.replace(/\s+/g, "");
}

//检测验证码是否正确√×
function CheckValidateCode(validateCode, divId, controlId, rowId) {
    $.ajax({
        type: 'POST',
        url: '/We7Controls/Register/CS/QueryAjax.ashx',
        data: 'name=Register.Simple.ascx&validateCode=' + escape(validateCode),
        cache: false,
        complete: function(msg, textStatus) {
            var data = msg.responseText;
            if (data == "true") {
                SetResult("rightValidateCode", "", divId, controlId, rowId);
            }
            else {
                SetResult("errorValidateCode", "", divId, controlId, rowId);
            }
        }
    });

}

