var xmlHttp

function ahah(url, target,postFunc,text)
{
    if(text=='')
	document.getElementById(target).innerHTML = '<img src="http://www.maxadventure.com.au/images/loading.gif"/>';
    else
	document.getElementById(target).innerHTML = text;
        if (!postFunc)
		if (!window.postFunc) postFunc = function () {};

	xmlHttp=GetXmlHttpObject()
	if (xmlHttp != undefined) 
	{
		xmlHttp.onreadystatechange = function() {ahahDone(url, target, postFunc);};
		xmlHttp.open("GET", url, true);
		xmlHttp.send("");
	}
}  

function ahahDone(url, target, postFunc) 
{
	if (xmlHttp.readyState == 4) // only if req is "loaded"
	{
		if (xmlHttp.status == 200) // only if "OK"
		{ 
			document.getElementById(target).innerHTML = xmlHttp.responseText;
			postFunc();
		} 
		else 
		{
			document.getElementById(target).innerHTML +="ahah error:\n"+ xmlHttp.status + "\n"+xmlHttp.statusText;
		}
	}
}

function GetXmlHttpObject()
{ 
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}	

function doShowDivDetails(divName, iFrame, e)
{
	var DivRef = document.getElementById(divName);
	var IfrRef = document.getElementById(iFrame);
	var iPosX, iPosY;
	if (!e)
	{
		iPosX = window.clientX;
		iPosY = window.clientY;
	}
	else
	{
		iPosX = e.clientX;
		iPosY = e.clientY;
	
	}	
	if (DivRef.style.visibility == 'hidden')
	{
		DivRef.style.display = 'block';
		DivRef.style.visibility = 'visible';
		DivRef.style.top = iPosY;
		DivRef.style.left = iPosX;

		IfrRef.style.display = 'block';
		IfrRef.style.width = parseInt(DivRef.offsetWidth,10) + 'px'; //DivRef.offsetWidth;
		IfrRef.style.height = parseInt(DivRef.offsetHeight,10) + 'px';
		IfrRef.style.top = DivRef.style.top;
		IfrRef.style.left = DivRef.style.left;
		IfrRef.style.zIndex = DivRef.style.zIndex - 1;
	}
	else
	{
		DivRef.style.display = "none";			
		DivRef.style.visibility = "hidden";
		IfrRef.style.display = "none";
	}
}	
function doGetEvents()
{
    oCalendar = document.getElementById('ajaxcalendar');
    if (oCalendar)
    {
        oCalendar.innerHTML = '';
        ahah('common/maxajax.php?process=eventdates','ajaxcalendar','','<div style="text-align:center;padding:50px 0;width:100%"><img src="http://www.maxadventure.com.au/images/loading.gif"/></div>');
    }
    oUpcomingEvents = document.getElementById('upcomingevents');
    if (oUpcomingEvents)
    {
        oUpcomingEvents.innerHTML = '';
        ahah('common/maxajax.php?process=upcomingevents','upcomingevents','','<div style="text-align:center;padding:50px 0;width:100%"><img src="http://www.maxadventure.com.au/images/loading.gif"/></div>');
    }
}

