	// This file should be included in the head of any active frames/ page
	// to make work. It assumes that all the layer ids passed are in the
	// same frame as this file! Got that!?
	
	// Set up static global variables

	// Set up the variables that tell us if we are in NS or IE
	// These work simply by examining the global objects available	
	
	// Only NS uses the layers obj to access CSS layers
	ns = (document.layers) ? true:false;
	// and only IE has the all obj to access CSS layers (amongst other things)
	ie = (document.all) ? true:false;
	
	_diamondRating = 0;
	_highlightColour = "#FF0000";
	_normalColour = "#000000";
	_formSubmitted = false;
	
	EMAIL_REG_EX		=	/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	
	function initialiseCommentPage()
	{
		_diamondRating = 0;
		_formSubmitted = false;
		doPreload();
	}
	
	function initialiseGMapPage()
	{
		doPreload();
	
		if (GBrowserIsCompatible())
		{
			var map = new GMap2(document.getElementById("map_canvas"));
			map.setCenter(new GLatLng(getCentreLat(), getCentreLong()), getZoomLevel(), G_HYBRID_MAP);
			map.setUIToDefault();
			
			if (showKaaba())
			{
				// Add point for the Kaaba
				var kaaba_icon = new GIcon();
				kaaba_icon.iconSize = new GSize(37,32);
				kaaba_icon.iconAnchor = new GPoint(37, 15);
				kaaba_icon.infoWindowAnchor = new GPoint(0, 32);
				markerOptions = { icon:kaaba_icon };
				kaaba_icon.image = "../res/map_icons/kaaba.png";
				var kaaba_point = new GMarker(new GLatLng(21.42254, 39.82635), markerOptions);
				map.addOverlay(kaaba_point);
				
				// Show an outline of the Haram as well
				var boundaries = new GLatLngBounds(new GLatLng(21.42059, 39.82359), new GLatLng(21.42535, 39.828));
				var haram = new GGroundOverlay("../res/map_icons/haraam_makkah.gif", boundaries);
				//map.addControl(new GSmallMapControl());
				//map.addControl(new GMapTypeControl());
				map.addOverlay(haram);
			}
			else
			{
				// Show Madinah Haram instead
				var dome_icon = new GIcon();
				dome_icon.iconSize = new GSize(37,35);
				dome_icon.iconAnchor = new GPoint(37, 16);
				dome_icon.infoWindowAnchor = new GPoint(0, 32);
				markerOptions = { icon:dome_icon };
				dome_icon.image = "../res/map_icons/dome.png";
				var dome_point = new GMarker(new GLatLng(24.46765, 39.61158), markerOptions);
				map.addOverlay(dome_point);
				
				// Show an outline of the Haram as well
				var m_boundaries = new GLatLngBounds(new GLatLng(24.46733, 39.608889), new GLatLng(24.470110, 39.6133));
				var m_haram = new GGroundOverlay("../res/map_icons/haraam_madinah.gif", m_boundaries);
				//map.addControl(new GSmallMapControl());
				//map.addControl(new GMapTypeControl());
				map.addOverlay(m_haram);
			}
			
			var hotel_icon = new GIcon();
			hotel_icon.iconSize = new GSize(32,50);
			hotel_icon.iconAnchor = new GPoint(32, 25);
			hotel_icon.infoWindowAnchor = new GPoint(0, 50);
			hotelMarkerOptions = { icon:hotel_icon };
			hotel_icon.image = "../res/map_icons/hotel.png";
			var hotel_point = new GMarker(new GLatLng(getHotelLat(), getHotelLong()), hotelMarkerOptions);
			map.addOverlay(hotel_point);
		}
    }
	
	function showZeroDiamond()
	{
		imageSwap("D1", "../res/hollow_d.gif");
		imageSwap("D2", "../res/hollow_d.gif");
		imageSwap("D3", "../res/hollow_d.gif");
		imageSwap("D4", "../res/hollow_d.gif");
		imageSwap("D5", "../res/hollow_d.gif");
	}
	
	function showOneDiamond()
	{
		imageSwap("D1", "../res/one_d.gif");
		imageSwap("D2", "../res/hollow_d.gif");
		imageSwap("D3", "../res/hollow_d.gif");
		imageSwap("D4", "../res/hollow_d.gif");
		imageSwap("D5", "../res/hollow_d.gif");
	}
	
	function showTwoDiamonds()
	{
		imageSwap("D1", "../res/one_d.gif");
		imageSwap("D2", "../res/one_d.gif");
		imageSwap("D3", "../res/hollow_d.gif");
		imageSwap("D4", "../res/hollow_d.gif");
		imageSwap("D5", "../res/hollow_d.gif");
	}
	
	function showThreeDiamonds()
	{
		imageSwap("D1", "../res/one_d.gif");
		imageSwap("D2", "../res/one_d.gif");
		imageSwap("D3", "../res/one_d.gif");
		imageSwap("D4", "../res/hollow_d.gif");
		imageSwap("D5", "../res/hollow_d.gif");
	}
	
	function showFourDiamonds()
	{
		imageSwap("D1", "../res/one_d.gif");
		imageSwap("D2", "../res/one_d.gif");
		imageSwap("D3", "../res/one_d.gif");
		imageSwap("D4", "../res/one_d.gif");
		imageSwap("D5", "../res/hollow_d.gif");
	}
	
	function showFiveDiamonds()
	{
		imageSwap("D1", "../res/one_d.gif");
		imageSwap("D2", "../res/one_d.gif");
		imageSwap("D3", "../res/one_d.gif");
		imageSwap("D4", "../res/one_d.gif");
		imageSwap("D5", "../res/one_d.gif");
	}
	
	function selectDiamondRating(rating_)
	{
		_diamondRating = rating_;
	}
	
	function showSelectedDiamonds()
	{
		if (0 == _diamondRating)
			{showZeroDiamond();}
		else if (1 == _diamondRating)
			{showOneDiamond();}
		else if (2 == _diamondRating)
			{showTwoDiamonds();}
		else if (3 == _diamondRating)
			{showThreeDiamonds();}
		else if (4 == _diamondRating)
			{showFourDiamonds();}
		else if (5 == _diamondRating)
			{showFiveDiamonds();} 
	}
	
	function onLoadHeader()
	{
		doPreload();
	}
	
	function noOp()
	{
		// Do Nothing!
	}
	
	function doPreload()
	{
		var the_images = new Array('./res/menu/std/home.gif', './res/menu/act/home.gif', './res/menu/std/umrah.gif', './res/menu/act/umrah.gif', './res/menu/std/hajj.gif', './res/menu/act/hajj.gif', './res/menu/std/hotels.gif', './res/menu/act/hotels.gif', './res/menu/std/resources.gif', './res/menu/act/resources.gif', './res/menu/std/about.gif', './res/menu/act/about.gif', './res/menu/std/contact.gif', './res/menu/act/contact.gif');
		preloadImages(the_images);
	}
	
	function checkAndSubmitHotelReview()
	{
		if (true == _formSubmitted)
		{
			// Already submitted. Do nothing
			return;
		}
		
		var success = true;
		if (false == checkTextEntryQuestion("disp_name", "DispNameQ"))
		{
			success = false;
		}
												
		if (false == checkEmailEntryQuestion("email", "eMailQ"))
		{
			success = false;
		}
		
		if (0 == _diamondRating)
		{
			// Means they didn't select a rating!
			hilightQuestion("ratingQ");
			success = false;
		}
		else
		{
			resetHighlight("ratingQ");
		}
		
		if (true == success)
		{
			_formSubmitted = true;
			document.getElementById('hotel_rating').value = _diamondRating;
			document.hotel_review.submit();
		}
		else
		{
			var theElem = document.getElementById("ErrTxt");
			theElem.style.color  = _highlightColour;
			theElem.innerHTML = "Please complete highlighted fields";
		}
	}
	
	function onNewsletterEmailFocus()
	{
		if (document.getElementById('email_address').value == 'enter your email')
		{
			document.getElementById('email_address').value = '';
		}
	}
	
	function submitNewsletterJoin()
	{
		var theElem = document.getElementById('email_address');
		var theEmailStr = trim(theElem.value);
		
		if (null == theEmailStr || 0 == theEmailStr.length)
		{
			alert('Please provide an email address');
			return;
		}
		
		if (false == verifyEmail(theEmailStr))
		{
			alert('Please provide a valid email address');
			return;
		}

		document.subscribe_form.submit();
	}
	
	function checkTextEntryQuestion(elementName_, highlightElemId_)
	{
		var theElem = document.getElementsByName(elementName_)[0];
		var theStr = trim(theElem.value);
		
		if (null == theStr || 0 == theStr.length)
		{
			hilightQuestion(highlightElemId_);
			return false;
		}
		
		resetHighlight(highlightElemId_);
		return true;
	}
	
	function checkEmailEntryQuestion(elementName_, highlightElemId_)
	{
		var theElem = document.getElementsByName(elementName_)[0];
		var theEmailStr = trim(theElem.value);
		
		if (null == theEmailStr || 0 == theEmailStr.length)
		{
			hilightQuestion(highlightElemId_);
			return false;
		}
		
		// Now know its not null, check its a valid email address
		if (false == verifyEmail(theEmailStr))
		{
			hilightQuestion(highlightElemId_);
			return false;
		}
		
		// We're good.
		resetHighlight(highlightElemId_);
		return true;
	}
	
	function verifyEmail(str_)
	{
		if (-1 == str_.search(EMAIL_REG_EX))
		{
			return false;
		}
		return true;
	}

	function preloadImages(the_images_array)
	{

		for(var imgNo = 0; imgNo < the_images_array.length; imgNo++)
		{
 			var an_image = new Image();
			an_image.src = the_images_array[imgNo];
		}
	}
	
	function hilightQuestion(elementId_)
	{
		var theElem = document.getElementById(elementId_);
		theElem.style.color  = _highlightColour;
	}
	
	function resetHighlight(elementId_)
	{
		var theElem = document.getElementById(elementId_);
		theElem.style.color  = _normalColour;
	}
	
	function imageSwap(element_, image_)
	{
		if (ie)
			{document.all[element_].src = image_;}
		else if (ns)
			{document.layers[element_].src = image_;}
		else
			{document.getElementsByName(element_)[0].src = image_;}
	}

	function hideLayer(id_)
	{
		if (ie)
			{document.all[id_].style.visibility = 'hidden';}
		else if (ns)
			{document.layers[id_].visibility = 'hide';}
		else
			{document.getElementsByName(element_)[0].visibility = 'hidden';}
	}

	function showLayer(id_)
	{
		if (ie) 
			{document.all[id_].style.visibility = 'visible';}
		else if (ns)
			{document.layers[id_].visibility = 'show';}
		else
			{document.getElementsByName(element_)[0].visibility = 'visible';}
	}
	
	function trim (str_) 
	{
		if (null == str_ || 0 == str_.length)
		{
			return null;
		}
		
		var whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
		for (var i = 0; i < str_.length; i++) {
			if (whitespace.indexOf(str_.charAt(i)) === -1) {
				str_ = str_.substring(i);
				break;
			}
		}
		for (i = str_.length - 1; i >= 0; i--) {
			if (whitespace.indexOf(str_.charAt(i)) === -1) {
				str_ = str_.substring(0, i + 1);
				break;
			}
		}
		return whitespace.indexOf(str_.charAt(0)) === -1 ? str_ : '';
	}