
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!");
																		return false;
													}
									}
		}
			if(xmlObject){return xmlObject;}
				else{xmlObject = null; return false;}
}
 
function sendAjaxGetResponse(submitMethod,url,data){
  return processXMLState(sendAjax(submitMethod,url,false,data));
}
   
function sendAjaxWithCallBack(submitMethod,url,data,aFunction){
    var xmlObject = sendAjax(submitMethod,url,true,data);
    if(aFunction){xmlObject.onreadystatechange = function(){aFunction(xmlObject);};}	
}
     
function sendAjax(submitMethod,url,async,data)
{
	if(async !== false && empty(async)){async = true;}
	var xmlObject = createAjaxObject();
	
	if(xmlObject)
	{
		
		if(!data){data = null;}
		xmlObject.open(submitMethod, url, async);
		xmlObject.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				
		if(submitMethod == "GET" || !data){xmlObject.send(null);}
		else if(submitMethod == "POST"){
			xmlObject.setRequestHeader('Content-length', data.length);
			xmlObject.send(data);
		}
		return xmlObject;
	}
	xmlObject = null;
}

function processXMLState(xmlObject){	
	if (xmlObject.readyState == 4){
		if(xmlObject.status == 200) {return xmlObject.responseText;} 
		else{document.write('There was a problem retrieving the XML data: ' + xmlObject.responseText);}
		xmlObject = null;
	}
}

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)){aFunction(xmlObject);}						
		}
	}
	else{
		document.getElementById(element).innerHTML = "<img src=\"skins/default/images/ajax-loader.gif\">";
		sendAjaxWithCallBack(submitMethod,url,'',function(xmlObject){ajaxWithWaitingScreen(xmlObject,null,null,aFunction,element,1);});	
	}
	xmlObject = null;
}
