var xmlHttp;
var actions = new Array();
var handlers = new Array();
var currentAction = 0;
function createXMLHttpRequest()
{
	if (window.ActiveXObject)
	{
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		xmlHttp = new XMLHttpRequest();
	}
}
var xmlHttp1;
function createXMLHttpRequest1()
{
	if (window.ActiveXObject)
	{
		xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		xmlHttp1 = new XMLHttpRequest();
	}
}
function getXMLHttpRequest()
{
	var oXmlHttp;
	if (window.ActiveXObject)
	{
		oXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		oXmlHttp = new XMLHttpRequest();
	}
	return oXmlHttp;
}
function createXMLDOM()
{
	var arrSigs = ["MSXML2.DOMDocument.6.0", "MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0", 
				   "MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument", "Microsoft.XmlDom"];
	
	var oXmlDom;			   
	for (var i=0; i< arrSigs.length; i++)
	{
		try
		{
			oXmlDom = new ActiveXObject(arrSigs[i]);
			return oXmlDom;
		}
		catch (oError){}
	}
	//throw new Error("MSXML is not installed on your system.");
	oXmlDom = document.implementation.createDocument("", "", null);
	
	if (!oXmlDom)
		throw new Error("No xml support is installed on your system.");
	else
		return oXmlDom;

}
function SendRequest(url, formAction, formData)
{
	try
	{
		if (StartActivityLoop)
			StartActivityLoop(document.getElementById("divActivity"));
	}
	catch (ex) {}

	url = url + "&timeStamp=" + new Date().getTime();
	createXMLHttpRequest();
	xmlHttp.open(formAction, url, true);
	xmlHttp.onreadystatechange = RequestHandler;
	xmlHttp.send(formData);
}
function RequestHandler()
{
	if (xmlHttp.readyState == 4)
	{
		try
		{
			if (CancelActivityLoop)
				CancelActivityLoop();
		}
		catch (ex) {}
	
	    var XDoc;
		if (xmlHttp.status == 200)
		{	
		    try {
			    XDoc = xmlHttp.responseXML;
			    var eNode = XDoc.getElementsByTagName("Error")[0];
			    if (eNode)
			    {
				    window.alert(eNode.firstChild.nodeValue);
				    ClearActions();
				    return;
			    }
                eNode = XDoc.getElementsByTagName("Message")[0];
                if (eNode)
                {
                    window.alert(eNode.firstChild.nodeValue);
                }
			}
			catch(ex) {};

			if (handlers[currentAction])
				handlers[currentAction](XDoc);
				
			currentAction++;
			
			if (actions[currentAction])
			{
				actions[currentAction]();
				if (!handlers[currentAction])
				{
					ClearActions();
				}
			}
			else
			{
				ClearActions();
			}
		}
		else
		{
			window.alert(xmlHttp.status + " error processing request.");
		}
	}
}
function ClearActions()
{
	actions.length = 0;
	handlers.length = 0;
	currentAction = 0;
}
function EmptyHandler()
{
	return;
}
function ProcessStack()
{
	currentAction = 0;
	actions[0]();
}

