aRequests = new Array();

/*
	params:
	- sDataToSend
	- sURL
	- sRequestType
	- bAsync
	- fResponseHandler
	- fErrorHandler
	- hHeaders
	- iTimeout
*/
function XMLRequest(hOptions) {
	var oThis = this;
	this.sID = hOptions.sID;
	this.sDataToSend = hOptions.sDataToSend;
	this.sURL = hOptions.sURL;

	this.sRequestType = (hOptions.sRequestType || 'GET');
	this.bAsync = (hOptions.bAsync || true);
	this.fResponseHandler = hOptions.fResponseHandler;
	this.fErrorHandler = hOptions.fErrorHandler;
	this.hHeaders = hOptions.hHeaders;
	this.bIsLoaded = false;

	/* timeout in seconds */
	this.iTimeout = (hOptions.iTimeout || 60);

	/* creating request object */
	if (window.XMLHttpRequest) {
		this.oRequest = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		try {
			this.oRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (err) {
			try {
				this.oRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (err2) {
				this.oRequest = false;
			}
		}
	}
	
	return this;
}

XMLRequest.prototype.exec = function() {
	if (this && this.oRequest) {
		var oThis = this;
		var sDataToSend = null;
		if (this.sDataToSend && this.sDataToSend != '') {
			this.sRequestType = 'POST';
			sDataToSend = this.sDataToSend;
		}
		this.oRequest.open(this.sRequestType, this.sURL, this.bAsync);
		this.oRequest.onreadystatechange = function() { oThis.readyStateChange(oThis) }
		this.oRequest.send(sDataToSend);
	}
}

XMLRequest.prototype.readyStateChange = function(oXMLRequest) {
	if (oXMLRequest && oXMLRequest.oRequest) {
		if (oXMLRequest.oRequest.readyState == 4 && oXMLRequest.fResponseHandler) {
			oXMLRequest.fResponseHandler(oXMLRequest.oRequest.responseXML);
		}
		oXMLRequest.bIsLoaded = true;
//		alert(oXMLRequest.oRequest.readyState)
	}
}

/*
	XMLHandler
	errors:
	- request not supported
	- timeout
	- status not 200
*/
