// Common ajax functions
function getxmlHttp() // determines which xmlHttp response to use
{
	try
	{
		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;      
			}    
		}  
	}
	return xmlHttp;
}
function genAjax(url, chngdiv, loader)
{
  if (document.getElementById(chngdiv).style.display = "none")
  {
    document.getElementById(chngdiv).style.display = "";
  }
  
  var xmlHttp;
  xmlHttp = getxmlHttp();
  
  xmlHttp.onreadystatechange=function()
  {
		if (loader.length > 0)
		{
			if(xmlHttp.readyState==1)
			{document.getElementById(chngdiv).innerHTML = loader;}
    }
    if(xmlHttp.readyState==4)
    {
      document.getElementById(chngdiv).innerHTML=xmlHttp.responseText;
    }
  }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);  
}

function ChangeContent(url, setHashTo)
{
	genAjax(url, "content", "<img src='/images/indicator.gif' />");
	document.location.hash = setHashTo;
	return false;
}

function LoadFromUrl() /* Parses pseudo-querystrings */
{
	if ( /#/.test(document.location) )
	{
		var result = document.location.toString().match(/(https?:\/\/[^\/]+)\/(.+)?#(.+)/i);
		if (result[3].length>1)
		{
			document.location = result[3];
		}
	}
}
