var xmlHttp=createXmlHttpRequestObject();

function createXmlHttpRequestObject()
{
  var xmlHttp;

  try {xmlHttp = new XMLHttpRequest();}
  catch(e)
  {
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0", "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP");
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
    {
      try{xmlHttp = new ActiveXObject(XmlHttpVersions[i]);}
      catch (e) {}
    }
  }
  if (!xmlHttp) alert("Error creating the XMLHttpRequest object."); else return xmlHttp;
}


function logout()
{
  if (xmlHttp.readyState==4 || xmlHttp.readyState==0)
  {
    xmlHttp.open("GET",root+"mod/reg/logout.php", true);
	xmlHttp.onreadystatechange=LogoutServerResponse;
    xmlHttp.send(null);
  }
  else {setTimeout("logout()", 300);}
}

function LogoutServerResponse()
{
  if (xmlHttp.readyState==4)
  {
    if (xmlHttp.status==200)
    {
      top.document.location=top.document.location;
    }
	else {alert("Ошибка при обращении к серверу: "+xmlHttp.statusText);}
  };
};

function login()
{
  if (xmlHttp.readyState==4 || xmlHttp.readyState==0)
  {
    logname=document.getElementById('login_input').value;
    pass=document.getElementById('pass_input').value;
    xmlHttp.open("GET",root+"mod/reg/login.php?login="+logname+"&pass="+pass, true);
	xmlHttp.onreadystatechange=LoginServerResponse;
    xmlHttp.send(null);
  }
  else {setTimeout("logout()", 300);}
};

function LoginServerResponse()
{
  if (xmlHttp.readyState==4)
  {
    if (xmlHttp.status==200)
    {
      top.document.location=top.document.location;
    }
	else {alert("Ошибка при обращении к серверу: "+xmlHttp.statusText);}
  };
};

function login_keydown(event){if(event.keyCode==13){login();};};
