/****** divName = area to display retrieved data
******* infoOne = $_GET info to send to php
******* infoTwo = $_GET info to send to php
******* url  = page to callback
*******/

function ajaxGETFunction(divName, infoOne, infoTwo, url)
{
	var xmlHttp;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState == 1)
		{
			document.getElementById(divName).innerHTML="Loading...<br /><img src='../images/ajax-loader.gif' />";
		}
		else if(xmlHttp.readyState == 2)
		{
			document.getElementById(divName).innerHTML="Loading...<br /><img src='../images/ajax-loader.gif' />";
		}
		else if(xmlHttp.readyState == 3)
		{
			document.getElementById(divName).innerHTML="Loading...<br /><img src='../images/ajax-loader.gif' />";
		}
		else if(xmlHttp.readyState == 4 || xmlHttp.readyState=="complete")
		{	
			document.getElementById(divName).innerHTML=xmlHttp.responseText;
			
			/** should try to avoid the below - should find a better way **/
			if(infoOne == 'delCat')
			{
				if(xmlHttp.responseText != 'error')
				{
					alert("Thank you your request has been completed");
					ajaxGETFunction('ajaxResponseCats', 'site_categories', xmlHttp.responseText, '../ajax_requests_responses/ajax_callback.php');
				}
				else
				{
					alert("There has been an error.\nIf this persists please contact an administrator")
				}
			}
		}
	}
	
	var fullUrl = url+"?infoOne="+infoOne+"&infoTwo="+infoTwo;
	
	xmlHttp.open("GET", fullUrl ,true);
	xmlHttp.send(null);
}
