﻿document.write("<script  language=\"javascript\"  src=\"\/js\/BigInt.js\"> <\/script>"); 
document.write("<script  language=\"javascript\"  src=\"\/js\/RSA.js\"> <\/script>"); 

    /**
    *
    * 注册工具类
    **/
var RegisterUtils = {
    mobileNodeId: "txtMobile",
    CNNameNodeId: "txtCNName",
    StockNo: "",
    ReturnUrl: "",

    doValidate: function(mobileNodeId, CNNameNodeId) {
        return auto_check_form([[mobileNodeId, "请填入您的手机号码", "check"],
                            [mobileNodeId, "您输入的手机号码格式不正确", "mobile"]
//,
//                            [CNNameNodeId, "真实姓名不能为空", "check"],
//                            [CNNameNodeId, "真实姓名只能最多填入10个字符", "maxnum", 10]
]);
    },
    //发送注册请求
    sendRegisterRequest: function() {
        if (!this.isInputSource(arguments)) {
            alert("请至少传入注册来源");
            return;
        }
        var ret = this.isUseDefaultControlId(arguments);
        this.mobileNodeId = ret ? this.mobileNodeId : arguments[1];
        this.CNNameNodeId = ret ? this.CNNameNodeId : arguments[2];
        if (arguments.length > 3)
            this.StockNo = arguments[3];
        if (arguments.length > 4)
            this.ReturnUrl = arguments[4];


        //开始验证传入的数据的正确性
        if (this.doValidate(this.mobileNodeId, this.CNNameNodeId)) {
            var tempCNName = encodeURI($("#" + this.CNNameNodeId).val());
            var sourceType = encodeURI(arguments[0]);
            var stockNo = "";
            if(this.StockNo !="")
                stockNo = $("#" + this.StockNo).val();
            //验证成功，开始发送注册请求
            $.ajax({
                type: "get",
                url: "/AjaxPage/RegisterAjax.aspx?Mobile=" + CmdEncrypt($("#" + this.mobileNodeId).val()) + "&CustomerName=" + tempCNName + "&Source=" + sourceType + "&ReturnUrl=" + this.ReturnUrl + "&StockNo=" + stockNo + "&" + new Date(),
                data: "",
                success: function(val) {
                    if (val > 0) {
                        window.parent.location = "https://zhuce.wlstock.com/Register.aspx?CustomerName=" + encodeURI(tempCNName) + "&RegisterSource=" + encodeURI(sourceType);
                    }
                    else if (val == -2) {
                    alert("不要太贪心喔，您刚才已经注册过啦！");
                    }
                    else {
                        alert("注册失败！");
                    }
                }
            });
        }

    },
    //是否使用默认的控件id
    isUseDefaultControlId: function(arg) {
        return false;
    },
    //验证使用者是否传入了来源
    isInputSource: function(arg) {
        if (arg.length == 0) {
            return false;
        }
        if (typeof arg[0] != "string") {
            return false;
        }
        return true;
    }
}

