//** Preload Images **//
var myimg = new Array();
function preloadimages() {
  for (i=0; i<preloadimages.arguments.length; i++) {
    myimg[i] = new Image();
    myimg[i].src = preloadimages.arguments[i];
  }
}
//preloadimages("interface/minimap_over.gif", "interface/button_cancelabooking_over.gif", "interface/button_checkavailability_over.gif", "interface/button_subscribe_over.gif", "interface/button_viewmap_over.gif");


//** emailThisPage **//
function emailThisPage() {
	var sThisPage = location.pathname;
	var newsite = "http://www.macdonaldhotels.co.uk"
	location.href = newsite+"/email.asp?ID=" + sThisPage;
	// document.getElementById("basehref").getAttribute("href") + "
}


//** setDefaultDates **//
if (document.forms['search']) {
	setDefaultDates(document.forms['search']);
}


//** Popup Window **//
function popUp(URL, popWidth, popHeight, popLeft, popTop, autoCenter) {
	day = new Date();
	id = day.getTime();
	if (autoCenter == 1) {
		var popLeft = (screen.width - popWidth) / 2;
		var popTop = (screen.height - popHeight) / 2;
	}
	eval("page"+id+" = window.open(URL, '"+id+"', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width="+popWidth+",height="+popHeight+",left="+popLeft+",top="+popTop+"');");
}

//** Popup NO SCROLLING Window **//
function popUpNS(URL, popWidth, popHeight, popLeft, popTop, autoCenter) {
	day = new Date();
	id = day.getTime();
	if (autoCenter == 1) {
		var popLeft = (screen.width - popWidth) / 2;
		var popTop = (screen.height - popHeight) / 2;
	}
	eval("page"+id+" = window.open(URL, '"+id+"', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+popWidth+",height="+popHeight+",left="+popLeft+",top="+popTop+"');");
}

function currentPage() {
	var prevLI = 0;
	if(document.getElementById("menu_items"))
	{
		menuUL = document.getElementById("menu_items");
		for(i=0;i<menuUL.childNodes.length;i++)
		{
			if(menuUL.childNodes[i].nodeName == 'LI')
			{
				menuLI = menuUL.childNodes[i];
				for(j=0;j<menuLI.childNodes.length;j++)
				{
					if(menuLI.childNodes[j].nodeName == 'A')
					{
						
						locat = location.href;
						myHref = menuLI.childNodes[j].href;
						firstSlash = 1 + locat.indexOf('/',9);
						firstSlash = 1 + locat.indexOf('/',(firstSlash));
						if(locat.indexOf('?') > 0)
						{
							locat = locat.substring(0,locat.indexOf('?'));
						}
						if((locat.length-1) == locat.lastIndexOf('/') && (myHref.length-1) != myHref.lastIndexOf('/'))
						{
							locat = locat + "index.htm";
						}
						if(locat.indexOf('business/', firstSlash) >= 0)
						{
							firstSlash = 1 + locat.indexOf('/', firstSlash);
						}
						if(locat.indexOf('/', (firstSlash)) > 0)
						{
							myHref = myHref.substring(0,myHref.lastIndexOf('/'));
							locat = locat.substring(0,locat.lastIndexOf('/'));
						}
						else
						{
							locat = locat.substring(0,myHref.length);
						}
						if(myHref == locat)
						{
						
							menuLI.className = "currentPage";
							if(prevLI != 0)
							{
								prevLI.className += " no_border";
							}
						}
					}
					if(menuLI.childNodes[j].nodeName == 'UL')
					{
						dropUL = menuLI.childNodes[j];
						for(k=0;k<dropUL.childNodes.length;k++)
						{
							if(dropUL.childNodes[k].nodeName == "LI")
							{
								dropLI = dropUL.childNodes[k];
								for(l=0;l<dropLI.childNodes.length;l++)
								{
									if(dropLI.childNodes[l].nodeName == "A")
									{
										locat = location.href;
										myHref = dropLI.childNodes[l].href;
										firstSlash = 1 + locat.indexOf('/',9);
										firstSlash = 1 + locat.indexOf('/',(firstSlash));
										if(locat.indexOf('?') > 0)
										{
											locat = locat.substring(0,locat.indexOf('?'));
										}
										if((locat.length-1) == locat.lastIndexOf('/') && (myHref.length-1) != myHref.lastIndexOf('/'))
										{
											locat = locat + "index.htm";
										}
										if(locat.indexOf('business/', firstSlash) >= 0)
										{
											firstSlash = 1 + locat.indexOf('/', firstSlash);
										}
										if(locat.indexOf('/', (firstSlash)) > 0)
										{
											myHref = myHref.substring(0,myHref.lastIndexOf('/'));
											locat = locat.substring(0,locat.lastIndexOf('/'));
										}
										else
										{
											locat = locat.substring(0,myHref.length);
										}
										if(myHref == locat)
										{

											menuLI.className = "currentPage";
											dropLI.className = "currentPage";
											if(prevLI != 0)
											{
												prevLI.className += " no_border";
											}
										}
									}
								}
							}
						}
					}
				}
				prevLI = menuLI;
			}
		}
	}
}

function dropmenu(menuItem) {
	var clickedLI = menuItem.parentNode.parentNode;
	var nextClass = "over"
	if(clickedLI.className == "over") { nextClass="down"; }
	var parentUL = menuItem.parentNode.parentNode.parentNode;
	for(i=0;i<parentUL.childNodes.length;i++)
	{
		if(parentUL.childNodes[i].nodeName == "LI")
		{
			parentUL.childNodes[i].className = "down";
			for(j=0;j<parentUL.childNodes[i].childNodes.length;j++)
			{
				if(parentUL.childNodes[i].childNodes[j].nodeName == "DIV" && parentUL.childNodes[i].childNodes[j].className == "offer_table")
				{
					if(parentUL.childNodes[i].childNodes[j].style.display == "block")
					{
						hiding = true;
						hidingDiv = parentUL.childNodes[i].childNodes[j];
						targetHeight = hidingDiv.offsetHeight;
						parentUL.childNodes[i].childNodes[j].style.height = targetHeight + "px"
						hideDiv(hidingDiv, targetHeight, 5);
					}
				}
			}
		}
	}
	clickedLI.className = nextClass;
	if(nextClass == "over")
	{
		for(i=0;i<clickedLI.childNodes.length;i++)
		{
			if(clickedLI.childNodes[i].nodeName == "DIV" && clickedLI.childNodes[i].className == "offer_table")
			{
				activeDiv = clickedLI.childNodes[i];
				clickedLI.childNodes[i].style.display = "block";
				targetHeight = clickedLI.childNodes[i].offsetHeight - 14;
				clickedLI.childNodes[i].style.overflow = "hidden";
				clickedLI.childNodes[i].style.height = "0px";
				revealDiv(activeDiv, targetHeight, 5);
			}
		}
	}
}

var activeDiv;
function revealDiv(myDiv, myHeight, timer)
{
	if(!hiding)
	{
		myDiv.style.display = "block";
		if(myDiv.offsetHeight < myHeight)
		{
			var currentHeight = myDiv.style.height;
			currentHeight = currentHeight.substring(currentHeight, (currentHeight.length-2));
			nextHeight = parseInt(currentHeight) + (myHeight / 8);
			if(nextHeight > myHeight)
			{
				myDiv.style.height = "100%";
				myDiv.style.overflow = "visible";
			}
			else
			{
				myDiv.style.height = nextHeight + "px";
				setTimeout("revealDiv(activeDiv, "+myHeight+", "+timer+")", timer);
			}
		}
		else
		{
			myDiv.style.height = "100%";
			myDiv.style.overflow = "visible";
		}
	}
	else
	{
		myDiv.style.display = "none";
		setTimeout("revealDiv(activeDiv, "+myHeight+", "+timer+")", timer);
	}
}

var hidingDiv;
var hiding = false;
function hideDiv(myDiv, hideHeight, timer)
{
	if(myDiv.offsetHeight > 0)
	{
		var currentHeight = myDiv.style.height;
		currentHeight = currentHeight.substring(currentHeight, (currentHeight.length-2));
		nextHeight = parseInt(currentHeight) - (parseInt(hideHeight) / 8);
		if(nextHeight < 0)
		{
			myDiv.style.display = "none";
			myDiv.style.height = "auto";
			hiding = false;
		}
		else
		{
			myDiv.style.height = nextHeight + "px";
			setTimeout("hideDiv(hidingDiv, "+hideHeight+", "+timer+")", timer);
		}
	}
	else
	{
		myDiv.style.display = "none";
		myDiv.style.height = "auto";
		hiding = false;
	}
}

function displayArea(menuItem, hide) {
	if(menuItem.parentNode.nodeName == "P")
	{
		var clickedLI = menuItem.parentNode.parentNode.parentNode;
		if(clickedLI.nodeName != "LI")
		{
			clickedLI = clickedLI.parentNode.parentNode;
		}
	}
	else
	var clickedLI = menuItem.parentNode.parentNode;
	var nextClass = "over"
	if(clickedLI.className == "over") { nextClass="down"; }
	var parentUL = menuItem.parentNode.parentNode.parentNode;
	if(hide)
	{
		for(i=0;i<parentUL.childNodes.length;i++)
		{
			if(parentUL.childNodes[i].nodeName == "LI")
			{
				parentUL.childNodes[i].className = "down";
				for(j=0;j<parentUL.childNodes[i].childNodes.length;j++)
				{
					if(parentUL.childNodes[i].childNodes[j].nodeName == "DIV" && parentUL.childNodes[i].childNodes[j].style.display != "none" && (parentUL.childNodes[i].childNodes[j].className.indexOf("dropbox_content") >= 0 || parentUL.childNodes[i].childNodes[j].className.indexOf("halfbox_content") >= 0))
					{
						hiding = true;
						hidingDiv = parentUL.childNodes[i].childNodes[j];
						targetHeight = hidingDiv.offsetHeight;
						parentUL.childNodes[i].childNodes[j].style.height = targetHeight + "px";
						parentUL.childNodes[i].childNodes[j].style.overflow = "hidden";
						hideDiv(hidingDiv, targetHeight, 5);
					}
				}
			}
		}
	}
	clickedLI.className = nextClass;
	if(nextClass == "over")
	{
		for(i=0;i<clickedLI.childNodes.length;i++)
		{
			if(clickedLI.childNodes[i].nodeName == "DIV" && (clickedLI.childNodes[i].className.indexOf("dropbox_content") >= 0 || clickedLI.childNodes[i].className.indexOf("halfbox_content") >= 0))
			{
				activeDiv = clickedLI.childNodes[i];
				clickedLI.childNodes[i].style.display = "block";
				targetHeight = clickedLI.childNodes[i].offsetHeight - 14;
				clickedLI.childNodes[i].style.overflow = "hidden";
				clickedLI.childNodes[i].style.height = "0px";
				revealDiv(activeDiv, targetHeight, 5);
			}
		}
	}
	else
	{
		for(i=0;i<clickedLI.childNodes.length;i++)
		{
			if(clickedLI.childNodes[i].nodeName == "DIV" && (clickedLI.childNodes[i].className.indexOf("dropbox_content") >= 0 || clickedLI.childNodes[i].className.indexOf("halfbox_content") >= 0))
			{
				hiding = true;
				hidingDiv = clickedLI.childNodes[i];
				targetHeight = hidingDiv.offsetHeight;
				clickedLI.childNodes[i].style.height = targetHeight + "px"
				clickedLI.childNodes[i].style.overflow = "hidden";
				hideDiv(hidingDiv, targetHeight, 5);
			}
		}
	}
	
}

function businessBanner()
{
	locat = location.href;
	if((locat.indexOf('business/index.htm') > 0) || (locat.indexOf('business/') == (locat.lastIndexOf('/') - 8)))
	{
		var middleDiv = document.getElementById('middle');
		for(i=0;i<middleDiv.childNodes.length;i++)
		{
			contentDiv = middleDiv.childNodes[i];
			if(contentDiv.className == "content")
			{
				contentDiv.innerHTML += '<a href="http://www.macdonaldhotels.co.uk/offers/shop_til_you_drop.htm"><img src="http://www.macdonaldhotels.co.uk/images/btn_shoptil.jpg" alt="Shop til you drop with Macdonald Hotel and Resorts" /></a>';
			}
		}
		
	}
}

function contactLink()
{
	//scrollTo(0,0); 
	displayCenterDiv('contact_form');
}

document.write('<link href="http://www.macdonaldhotels.co.uk/sharedhotelsitefiles/css/javascript.css" rel="stylesheet" type="text/css" media="all" />');

startList = function() {
	if(document.getElementById("menu_items"))
	{
		navRoot = document.getElementById("menu_items");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (document.all&&document.getElementById) {
				if (node.nodeName == "LI") {
					node.onmouseover = function() {
						this.className += " over";
					}
					node.onmouseout = function() {
						this.className = this.className.replace(" over", "");
					}
				}
			}
			for (j=0; j<node.childNodes.length; j++)
			{
				DivNode = node.childNodes[j];
				if (DivNode.nodeName == "DIV") {
					DivNode.style.width = node.offsetWidth + 'px';
				}
			}
		}
	}
}
window.onload = startList;

function RouteShowImage() {}

function openLinkedOffer() {
	var pageHash = location.hash;
	pageHash = pageHash.substring(1,pageHash.length);
	if(document.getElementById(pageHash + '_link'))
	{
		displayArea(document.getElementById(pageHash + '_link'), false);
	}
	if(pageHash == "ContactForm") {
		contactLink();
	}
}

function redeyeload()
{
	var redEyeStart = "http://reporting.macdonaldhotels.com/cgi-bin/rr/";
	var redEyeEnd = "?nourl=www.macdonaldhotels.co.uk/";

	for(var i=0;i<document.anchors.length;i++)
	{
		var oldHref = document.anchors[i].href;
		var linkName = document.anchors[i].name;
		if(linkName.indexOf('_lnk_') > 0)
		{
			linkName = linkName.replace(/_/ig,"/");
			document.anchors[i].href=redEyeStart+oldHref+redEyeEnd+linkName;
		}
	}
}


function redeyetag()
{
	var redeyedomain = 'reporting.macdonaldhotels.com';
	var nourlvalue = location.href;
	nourlvalue = nourlvalue.toLowerCase();
	if(nourlvalue.indexOf('?') > 0) { nourlvalue = nourlvalue.substring(0,nourlvalue.indexOf('?')); }
	if(nourlvalue.lastIndexOf("/") == (nourlvalue.length-1))
	{ 
		if(nourlvalue.indexOf(".co.uk/") == nourlvalue.lastIndexOf("/") - 6 || nourlvalue.indexOf(".co.uk/resorts/") == nourlvalue.lastIndexOf("/") - 14)
		{
			nourlvalue += "home.htm" 
		}
		else
		nourlvalue += "index.htm" 
	}
	var tag = 'http://' + redeyedomain + '/cgi-bin/rr.cgi/images/blank.gif?nourl=' + nourlvalue + '&norefer=' + escape(window.document.referrer);

	var enquiryID = "";
	var GETDATA = new Array();
	var sGet = window.location.search;
	if (sGet)
	{
		sGet = sGet.substr(1);
		var sNVPairs = sGet.split("&");
		for (var i = 0; i < sNVPairs.length; i++)
		{
			var sNV = sNVPairs[i].split("=");
			var sName = sNV[0];
			var sValue = sNV[1];
			if(sName = 'enquiryReference')
			{
				enquiryID = sValue;
			}
		}
	}

	if(nourlvalue.indexOf('weddings/thanks.asp') > 0 || nourlvalue.indexOf('weddings/thanks.htm') > 0)
	{
		tag += "&amp;r_wedding_enquiry=confirm&amp;f_wedding_enqref=" + enquiryID;
	}
	else if((nourlvalue.indexOf('thankyou.asp') > 0 || nourlvalue.indexOf('thankyou.htm') > 0) && nourlvalue.indexOf('/resorts/') > 0)
	{
		tag += "&amp;r_resort_enquiry=confirm&amp;f_resorts_enqref=" + enquiryID;
	}
	else if((nourlvalue.indexOf('thankyou.asp') > 0 || nourlvalue.indexOf('thankyou.htm') > 0) && nourlvalue.indexOf('/rfp/') < 0 && nourlvalue.indexOf('/golf/') < 0)
	{
		if(nourlvalue.indexOf('business/') > 0)
		tag += "&amp;r_hotel_enquiry=confirm&amp;f_hotelbus_enqref=" + enquiryID;
		else
		tag += "&amp;r_hotel_enquiry=confirm&amp;f_hotel_enqref=" + enquiryID;
	}
	else if((nourlvalue.indexOf('thankyou.asp') > 0 || nourlvalue.indexOf('thankyou.htm') > 0) && nourlvalue.indexOf('/rfp/') >= 0)
	{
		tag += "&amp;r_business_enquiry=confirm&amp;f_businessrfp_enqref=" + enquiryID;
	}
	else if((nourlvalue.indexOf('thankyou.asp') > 0 || nourlvalue.indexOf('thankyou.htm') > 0) && nourlvalue.indexOf('/golf/') >= 0)
	{
		tag += "&amp;r_golf_enquiry=confirm&amp;f_golf_enqref=" + enquiryID;
	}
	else if(nourlvalue.indexOf('thanksfortheenquiry') > 0)
	{
		tag += "&amp;r_offer_enquiry=confirm&amp;f_offer_enqref=" + enquiryID;
	}

	document.write("<img src='" + tag + "' width='1' height='1' alt='' />");
}