// Global variables for dynamic content loading

var xmlhttp;
var dynObjID;

// Fade-in/over functions
// Adapted for cross-browser compatibility on 22/05/2008
// by using opacity loop instead of blendtrans filter (IE only) method

function setOpacity(objID, opac)
{
	theObjStyle=document.getElementById(objID).style; 
	theObjStyle.opacity = (opac / 100);
	theObjStyle.MozOpacity = (opac / 100);
	theObjStyle.KhtmlOpacity = (opac / 100);
	theObjStyle.filter = "alpha(opacity=" + opac + ")";
}

function fadeObj(objID, fadeTime, opacStart, opacEnd)
{
	fadeSpeed = Math.round(fadeTime / 100);
	timer = 0;

	if(opacStart > opacEnd)
	{
		for(i = opacStart; i >= opacEnd; i--)
		{
			setTimeout("setOpacity('" + objID + "', " + i + ")",(timer * fadeSpeed));
			timer++;
		}
	}
	else if(opacStart < opacEnd)
	{
		for(i = opacStart; i <= opacEnd; i++)
		{
			setTimeout("setOpacity('" + objID + "', " + i + ")",(timer * fadeSpeed));
			timer++;
		}
	}
}

function fadeObjIn(objID, fadeSec)
{
	fadeObj(objID, fadeSec * 1000, 0, 100);
}

function fadeObjOut(objID, fadeSec)
{
	fadeObj(objID, fadeSec * 1000 , 100, 0);
}

function delayScript(delayTime, actionScript)
{
	setTimeout(actionScript, delayTime * 1000);
}

// Dynamic content loading functions
// Extended for cross-browser compatibilty on 21/05/2008
// with the introduction of the createXMLHttp() method

function createXMLHttp()
{
	if (typeof XMLHttpRequest != "undefined")
	{
	        return new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{
		var aVersions = [ "MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];

		for (var i = 0; i < aVersions.length; i++) 
		{
			try
			{
				var oXmlHttp = new ActiveXObject(aVersions[i]);
				return oXmlHttp;
			}
			catch (oError)
			{
		            //Do nothing
			}
		}
	}

	throw new Error("Dynamic page cannot be loaded - XMLHttp object could not be created.");
}

function loadPage(objID, pageUrl)
{
	dynObjID = objID;

	fadeObj(dynObjID, 500, 100, 0);

	xmlhttp = createXMLHttp();
	xmlhttp.onreadystatechange = receivePage;
	xmlhttp.open("GET", pageUrl, true);
	xmlhttp.send(null);

	return false;
}

function receivePage()
{
	if (xmlhttp.readyState == 4)
	{
		if ((xmlhttp.status == 200) || (xmlhttp.status == 0))
		{
			setTimeout('showPage()', 500);
		}
	}
}

function showPage()
{
	theObj=document.getElementById(dynObjID);
	theObj.innerHTML = xmlhttp.responseText;
	fadeObj(dynObjID, 500, 0, 100);
}

