var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var xmousepos = 0;
var ymousepos = 0;

function getMouseXY(e) {
	if (IE) { // grab the x-y pos.s if browser is IE
		xmousepos = event.clientX + document.body.scrollLeft;
		ymousepos = event.clientY + document.body.scrollTop;
	}
	else {  // grab the x-y pos.s if browser is NS
		xmousepos = e.pageX;
		ymousepos = e.pageY;
	}  
	if (xmousepos < 0){xmousepos = 0;}
	if (ymousepos < 0){ymousepos = 0;}  

	//Adjust them a little, for the purpose of making ToolTip hover to bottom right of cursor.
	xmousepos = xmousepos + 20;
	//ymousepos = ymousepos + 20;
}

var ToolTip=document.createElement("div");
function ShowToolTip(heading,text) {	
	var dvHdr=document.createElement("div");
	dvHdr.innerHTML = '';
	var dvBdy=document.createElement("div");
	dvHdr.innerHTML = '';

	ToolTip.innerHTML = '';

	//ToolTip.appendChild(dvHdr);
	ToolTip.appendChild(dvBdy);

	ToolTip.style.position="absolute";
	ToolTip.style.visibility='visible';
	ToolTip.style.zIndex="100000"
	document.body.appendChild(ToolTip);	

	dvHdr.innerHTML = heading;
	dvHdr.style.fontWeight='bold';
	//dvHdr.style.width='';
	dvHdr.style.fontFamily='arial';
	dvHdr.style.border='1px solid #A5CFE9';
	dvHdr.style.padding='3';
	dvHdr.style.fontSize='11';
	dvHdr.style.color='#4B7A98';
	dvHdr.style.background='#D5EBF9';
	/*dvHdr.style.filter='alpha(opacity=85)';*/ // IE
	/*dvHdr.style.opacity='0.85';*/ // FF

	dvBdy.innerHTML= text;

	dvBdy.style.borderTop='1px solid #A5CFE9';
	dvBdy.style.borderBottom='1px solid #A5CFE9';
	dvBdy.style.borderLeft='1px solid #A5CFE9';
	dvBdy.style.borderRight='1px solid #A5CFE9';
	//dvBdy.style.width='100px';
	dvBdy.style.fontFamily='arial';
	dvBdy.style.fontSize='11';
	dvBdy.style.padding='3';
	dvBdy.style.color='#1B4966';
	dvBdy.style.background='#FFFFFF';
	//dvBdy.style.filter='alpha(opacity=85)'; // IE
	//dvBdy.style.opacity='0.85'; // FF

	ToolTip.style.left = xmousepos;
	ToolTip.style.top = ymousepos;
}

function UpdateToolTip() {
	if (ToolTip) {
		ToolTip.style.left = xmousepos;
		ToolTip.style.top = ymousepos;
	}
}

function HideToolTip() {
	if (ToolTip) {
		ToolTip.style.visibility = 'hidden';

		try {
			document.body.removeChild(ToolTip);
		} catch (e) {
			//alert(e);

			//Do nothing
			//Not sure why there's the occasional exception error here on this removeChild statement, but 
			//it appears to be due to the very quick addition/removal of a child object, during each mouseover/mouseout and 
			//the browser sometimes gets confused. So we catch and store it anyway, to avoid the error icon in the browser.
			//No functionality is lost by this error.
		}
	}
}





//**************************************************************************************************
// RS. 
// showLocationLayer handler. Use this function to display/hide location selection popups on YourGuide & Life Is Local.
//
// REQUIRED PARAMETERS:
//
// - LayerID - the ID of the particular DIV to be displayed, e.g. "NSW"
//
// - VisibleLayerType - the type of layer we're displaying (e.g. "weather" or "state")
//
// - HiddenLayerType - the type of layer we're hiding (e.g. "weather" or "state"). For example, Life Is Local has 
// both State and Weather popups. So if the user clicks a state, all weather layers must also be hidden (and vice versa).
// If unnecessary, pass this value as an empty string. 
//
// - AdName - Sometimes an Ad on the page needs to be hidden when the popup appears, or else 
// it overlays the popup (e.g. when it's a Flash Ad). In that case, put a DIV around the ad, give the DIV an ID, 
// and pass that ID here in this parameter). If unnecessary, pass this value as an empty string.
//
// - AdAction - the action (hidden or visible) of the Ad. Only required if AdName is passed, otherwise pass this value as 
// an empty string.
//
// OPTIONAL PARAMETERS:
//
// - PosX - COMPLETELY OPTIONAL. If a value is passed, the layer's X position will be adjusted accordingly. If unnecessary
// do not pass this parameter at all - it's absence will be ignored.
//**************************************************************************************************
function showLocationLayer(LayerID, VisibleLayerType, HiddenLayerType, AdName, AdAction, PosX) { 
	var i;
	var MyShowState;
	var MyHideState;
	var MyAd;
	var MyHideSelect;

	//Find and hide/display ads with z-index issues, as required.
	if (AdName != '') {
		MyAd = document.getElementById(AdName);
		if (MyAd) {
			MyAd.style.visibility = AdAction;
		}
	}

	if (document.all)
	{
		// IE browsers.
		var aDivCollection = document.all.tags("div");
		var aSelectCollection = document.all.tags("select");
	}
	else
	{
		//Mozilla browsers.
		var aDivCollection = document.getElementsByTagName("div"); 
		var aSelectCollection = document.getElementsByTagName("select");
	}

	//Find and hide all select tags on the page.
	if (aSelectCollection!=null) {
		for (i=0; i<aSelectCollection.length; i++) 
		{
			if (aSelectCollection[i].id) {
				if (document.getElementById(aSelectCollection[i].id)) {
					MyHideSelect = document.getElementById(aSelectCollection[i].id);
					MyHideSelect.style.visibility = 'hidden';
				}
			}
		}
	}



	if (aDivCollection!=null)
	{
			
		for (i=0; i<aDivCollection.length; i++) 
		{
			//Make sure all location layers prefixed by <HiddenLayerType> are hidden.
			if ((HiddenLayerType!=null) && (HiddenLayerType != '')) {
				if (aDivCollection[i].id.indexOf(HiddenLayerType) != -1)  //Is the word <HiddenLayerType> part of the current DIV tag's ID? Let's hide all DIVs that start with whatever the parameter says.
				{
					MyHideState = document.getElementById(aDivCollection[i].id);
					MyHideState.style.visibility = 'hidden';
				}
			}

			if (aDivCollection[i].id.indexOf(VisibleLayerType) != -1)  //Is the word <VisibleLayerType> part of the current DIV tag's ID? Only mess with DIVs that start with whatever the parameter says.
			{	
				//alert(LayerID);
				if (aDivCollection[i].id == VisibleLayerType + "_" + LayerID)
				{
					// Found the item we want to display.
					MyShowState = document.getElementById(VisibleLayerType + "_" + LayerID);
					
					MyShowState.style.visibility = 'visible';
					if (PosX!=null) {
						MyShowState.style.left = PosX;
					}
				}
				else {
					// All other items are hidden.
					MyHideState = document.getElementById(aDivCollection[i].id);
					MyHideState.style.visibility = 'hidden';
				}
			}
		}
	}
}



//****************************************************************************************************
// RS. 
// HideAllLocationLayers handler. Use this function to hide location selection popups on YourGuide & Life Is Local, when clicking
// any other part of the screen.
//
// REQUIRED PARAMETERS:
//
// - HiddenLayerType1 - the type of layer we're hiding (e.g. "weather" or "state"). For example, Life Is Local has 
// both State and Weather popups. 
//
// - AdName - If an Ad on the page was hidden via the showLocationLayer function (above) and then the user hides the menu by 
// clicking any other part of the screen, then this function may need to re-display the Ad again. If unnecessary, pass this value 
// as an empty string.
//
// - AdAction - the action (should always be passed as 'visible') of the Ad. Only required if AdName is passed, otherwise pass this value as 
// an empty string.
//
// OPTIONAL PARAMETERS:
//
// - HiddenLayerType2 - for use if a second type of layer is used on the page. If unnecessary
// do not pass this parameter at all - it's absence will be ignored.
//*****************************************************************************************************

var bOverMenu;
bOverMenu = false;

function HideAllLocationLayers (HiddenLayerType1, HiddenLayerType2, AdName, AdAction) {
	var i;
	if (bOverMenu==false) {

		//Find and hide/display ads with z-index issues, as required.
		if (AdName != '') {
			MyAd = document.getElementById(AdName);
			if (MyAd) {
				MyAd.style.visibility = AdAction;
			}
		}


		//Find all layers of whatever types were specified, and hide them

		if (document.all)
		{
			// IE browsers.
			var aDivCollection = document.all.tags("div");
			var aSelectCollection = document.all.tags("select");
		}
		else
		{
			//Mozilla browsers.
			var aDivCollection = document.getElementsByTagName("div"); 
			var aSelectCollection = document.getElementsByTagName("select"); 
		}

		//Find and display all select tags on the page.
		if (aSelectCollection!=null) {
			for (i=0; i<aSelectCollection.length; i++) 
			{
				if (aSelectCollection[i].id) {
					if (document.getElementById(aSelectCollection[i].id)) {
						MyHideSelect = document.getElementById(aSelectCollection[i].id);
						MyHideSelect.style.visibility = 'visible';
					}
				}
			}
		}


		if (aDivCollection!=null)
		{
			for (i=0; i<aDivCollection.length; i++) 
			{
				//Make sure all location layers prefixed by <HiddenLayerType1> are hidden.
				if ((HiddenLayerType1!=null) && (HiddenLayerType1 != '')) {
					if (aDivCollection[i].id.indexOf(HiddenLayerType1) != -1)  //Is the word <HiddenLayerType> part of the current DIV tag's ID? Let's hide all DIVs that start with whatever the parameter says.
					{
						MyHideState = document.getElementById(aDivCollection[i].id);
						MyHideState.style.visibility = 'hidden';
					}
				}

				//Make sure all location layers prefixed by <HiddenLayerType2> are hidden.
				if ((HiddenLayerType2!=null) && (HiddenLayerType2 != '')) {
					if (aDivCollection[i].id.indexOf(HiddenLayerType2) != -1)  //Is the word <HiddenLayerType> part of the current DIV tag's ID? Let's hide all DIVs that start with whatever the parameter says.
					{
						MyHideState = document.getElementById(aDivCollection[i].id);
						MyHideState.style.visibility = 'hidden';
					}
				}
			}
		}
	}
}

