function XMLHttpRequestObject(beforeCallback,
                              afterCallback,
                              parseCallback,
                              url,
                              postContent,
                              username,
                              password)
{
	this.beforeCallback = beforeCallback;
	this.afterCallback = afterCallback;
	this.parseCallback = parseCallback;
	this.wait = false;
	this.requestObj = null;
	this.username = username || "";
	this.password = password || "";
	
	try
	{
		this.requestObj = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		try
		{
			this.requestObj = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (ee)
		{
			this.requestObj = null;
		}
	}
	
	if (!this.requestObj && typeof(XMLHttpRequest) != "undefined")
	{
		this.requestObj = new XMLHttpRequest();
	}
	
	if (url)
	{
		this.send(url, postContent);
	}
}

XMLHttpRequestObject.prototype.send = function(url, postContent, forceReset)
{
	if (this.wait && !forceReset)
	{
		return false;
	}
	
	this.wait = true;
	
	if (this.beforeCallback)
	{
		this.beforeCallback();
	}
	
	try
	{
		this.requestObj.open(postContent ? 'POST' : 'GET', url, true, this.username, this.password);
		
		/**
		 * What is happening here?
		 */
		
		var object = this;
		
 		this.requestObj.onreadystatechange = function() {
			return object.handleResponse.apply(object);
		};
		
		if (postContent)
		{
			this.requestObj.setRequestHeader("Content-type",
			                                 "application/x-www-form-urlencoded");
			this.requestObj.setRequestHeader("Content-length",
			                                 postContent.length);
			this.requestObj.setRequestHeader("Connection", "close");
		}
		
		this.requestObj.send(postContent);
	}
	catch (e)
	{
		return false;
	}
	
	return true;
};

XMLHttpRequestObject.prototype.handleResponse = function()
{
	if (this.requestObj.readyState == 4)
	{
		this.wait = false;
		
		if (this.afterCallback)
		{
			this.afterCallback(this.requestObj);
		}
		
		if (this.requestObj.status != 200)
		{
			return;
		}
		
		if (!this.requestObj.responseXML ||
			typeof(this.requestObj.responseXML) == "undefined")
		{
			return;
		}

		if (this.parseCallback)
		{
		 	var xmlDoc = this.requestObj.responseXML;
		    
      		try
      		{
      			if(xmlDoc) 
		 		{
        			this.parseCallback(xmlDoc);
      			}
      		}
      		catch (e)
			{
				//for FF, some third part js (My Space) block us from sharing the same responseXML with permission denied.
				//So we create DOM from reponseText instead.
				if (window.DOMParser) 
		 		{
          			var oParser = new DOMParser();
          			xmlDoc = oParser.parseFromString(this.requestObj.responseText, "text/xml");
          		}
          		this.parseCallback(xmlDoc);
			}
			
		}
	}
};
