var http_xml_gateway;
var arr_gateway_queue = new Array();
var bool_gateway_executing = false;
var fn_gateway_callback;

function execute_http_request(url, callback)
{
	arr_gateway_queue[arr_gateway_queue.length] = new queue_item(url, callback);

	if (!bool_gateway_executing)
	{
		// load the first queue item
		start_gateway_execution();
	}

}

function gateway_callback()
{
	if (http_xml_gateway.readyState == 4)
	{
		if (http_xml_gateway.status == 200)
		{
			if (fn_gateway_callback)
			{
				fn_gateway_callback();
			}
			
			start_gateway_execution();
		}
	}
}

function start_gateway_execution()
{
	if (arr_gateway_queue.length == 0)
	{
		bool_gateway_executing = false;
		return;
	}
	
	bool_gateway_executing = true;

	var o = arr_gateway_queue.shift();
	
	if (o.url)
	{
		// forced reset of object
		http_xml_gateway = null;
		
		/*@cc_on @*/
		/*@if (@_jscript_version >= 5)
		try
		{
			http_xml_gateway = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				http_xml_gateway = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (E)
			{
				http_xml_gateway = false;
			}
		}
		@end @*/


		if (!http_xml_gateway && typeof(XMLHttpRequest) != 'undefined')
		{
			http_xml_gateway = new XMLHttpRequest();
		}
		
		fn_gateway_callback = o.callback;
		
		http_xml_gateway.onreadystatechange = gateway_callback;
		http_xml_gateway.open("GET", o.url);
		http_xml_gateway.setRequestHeader('Content-Type', 'text/xml');
		http_xml_gateway.setRequestHeader("MessageType", "CALL");
		http_xml_gateway.send("");
	}
	else
	{
		fn_gateway_callback = o.callback;
		gateway_callback();
	};
}

function queue_item(url, callback)
{
	this.url = url;
	this.callback = callback;
}