﻿    /**
    *
    * 注册工具类
    **/
    var RegisterUtils = {
        mobileNodeId : "txtMobile",
        CNNameNodeId : "txtCNName",
        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.ReturnUrl = arguments[3];

            
            //开始验证传入的数据的正确性
            if(this.doValidate(this.mobileNodeId, this.CNNameNodeId))
            {
                var tempCNName = encodeURI($("#"+this.CNNameNodeId).val().trim());
                var sourceType = encodeURI(arguments[0])
                //验证成功，开始发送注册请求
                $.ajax({
 		            type: "get",
		            url:"/AjaxPage/RegisterAjax.aspx?mobile=" + $("#"+this.mobileNodeId).val() + "&CNName=" + tempCNName + "&sourceType=" + sourceType +"&ReturnUrl="+this.ReturnUrl+"&" + new Date(),
		            data:"",
		            success:this.onRegisterSuccess
		            }) ;
            }
            
        },
        //是否使用默认的控件id
        isUseDefaultControlId : function (arg)
        {
            return false;
        },
        //验证使用者是否传入了来源
        isInputSource : function(arg)
        {
            if(arg.length == 0)
            {
                return false;
            }
            if(typeof arg[0] != "string")
            {
                return false;
            }
            return true;
        },
        //发送注册请求后怎样响应？若要进行不同的操作请重载此方法
        onRegisterSuccess : function (res)
        {
            eval("var result = " + res);
            if(result.ErrorMessage == null)
            {
                var url = 'http://www.wlstock.com/Register/MobileRegisterStepTwo.aspx?mobile=' + result.Mobile ;
                if(result.ReturnURL !="")
                    url = url + "&ReturnUrl=" + result.ReturnURL;
                window.location = url;
            }
            else
            {
                alert(result.ErrorMessage)
            }
        }
    }
