/******** AJAX code starts here   ******/
function NS_GetXMLHttpRequest() 
{
	if (window.XMLHttpRequest) 
	{
		return new XMLHttpRequest();
	} else 
	{
		var progIDs = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
		for (var i = 0; i < progIDs.length; ++i) 
		{
			var progID = progIDs[i];
			try 
			{
				var x = new ActiveXObject(progID);
				window.Anthem_XMLHttpRequestProgID = progID;
				return x;
			} catch (e) 
			{
			}
		}
	}
	return null;
}
// To Call any method of an ASPX page having its "Custom Attribute" set
// reqPage:			Page Class containing method including namespace (case sensitive) e.g ea.TestPage
// reqMethod:		specific Method name to which you want to call (case sensitive)
// methodArgs:		Array containing arguments/parameters for the Method
// methodCallBack:	Javascript function whihc will recieve the "Response Text" from calling method e.g function fun(text){ }
function sendAjaxRequest(reqPage,reqMethod,methodArgs,methodCallBack)
{
	var reqObj;
	var requestData = "";
	reqObj = NS_GetXMLHttpRequest();
	if (reqObj)
	{
		reqObj.open("POST", "/AJAXServer.aspx",true);
		reqObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
		reqObj.onreadystatechange = function()
									{
										if (reqObj.readyState == 4)
										{
											if(reqObj.status == 200)
											{
												if(methodCallBack)
												{
													methodCallBack(reqObj.responseText);
												}
											}
											else
											{
												alert("Page not found.\nStatus: "+reqObj.status);
											}
											reqObj = null;
										}
									};
		requestData += "Page=" + reqPage;
		requestData += "&Method=" + reqMethod;
		if (methodArgs)	
		{
			for (var argsIndex = 0; argsIndex < methodArgs.length; ++argsIndex) 
			{	// Concatinating "method arguements" in HTTP Request
				requestData += "&Args" + argsIndex + "=" + encodeURIComponent(htmlEncode(methodArgs[argsIndex]));	// encoding arguments to have them correct on the other side
			}
		}
		reqObj.send(requestData);
	}
	
	function htmlEncode(s)
	{
	var str = new String(s);
	str = str.replace(/&/g, "&amp;");
	str = str.replace(/</g, "&lt;");
	str = str.replace(/>/g, "&gt;");
	str = str.replace(/"/g, "&quot;");
	return str;
	}
}
/******** AJAX code ENDS here   ******/
