var xmlHttp = createXmlHttpRequestObject();
var write;
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 process(method,adress,writeto,param)
{
write=writeto;
  if (xmlHttp)
  {
    try
    {	//alert(method+adress+writeto+param);
      xmlHttp.open(method,adress, true);
      xmlHttp.onreadystatechange = handleRequestStateChange;
      xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      xmlHttp.send(param);
    }
    catch (e)
    {
      alert("Can't connect to server:\n" + e.toString());
    }
  }
}



function handleRequestStateChange()
{
 myDiv = document.getElementById(write);
 if (xmlHttp.readyState == 4)
  {
    // continue only if HTTP status is "OK"
    if (xmlHttp.status == 200)
    {
      try
      {
        response = xmlHttp.responseText;

        myDiv.innerHTML = response;
      }
      catch(e)
      {
        // display error message
        alert("Error reading the response: " + e.toString());
      }
    }
    else
    {
      // display status message
      alert("There was a problem retrieving the data:\n" +
            xmlHttp.statusText);
    }
  }
}
function ready(method,adress,writeto,param)
{

	myDiv = document.getElementById(writeto);
	myDiv.innerHTML = "Выполняется...";
	process(method,adress,writeto,param);
}
