﻿//清空空格
function trim(str)   
{   
      return str.replace(/(^\s*)|(\s*$)/g, "")   
}

//清空文本框   
function clearText()
{
    document.getElementById("txtCheckCode").value = "";
    document.getElementById("txtName").value = "";
    document.getElementById("txtPsw").value = "";
    document.getElementById("txtSurePsw").value = "";
    document.getElementById("txtEmail").value = "";
    document.getElementById("txtAnswer").value = "";
    document.getElementById("txtBirthday").value = "";
    document.getElementById("txtQQ").value = "";
    document.getElementById("txtPhone").value = "";
    document.getElementById("txtAddress").value = "";
    document.getElementById("txtIntroduce").value = "";
    
}
//验证用户名是否存在（编辑信息时）
function checkUserNameForEdit()
{
   //据ID获取各文本框值
    var tempName= trim(document.getElementById("txtTempName").value);
    var name= trim(document.getElementById("txtName").value);
    if(tempName != name)
    {
        var xmlHttp=null;
        //针对ie7,ie8,firefox等浏览器
        if(window.XMLHttpRequest)
        {
            xmlHttp=new XMLHttpRequest();
        }
        else if(window.ActiveXObject)
        {
            var activeName= ["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
             //针对IE6，IE5.5，IE5
             //两个可以用于创建XMLHTTPRequest对象的控件名称，保存在一个js的数组中
             //排在前面的版本较新
            for(i=0;i<activeName.length;i++){
               try
               {
                   xmlHttp=new ActiveXObject(activeName[i]);
                   break;
               }
               catch(e){}
            }
        }
         //post方式提交数据s
         xmlHttp.open("post","AjaxAddUser.aspx?action=Check&name="+encodeURI(name),true);
         //POST方式需要自己设置http的请求头
         xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
         //POST方式发送数据
         xmlHttp.send(null);
            
        //确认XMLHTtpRequest对象创建成功,回调显示
        xmlHttp.onreadystatechange=function()
        {
            if(xmlHttp.readyState==4)
            {
                if(xmlHttp.status==200)
                {
                   var returnStatus = trim(xmlHttp.responseText);
                   if(returnStatus == "Existed")
                   {
                      alert("用户名   " + name + "   已经存在 ！");
                      document.getElementById("txtName").value = tempName;
                      document.getElementById("txtName").focus();
                   }
                }
                else
                {
			        alert(" 验证用户名发生错误注册失败请重试，谢谢 ！");
		        }
           }
        }
    }
    else
    {
       return;
    }
}
//验证用户名是否存在（增加用户时）
function checkUserNameForAdd()
{
   //据ID获取各文本框值
    
    var name= trim(document.getElementById("txtName").value);
    
    var xmlHttp=null;
    //针对ie7,ie8,firefox等浏览器
    if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        var activeName= ["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
         //针对IE6，IE5.5，IE5
         //两个可以用于创建XMLHTTPRequest对象的控件名称，保存在一个js的数组中
         //排在前面的版本较新
        for(i=0;i<activeName.length;i++){
           try
           {
               xmlHttp=new ActiveXObject(activeName[i]);
               break;
           }
           catch(e){}
        }
    }
    
     //post方式提交数据s
     xmlHttp.open("post","AjaxAddUser.aspx?action=Check&name="+encodeURI(name),true);
     //POST方式需要自己设置http的请求头
     xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
     //POST方式发送数据
     xmlHttp.send(null);
        
    //确认XMLHTtpRequest对象创建成功,回调显示
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            if(xmlHttp.status==200)
            {
               var returnStatus = trim(xmlHttp.responseText);
               if(returnStatus == "Existed")
               {
                  alert("用户名   " + name + "   已经存在 ！");
                  document.getElementById("txtName").value = "";
                  document.getElementById("txtName").focus();
               }
            }
            else
            {
			    alert(" 验证用户名发生错误注册失败请重试，谢谢 ！");
			    document.getElementById("txtName").value = "";
		    }
       }
    }
}

//验证用户名是否存在（增加用户时） 英文
function checkUserNameForAddEn()
{
   //据ID获取各文本框值
    
    var name= trim(document.getElementById("txtName").value);
    
    var xmlHttp=null;
    //针对ie7,ie8,firefox等浏览器
    if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        var activeName= ["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
         //针对IE6，IE5.5，IE5
         //两个可以用于创建XMLHTTPRequest对象的控件名称，保存在一个js的数组中
         //排在前面的版本较新
        for(i=0;i<activeName.length;i++){
           try
           {
               xmlHttp=new ActiveXObject(activeName[i]);
               break;
           }
           catch(e){}
        }
    }
    
     //post方式提交数据s
     xmlHttp.open("post","AjaxAddUserEn.aspx?action=Check&name="+encodeURI(name),true);
     //POST方式需要自己设置http的请求头
     xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
     //POST方式发送数据
     xmlHttp.send(null);
        
    //确认XMLHTtpRequest对象创建成功,回调显示
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            if(xmlHttp.status==200)
            {
               var returnStatus = trim(xmlHttp.responseText);
               if(returnStatus == "Existed")
               {
                  alert("The Name   " + name + "   is Existed ！");
                  document.getElementById("txtName").value = "";
                  document.getElementById("txtName").focus();
               }
            }
            else
            {
			    alert("User authentication error,Please retry it , Thank you ！");
			    document.getElementById("txtName").value = "";
		    }
       }
    }
}

//Ajax异步提交用户注册信息
function addUser()
{
   //取得cookie值中的验证码
   var checkCode;
   var cookCode=document.cookie.split(",");
   var cookCode=document.cookie.split(";");
   for(var i = 0 ; i < cookCode.length ; i++)
   {
      var myCook=cookCode[i].split("=");
      if("CheckCode" == trim(myCook[0]))
      {
         checkCode = myCook[1];
         break;
      }
   }  
    //据ID获取各文本框相关值
    var inputCheckCode= trim(document.getElementById("txtCheckCode").value.toUpperCase());    
    var name= trim(document.getElementById("txtName").value);
    var psw= trim(document.getElementById("txtPsw").value);
    var surePsw= trim(document.getElementById("txtSurePsw").value);
    var email= trim(document.getElementById("txtEmail").value);    
    var answer= trim(document.getElementById("txtAnswer").value);   
    var birthday= trim(document.getElementById("txtBirthday").value);   
    var qq = trim(document.getElementById("txtQQ").value);   
    var phone = trim(document.getElementById("txtPhone").value);   
    var sex = trim(document.getElementById("rbnSex").value);
    var address= trim(document.getElementById("txtAddress").value);
    var introduce= trim(document.getElementById("txtIntroduce").value);
    var question = trim(document.getElementById("rbnQuestion").value);

    //为空则返回   
    if(inputCheckCode == "")
    {
        alert("验证码不能为空 ！");
        document.getElementById("txtCheckCode").focus();
        return;
    }

    if(inputCheckCode != checkCode)
    {
        alert("验证码填写错误，请重新填写 ！");
        document.getElementById("txtCheckCode").focus();
        return;     
    }
    if(name == "")
    {
        alert("用户名不能为空 ！");
        document.getElementById("txtName").focus();
        return;
    }
    if(psw == "")
    {
        alert("密码不能为空 ！");
        document.getElementById("txtPsw").focus();
        return;
    }
    if(psw.length < 6 || psw.length > 10)
    {
        alert("密码位数请设定在6-8位数字或字母 ！");
        document.getElementById("txtPsw").focus();
        return;
    }
    if(surePsw == "")
    {
        alert("确认密码不能为空 ！");
        document.getElementById("txtSurePsw").focus();
        return;
    } 
    if(psw != surePsw)
    {
        alert("两次输入密码不一致，请重新输入 ！");
        document.getElementById("txtPsw").focus();
        document.getElementById("txtSurePsw").value = "";
        return;  
    }
    if(email == "")
    {
        alert("Email不能为空 ！");
        document.getElementById("txtEmail").focus();
        return;
    }
    else
    {
        var pattern =/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
        if(!pattern.exec(email))
        {
            alert("Email格式错误 ！");
            document.getElementById("txtEmail").focus(); 
            return;
        }
    }
    
    if(question!="" && answer == "")
    {
         alert("问题答案不能为空 ！");
         document.getElementById("txtAnswer").focus(); 
         return;      
    }
    
    if(qq != "") 
    {
        var pattern =/^(\d{5,10})$/;
        if(!pattern.exec(qq))
        {
            alert("QQ号码格式错误 ！");
            document.getElementById("txtQQ").focus(); 
            return;
        }
    }
    
    if(phone != "") 
    {
        var pattern =/^\d{11}|^(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})$/;
        if(!pattern.exec(phone))
        {
            alert("电话号码格式错误 ！");
            document.getElementById("txtPhone").focus(); 
            return;
        }
    }

    var xmlHttp=null;
    //针对ie7,ie8,firefox等浏览器
    if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        var activeName= ["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
         //针对IE6，IE5.5，IE5
         //两个可以用于创建XMLHTTPRequest对象的控件名称，保存在一个js的数组中
         //排在前面的版本较新
        for(i=0;i<activeName.length;i++){
           try
           {
               xmlHttp=new ActiveXObject(activeName[i]);
               break;
           }
           catch(e){}
        }
    }
     //post方式提交数据s
     xmlHttp.open("post","AjaxAddUser.aspx?action=Add&name="+encodeURI(name)+"&psw="+encodeURI(psw)+"&email="+encodeURI(email)+"&answer="+encodeURI(answer)+"&birthday="+encodeURI(birthday)+"&qq="+encodeURI(qq)+"&phone="+encodeURI(phone)+"&sex="+encodeURI(sex)+"&address="+encodeURI(address)+"&introduce="+encodeURI(introduce)+"&question="+encodeURI(question),true);
     //POST方式需要自己设置http的请求头
     xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
     //POST方式发送数据
     xmlHttp.send(null);
        
    //确认XMLHTtpRequest对象创建成功,回调显示
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            if(xmlHttp.status==200)
            {
                alert("恭喜您成功注册为正式会员 ！");
                clearText();
                //刷新验证码
                document.getElementById("imgCheck").src="CheckCode.aspx?rand2=" + Math.random();
                window.location.href="../Default.aspx";
            }
            else
            {
				 alert("注册失败请重试，谢谢 ！");
		    }
       }
    }
}
//Ajax异步提交用户注册信息 英文
function addUserEn()
{
   //取得cookie值中的验证码
   var checkCode;
   var cookCode=document.cookie.split(",");
   var cookCode=document.cookie.split(";");
   for(var i = 0 ; i < cookCode.length ; i++)
   {
      var myCook=cookCode[i].split("=");
      if("CheckCode" == trim(myCook[0]))
      {
         checkCode = myCook[1];
         break;
      }
   }  
    //据ID获取各文本框相关值
    var inputCheckCode= trim(document.getElementById("txtCheckCode").value.toUpperCase());    
    var name= trim(document.getElementById("txtName").value);
    var psw= trim(document.getElementById("txtPsw").value);
    var surePsw= trim(document.getElementById("txtSurePsw").value);
    var email= trim(document.getElementById("txtEmail").value);    
    var answer= trim(document.getElementById("txtAnswer").value);   
    var birthday= trim(document.getElementById("txtBirthday").value);   
    var qq = trim(document.getElementById("txtQQ").value);   
    var phone = trim(document.getElementById("txtPhone").value);   
    var sex = trim(document.getElementById("rbnSex").value);
    var address= trim(document.getElementById("txtAddress").value);
    var introduce= trim(document.getElementById("txtIntroduce").value);
    var question = trim(document.getElementById("rbnQuestion").value);

    //为空则返回   
    if(inputCheckCode == "")
    {
        alert("Verification Code is required ！");
        document.getElementById("txtCheckCode").focus();
        return;
    }

    if(inputCheckCode != checkCode)
    {
        alert("Verification Code  is wrong , please re-fill ！");
        document.getElementById("txtCheckCode").focus();
        return;     
    }
    if(name == "")
    {
        alert("User Name  is required ！");
        document.getElementById("txtName").focus();
        return;
    }
    if(psw == "")
    {
        alert("Password  is required ！");
        document.getElementById("txtPsw").focus();
        return;
    }
    if(psw.length < 6 || psw.length > 10)
    {
        alert("Password at least 6, up to 12 ！ ");
        document.getElementById("txtPsw").focus();
        return;
    }
    if(surePsw == "")
    {
        alert("Sure Password  is required ！");
        document.getElementById("txtSurePsw").focus();
        return;
    } 
    if(psw != surePsw)
    {
        alert("Password inconsistent ！");
        document.getElementById("txtPsw").focus();
        document.getElementById("txtSurePsw").value = "";
        return;  
    }
    if(email == "")
    {
        alert("Email is required ！");
        document.getElementById("txtEmail").focus();
        return;
    }
    else
    {
        var pattern =/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
        if(!pattern.exec(email))
        {
            alert("Email format error, please re-fill ！");
            document.getElementById("txtEmail").focus(); 
            return;
        }
    }
    
    if(question!="" && answer == "")
    {
         alert("Question answer  is required ！");
         document.getElementById("txtAnswer").focus(); 
         return;      
    }
    
    if(qq != "") 
    {
        var pattern =/^(\d{5,10})$/;
        if(!pattern.exec(qq))
        {
            alert("QQ format error, please re-fill ！");
            document.getElementById("txtQQ").focus(); 
            return;
        }
    }
    
    if(phone != "") 
    {
        var pattern =/^\d{11}|^(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})$/;
        if(!pattern.exec(phone))
        {
            alert("Telephone number format error, please re-fill ！");
            document.getElementById("txtPhone").focus(); 
            return;
        }
    }

    var xmlHttp=null;
    //针对ie7,ie8,firefox等浏览器
    if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        var activeName= ["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
         //针对IE6，IE5.5，IE5
         //两个可以用于创建XMLHTTPRequest对象的控件名称，保存在一个js的数组中
         //排在前面的版本较新
        for(i=0;i<activeName.length;i++){
           try
           {
               xmlHttp=new ActiveXObject(activeName[i]);
               break;
           }
           catch(e){}
        }
    }
     //post方式提交数据s
     xmlHttp.open("post","AjaxAddUserEn.aspx?action=Add&name="+encodeURI(name)+"&psw="+encodeURI(psw)+"&email="+encodeURI(email)+"&answer="+encodeURI(answer)+"&birthday="+encodeURI(birthday)+"&qq="+encodeURI(qq)+"&phone="+encodeURI(phone)+"&sex="+encodeURI(sex)+"&address="+encodeURI(address)+"&introduce="+encodeURI(introduce)+"&question="+encodeURI(question),true);
     //POST方式需要自己设置http的请求头
     xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
     //POST方式发送数据
     xmlHttp.send(null);
        
    //确认XMLHTtpRequest对象创建成功,回调显示
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            if(xmlHttp.status==200)
            {
                alert("Congratulations you have successfully registered as a Member ！");
                clearText();
                //刷新验证码
                document.getElementById("imgCheck").src="CheckCode.aspx?rand2=" + Math.random();
                window.location.href="../DefaultEn.aspx";
            }
            else
            {
				 alert("注册失败请重试，谢谢 ！");
		    }
       }
    }
}
//Ajax异步编辑用户注册信息
    function editUser()
    {  
       //取得cookie值中的验证码

       var checkCode;
       var cookCode=document.cookie.split(",");
       var cookCode=document.cookie.split(";");
       for(var i = 0 ; i < cookCode.length ; i++)
       {
          var myCook=cookCode[i].split("=");
          if("CheckCode" == trim(myCook[0]))
          {
             checkCode = myCook[1];
             break;
          }
       }  
        //据ID获取各文本框相关值        
        var inputCheckCode= trim(document.getElementById("txtCheckCode").value.toUpperCase());    
        var id = trim(document.getElementById("txtTempID").value);    
        var name= trim(document.getElementById("txtName").value);
        var psw= trim(document.getElementById("txtPsw").value);
        var surePsw= trim(document.getElementById("txtSurePsw").value);
        var email= trim(document.getElementById("txtEmail").value);    
        var answer= trim(document.getElementById("txtAnswer").value);   
        var birthday= trim(document.getElementById("txtBirthday").value);   
        var qq = trim(document.getElementById("txtQQ").value);   
        var phone = trim(document.getElementById("txtPhone").value);   
        var sex = trim(document.getElementById("rbnSex").value);
        var address= trim(document.getElementById("txtAddress").value);
        var introduce= trim(document.getElementById("txtIntroduce").value);
        var question = trim(document.getElementById("rbnQuestion").value);

        //为空则返回   
        if(inputCheckCode == "")
        {
            alert("验证码不能为空 ！");
            document.getElementById("txtCheckCode").focus();
            return;
        };

        if(inputCheckCode != checkCode)
        {
            alert("验证码填写错误，请重新填写 ！");
            document.getElementById("txtCheckCode").focus();
            return;     
        }
        if(name == "")
        {
            alert("用户名不能为空 ！");
            document.getElementById("txtName").focus();
            return;
        }
        if(psw == "")
        {
            alert("密码不能为空 ！");
            document.getElementById("txtPsw").focus();
            return;
        }
        if(psw.length < 6 || psw.length > 10)
        {
            alert("密码位数请设定在6-8位数字或字母 ！");
            document.getElementById("txtPsw").focus();
            return;
        }
        if(surePsw == "")
        {
            alert("确认密码不能为空 ！");
            document.getElementById("txtSurePsw").focus();
            return;
        } 
        if(psw != surePsw)
        {
            alert("两次输入密码不一致，请重新输入 ！");
            document.getElementById("txtPsw").focus();
            document.getElementById("txtSurePsw").value = "";
            return;  
        }
        if(email == "")
        {
            alert("Email不能为空 ！");
            document.getElementById("txtEmail").focus();
            return;
        }
        else
        {
            var pattern =/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
            if(!pattern.exec(email))
            {
                alert("Email格式错误 ！");
                document.getElementById("txtEmail").focus(); 
                return;
            }
        }
        
        if(question!="" && answer == "")
        {
             alert("问题答案不能为空 ！");
             document.getElementById("txtAnswer").focus(); 
             return;      
        }
        
        if(qq != "") 
        {
            var pattern =/^(\d{5,10})$/;
            if(!pattern.exec(qq))
            {
                alert("QQ号码格式错误 ！");
                document.getElementById("txtQQ").focus(); 
                return;
            }
        }
        
        if(phone != "") 
        {
            var pattern =/^\d{11}|^(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})$/;
            if(!pattern.exec(phone))
            {
                alert("电话号码格式错误 ！");
                document.getElementById("txtPhone").focus(); 
                return;
            }
        }

        var xmlHttp=null;
        //针对ie7,ie8,firefox等浏览器
        if(window.XMLHttpRequest)
        {
            xmlHttp=new XMLHttpRequest();
        }
        else if(window.ActiveXObject)
        {
            var activeName= ["MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
             //针对IE6，IE5.5，IE5
             //两个可以用于创建XMLHTTPRequest对象的控件名称，保存在一个js的数组中
             //排在前面的版本较新
            for(i=0;i<activeName.length;i++){
               try
               {
                   xmlHttp=new ActiveXObject(activeName[i]);
                   break;
               }
               catch(e){}
            }
        }
         //post方式提交数据s
         xmlHttp.open("post","AjaxAddUser.aspx?action=Edit&id="+id+"&name="+encodeURI(name)+"&psw="+encodeURI(psw)+"&email="+encodeURI(email)+"&answer="+encodeURI(answer)+"&birthday="+encodeURI(birthday)+"&qq="+encodeURI(qq)+"&phone="+encodeURI(phone)+"&sex="+encodeURI(sex)+"&address="+encodeURI(address)+"&introduce="+encodeURI(introduce)+"&question="+encodeURI(question),true);
         //POST方式需要自己设置http的请求头
         xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
         //POST方式发送数据
         xmlHttp.send(null);
            
        //确认XMLHTtpRequest对象创建成功,回调显示
        xmlHttp.onreadystatechange=function()
        {
            if(xmlHttp.readyState==4)
            {
                if(xmlHttp.status==200)
                {
                    alert("恭喜您信息修改成功 ！");
                }
                else
                {
				     alert("注册失败请重试，谢谢 ！");
		        }
           }
        }
   }
