/// XmlHttp Singleton Class
///	Written By: Matthew Gaddis <matthew_gaddis@yahoo.com>
/// Created: 2005-01-07

var XmlHttp =
{
	isIE: false,
	req: [],
	spawn: function(strObjectTarget, intIndex)
	{
		var index = (intIndex != null) ? intIndex : this.req.length;
		
		if (window.XMLHttpRequest) 
		{
			this.req[index] = new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{
			this.isIE = true;
			this.req[index] = new ActiveXObject("Microsoft.XMLHTTP");
		}
		if (this.req[index]) 
		{
			return this.applyReadyChangeState(strObjectTarget, index);
		}
		else
			return -1;
	},
	get: function(strObjectTarget)
	{
		var index = null;
		
		for(var i = 0; i < this.req.length; i++)
		{
			switch(this.req[i].readyState)
			{
				case 0:
				case 4:
					//At this point I tried to recycle the object
					//however in IE the readyState of the request stuck
					//and would not accept new requests
					//so the result was to respawn the request object... yuck
					index = this.spawn(strObjectTarget, i);
					break;
			}
			if(index != null)
				break;
		}
		
		if(index == null)
			index = this.spawn(strObjectTarget);
		
		return index;
	},
	applyReadyChangeState: function(strObjectTarget, intIndex)
	{
		this.req[intIndex].onreadystatechange = function() { eval(strObjectTarget + '.prototype.processHTTPRequestChange(' + intIndex + ')'); };
		
		return intIndex;
	}
}