/*---------------------------------------------------------------------------
 * XMLHTTP Constructor
 *-------------------------------------------------------------------------*/
XMLHTTP = function() {
    this._callback = undefined;
    this._request = this._getXMLHTTPRequest();

	if(this._request == undefined) {
	   this.ajaxEnabled = false;
	}
} 


/*---------------------------------------------------------------------------
 * XMLHTTP instance variables
 *-------------------------------------------------------------------------*/
XMLHTTP.prototype._callback = undefined;
XMLHTTP.prototype._request = undefined;
XMLHTTP.prototype.ajaxEnabled = undefined;


/*-----------------------------------------------------------------------------
 * XMLHTTP method setCallback 
 * sets the callback function for this instance
 *---------------------------------------------------------------------------*/
XMLHTTP.prototype.setCallback = function(newCallback) {
    this._callback = newCallback;
}


/*-----------------------------------------------------------------------------
 * XMLHTTP method _getXMLHTTPRequest
 * returns: an XMLHTTPRequest instance (based on browser IE/Mozilla)
 *---------------------------------------------------------------------------*/
XMLHTTP.prototype._getXMLHTTPRequest = function() {
	var xmlHttp;
	
	// temporary hack to imitate a JavaScript-enabled, non-AJAX browser:
	//return xmlHttp;
	
	try {
		xmlHttp = new ActiveXObject("Msxml2.XMLHttp");
	} catch(e) {
		try {
			xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
		} catch(e2) {}
	}
	
	if(xmlHttp == undefined && (typeof XMLHttpRequest != "undefined")) {
		xmlHttp = new XMLHttpRequest();
	}
	
	return xmlHttp;
}


/*-----------------------------------------------------------------------------
 * XMLHTTP method getDocument
 * AJAX request with XMLHTTPRequest
 *---------------------------------------------------------------------------*/
XMLHTTP.prototype.getDocument = function(URL) {
	// set the var so we can scope the callback
	var _this = this;

	// callback will be an anonymous function that calls back into our class
	// this allows the call back in which we handle the response (_onData())
	// to have the correct scope.
	this._request.onreadystatechange = function() { _this._callback() };
	/*function(){_this._onReadyStateChange()};*/
	//alert(URL);
	this._request.open("GET", URL, true);
	this._request.send(null);
}


/*-----------------------------------------------------------------------------
 * as a bonus, code example how to load an XML file on
 * disk and define callback function
 *---------------------------------------------------------------------------*/
 /*
function importXML(filename)
{
	if (document.implementation && document.implementation.createDocument) {
		
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = handleXML;

	} else if (window.ActiveXObject) {
	
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function () {
			if (xmlDoc.readyState == 4) handleXML()
		};
 	} else {
		alert('Your browser can\'t handle this script');
		return;
	}

	if (filename != undefined) {
	   xmlDoc.load(filename);
	}
}
*/

