// Script: macdsite.js
// Summary: Shared JavaScript functions for main portal web site
// Dependencies: dw_event.js, js/dw_viewport.js and js/dw_tooltip.js (tooltip)

// Wrapper functions for tooltip
function macdsite_doToolTip(e, msg)
{
	if ( typeof dw_Tooltip == "undefined" || !dw_Tooltip.ready ) return;
	if (dw_Tooltip.ovTimer) clearTimeout(dw_Tooltip.ovTimer);
	dw_Tooltip.ovTimer = setTimeout("dw_Tooltip.toggleOverlay(" + 1 + ")", 200);
	dw_Tooltip.show(e, msg);
}
function macdsite_hideToolTip()
{
	if ( typeof dw_Tooltip == "undefined" || !dw_Tooltip.ready ) return;
	if (dw_Tooltip.ovTimer) clearTimeout(dw_Tooltip.ovTimer);
	dw_Tooltip.ovTimer = setTimeout("dw_Tooltip.toggleOverlay(" + 0 + ")", 200);
	dw_Tooltip.hide();
}


// Summary: Initialise tooltip and overlay
// Remarks: Called at end of document
function macdsite_initToolTip ()
{
	dw_Tooltip.init();
	macdsite_initToolTipOverlay();
}


// Creates additional IFrame to position below tooltip and prevent form elements
// from showing in front of tooltip
// Remarks: Positioned at end of document so that IFrame added to end
function macdsite_initToolTipOverlay ()
{
	dw_Tooltip.ovTimer = 0;
	dw_Tooltip.followMouse = false;
	// check need for and support of iframe shim
	dw_Tooltip.supportsOverlay = typeof document.body != "undefined" &&
		typeof document.body.insertAdjacentHTML != "undefined" &&
		!window.opera && navigator.appVersion.indexOf("MSIE 5.0") == -1;

	// tipFollowMouse set true by default, so we need to move iframe shim with mouse movement
	dw_Tooltip.trackMouse = function(e) {
		e = dw_event.DOMit(e);
		dw_Tooltip.positionTip(e);
		if (dw_Tooltip.shim) {
		dw_Tooltip.shim.style.left = dw_Tooltip.tip.style.left;
		dw_Tooltip.shim.style.top = dw_Tooltip.tip.style.top;
		}
	}

	// called from doTooltip and hideTip
	dw_Tooltip.toggleOverlay = function(bVis) {
		if ( dw_Tooltip.supportsOverlay ) {
		if ( !document.getElementById('tipShim') )
			document.body.insertAdjacentHTML("beforeEnd", "<iframe id='tipShim' src='https://www.macdonald-hotels.co.uk/blank.html' style='position:absolute; left:0; top:0; z-index:500; visibility:hidden' scrolling='no' frameborder='0'></iframe>");
		dw_Tooltip.shim = document.getElementById('tipShim');
		if (dw_Tooltip.shim) {
			switch (bVis) {
			case 1 :
				dw_Tooltip.shim.style.left = dw_Tooltip.tip.style.left;
				dw_Tooltip.shim.style.top = dw_Tooltip.tip.style.top;
				dw_Tooltip.shim.style.width = dw_Tooltip.tip.offsetWidth + "px";
				dw_Tooltip.shim.style.height = dw_Tooltip.tip.offsetHeight + "px";
				dw_Tooltip.shim.style.visibility = "visible";
			break;
			case 0 :
				dw_Tooltip.shim.style.visibility = "hidden";
				dw_Tooltip.shim = null;
			break;
			}
		}
		}
	}
}

	

// Purpose: Indicates whether Flash headers are enabled
// Remarks: DHTML menu displays sub-options beneath Flash movies in older browsers
function macdsite_isFlashHeaderEnabled() {
	// Asks for browser checking .. please?
	var bc;
	bc = new macdsite_browserCheck();
	if (bc.ie5up == true || bc.nav7up == true) {
		alert("ie5up: "+bc.ie5up+"       nav7up: "+bc.nav7up);
	}
	
	// Look in EDIT file for more info.
}

// Purpose: Checks for browser version better than IE5+ and NS7+
function macdsite_browserCheck() {
	var agt = navigator.userAgent;
	
	// MSIE Test
	this.ie			= ((agt.indexOf("MSIE") != -1) && (agt.indexOf("Opera") == -1));
  this.ie3		= (this.ie && (this.major < 4));
  this.ie4		= (this.ie && (this.major == 4) && (agt.indexof("MSIE 4") != -1) );
	this.ie5up	= (this.ie && !this.ie3 && !this.ie4);

	// Netscape Test
	this.moz = ((agt.indexOf('Mozilla') != -1) && (agt.indexOf('Spoofer') == -1) && (agt.indexOf('Compatible') == -1) && (agt.indexOf('Opera') == -1) && (agt.indexOf('WebTV') == -1) && (agt.indexOf('HotJava') == -1));
	this.major = parseInt(navigator.appVersion);

	this.nav6		= (this.moz && (this.major == 5) && (agt.indexOf("Netscape6/6") != -1));
  this.nav6up	= (this.moz && (this.major >= 5) && (agt.indexOf("Netscape") != -1));
	this.nav7up	= (this.nav6up && !this.nav6);
};


// Purpose: Directs user to email.asp passing current url as parameter
function macdsite_emailThisPage ()
{
	var sThisPage = location.pathname;
	location.href = document.getElementById("basehref").getAttribute("href") + "email.asp?ID=" + sThisPage;
}


// Purpose: Redirects to url web site and appends querystring parameters.
// Parameters are picked up by JavaScript code in hotel web site header 
// so that link back to last Macdonald page is displayed in header
// Remarks: Appends items to querystring 
function macdsite_redirectToHotelURL (url, title)
{
	var strURL;
	
	strURL = url + '?macd_source_link=' + escape(window.document.location);
	if (title != undefined)
	{
		// Append title if defined
		strURL += '&macd_source_title=' + escape(title);
	}
	window.document.location = strURL;
}

