/**
* Modifié par Christian Ouellet 2004-09-09 pour supporter les requêtes asynchrones.
* J'ai ajouté la fonction createXmlHttpRequest.
*
*/

/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is Netscape code.
 *
 * The Initial Developer of the Original Code is
 * Netscape Corporation.
 * Portions created by the Initial Developer are Copyright (C) 2003
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s): Marcio Galli <mgalli@mgalli.com>
 * Contributors(s): Elder Reami <reami@yahoo.com>
 *
 * ***** END LICENSE BLOCK ***** */ 
 


function XMLRemoteRequest() {
	
	this.XMLHttpComponent = this.getXMLHttpComponentInstance();

}

XMLRemoteRequest.prototype.getXMLHttpComponentInstance = function () {
	var xComp = null;

	try {
        xComp = new ActiveXObject("Microsoft.XMLHTTP");

                    this.handleRequestAsString = ieRequestAsStringHandler;
        this.handleRequestDOM = ieRequestDOMHandler;
	} catch (err) {
		xComp = new XMLHttpRequest();
		this.handleRequestAsString = netscapeRequestAsStringHandler;
		this.handleRequestDOM = netscapeRequestDOMHandler;
	}

	return xComp;
}

XMLRemoteRequest.prototype.getRemoteDocument = function (urlString) {
	var rv =  this.handleRequestDOM(this.XMLHttpComponent, urlString);
        return rv;

}

XMLRemoteRequest.prototype.getRemoteDocumentString = function (urlString) {
	return this.handleRequestAsString(this.XMLHttpComponent, urlString);
}


// Netscape specifics
function netscapeRequestDOMHandler(xmlComp, urlString) {
	xmlComp.open("GET", urlString, false);
	xmlComp.send(null);

	if (xmlComp.responseXML) {
		return xmlComp.responseXML;
	}

	return null;
}

function netscapeRequestAsStringHandler(xmlComp, urlString) {
	xmlComp.open("GET", urlString, false);
	xmlComp.send(null);

	if (xmlComp.responseXML) {
		var dummyDoc = xmlComp.responseXML;
		var dummySerializer = new XMLSerializer();
		docString = dummySerializer.serializeToString(dummyDoc);

		return docString;
	}

	return null;
}

// IE specifics
function ieRequestDOMHandler(xmlComp, requestString) {
	xmlComp.open("GET", requestString, false);
	xmlComp.send();
	return xmlComp.responseXML;
}

function ieRequestAsStringHandler(xmlComp, requestString) {
	xmlComp.open("GET", requestString, false);
	xmlComp.send();

	return xmlComp.responseText;
}


function testXMLHTTPRequest() {
 var xComp=null;
   xComp = new XMLHttpRequest();
alert('1');
	if(xComp) return true;

   xComp = new ActiveXObject("Microsoft.XMLHTTP");
alert('2');
	if(xComp) return true;

   return false;
}

function createXmlHttpRequest() {
   try {
      if (window.XMLHttpRequest) {
         var req = new XMLHttpRequest();
         
         // some older versions of Moz did not support the readyState property
         // and the onreadystate event so we patch it!
         if (req.readyState == null) {
            req.readyState = 1;
            req.addEventListener("load", function () {
               req.readyState = 4;
               if (typeof req.onreadystatechange == "function")
                  req.onreadystatechange();
            }, false);
         }
         
         return req;
      }
      if (window.ActiveXObject) {
         return new ActiveXObject("Microsoft.XmlHttp");
      }
   }
   catch (ex) {}
   // fell through
   throw new Error("Your browser does not support XmlHttp objects");
}