﻿// JScript 文件
// JScript 文件
//创建xmlHttp
var xmlhttp=null;
function createxmlhttp()
{
//用于创建XMLHttpRequest对象
   
      
        //根据window.XMLHttpRequest对象是否存在使用不同的创建方式
        if (window.XMLHttpRequest) {
           xmlhttp = new XMLHttpRequest();                  //FireFox、Opera等浏览器支持的创建方式
        } else {
           xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");//IE浏览器支持的创建方式
        }
       
}
//验证用户是否存在
function myhx_usernamevalidation()
{
    createxmlhttp();
    var name=document.getElementById("txtyhm").value;

    xmlhttp.open("Post","check.aspx?name="+name);
    xmlhttp.onreadystatechange=myhx_OnMessageBack;
    xmlhttp.send(null);
}
function myhx_OnMessageBack()
{
        //判断请求状态及HTTP状态是否都能满足条件
     
        if (xmlhttp.readyState==4)
        { if(xmlhttp.status==200)   
          { 
                //将返回的文本打印到页面上 
              if(xmlhttp.responseText=="1")
              {
                // alert(xmlhttp.responseText);
                   
                    document.getElementById("txtError").value="";
               //   document.getElementById("txtError").style.width="14px";
                    document.getElementById("txtError").className="ok"; 
               }
               else
               {
               document.getElementById("txtError").className="ok1"; 
                 document.getElementById("txtError").style.color="Red";
                     document.getElementById("txtError").value=xmlhttp.responseText;
              }
                
           }
        }
}
    //验证密码
//function myhx_passwordvalidation()
//{
//        createxmlhttp();
//        var password=document.getElementById("txtpassword").value;
//        if(password.length>20 || password.length < 6 ||password.length==0)
//        {
//            document.getElementById("txtvpassword").style.color="Red";
//            return false;
//        }
//        else 
//        {
//            document.getElementById("txtvpassword").style.color="Black";
//            document.getElementById("txtvpassword").value="";
//            return true;
//        }

//}

function OnPMessageBack()
    {
        //判断请求状态及HTTP状态是否都能满足条件
        
        if (xmlhttp.readyState==4)
        { if(xmlhttp.status==200)   
          { 
            //将返回的文本打印到页面上
            
            document.getElementById("txtvpassword").style.color="Red";
             //document.getElementById("txtvpassword").value=xmlhttp.responseText;
           }
        }
    }
   
    //重复密码
    function myhx_rpasswordvalidation()
    {
        var password=document.getElementById("txtpassword").value;
        var rpassword=document.getElementById("txtRPassword").value;
        if(rpassword.length>20 || rpassword.length < 6 ||rpassword.length==0)
        {
             document.getElementById("txtvRPassword").className="ok1"; 
            document.getElementById("txtvRPassword").style.color="Red";
            document.getElementById("txtvRPassword").value="密码由6-20个数字或字母组成！"
        }
        else if(password!=rpassword)
            {
                document.getElementById("txtvRPassword").className="ok1"; 
                document.getElementById("txtvRPassword").style.color="Red";
                document.getElementById("txtvRPassword").value="密码与确认密码不同";
            }
        else
            {
                    document.getElementById("txtvRPassword").value="";
                    document.getElementById("txtvRPassword").className="ok";
//                document.getElementById("txtpassword").style.color="Black";
//                document.getElementById("txtvRPassword").value="";
            }
    }
function OnRPMessageBack()
    {
        //判断请求状态及HTTP状态是否都能满足条件
        
        if (xmlhttp.readyState==4)
        { if(xmlhttp.status==200)   
          { 
            //将返回的文本打印到页面上
                document.getElementById("txtvRPassword").value=xmlhttp.responseText;
           }
        }
    }
    //验证email
    function myhx_emailvalidation()
    {
        var email= document.getElementById("txtEmail").value;
        var emailPat=/^([_a-z0-9])+@([_a-z0-9]+\.)+([a-z0-9]{2,3}$)/; 
        var matchArray=email.match(emailPat); 
        if (matchArray==null) 
        { 
            document.getElementById("txtVAemail").style.color="Red";
            //document.getElementById("txtVAemail").value="email格式错误"; 
            return false;
        }
        else
        
        {
        
            createxmlhttp();
            var email=document.getElementById("txtEmail").value;
            xmlhttp.open("Post","check.aspx?email="+email);
            xmlhttp.onreadystatechange=myhx_OnEMessageBack;
            xmlhttp.send(null);
        }
       
    }
    function myhx_OnEMessageBack()
    {
        //判断请求状态及HTTP状态是否都能满足条件
        
        if (xmlhttp.readyState==4)
        { if(xmlhttp.status==200)   
          { 
            //将返回的文本打印到页面上
            
                document.getElementById("txtVAemail").value=xmlhttp.responseText;
           }
        }
    }
/** * 校验只能输入数字 * @return 如果输入是数字，则返回true，否则返回false */
function myhx_checkIsNumber(oObject)
{     
//如果为空，则通过校验 
   if(oObject.value == "")  
      return true;    
       var reg=/^(13|15|18)\d{9}$/g;
       if(!reg.test(oObject.value) )
       {
           document.getElementById("lblvModilePhone").className="ok1"; 
            document.getElementById("lblvModilePhone").style.color="Red";
            document.getElementById("lblvModilePhone").value="手机号码输入错误！";
            return false;
       }
   if(/^\d*$/.test(oObject.value) && oObject.value.length==11)  
   {
         document.getElementById("lblvModilePhone").value="";

                document.getElementById("lblvModilePhone").className="ok"; 
                return true;
   }  
    else     
     {    
      document.getElementById("lblvModilePhone").className="ok1"; 
            document.getElementById("lblvModilePhone").style.color="Red";
            document.getElementById("lblvModilePhone").value="手机号码输入错误！";
            return false;
      }
   
      
}

