﻿function showImg() {
    doAjaxQuick("setImg", "Ajax/YZM_Action.ashx");
}
function setImg() {
    if (isSussecc()) {
        var val = getAjaxText().split("|");
        document.getElementById("hdn_yzm").value = val[0];
        document.getElementById("img_yzm").src = "Control/CheckCode.ashx?image=" + val[1];
    }
}
function isYZM() {
    if (document.getElementById("txtYZM").value == document.getElementById("hdn_yzm").value) {
        return true;
    } else {
        return false;
    }
}
function hasLoginID() {
    var vipLoginID = document.getElementById("txtVipLoginID").value;
    var m5 = /^[a-zA-Z0-9-_\.-@]{4,20}$/;    
    if (vipLoginID.length < 1) {
        alert("请输入会员名！");
        onFocus("txtVipLoginID");
    } else if (!m5.test(vipLoginID)) {
        alert("会员名的格式不正确！");
        onFocus("txtVipLoginID");
    } else {
        doAjaxQuick("doLoginID", "Ajax/RegisterAction.ashx", "operator", "haslogin", "vipLoginID", vipLoginID);
    }
}
function doLoginID() {
    if (isSussecc()) {
        if (getAjaxText() == "true") {
            alert("该用户名已存在，请使用别的用户名！");
            document.getElementById("txtVipLoginID").value = "";
            onFocus("txtVipLoginID");
        }
    }
}
function hasEmail() {
    var vipEmail = document.getElementById("txtVipEmail").value;
    var m5 = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    if (vipEmail.length < 1) {
        alert("请输入E-mail！");
        onFocus("txtVipEmail");
    } else if(!m5.test(vipEmail)) {
        alert("E-mail的格式不正确！");
        onFocus("txtVipEmail");
    } else {
        doAjaxQuick("doEmail", "Ajax/RegisterAction.ashx", "operator", "hasemail", "vipEmail", vipEmail);
    }
}
function doEmail() {
    if (isSussecc()) {
        if (getAjaxText() == "true") {
            alert("该E-mail已存在，请使用别的E-mail！");
            onFocus("txtVipEmail");
            document.getElementById("vipEmail").value = "";
        }
    }
}
function page_load() {
    var userLinkID = Request("ID");
    if (userLinkID != null && userLinkID != '') {
        document.getElementById("txtUserLinkID").value = userLinkID;
        document.getElementById("txtUserLinkID").disabled = true;
    }
}
function setCity() {
    var provinceID = document.getElementById("slcVipCountry").value;
    doAjaxQuick("doSetCity", "Ajax/RegisterAction.ashx", "operator", "getcitys", "provinceID", provinceID);
}
function doSetCity() {
    if (isSussecc()) {
        document.getElementById("slcVipCity").options.length = 0;
        var str = getAjaxText();
        var arrayStr = str.split("|");
        for (var i = 0; i < arrayStr.length; i++) {
            var s = arrayStr[i].split("^");
            var opt = new Option(s[1], s[0]);
            document.getElementById("slcVipCity").options.add(opt);
        }
    }
}
function IsPassword() {
    var pwd = document.getElementById("txtVipPassword").value;
    if (pwd.length < 6) {
        alert("密码长度太短！");
        document.getElementById("txtVipPassword").value = "";
        onFocus("txtVipPassword");
    }
}
function IsRePassoord() {
    if (document.getElementById("txtVipPassword").value != document.getElementById("txtReVipPassword").value) {
        alert("两次输入的密码不一致！");
        document.getElementById("txtVipPassword").value = "";
        document.getElementById("txtReVipPassword").value = "";
        onFocus("txtVipPassword");
    }
}
function IsMobile() {
    var mobile = /^1[3,5,8]{1}[0-9]{1}[0-9]{8}$/;
    if (!mobile.test(document.getElementById("txtVipMobile").value)) {
        alert("请输入正确的手机号！");
        document.getElementById("txtVipMobile").value = "";
        onFocus("txtVipMobile");
    }
}
function IsPhone() {
    var phone = /(^(\d{2,4}[-]?)?\d{3,8}([-]?\d{3,8})?([-]?\d{1,7})?$)|(^0?1[35]\d{9}$)/;
    if (!phone.test(document.getElementById("txtVipPhone").value)) {
        alert("请输入正确的固定电话！");
        document.getElementById("txtVipPhone").value = "";
        onFocus("txtVipPhone");
    }
}
function IsFax() {
    var phone = /(^(\d{2,4}[-]?)?\d{3,8}([-]?\d{3,8})?([-]?\d{1,7})?$)|(^0?1[35]\d{9}$)/;
    if (!phone.test(document.getElementById("txtVipFax").value)) {
        alert("请输入正确的传真！");
        document.getElementById("txtVipFax").value = "";
        onFocus("txtVipFax");
    }
}
function IsUserLinkID() {
    if (document.getElementById("txtUserLinkID").value.length > 5) {
        alert("专员号过长，请输入正确的专员号！");
        document.getElementById("txtUserLinkID").value = "";
    }
}
function register_ing() {    
    if (!isYZM()) {
        alert("请输入正确的验证码！");
        onFocus("txtYZM");
        return;
    } else if (document.getElementById("txtVipLoginID").value == "") {
        alert("请输入会员名！");
        onFocus("txtVipLoginID");
        return;
    } else if (document.getElementById("txtVipCompany").value == "") {
        alert("请输入公司(个人)名称！");
        onFocus("txtVipCompany");
        return;
    } else if (document.getElementById("txtVipPassword").value == "") {
        alert("请输入密码！");
        onFocus("txtVipPassword");
        return;
    } else if (document.getElementById("txtReVipPassword").value == "") {
        alert("请输入确认密码！");
        onFocus("txtReVipPassword");
        return;
    } else if (document.getElementById("txtVipEmail").value == "") {
        alert("请输入电子信箱！");
        onFocus("txtVipEmail");
        return;
    } else if (document.getElementById("txtVipName").value == "") {
        alert("请输入联系人！");
        onFocus("txtVipName");
        return;
    } else if (document.getElementById("txtVipMobile").value == "") {
        alert("请输入联系手机！");
        onFocus("txtVipMobile");
        return;
    } else if (document.getElementById("txtVipFax").value == "") {
        alert("请输入传真！");
        onFocus("txtVipFax");
        return;
    } else if (document.getElementById("txtVipPhone").value == "") {
        alert("请输入固定电话！");
        onFocus("txtVipPhone");
        return;
    } else if (document.getElementById("txtUserLinkID").value == "") {
        alert("请输入销售专员号！若没有制定专员号，请填写 * ");
        document.getElementById("txtUserLinkID").value = "*";
        onFocus("txtUserLinkID");
        return;
    } else {
        showDiv();
        var vipSex = "0";
        if (document.getElementById("rdoVipSexWmn").checked) {
            vipSex = "1";
        }
        doAjaxQuick("doRegister", "Ajax/RegisterAction.ashx",
                    "operator", "register",
                    "vipLoginID", document.getElementById("txtVipLoginID").value,
                    "vipCompany", document.getElementById("txtVipCompany").value,
                    "vipPassword", document.getElementById("txtVipPassword").value,
                    "vipSex", vipSex,
                    "vipCountry", document.getElementById("slcVipCountry").value,
                    "vipCity", document.getElementById("slcVipCity").value,
                    "vipEmail", document.getElementById("txtVipEmail").value,
                    "vipName", document.getElementById("txtVipName").value,
                    "vipMobile", document.getElementById("txtVipMobile").value,
                    "vipFax", document.getElementById("txtVipFax").value,
                    "vipPhone", document.getElementById("txtVipPhone").value,
                    "vipInternet", document.getElementById("txtVipInternet").value,
                    "userLinkID", document.getElementById("txtUserLinkID").value);
    }
}
function doRegister() {
    if (isSussecc()) {
        var path = getAjaxText();
        if (path != "false") {
            window.location = path;
        } else {
            alert("系统繁忙，请稍候再注册！");
            removeDiv();
        }
    }
}

function DivAlert(messageDiv) {
    this.messageDiV = messageDiv;
    this.bottomDIV = document.createElement("div");
    var x = document.body.clientWidth;
    var y = document.body.clientHeight;
    this.bottomDIV.style.opacity = "0.50";
    this.bottomDIV.style.filter = "Alpha(opacity=50);";
    this.bottomDIV.style.backgroundColor = "#CCCCCC";
    this.bottomDIV.style.width = x;
    this.bottomDIV.style.height = y;
    this.bottomDIV.style.marginTop = "0px";
    this.bottomDIV.style.marginLeft = "0px";
    this.bottomDIV.style.position = "absolute";
    this.bottomDIV.style.top = "0px";
    this.bottomDIV.style.left = "0px";
    this.bottomDIV.style.zIndex = 100;
    //显示提示框
    this.show = function() {
        document.body.appendChild(this.bottomDIV);
        this.messageDiV.style.display = "inline";
        this.messageDiV.style.position = "absolute";
        this.messageDiV.style.top = "200px";
        this.messageDiV.style.left = "300px";
        this.messageDiV.style.zIndex = 101;
    }
    //移除提示框
    this.remove = function() {
        document.body.removeChild(this.bottomDIV);
        this.messageDiV.style.display = "none";
    }
}
var dc;
function showDiv() {
    var d = document.getElementById("div_show");
    dc = new DivAlert(d);
    dc.show();
}
function removeDiv() {
    dc.remove();
}
function onFocus(id) {
    //document.getElementById(id).focus();
}