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 process(adr,f,target){
  if (xmlHttp){
    try{
//prompt("url",adr);
//alert(adr);
      xmlHttp.open("GET", adr, true);
	  //xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      xmlHttp.onreadystatechange = function(){handleRequestStateChange(f,target);}
      xmlHttp.send(null);
    }catch (e){
      alert("Can't connect to server:\n" + e.toString());
    }
  }
}

function handleRequestStateChange(f,target){
	if (xmlHttp.readyState == 4){
		if (xmlHttp.status == 200){
			try{
				response=xmlHttp.responseText;
				//alert(response);
				if (response.indexOf("ERRNO") >= 0 || response.indexOf("error:") >= 0 || response.length == 0)
				throw(response.length == 0 ? "Void server response." : response);
				if(f!=null) f(response,target);
			}catch(e){
				displayError(e.toString()); 
			} 
		}else{
			displayError("There was a problem retrieving the data:\n" + xmlHttp.statusText);
		}
	}
}

function appendHTML(response,target){
	if(document.getElementById('asyncTemp')) target.removeChild(document.getElementById('asyncTemp'));
	target.innerHTML+=response;
}
function replHTML(response,target){
	target.innerHTML=response;
}