function XmlHttp(){
 var xh = false;
 try{ xh = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try{ xh = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e) { xh = false; }
 }
 if (!xh && typeof XMLHttpRequest!='undefined') { xh = new XMLHttpRequest(); }

 this.xmlhttp = xh;
}

function XmlHttp_open(theMethod, theFile) { 
 try {
   // Needed for Mozilla if local file tries to access an http URL
   netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
 } catch (e) {
   // ignore
 }
 this.xmlhttp.open( theMethod, theFile, true ); 
}
function XmlHttp_setHeader( theParam, theValue){ this.xmlhttp.setRequestHeader(theParam, theValue); }
function XmlHttp_sendAndLoad( theData, fctRet, fctRetErr, retDiv ){
 this.retDiv = retDiv;
 var thisLoc = this; // besoin pour ecrire la function ci-dessous
 this.getStatus();
 this.xmlhttp.onreadystatechange=function() { 
                                             thisLoc.getStatus();
                                             if( thisLoc.xmlhttp.readyState == 4 ) {
                                              try{ 
                                               var stat = thisLoc.xmlhttp.status;
                                               if(stat != "200" ){
                                                if(fctRetErr != null){ fctRetErr( thisLoc.xmlhttp );} else {alert("Server Error : " + stat);}
                                               }else{ fctRet( thisLoc.xmlhttp ); thisLoc.getStatus(); }
                                              }
                                              catch(e){
                                               //debug("desc "+e.description+" num "+e.number);
                                               if(fctRetErr != null){ fctRetErr( thisLoc.xmlhttp );} else {alert("Server Unknown Error");}
                                              }
                                             } 
                                            }
 this.getStatus();
 this.xmlhttp.send(theData);
}

function XmlHttp_getStatus(){
 isReady = this.xmlhttp.readyState;
 ( (isReady == 0) ? (msg = "uninitialized") :
 ( (isReady == 1) ? (msg = "loading")       :
 ( (isReady == 2) ? (msg = "loaded")        :
 ( (isReady == 3) ? (msg = "interactive")   : 
 ( (isReady == 4) ? (msg = "complete")      : (msg = "problem") ) ) ) ) );

 if ( this.retDiv != null ) { this.retDiv.innerHTML = "connexion status : " + msg ; }
 else                       { top.status            = "connexion status : " + msg ; }

}

XmlHttp.prototype.openXhr      = XmlHttp_open;
XmlHttp.prototype.setHeader    = XmlHttp_setHeader;
XmlHttp.prototype.sendAndLoad  = XmlHttp_sendAndLoad;
XmlHttp.prototype.getStatus    = XmlHttp_getStatus;

/* ------------------------------------------------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------------------------- */

function createXhr( ){
 var myXHR = new XmlHttp();
 return( myXHR );
}

function sendData(theMethod, theFile, theData, theFct, theFctErr, retDiv){
 var xhr = createXhr();
 xhr.openXhr    ( theMethod, theFile ); 
 xhr.setHeader  ( "Content-Type","application/x-www-form-urlencoded;" );
 xhr.sendAndLoad( theData, theFct, theFctErr, retDiv );
}