var xhr_object = null; 

function ahah(url,target) {
	
   // native XMLHttpRequest object
   //document.getElementById(target).innerHTML = 'sending...';
   var loader=document.getElementById("loader");
   loader.style.display="block";
   
   if (window.XMLHttpRequest) {
       xhr_object = new XMLHttpRequest();
	   xhr_object.onreadystatechange = function() {ahahDone(target);};
       xhr_object.open("GET", url, true);
       xhr_object.setRequestHeader('Content-type', 'text/plain;charset=UTF-8;');
	   xhr_object.send(null);
   // IE/Windows ActiveX version
   } else if (window.ActiveXObject) {
	   xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
       if (xhr_object) {
		   xhr_object.onreadystatechange = function() {ahahDone(target);};
           xhr_object.open("GET", url, true);
           xhr_object.setRequestHeader('Content-type', 'text/plain;charset=UTF-8;');
		   xhr_object.send();
       }
   }
   
}    

function ahahDone(target) {
   // only if req is "loaded"
   //alert("State : "+xhr_object.readyState+"\n\nStatus : "+xhr_object.status+"\n\nResponseText : "+xhr_object);

   if (xhr_object.readyState == 4) {
       // only if "OK"
       if (xhr_object.status == 200 || xhr_object.status == 304) {
		   //alert("ahah5");
		   document.getElementById("loader").style.display="none";
		   //alert("State : "+xhr_object.readyState+"\n\nStatus : "+xhr_object.status+"\n\nResponseText : "+xhr_object);
           results = xhr_object.responseText;
		   //results = "RESULTAT";
		   //alert("ahah7");
           document.getElementById(target).innerHTML = results;
		   //alert("ahah8");
       } else {
           document.getElementById(target).innerHTML="ahah error:\n" +
               xhr_object.statusText;
       }
   }
}
