﻿var xmlHttp;
function trim(str)
{//去掉字符串空格
 while(str.charAt(0)==" ") 
 {
  str=str.substr(1);
 }
 while(str.charAt(str.length-1)==" ") 
 {
  str=str.substring(0,str.length-1);
 }
 return str; 
}

function CheckName()
{//检查用户名是否可用
    if(xmlHttp.readyState==4)
    {
        if(xmlHttp.status==200)
        {
            if(xmlHttp.responseText=="true")
            {
                document.getElementById("imgUsername").src="../images/true.gif";
                document.getElementById("imgUsername").style.display="inline-block";
                document.getElementById("tip").innerText="用户名验证通过";
                document.getElementById("btnReg").disabled=false;
            }
            else if(xmlHttp.responseText=="false")
            {
                document.getElementById("imgUsername").src="../images/false.gif";
                document.getElementById("imgUsername").style.display="inline-block";
                document.getElementById("tip").innerText="用户名已经存在";
                document.getElementById("btnReg").disabled=true;
            }
        }
    }
}
function CheckUsername(username)
{//
    if(username.length < 2)
    {
        document.getElementById("imgUsername").style.display="none";
        document.getElementById("tip").innerText="";
        document.getElementById("btnReg").disabled=true;
        return;
    }
    CreateXMLHTTP();
    var url="CheckUsername.aspx?Name="+ encodeURIComponent(username) + "&temp=" +Math.round(Math.random()*10000);
    xmlHttp.open("GET",url,true);
    xmlHttp.onreadystatechange=CheckName;
    xmlHttp.send(null);
}

function CreateXMLHTTP()
{//创建XMLHTTPRequest对象
    if(window.XMLHttpRequest)
    {
        xmlHttp=new XMLHttpRequest();
    }
    else if(window.ActiveXObject)
    {
        try
        {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");//IE老版本
        }
        catch(e)
        {
            try
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");//新版本
            }
            catch(e)
            {
            }
        }
        
    }
    if(!xmlHttp)
    {
        window.alert("不能创建XMLHTTPRequest对象!");
        return false;
    }
    
}

function onClickMore(b){
    var min=document.getElementById("fldMin");
    var max=document.getElementById("fldMax");
    if(b){
        min.style.display="none";
        max.style.display="block";
    }else{
        min.style.display="block";
        max.style.display="none";
    }
    
}

