var xmlHttp=createXmlHttpRequest();
function gebi(id) {
    return document.getElementById(id);
}
function createXmlHttpRequest() {
    var xmlHttp;
    try {
      if(window.ActiveXObject)
          xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      else
          xmlHttp=new XMLHttpRequest();
    }
    catch(e) {
        xmlHttp=false;
        alert("Объект XMLHttpRequest не создан!");
    }
    return xmlHttp;
}
function checkName() {
    if(xmlHttp.readyState==4 || xmlHttp.readyState==0) {
        usname=encodeURIComponent(gebi("username").value);
        xmlHttp.open("GET", "handler.php?username="+usname, true);
        xmlHttp.onreadystatechange=handleResponse;
        xmlHttp.send(null);
    }
}


function handleResponse() {
    if(xmlHttp.readyState==4) {
        if(xmlHttp.status==200) {
            xmlResponse=xmlHttp.responseXML;
            xmlElement=xmlResponse.documentElement;
            res=xmlElement.firstChild.data;
            var umess=gebi("umess");
            if(res=='true')
               umess.innerHTML="<br><input type=\"submit\" class=\"button\" name=\"submit\" value=\"Узнать результат теста!\" />";
            else
                umess.innerHTML="<input type=\"button\" onclick=\"checkName()\" value=\"Проверить пароль\"><br><font color=\"red\"><b>Пароль неверный!</b></font>";
        }
        else
            alert("Ошибка при обращении к серверу. ")+xmlHttp.statusText;
    }
}