function closeCalendar()
{
	var popupCalendar = document.getElementById("popupCalendar");
	popupCalendar.style.display = "none";
}

function openCalendar()
{
	var popupCalendar = document.getElementById("popupCalendar");

	if (popupCalendar.style.display == "block")
	{
		popupCalendar.style.display = "none";
	}
	else
	{
		popupCalendar.style.display = "block";
	}
}

function closeCalendar1()
{
	var popupCalendar = document.getElementById("popupCalendar1");
	popupCalendar.style.display = "none";
}

function openCalendar1()
{
	var popupCalendar = document.getElementById("popupCalendar1");
	if (popupCalendar.style.display == "block")
	{
		popupCalendar.style.display = "none";
	}
	else
	{
		popupCalendar.style.display = "block";
	}
}

function closeCalendar2()
{
	var popupCalendar = document.getElementById("popupCalendar2");
	popupCalendar.style.display = "none";
}

function openCalendar2()
{
	var popupCalendar = document.getElementById("popupCalendar2");

	if (popupCalendar.style.display == "block")
	{
		popupCalendar.style.display = "none";
	}
	else
	{
		popupCalendar.style.display = "block";
	}
}

function closePleaseWait()
{
	try
	{
		var divPleaseWait = document.getElementById("divPleaseWait");
		var divPleaseWaitInner = document.getElementById("divPleaseWaitInner");

		if (divPleaseWait)
		{
			divPleaseWait.style.display = "none";
			divPleaseWaitInner.style.display = "none";

			var flash_banner = document.getElementById("flash_banner");
			if (flash_banner && flash_banner.getElementsByTagName("object") && flash_banner.getElementsByTagName("object")[0])
			{
				flash_banner.getElementsByTagName("object")[0].style.visibility = "visible";
			}
			
			var center_flash_header = document.getElementById("center_flash_header");
			if (center_flash_header && center_flash_header.getElementsByTagName("object") && center_flash_header.getElementsByTagName("object")[0])
			{
				if (center_flash_header.getElementsByTagName("object")[0])
				{	
					center_flash_header.getElementsByTagName("object")[0].style.visibility = "visible";
				}
			}

			return true;
		}

		return false;
	}
	catch (exc)
	{
		showError(exc);
	}
}

function pleaseWaitNoCancel()
{
	try
	{
		pleaseWait();
		
		var btnPleaseWaitCancel = document.getElementById("btnPleaseWaitCancel");
			
		btnPleaseWaitCancel.style.display = "none";
	}
	catch (exc)
	{
		showError(exc);
	}	
	
	return false;
}

function pleaseWait()
{
	try
	{
		var divPleaseWait = document.getElementById("divPleaseWait");
		var divPleaseWaitInner = document.getElementById("divPleaseWaitInner");

		if (divPleaseWait)
		{
			divPleaseWait.style.display = "block";
			divPleaseWaitInner.style.display = "block";
			divPleaseWait.style.height = document.body.clientHeight + "px";
			divPleaseWait.style.width = document.body.clientWidth + "px";

			divPleaseWaitInner.style.top = "200px";

			var flash_banner = document.getElementById("flash_banner");
			if (flash_banner && flash_banner.getElementsByTagName("object") && flash_banner.getElementsByTagName("object")[0])
			{
				flash_banner.getElementsByTagName("object")[0].style.visibility = "hidden";
			}

			var center_flash_header = document.getElementById("center_flash_header");
			if (center_flash_header && center_flash_header.getElementsByTagName("object") && center_flash_header.getElementsByTagName("object")[0])
			{
				if (center_flash_header.getElementsByTagName("object")[0])
				{	
					center_flash_header.getElementsByTagName("object")[0].style.visibility = "hidden";
				}
			}
			
			//scroll to the top of the page
			scroll(0,0);
			
			var btnPleaseWaitCancel = document.getElementById("btnPleaseWaitCancel");
			
			btnPleaseWaitCancel.style.display = "";
		}
	}
	catch (exc)
	{
		showError(exc);
	}

	return false;
}

function showError(exc, blnClose)
{
	try
	{
		alert("Sorry an error has occurred: \n" + exc.name + "\n" + exc.message);
		if (!blnClose) {closePleaseWait();}
	}
	catch (exc)
	{
		alert(exc);
	}

}

function stopReload()
{
	try
	{
		if (window.stop)
		{
			window.stop();
			closePleaseWait();
			return true;
		}

		if (document.execCommand)
		{
			document.execCommand("Stop", true, "");
			closePleaseWait();
			return true;
		}
	}
	catch (exc)
	{
		showError(exc, true)	
	}

	window.location = window.location;
	return false;
}

/* ordering control functions */
function move(index,to) {
	var list = document.forms[0].order;
	var total = list.options.length-1;
	
	if (index == -1) return false;
	if (to == +1 && index == total) return false;
	if (to == -1 && index == 0) return false;

	var bufferV = list.options[index].value;
	var bufferT = list.options[index].text;
	
	var bufferVN = list.options[index+to].value;
	var bufferTN = list.options[index+to].text;

	list.options[index].value = bufferVN;
	list.options[index].text = bufferTN;
	
	list.options[index+to].value = bufferV;
	list.options[index+to].text = bufferT;    
	list.selectedIndex += to;
	list.focus();
}

function submitOrder() {
	document.forms[0].setOrder.value = "";
	var c = 2;
	for (var i = 0; i <= document.forms[0].order.options.length-1 ; i++) { 
		document.forms[0].setOrder.value += c + "=" + document.forms[0].order.options[i].value;
		c++;
		document.forms[0].setOrder.value += "|";
	}
}

function swapProductImage(iImageID, iFilePosition){
	document.getElementById('productMainImage').src='downloadImage.aspx?imgID=' + iImageID +' &imgType=shop';
	for (i=0; i<7;i++)
	{
		// If image exists then make is standard class
		if (document.getElementById('productImageButton'+i)!= null)
		{
			document.getElementById('productImageButton'+i).innerHTML=i;
			document.getElementById('productImageButton'+i).className='shopButton';
		}
	}
	// Highlight button pressed with new class
	// document.getElementById('productImageButton'+iFilePosition).className='shopButtonOn';
}


function runWOSubmit ()  {
	var msg="";
	if (!check(document.forms[0].contactQuestionTitle, "Please provide your Title.")) return;
	if (!check(document.forms[0].contactQuestionForename, "Please provide your Forename.")) return;
	if (!check(document.forms[0].contactQuestionSurname, "Please provide your Surname.")) return;
	if (document.forms[0].contactQuestionEmail){ if (!check(document.forms[0].contactQuestionEmail, "Please provide your Email Address.")) return; }
//	document.forms[0].action="wales-open-form-submission.aspx"
	document.forms[0].action="formSubmission.aspx"
	
	document.forms[0].submit();
	return;
}

function runComprehensiveSubmit ()  {
	var msg="";
	if (!check(document.forms[0].contactQuestionTitle, "Please provide your Title.")) return;
	if (!check(document.forms[0].contactQuestionForename, "Please provide your Forename.")) return;
	if (!check(document.forms[0].contactQuestionSurname, "Please provide your Surname.")) return;
	if (document.forms[0].contactQuestionEmail){ if (!check(document.forms[0].contactQuestionEmail, "Please provide your Email Address.")) return; }
	document.forms[0].action="formSubmission.aspx"
	document.forms[0].submit();
	return;
}
function runComprehensiveWithOneTelSubmit ()  {
	var msg="";
	if (!check(document.forms[0].contactQuestionTitle, "Please provide your Title.")) return;
	if (!check(document.forms[0].contactQuestionForename, "Please provide your Forename.")) return;
	if (!check(document.forms[0].contactQuestionSurname, "Please provide your Surname.")) return;

	// validatePrompt (Ctrl, PromptStr)

	if (document.forms[0].contactQuestionTelephone.value == "" && document.forms[0].contactQuestionTelephone2.value == "" && document.forms[0].contactQuestionMobile.value=="")
	{	
		if(document.forms[0].contactQuestionTelephone.value == "") { validatePrompt (Ctrl, "Please enter at least one telephone number")
		} else if(document.forms[0].contactQuestionTelephone2.value == "") { validatePrompt (Ctrl, "Please enter at least one telephone number")
		} else if(document.forms[0].contactQuestionMobile.value == "") { validatePrompt (Ctrl, "Please enter at least one telephone number") }
		return;
	}

	if (document.forms[0].contactQuestionEmail){ if (!check(document.forms[0].contactQuestionEmail, "Please provide your Email Address.")) return; }
	document.forms[0].action="formSubmission.aspx"
	document.forms[0].submit();
	return;
}

function runWOCompetitionSubmit ()  {
	var msg="";
	if (!check(document.forms[0].contactQuestionTitle, "Please provide your Title.")) return;
	if (!check(document.forms[0].contactQuestionForename, "Please provide your Forename.")) return;
	if (!check(document.forms[0].contactQuestionSurname, "Please provide your Surname.")) return;
	if (document.forms[0].contactQuestionEmail){ if (!check(document.forms[0].contactQuestionEmail, "Please provide your Email Address.")) return; }
	if (!check(document.forms[0].marketingQuestion106, "Please provide your ticket type.")) return;
	if (!check(document.forms[0].marketingQuestionQuest108, "Please provide your ticket number.")) return;
	document.forms[0].action="formSubmission.aspx"
	document.forms[0].submit();
	return;
}

function runBrochureSubmit ()  {
	var msg="";
	if (!check(document.forms[0].contactQuestionTitle, "Please provide your Title.")) return;
	if (!check(document.forms[0].contactQuestionForename, "Please provide your Forename.")) return;
	if (!check(document.forms[0].contactQuestionSurname, "Please provide your Surname.")) return;

	count = 0;
	for(x=0; x<document.forms[0].elements.length; x++){
		if(document.forms[0].elements[x].type == "checkbox"){
			if(document.forms[0].elements[x].name.indexOf("brochureQuestion") >= 0){
				if(document.forms[0].elements[x].checked==true){
					count++;
				}
			}
		}
	}
    if(count==0){
		alert("You must choose at least 1 brochure.");
        return false;
    }
	if(count>=5){
		alert("You must choose a maximum of 4 brochures.");
        return false;
    }



	document.forms[0].action="formSubmission.aspx"
	document.forms[0].submit();
	return;
}

function check(thing, Prompt) {
	Ctrl = thing;
	if (Ctrl.value == "") {
		validatePrompt (Ctrl, Prompt)
		return (false);
	} else
		return (true);
}

function validatePrompt (Ctrl, PromptStr) {
	alert (PromptStr)
	Ctrl.focus();
	return;
}

function openPopup(strURL, strName)
{
	window.open(strURL, strName, "width=500,height=500,resizable=1,scrollbars=1,toolbar=0,status=0,menubar=0,location=0");
}
function openPopup(strURL, strName, numWidth, numHeight)
{
	window.open(strURL, strName, "width=" + numWidth + ",height=" + numHeight + ",resizable=1,scrollbars=1,toolbar=0,status=0,menubar=0,location=0");
}
function openFamilyPolicy()
{
	openPopup("family-policy.aspx", "familyPolicy", 500, 500);
}
function openGolfConditions(strLink)
{
	openPopup("Conditions-of-Play.aspx#" + strLink , "conditionsOfPlay", 500, 500);
}
function openPublicGolfConditions(strLink)
{
	openPopup("Visitors-Conditions-of-Play.aspx#" + strLink , "visitorsConditionsOfPlay", 500, 500);
}

function openBookingTerms()
{
	openPopup("booking-terms.aspx", "bookingTerms", 500, 500);
}
function openBookingHelp()
{
	openPopup("booking-help.aspx", "bookingHelp", 500, 500);
}
function openCancellationPolicy()
{
	openPopup("cancellation-policy.aspx", "cancellationPolicy", 500, 500);
}
function openMemberBookingHistory()
{
	openPopup("Members-Golf-History.aspx", "membersGolfHistory", 500, 600);
}
function openMemberFavouritePlayers()
{
	openPopup("Members-Golf-Favourite-Players.aspx", "membersGolfHistory", 500, 600);
}
function openOWSHelp(numStage)
{
	openPopup("booking-help-step-" + numStage + ".aspx", "bookingHelpStep" + numStage, 500, 500);
}


function PageLoad() {
	if(window.LoadMap) { LoadMap(); }
	setTextSizeOnLoad();
}
function PageUnload() {
	if(window.GUnload) { GUnload(); }
}

/*  ------------------- START OF TEXT RESIZING -------------------------------- */
function SetCookie(cookieName, cookieData) {
	var expires = new Date ();
	var days = 1;
	expires.setTime(expires.getTime() + days * (24 * 60 * 60 * 1000)); 
	document.cookie = cookieName + "=" + escape(cookieData) + "; expires=" + expires.toGMTString();
}

function GetCookie(name) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return GetCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
	  }
	return null;
}

function GetCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function setTextSizeOnLoad() {
	var cookie = GetCookie('textSize');
	var body = document.getElementsByTagName('BODY');
	if (cookie == 'large')
	{ document.body.className='large'; }
	else if (cookie == 'medium')
	{ document.body.className='medium'; }
	else if (cookie == 'small')
	{ document.body.className='small'; }
	return true;
}

function setTextSize(size) 
{
	document.body.className=size;
	SetCookie('textSize', size);
}
/*  ------------------- END OF TEXT RESIZING -------------------------------- */

