/* ***** 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 XMLHttpRequest();
		this.handleRequestAsString = netscapeRequestAsStringHandler;
		this.handleRequestDOM = netscapeRequestDOMHandler;
	} catch (e) {
		try {
			//xComp = new ActiveXObject("Msxml2.XMLHttp");
			xComp = new ActiveXObject("Microsoft.XMLHTTP");
			
                        this.handleRequestAsString = ieRequestAsStringHandler;
			this.handleRequestDOM = ieRequestDOMHandler;
		} catch (e) {
			window.alert("Vers�o de browser com funcionalidade insuficientes para execu��o desta rotina. Atualize seu browser para IE 5.5 (ou posterior) ou Netscape 6 (ou posterior).");
		}
	}

	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);
}

XMLRemoteRequest.prototype.sendDocument = function (urlString,docString) {
    this.XMLHttpComponent.open("POST",urlString,false);
    this.XMLHttpComponent.send(docString);
    return;
}


// 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;
	} else if (xmlComp.responseText) {
		return xmlComp.responseText;
	} 

	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;
}


