﻿    //<![CDATA[
    $(document).ready(function() {
        $.idcode.setCode(); //设置验证码
        $("#imgBtnRegister").click(function(){
             
            var vRtxtUserName=$.trim($("#txtUserNameR").val());
            var vRtxtPswR=$.trim($("#txtPswR").val());
            var vRtxtPswROk=$.trim($("#txtPswROK").val());
            var vRemail=$.trim($("#txtEmailR").val());
            if((vRtxtUserName.length < 3) | (vRtxtUserName.length>20))
            {
                alert('您输入用户名称的长度不合法！');
                return;
            }
            if(!/^[\u4e00-\u9fa5\w]+$/.test(vRtxtUserName))
            {
                alert('用户名只能包括中文、英文字母、数字和下划线！');
                
                return;
            }   
           
            if(vRtxtPswR=="")
            {
                alert('请您输入用户密码！');
                return;
            }
             if(vRtxtPswR.length < 4)
            {
                alert('请您输入长度至少为四位的密码！');
                return;
            }
             if(vRtxtPswROk=="")
            {
                alert('请您输入用户确认密码！');
                return;
            }
            if(vRtxtPswR!=vRtxtPswROk)
            {
                alert('您输入的用户确认密码不正确！');
                return;
            }
            if(vRemail=="" || ( vRemail!="" && !/.+@.+\.[a-zA-Z]{2,4}$/.test(vRemail) ))
            {
                alert('您输入的电子邮件格式不正确！');
                return;
            }
            //判断验证码
            if($.trim($("#txtValidateCodeR").val())!=$.trim($("#txtValidateCodeHide").val()))
            {
                alert('请输入正确的验证码！');
                return;
            }
            var sIsCanSDB=$("#isCanSaveToDB").val();
            if(sIsCanSDB=="-1")
            {
                alert('注册失败，请检查输入数据的合法性！');
                return;

            }
            //判断是否存在该用户名称以及URL条转
            $.ajax({
                type: "GET",
                dataType: "html",
                url: "CheckUserAndRegi.aspx",
                data: "E="+escape(vRemail)+"&P="+escape(vRtxtPswROk)+"&U=" + escape(vRtxtUserName) + "&action=delete&T=" + new Date(),
                success: function(result) {
                    var vRetUrl = $.query.get('RetUrl');
                
                    if((result=="1")&(vRetUrl!=""))
                    {
                        //不存在并且注册成功
                        window.location.href=vRetUrl;
                        return;
                    }
                    if (result == "-1") {
                       
                        alert('注册失败，您输入的用户名已经被占用！');
                        return;
                    }
                     if (result == "-2") {
                       
                        alert('注册失败，您输入的电子邮箱已经被占用！');
                        return;
                    }
                    if(result=="1")
                    {
                        //不存在并且注册成功
                        window.location.href="/CustomerUser/member.aspx";
                        return;
                    }
                }
            })
           //判断结束
           
           
            
        })
            
         $("#txtUserNameR").blur(function (){
             //判断是否存在该用户名称以及URL条转
             var vRtxtUserName=$.trim($("#txtUserNameR").val());
             if(vRtxtUserName==""|(vRtxtUserName.length < 3) | (vRtxtUserName.length>20))
             {
                 $("#isHaveSUN").html("您输入的用户名称不合法！");
                 $("#isCanSaveToDB").val("-1");
                 return;
             }
           
            if(!/^[\u4e00-\u9fa5\w]+$/.test(vRtxtUserName))
            {
                $("#isHaveSUN").html("用户名只能包括中文、英文字母、数字和下划线！");
               
                $("#isCanSaveToDB").val("-1");
                return;
            }   
           
            $.ajax({
                type: "GET",
                dataType: "html",
                url: "CheckUserName.aspx",
                data: "username=" + escape(vRtxtUserName) + "&action=delete&T=" + new Date(),
                success: function(result) {
                   
                    if(result=="1")
                    {
                        $("#isCanSaveToDB").val("-1");
                        $("#isHaveSUN").html("抱歉，该用户名已经被占用！");
                        return;
                    }
                    if (result == "0") {
                        $("#isCanSaveToDB").val("0");
                        $("#isHaveSUN").html("恭喜您，该用户名可用！");
                        return;
                    }
                    
                    }
                })
         })
         //验证邮箱号码
           $("#txtEmailR").blur(function (){
        
             //判断是否存在邮箱以及URL条转
             var vRemail=$.trim($("#txtEmailR").val());
            if(vRemail=="" || ( vRemail!="" && !/.+@.+\.[a-zA-Z]{2,4}$/.test(vRemail) ))
            {
                $("#isCanSaveToDB").val("-1");
                $("#EmailTip").html("您输入的电子邮件格式不正确！");
                return;
            }
            $.ajax({
                type: "GET",
                dataType: "html",
                url: "CheckUserEmailReg.aspx",
                data: "emial=" + escape(vRemail) + "&action=delete&T=" + new Date(),
                success: function(result) {
                   
                    if(result=="3")
                    {
                      
                        $("#EmailTip").html("抱歉，该邮箱已经被占用！");
                        $("#isCanSaveToDB").val("-1");
                        return;
                    }
                      if(result=="2")
                    {
                      
                        $("#EmailTip").html("抱歉，该邮箱已经被占用！");
                        $("#isCanSaveToDB").val("-1");
                        return;
                    }
                    if (result == "1") {
                       
                        $("#EmailTip").html("恭喜您，该邮箱可用！");
                        $("#isCanSaveToDB").val("0");
                        return;
                    }
                    
                    }
                })
         })
    
         $("#imgBtnLoginOK").click(function(){
            var vUserName=$.trim($("#txtUserName").val());
            var vPsw=$.trim($("#txtPsw").val());
            if(vUserName=="")
            {
                alert('请您输入用户名称！');
                return;
            }
            if(vPsw=="")
            {
                alert('请您输入密码！');
                return;
            }
            //判断验证码
            if( $.idcode.validateCode()==false)
            {
                 alert('请您输入正确的验证码！');
                 return;
            }
            //ajax判断是否可以登录
            var isLoginAuto;
            //记住用户名
            if($("#ckRemUser").attr("checked") ==true)
            {
                
                isLoginAuto="1";
            }
            else
            {
                isLoginAuto="0";
            }
            //Ajax登录BBS
            
            $.ajax({
                type: "GET",
                dataType: "html",
                url: "CheckUserLogin.aspx",
                data: "U="+escape(vUserName)+"&P=" + escape(vPsw) + "&action=delete&T=" + new Date(),
                success: function(result) {
                    var vRetUrl = $.query.get('RetUrl');
                    
                    if((result=="1")&(vRetUrl!=""))
                    {
                       window.location.href=vRetUrl;
                    }
                    if (result == "1") {
                       
                      
                       window.location.href="/CustomerUser/member.aspx?LA="+isLoginAuto+"";
                    }
                    if(result == "0")
                    {
                        alert("您输入的用户名或密码不正确！");
                    }
                    
                }
            })
            
         })
         
        })
     
    //]]>
