
function createAjaxObject()
{
	var xmlObject;
	
	try{xmlObject=new XMLHttpRequest();}
	catch (e)
	{
		// Internet Explorer
		
		try{xmlObject=new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e)
		{
			try{xmlObject=new ActiveXObject("Microsoft.XMLHTTP");}
			catch (e)
			{
				alert("Your browser does not support AJAX please contact your system administrator");
				return false;
			}
		}
	}
	if(xmlObject){return xmlObject;}
	else{return false;}
}
 
 function sendAjaxGetResponse(submitMethod,url)
 {
 	
 	var xmlObject = sendAjax(submitMethod,url,false);
 	return processXMLState(xmlObject);
 }
 
 function sendAjaxWithCallBack(submitMethod,url,aFunction)
 {
 	var xmlObject = sendAjax(submitMethod,url,true);
 	xmlObject.onreadystatechange = function(){eval(aFunction);};
	
 }
 
 function sendAjax(submitMethod,url,async)
 {
 	if(async !== false && empty(async)){async = true;}
 	var xmlObject = createAjaxObject();
 	
 	if(xmlObject)
 	{
		xmlObject.open(submitMethod, url, async);
		xmlObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlObject.send(null);
		return xmlObject;
	}
 }

function processXMLState(xmlObject)
{
	
	if (xmlObject.readyState == 4) 
	{
        	if(xmlObject.status == 200) {return xmlObject.responseText;} 
		else{alert('There was a system error, please contact your system administrator with error code 001: ' + xmlObject.responseText);}
    	}
}

function ajaxWithWaitingScreen(xmlObject,submitMethod,url,aFunction,element,state)
{
	if(state==1)
	{
		if(typeof(xmlObject.responseText)!="unknown" && xmlObject.readyState == 4 && xmlObject.status == 200)
    		{
			document.getElementById(element).innerHTML = "";
			if(!empty(aFunction)){eval(aFunction);}
		}
	}
	else
	{
		document.getElementById(element).innerHTML = "<img src=\"skins/default/images/ajax-loader.gif\">";
		var xmlObject = sendAjaxWithCallBack(submitMethod,url,"ajaxWithWaitingScreen(xmlObject,null,null,'" + aFunction + "','" + element + "',1);");	
	}
}
