﻿    $(function(){
        $("#ParentAgentID").blur(function(){check1(this,true,"ParentAgentID");});
        $("#AgentName").blur(function(){check2(this,false,"NickName");});
        $("#AgentID").blur(function(){check2(this,false,"PlayerID");});
        $("#Submit").click(function(){reg();});
    });    
    function Check() {    
//    if (document.getElementById("ParentAgentID").value.length==0)
//    {
//        alert("请输入代理商帐号！");
//        document.getElementById("ParentAgentID").focus();
//        return false;
//    } 
   
    if($("#err_ParentAgentID").html("").length>2)
    {
        //alert("错误：所填写代理商不存在！");
        //return false;
    }
    if (document.getElementById('AgentName').value.length==0)
    {
        alert("请输入会员昵称！");
        document.getElementById('AgentName').focus();
        return false;
    } 
    else
    {
        var patrn=/^[a-zA-Z0-9]{4,15}$/;   
        if (!patrn.exec(document.getElementById('AgentName').value))
        {
            alert("会员名只能使用字母数字的组合，长度4到15位！");
            return false;
        }
       
    }
    if($("#err_AgentName").html().length>2)
    {
        alert("错误：所填昵称已经被占用，请另填！");
        return false;
    }    
    if (document.getElementById('AgentID').value.length==0)
    {
        alert("请输入会员帐号！");
        document.getElementById('AgentID').focus();
        return false;
    }   
    if($("#err_AgentID").html("").length>2)
    {
        alert("错误：所填帐号已经被占用，请另填！");
        return false;
    }  
    if (document.getElementById('AgentPassword').value.length==0)
    {
        alert("请填写会员密码！");
        document.getElementById('AgentPassword').focus();
        return false;
    } 
         
    if (document.getElementById('AgentPassword1').value.length==0)
    {
        alert("请输入会员确认密码！");
        document.getElementById('AgentPassword1').focus();
        return false;
        
    }
           
    if (document.getElementById('AgentPassword').value!=document.getElementById('AgentPassword1').value)
    {
        alert("两次输入的密码不一致,请重新输入！");
        document.getElementById('AgentPassword1').focus();
        return false;
    }       

    if (document.getElementById('realName').value.length==0)
    {
        alert("请填写真实姓名！");
        document.getElementById('realName').focus();
        return false;
        
    }
    if (document.getElementById('birthday').value.length==0)
    {
        alert("请选择出生日期！");
        document.getElementById('birthday').focus();
        return false;
        
    }
    if (document.getElementById('tel').value.length==0)
    {
        alert("请填写联系电话！");
        document.getElementById('tel').focus();
        return false;
        
    }
    if (document.getElementById('email').value.length==0)
    {
        alert("请填写联系邮箱！");
        document.getElementById('email').focus();
        return false;
    }       
    if (document.getElementById('addr').value.length==0)
    {
        alert("请填写收货地址！");
        document.getElementById('addr').focus();
        return false;
    }          
    return true;
    }
    
    function check1(obj,bool,type)
    {
        var name=$("#"+obj.id).val();
        if($.trim(name).length>0)
        {
            $.get(
                "Register.aspx",
                {key:"check",name:name,type:type,n:Math.random()},
                function(result){
                    if(result!=""&&bool)
                        $("#err_"+obj.id).html(result);
                    else if(result==""&&!bool)
                         $("#err_"+obj.id).html("出错：所填写的会员已被占用");
                    else
                        $("#err_"+obj.id).html("");
                }
            );
        }
        else
        {
            $("#err_"+obj.id).html("");
        }
    }
    function check2(obj,bool,type)
    {
        var name=$("#"+obj.id).val();
        if($.trim(name).length>0)
        {
            $.get(
                "Register.aspx",
                {key:"check1",name:name,type:type,n:Math.random()},
                function(result){
                    if(result!=""&&bool)
                        $("#err_"+obj.id).html(result);
                    else if(result==""&&!bool)
                         $("#err_"+obj.id).html("出错：所填写的会员已被占用");
                    else
                        $("#err_"+obj.id).html("");
                }
            );
        }
        else
        {
            $("#err_"+obj.id).html("");
        }
    }    
    
    function reg()
    {
        if(Check())
        {
            var ParentAgentID="";//$("#ParentAgentID").val();
            var AgentName=$("#AgentName").val();
            var AgentID=$("#AgentID").val();
            var AgentPassword=$("#AgentPassword").val();
            var realName=escape($("#realName").val());
            var birthday=$("#birthday").val();
            var tel=$("#tel").val();
            var email=$("#email").val();
            var addr = $("#addr").val();
            $.ajax({
                url: "Register.aspx",
                type: 'GET',
                data:{key:"reg",ParentAgentID:ParentAgentID,AgentName:AgentName,AgentID:AgentID,AgentPassword:AgentPassword,realName:realName,birthday:birthday,tel:tel,email:email,addr:addr,n:Math.random()},
                //dataType: 'json',
                timeout: 1000,
                error: function(request, error, status,result){ 
                    alert("注册失败");
                },
                success: function(result){
                    alert(result);
                    window.location='user/login.aspx';
                    $("#ParentAgentID").val("");
                    $("#AgentName").val("");
                    $("#AgentID").val("");
                    $("#AgentPassword").val("");
                    $("#AgentPassword1").val("");
                }
            });
return;

            $.get(
                "Register.aspx",
                {key:"reg",ParentAgentID:ParentAgentID,AgentName:AgentName,AgentID:AgentID,AgentPassword:AgentPassword,realName:realName,birthday:birthday,tel:tel,email:email,n:Math.random()},
                function(result){
                    alert(result);
                    window.location='user/login.aspx';
                    $("#ParentAgentID").val("");
                    $("#AgentName").val("");
                    $("#AgentID").val("");
                    $("#AgentPassword").val("");
                    $("#AgentPassword1").val("");
                }
            );
        }
    }