

///////////////////////////// date stuff /////////////////////////////////

var differenceInWeeks = 0;

function swopNumberForDay(theNumber) {
	if (theNumber == 0) { return "Sun"; }
	else if (theNumber == 1) { return "Mon"; }
	else if (theNumber == 2) { return "Tue"; }
	else if (theNumber == 3) { return "Wed"; }
	else if (theNumber == 4) { return "Thu"; }
	else if (theNumber == 5) { return "Fri"; }
	else if (theNumber == 6) { return "Sat"; }
}

function resetDifferenceInWeeks() {
	var today = new Date();

	today.setHours(12);
	today.setMinutes(0);
	today.setSeconds(0);
	today.setMilliseconds(0);

	var todaysDayOfWeek = swopNumberForDay(today.getDay());
	var daysToAdd = 0;
	if (todaysDayOfWeek == "Sun") { daysToAdd = 0; }
	else if (todaysDayOfWeek == "Mon") { daysToAdd = 6; }
	else if (todaysDayOfWeek == "Tue") { daysToAdd = 5; }
	else if (todaysDayOfWeek == "Wed") { daysToAdd = 4; }
	else if (todaysDayOfWeek == "Thu") { daysToAdd = 3; }
	else if (todaysDayOfWeek == "Fri") { daysToAdd = 2; }
	else if (todaysDayOfWeek == "Sat") { daysToAdd = 1; }

	var nextSundaysMilliseconds = today.getTime() + (60 * 60 * 24 * daysToAdd * 1000);
	var differenceInMilliseconds = nextSundaysMilliseconds - currentlyUsedSundayMillisecs;
	var differenceInWeeks = (((((differenceInMilliseconds/1000)/60)/60)/24)/7);


	for (var i = 0; i < differenceInWeeks; i++) {
		if (differenceInWeeks >= 1) { // stops daylight saving error
			shiftPriceArrays();
		}
	}

	currentlyUsedSundayMillisecs = nextSundaysMilliseconds;

}

function shiftPriceArrays() {
	arrayOfPrAvFor1.shift();
	arrayOfPrAvFor1.push(0);
	arrayOfPrAvFor2.shift();
	arrayOfPrAvFor2.push(0);
	arrayOfPrAvFor3.shift();
	arrayOfPrAvFor3.push(0);
	arrayOfPrAvFor4.shift();
	arrayOfPrAvFor4.push(0);
	arrayOfPrAvFor5.shift();
	arrayOfPrAvFor5.push(0);
	arrayOfPrAvFor6.shift();
	arrayOfPrAvFor6.push(0);
	arrayOfPrAvFor7.shift();
	arrayOfPrAvFor7.push(0);
	arrayOfPrAvFor8.shift();
	arrayOfPrAvFor8.push(0);
	arrayOfPrAvFor9.shift();
	arrayOfPrAvFor9.push(0);
	arrayOfPrAvFor10.shift();
	arrayOfPrAvFor10.push(0);
}


///////////////////////////// END of date stuff /////////////////////////////////




var theUrl = unescape(location.href);



function submitTheForm() {
	document.forms[0].accNo.value = accountNumber;

	document.forms[0].currentusedms.value = currentlyUsedSundayMillisecs;
	document.forms[0].htmlcurr.value = htmlCurr;
	document.forms[0].busname.value = busName;
	document.forms[0].nounits.value = noUnits;
	document.forms[0].nofriunits.value = noFriUnits;
	document.forms[0].nosatunits.value = noSatUnits;

	document.forms[0].cott1.value = cottNo1Name;
	document.forms[0].cott2.value = cottNo2Name;
	document.forms[0].cott3.value = cottNo3Name;
	document.forms[0].cott4.value = cottNo4Name;
	document.forms[0].cott5.value = cottNo5Name;
	document.forms[0].cott6.value = cottNo6Name;
	document.forms[0].cott7.value = cottNo7Name;
	document.forms[0].cott8.value = cottNo8Name;
	document.forms[0].cott9.value = cottNo9Name;
	document.forms[0].cott10.value = cottNo10Name;


	alertedToSave = "yes"

	document.getElementById("onsubmitofform").style.visibility = "visible";
	document.forms[0].submit();
}



var waitedOnce = "no";
var alertedAlready = "no";
function initialiseOnload() {
	

	if (noOfJSLoaded > 1) { // if all loaded - just in case onload is not reliable
		resetDifferenceInWeeks();
		reWritePage();

	}
	else {
		if (waitedOnce == "no") {
			timerID = setTimeout('initialiseOnload()',10000);
			waitedOnce = "yes";
		}
		else {
			if ( alertedAlready == "no" && theUrl.indexOf("private") != -1 ) {
				alert("If you have any problems please contact us on 01288 275011.\nWe have full backups including any Save Changes you have done today. Please click OK now.");			
				alertedAlready = "yes";
			}
			timerID = setTimeout('initialiseOnload()',5000);
		}
	}
}





var winWidth = 0;
var winWidth2 = 0;
function getInsideWindowWidth() {
	isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
	if (window.innerWidth) {
		return window.innerWidth;
	}
	else if (isIE6CSS) {
		// measure the html element's clientWidtht
		return document.documentElement.clientWidth;
	}
	else if (document.body && document.body.clientWidth) {
		return document.body.clientWidth;
	}
	return 1; // 0 could lead to dividing 0 by 2.
}



var winHeight = 0;
function getInsideWindowHeight() {
	isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
	if (window.innerHeight) {
		return window.innerHeight;
	}
	else if (isIE6CSS) {
		// measure the html element's clientHeight
		return document.documentElement.clientHeight;
	}
	else if (document.body && document.body.clientHeight) {
		return document.body.clientHeight;
	}
	return 1; // 0 could lead to dividing 0 by 2.
}




var idExp6 = "no";
var agt2 = new String(navigator.userAgent.toLowerCase());
if (agt2.indexOf("msie 6") != -1) {
	idExp6 = "yes";
}

function resetStyleSheet() {
	winWidth = getInsideWindowWidth();
	winHeight = getInsideWindowHeight();

	if (idExp6 == "yes" || winHeight < 500) {

//		document.getElementById("body").style.backgroundColor = "white";

		document.getElementById("fixedheader").style.position = "absolute";
		document.getElementById("fixedheader").style.left = "0px"; // prob don't need
		document.getElementById("fixedheader").style.top = "0px"; // prob don't need


		document.getElementById("fixedslides").style.position = "absolute";
		document.getElementById("fixedslides").style.left = "500px"; // prob don't need
		document.getElementById("fixedslides").style.top = "290px"; // prob don't need


		document.getElementById("fixedpara").style.position = "absolute";
		document.getElementById("fixedpara").style.left = "450px"; // prob don't need

		document.getElementById("topbar").style.position = "absolute";
		document.getElementById("topbar").style.left = "0px"; // prob don't need
		document.getElementById("topbar").style.top = "0px"; // prob don't need
		document.getElementById("leftlogo").style.position = "absolute";
		document.getElementById("leftlogo").style.left = "0px"; // prob don't need
		document.getElementById("leftlogo").style.top = "0px"; // prob don't need
		document.getElementById("pagelinks").style.position = "absolute";
		document.getElementById("pagelinks").style.left = "407px"; // prob don't need
		document.getElementById("pagelinks").style.top = "0px"; // prob don't need
		document.getElementById("rightlogo").style.position = "absolute";
		document.getElementById("rightlogo").style.left = "717px"; // prob don't need
		document.getElementById("rightlogo").style.top = "0px"; // prob don't need
		document.getElementById("formtoemailleft").style.position = "absolute";
		document.getElementById("formtoemailleft").style.left = "20px"; // prob don't need
		document.getElementById("formtoemailleft").style.top = "120px"; // prob don't need
		document.getElementById("formtoemailright").style.position = "absolute";
		document.getElementById("formtoemailright").style.left = "440px"; // prob don't need
		document.getElementById("formtoemailright").style.top = "100px"; // prob don't need
		document.getElementById("formtext").style.position = "absolute";
		document.getElementById("formtext").style.left = "540px"; // prob don't need
		document.getElementById("formtext").style.top = "340px"; // prob don't need
		document.getElementById("popupbox").style.position = "absolute";
		document.getElementById("popupbox").style.left = "328px"; // prob don't need
		document.getElementById("popupbox").style.top = "295px"; // prob don't need
		document.getElementById("cancelbutton").style.position = "absolute";
		document.getElementById("cancelbutton").style.left = "600px"; // prob don't need
		document.getElementById("cancelbutton").style.top = "350px"; // prob don't need
		document.getElementById("savechangesbutton").style.position = "absolute";
		document.getElementById("savechangesbutton").style.left = "10px"; // prob don't need
		document.getElementById("savechangesbutton").style.top = "235px"; // prob don't need


	}


	var extraForLeft = (winWidth - 1000)/2;
	if (extraForLeft > 10) {
		extraForLeft -= 10;
	}



	document.getElementById("fixedheader").style.left = extraForLeft + "px";
	document.getElementById("topbar").style.left = extraForLeft + "px";
	document.getElementById("leftlogo").style.left = extraForLeft + "px";
	document.getElementById("pagelinks").style.left = 407 + extraForLeft + "px";
	document.getElementById("rightlogo").style.left = 690 + extraForLeft + "px";

	document.getElementById("fixedslides").style.left = 500 + adjustfixedslidesH + extraForLeft + "px";
	document.getElementById("fixedslides").style.top = 295 + adjustfixedslidesV + "px";

	document.getElementById("fixedpara").style.left = 450 + adjustfixedparaH + extraForLeft + "px";
	document.getElementById("fixedpara").style.width = 525 + adjustfixedparaW  + "px";



	document.getElementById("formtoemailleft").style.left = 20 + extraForLeft + "px";
	document.getElementById("formtoemailright").style.left = 440 + extraForLeft + "px";
	document.getElementById("cancelbutton").style.left = 370 + extraForLeft + "px";
	document.getElementById("formtext").style.left = 540 + extraForLeft + "px";
	document.getElementById("pagebackground").style.left = extraForLeft + "px";
	document.getElementById("popupbox").style.left = 328 + extraForLeft + "px";
	document.getElementById("pricestable").style.left = 22 + extraForLeft + "px";


	if (winWidth < 1100) {
//		document.getElementById("body").style.backgroundColor = "white";
	}

}





function showPopUp(inComing) {
	if ( theUrl.indexOf("private") == -1 ) { //not owner
			if ( inComing == "pw" ) {
				document.getElementById("popupbox").innerHTML = "This week is only partly available.";
				document.getElementById("popupbox").style.visibility = "visible";
			}
			else {
				document.getElementById("popupbox").innerHTML = "";
				document.getElementById("popupbox").style.visibility = "hidden";

			}
	}
}



function reWritePage() {


	var newC = '<table id="pricestable">';

	for (var i = 0; i < 100; i++ ) { 

		var thisDateMilli = currentlyUsedSundayMillisecs + 604800000*i;

		var wkingoutFri1 = thisDateMilli - 172800000;
		var wkingoutSat1 = thisDateMilli - 86400000;

		var wkingoutFri2 = new Date(wkingoutFri1);
		var wkingoutSat2 = new Date(wkingoutSat1);
	
		var friYear = wkingoutFri2.getFullYear();
		var friMonth = wkingoutFri2.getMonth();

		if (friMonth == 0) { friMonth = "Jan "; }
		else if (friMonth == 1) { friMonth = "Feb "; }
		else if (friMonth == 2) { friMonth = "Mar "; }
		else if (friMonth == 3) { friMonth = "Apr "; }
		else if (friMonth == 4) { friMonth = "May "; }
		else if (friMonth == 5) { friMonth = "Jun "; }
		else if (friMonth == 6) { friMonth = "Jul "; }
		else if (friMonth == 7) { friMonth = "Aug "; }
		else if (friMonth == 8) { friMonth = "Sep "; }
		else if (friMonth == 9) { friMonth = "Oct "; }
		else if (friMonth == 10) { friMonth = "Nov "; }
		else if (friMonth == 11) { friMonth = "Dec "; }

		var satYear = wkingoutSat2.getFullYear();
		var satMonth = wkingoutSat2.getMonth();
		if (satMonth == 0) { satMonth = "Jan "; }
		else if (satMonth == 1) { satMonth = "Feb "; }
		else if (satMonth == 2) { satMonth = "Mar "; }
		else if (satMonth == 3) { satMonth = "Apr "; }
		else if (satMonth == 4) { satMonth = "May "; }
		else if (satMonth == 5) { satMonth = "Jun "; }
		else if (satMonth == 6) { satMonth = "Jul "; }
		else if (satMonth == 7) { satMonth = "Aug "; }
		else if (satMonth == 8) { satMonth = "Sep "; }
		else if (satMonth == 9) { satMonth = "Oct "; }
		else if (satMonth == 10) { satMonth = "Nov "; }
		else if (satMonth == 11) { satMonth = "Dec "; }


		var dateFri = friMonth + wkingoutFri2.getDate() + ' <span class="smallyear">' + friYear + '</span>';
		var dateSat = satMonth + wkingoutSat2.getDate() + ' <span class="smallyear">' + satYear + '</span>';
		
		
		dateFri = checkForChristmasOverride(dateFri);
		dateSat = checkForChristmasOverride(dateSat);
	

		var bS1 = "av"; // av, bk, pw, un (uninitiated)
		var bS2 = "av"; 
		var bS3 = "av"; 
		var bS4 = "av";
		var bS5 = "av";
		var bS6 = "av";
		var bS7 = "av";
		var bS8 = "av";
		var bS9 = "av"; 
		var bS10 = "av";

		var str1 = new String(arrayOfPrAvFor1[i]);
		var str2 = new String(arrayOfPrAvFor2[i]);
		var str3 = new String(arrayOfPrAvFor3[i]);
		var str4 = new String(arrayOfPrAvFor4[i]);
		var str5 = new String(arrayOfPrAvFor5[i]);
		var str6 = new String(arrayOfPrAvFor6[i]);
		var str7 = new String(arrayOfPrAvFor7[i]);
		var str8 = new String(arrayOfPrAvFor8[i]);
		var str9 = new String(arrayOfPrAvFor9[i]);
		var str10 = new String(arrayOfPrAvFor10[i]);

		if (str1.indexOf("P") != -1) { bS1 = "pw"; }
		else if (str1.indexOf("B") != -1) { bS1 = "bk"; }
		else if (arrayOfPrAvFor1[i] == 0) { bS1 = "un"; }

		if (str2.indexOf("P") != -1) { bS2 = "pw"; }
		else if (str2.indexOf("B") != -1) { bS2 = "bk"; }
		else if (arrayOfPrAvFor2[i] == 0) { bS2 = "un"; }

		if (str3.indexOf("P") != -1) { bS3 = "pw"; }
		else if (str3.indexOf("B") != -1) { bS3 = "bk"; }
		else if (arrayOfPrAvFor3[i] == 0) { bS3 = "un"; }

		if (str4.indexOf("P") != -1) { bS4 = "pw"; }
		else if (str4.indexOf("B") != -1) { bS4 = "bk"; }
		else if (arrayOfPrAvFor4[i] == 0) { bS4 = "un"; }

		if (str5.indexOf("P") != -1) { bS5 = "pw"; }
		else if (str5.indexOf("B") != -1) { bS5 = "bk"; }
		else if (arrayOfPrAvFor5[i] == 0) { bS5 = "un"; }

		if (str6.indexOf("P") != -1) { bS6 = "pw"; }
		else if (str6.indexOf("B") != -1) { bS6 = "bk"; }
		else if (arrayOfPrAvFor6[i] == 0) { bS6 = "un"; }

		if (str7.indexOf("P") != -1) { bS7 = "pw"; }
		else if (str7.indexOf("B") != -1) { bS7 = "bk"; }
		else if (arrayOfPrAvFor7[i] == 0) { bS7 = "un"; }

		if (str8.indexOf("P") != -1) { bS8 = "pw"; }
		else if (str8.indexOf("B") != -1) { bS8 = "bk"; }
		else if (arrayOfPrAvFor8[i] == 0) { bS8 = "un"; }

		if (str9.indexOf("P") != -1) { bS9 = "pw"; }
		else if (str9.indexOf("B") != -1) { bS9 = "bk"; }
		else if (arrayOfPrAvFor9[i] == 0) { bS9 = "un"; }

		if (str10.indexOf("P") != -1) { bS10 = "pw"; }
		else if (str10.indexOf("B") != -1) { bS10 = "bk"; }
		else if (arrayOfPrAvFor10[i] == 0) { bS10 = "un"; }

		str1 = str1.replace(/P/g, "*")
		str1 = str1.replace(/B/g, "")
		str2 = str2.replace(/P/g, "*")
		str2 = str2.replace(/B/g, "")
		str3 = str3.replace(/P/g, "*")
		str3 = str3.replace(/B/g, "")
		str4 = str4.replace(/P/g, "*")
		str4 = str4.replace(/B/g, "")
		str5 = str5.replace(/P/g, "*")
		str5 = str5.replace(/B/g, "")
		str6 = str6.replace(/P/g, "*")
		str6 = str6.replace(/B/g, "")
		str7 = str7.replace(/P/g, "*")
		str7 = str7.replace(/B/g, "")
		str8 = str8.replace(/P/g, "*")
		str8 = str8.replace(/B/g, "")
		str9 = str9.replace(/P/g, "*")
		str9 = str9.replace(/B/g, "")
		str10 = str10.replace(/P/g, "*")
		str10 = str10.replace(/B/g, "")

		//arrayOfPrAvFor1[i] = str1;
		//arrayOfPrAvFor2[i] = str2;
		//arrayOfPrAvFor3[i] = str3;
		//arrayOfPrAvFor4[i] = str4;
		//arrayOfPrAvFor5[i] = str5;
		//arrayOfPrAvFor6[i] = str6;
		//arrayOfPrAvFor7[i] = str7;
		//arrayOfPrAvFor8[i] = str8;
		//arrayOfPrAvFor9[i] = str9;
		//arrayOfPrAvFor10[i] = str10;

		if (arrayOfPrAvFor1[i] == 0) { str1 = "call"; arrayOfPrAvFor1[i] = "call"; }
		if (arrayOfPrAvFor2[i] == 0) { str2 = "call"; arrayOfPrAvFor2[i] = "call"; }
		if (arrayOfPrAvFor3[i] == 0) { str3 = "call"; arrayOfPrAvFor3[i] = "call"; }
		if (arrayOfPrAvFor4[i] == 0) { str4 = "call"; arrayOfPrAvFor4[i] = "call"; }
		if (arrayOfPrAvFor5[i] == 0) { str5 = "call"; arrayOfPrAvFor5[i] = "call"; }
		if (arrayOfPrAvFor6[i] == 0) { str6 = "call"; arrayOfPrAvFor6[i] = "call"; }
		if (arrayOfPrAvFor7[i] == 0) { str7 = "call"; arrayOfPrAvFor7[i] = "call"; }
		if (arrayOfPrAvFor8[i] == 0) { str8 = "call"; arrayOfPrAvFor8[i] = "call"; }
		if (arrayOfPrAvFor9[i] == 0) { str9 = "call"; arrayOfPrAvFor9[i] = "call"; }
		if (arrayOfPrAvFor10[i] == 0) { str10 = "call"; arrayOfPrAvFor10[i] = "call"; }

		newC += '<tr>';

		if (noFriUnits > 0) {
			newC += '<td class="date' + '">' + dateFri + '</td>';
		}
		else {
			newC += '<td class="date' + '">' + dateSat + '</td>';
		}

		
		newC += '<td id="' + i + '" class="price' +  bS1 + '"><a href="javascript:void clickPrice(' + i + ')" class="' + bS1 + '" onmouseover="showPopUp(\'' + bS1 + '\')">';
		newC += htmlCurr + str1 + '</a></td>';


		if (noUnits > 1) { 
			if (noFriUnits > 0 && noSatUnits > 0 && noFriUnits == 1) {
				newC += '<td class="datesat">' + dateSat + '</td>';
			}
			newC += '<td id="' + (i + 100) + '" class="price' +  bS2 + '"><a href="javascript:void clickPrice(' + (i + 100) + ')" class="' + bS2 + '" onmouseover="showPopUp(\'' + bS2 + '\')">';
			newC += htmlCurr + str2 + '</a></td>';
			if (noUnits > 2) {
				if (noFriUnits > 0 && noSatUnits > 0 && noFriUnits == 2) {
					newC += '<td class="datesat">' + dateSat + '</td>';
				}
				newC += '<td id="' + (i + 100*2) + '" class="price' +  bS3 + '"><a href="javascript:void clickPrice(' + (i + 100*2) + ')" class="' + bS3 + '" onmouseover="showPopUp(\'' + bS3 + '\')">';
				newC += htmlCurr + str3 + '</a></td>';
				if (noUnits > 3) {
					if (noFriUnits > 0 && noSatUnits > 0 && noFriUnits == 3) {
						newC += '<td class="datesat">' + dateSat + '</td>';
					}
					newC += '<td id="' + (i + 100*3) + '" class="price' +  bS4 + '"><a href="javascript:void clickPrice(' + (i + 100*3) + ')" class="' + bS4 + '" onmouseover="showPopUp(\'' + bS4 + '\')">';
					newC += htmlCurr + str4 + '</a></td>';
					if (noUnits > 4) {
						if (noFriUnits > 0 && noSatUnits > 0 && noFriUnits == 4) {
							newC += '<td class="datesat">' + dateSat + '</td>';
						}
						newC += '<td id="' + (i + 100*4) + '" class="price' +  bS5 + '"><a href="javascript:void clickPrice(' + (i + 100*4) + ')" class="' + bS5 + '" onmouseover="showPopUp(\'' + bS5 + '\')">';
						newC += htmlCurr + str5 + '</a></td>';
						if (noUnits > 5) {
							if (noFriUnits > 0 && noSatUnits > 0 && noFriUnits == 5) {
								newC += '<td class="datesat">' + dateSat + '</td>';
							}
							newC += '<td id="' + (i + 100*5) + '" class="price' +  bS6 + '"><a href="javascript:void clickPrice(' + (i + 100*5) + ')" class="' + bS6 + '" onmouseover="showPopUp(\'' + bS6 + '\')">';
							newC += htmlCurr + str6 + '</a></td>';
							if (noUnits > 6) {
								if (noFriUnits > 0 && noSatUnits > 0 && noFriUnits == 6) {
									newC += '<td class="datesat">' + dateSat + '</td>';
								}
								newC += '<td id="' + (i + 100*6) + '" class="price' +  bS7 + '"><a href="javascript:void clickPrice(' + (i + 100*6) + ')" class="' + bS7 + '" onmouseover="showPopUp(\'' + bS7 + '\')">';
								newC += htmlCurr + str7 + '</a></td>';
								if (noUnits > 7) {
									if (noFriUnits > 0 && noSatUnits > 0 && noFriUnits == 7) {
										newC += '<td class="datesat">' + dateSat + '</td>';
									}
									newC += '<td id="' + (i + 100*7) + '" class="price' +  bS8 + '"><a href="javascript:void clickPrice(' + (i + 100*7) + ')" class="' + bS8 + '" onmouseover="showPopUp(\'' + bS8 + '\')">';
									newC += htmlCurr + str8 + '</a></td>';
									if (noUnits > 8) {
										if (noFriUnits > 0 && noSatUnits > 0 && noFriUnits == 8) {
											newC += '<td class="datesat">' + dateSat + '</td>';
										}
										newC += '<td id="' + (i + 100*8) + '" class="price' +  bS9 + '"><a href="javascript:void clickPrice(' + (i + 100*8) + ')" class="' + bS9 + '" onmouseover="showPopUp(\'' + bS9 + '\')">';
										newC += htmlCurr + str9 + '</a></td>';
										if (noUnits > 9) {
											if (noFriUnits > 0 && noSatUnits > 0 && noFriUnits == 9) {
												newC += '<td class="datesat">' + dateSat + '</td>';
											}
											newC += '<td id="' + (i + 100*9) + '" class="price' +  bS10 + '"><a href="javascript:void clickPrice(' + (i + 100*9) + ')" class="' + bS10 + '" onmouseover="showPopUp(\'' + bS10 + '\')">';
											newC += htmlCurr + str10 + '</a></td>';
										}
									}
								}
							}
						}
					}
				}
			}
		}
		newC += '</tr>';
	}
	newC += '</table>';


	if ( theUrl.indexOf("private") == -1 ) { 
//		newC += '<p class="donotprint"><a href="../private/trterret.html" class="normallink">Owner update system</a>.</p>';
	}

	document.getElementById("allcontent").innerHTML = newC;

} // end reWritePage()



function showPricesAgain() {
		document.getElementById("formtoemailleft").style.visibility = "hidden";
		document.getElementById("formtoemailright").style.visibility = "hidden";
		document.getElementById("formtext").style.visibility = "hidden";
		document.getElementById("fixedslides").style.visibility = "visible";
		document.getElementById("cancelbutton").style.visibility = "hidden";
		document.getElementById("allcontent").style.display = "block";
}




var lastNumberTyped = 123;

function clickPrice(idNo) {


	if ( theUrl.indexOf("private") == -1 ) { //not owner
		scrollTo(0,0);

		var whichCottage = "";
		var whichDayOfWeek = "";
		
		
		if (idNo < 100) { arrayIndex = idNo; whichCottage = cottNo1Name; }
		else if (idNo < 200) { arrayIndex = idNo - 100; whichCottage = cottNo2Name; }
		else if (idNo < 300) { arrayIndex = idNo - 200; whichCottage = cottNo3Name; }
		else if (idNo < 400) { arrayIndex = idNo - 300; whichCottage = cottNo4Name; }
		else if (idNo < 500) { arrayIndex = idNo - 400; whichCottage = cottNo5Name; }
		else if (idNo < 600) { arrayIndex = idNo - 500; whichCottage = cottNo6Name; }
		else if (idNo < 700) { arrayIndex = idNo - 600; whichCottage = cottNo7Name; }
		else if (idNo < 800) { arrayIndex = idNo - 700; whichCottage = cottNo8Name; }
		else if (idNo < 900) { arrayIndex = idNo - 800; whichCottage = cottNo9Name; }
		else if (idNo < 1000) { arrayIndex = idNo - 900; whichCottage = cottNo10Name; }

		if (idNo < 100 && noFriUnits > 0) {
			whichDayOfWeek = "Fri"
		}
		else if (idNo < 200 && noFriUnits > 1) {
			whichDayOfWeek = "Fri"
		}
		else if (idNo < 300 && noFriUnits > 2) {
			whichDayOfWeek = "Fri"
		}
		else if (idNo < 400 && noFriUnits > 3) {
			whichDayOfWeek = "Fri"
		}
		else if (idNo < 500 && noFriUnits > 4) {
			whichDayOfWeek = "Fri"
		}
		else if (idNo < 600 && noFriUnits > 5) {
			whichDayOfWeek = "Fri"
		}
		else if (idNo < 700 && noFriUnits > 6) {
			whichDayOfWeek = "Fri"
		}
		else if (idNo < 800 && noFriUnits > 7) {
			whichDayOfWeek = "Fri"
		}
		else if (idNo < 900 && noFriUnits > 8) {
			whichDayOfWeek = "Fri"
		}
		else if (idNo < 1000 && noFriUnits > 9) {
			whichDayOfWeek = "Fri"
		}
		else {
			whichDayOfWeek = "Sat"
		}
	

		var milliSecondsOfDateClicked = currentlyUsedSundayMillisecs + 604800000*arrayIndex;

		var workingoutFri1 = milliSecondsOfDateClicked - 172800000;
		var workingoutSat1 = milliSecondsOfDateClicked - 86400000;

		var workingoutFri2 = new Date(workingoutFri1);
		var workingoutSat2 = new Date(workingoutSat1);

		var friDay = workingoutFri2.getDate();
		var friYear = workingoutFri2.getFullYear();
		var friMonth = workingoutFri2.getMonth();

		if (friMonth == 0) { friMonth = "Jan "; }
		else if (friMonth == 1) { friMonth = "Feb "; }
		else if (friMonth == 2) { friMonth = "Mar "; }
		else if (friMonth == 3) { friMonth = "Apr "; }
		else if (friMonth == 4) { friMonth = "May "; }
		else if (friMonth == 5) { friMonth = "Jun "; }
		else if (friMonth == 6) { friMonth = "Jul "; }
		else if (friMonth == 7) { friMonth = "Aug "; }
		else if (friMonth == 8) { friMonth = "Sep "; }
		else if (friMonth == 9) { friMonth = "Oct "; }
		else if (friMonth == 10) { friMonth = "Nov "; }
		else if (friMonth == 11) { friMonth = "Dec "; }


		var satDay = workingoutSat2.getDate();
		var satYear = workingoutSat2.getFullYear();
		var satMonth = workingoutSat2.getMonth();

		if (satMonth == 0) { satMonth = "Jan "; }
		else if (satMonth == 1) { satMonth = "Feb "; }
		else if (satMonth == 2) { satMonth = "Mar "; }
		else if (satMonth == 3) { satMonth = "Apr "; }
		else if (satMonth == 4) { satMonth = "May "; }
		else if (satMonth == 5) { satMonth = "Jun "; }
		else if (satMonth == 6) { satMonth = "Jul "; }
		else if (satMonth == 7) { satMonth = "Aug "; }
		else if (satMonth == 8) { satMonth = "Sep "; }
		else if (satMonth == 9) { satMonth = "Oct "; }
		else if (satMonth == 10) { satMonth = "Nov "; }
		else if (satMonth == 11) { satMonth = "Dec "; }

		

		document.forms[0].cottagename.value = whichCottage;

		if (whichDayOfWeek == "Fri") {
			document.forms[0].dates.value = friDay + " " + friMonth + " " + friYear;
		}
		else {
			document.forms[0].dates.value = satDay + " " + satMonth + " " + satYear;;
		}	
		
		document.getElementById("formtoemailleft").style.visibility = "visible";
		document.getElementById("formtoemailright").style.visibility = "visible";
		document.getElementById("formtext").style.visibility = "visible";
		document.getElementById("fixedslides").style.visibility = "hidden";
		document.getElementById("cancelbutton").style.visibility = "visible";
		document.getElementById("allcontent").style.display = "none";
		

		
		


	}
	else { // owner



		var htmlToWrite = "";

		var priceAlreadyIn = 0;
		
		if (idNo < 100) { priceAlreadyIn = arrayOfPrAvFor1[idNo]; }
		else if (idNo < 200) { priceAlreadyIn = arrayOfPrAvFor2[idNo - 100]; }
		else if (idNo < 300) { priceAlreadyIn = arrayOfPrAvFor3[idNo - 200]; }
		else if (idNo < 400) { priceAlreadyIn = arrayOfPrAvFor4[idNo - 300]; }
		else if (idNo < 500) { priceAlreadyIn = arrayOfPrAvFor5[idNo - 400]; }
		else if (idNo < 600) { priceAlreadyIn = arrayOfPrAvFor6[idNo - 500]; }
		else if (idNo < 700) { priceAlreadyIn = arrayOfPrAvFor7[idNo - 600]; }
		else if (idNo < 800) { priceAlreadyIn = arrayOfPrAvFor8[idNo - 700]; }
		else if (idNo < 900) { priceAlreadyIn = arrayOfPrAvFor9[idNo - 800]; }
		else if (idNo < 1000) { priceAlreadyIn = arrayOfPrAvFor10[idNo - 900]; }

		if (priceAlreadyIn > 200 || priceAlreadyIn.indexOf("B") != -1 || priceAlreadyIn.indexOf("P") != -1 ) {
			var newPrice1 = prompt("Type a new price, add \'B\' \(booked\) or \'P\' \(part-booked\):", priceAlreadyIn)
		}
		else {
			var newPrice1 = prompt("Type a new price, add \'B\' \(booked\) or \'P\' \(part-booked\):", lastNumberTyped)
		}
		


		if (newPrice1 == "B" || newPrice1 == "b") {
			newPrice1 = "B" + priceAlreadyIn;
		}
		else if (newPrice1 == "P" || newPrice1 == "p") {
			newPrice1 = "P" + priceAlreadyIn;
		}




		var newPrice = new String(newPrice1);



		if (newPrice.indexOf("£") != -1) {
			alert("There is no need to type the £ symbol - just type the price next time");
		}
		var withoutPoundSign = new String(newPrice);
		withoutPoundSign = withoutPoundSign.replace(/\£/g, "")
		newPrice = withoutPoundSign;

		if ( newPrice == 0) {
		//	htmlToWrite = '<a href="javascript:void clickPrice(' + idNo + ')">X</a>';
		//	document.getElementById(idNo).innerHTML = htmlToWrite;
			saveToArray(idNo, 0);
			document.getElementById("savechangesbutton").style.visibility = "visible";
			lastNumberTyped = newPrice;
		}
		else if (newPrice.indexOf("p") != -1 || newPrice.indexOf("P") != -1) { 
		//	htmlToWrite = '<a href="javascript:void clickPrice(' + idNo + ')">P</a>';
		//	document.getElementById(idNo).innerHTML = htmlToWrite;

			newPrice = newPrice.replace(/p/gi, "P")
			saveToArray(idNo, newPrice);
			document.getElementById("savechangesbutton").style.visibility = "visible";
			lastNumberTyped = newPrice;
		}
		else if (newPrice.indexOf("b") != -1 || newPrice.indexOf("B") != -1) { 

		//	htmlToWrite = '<a href="javascript:void clickPrice(' + idNo + ')">P</a>';
		//	document.getElementById(idNo).innerHTML = htmlToWrite;

			newPrice = newPrice.replace(/b/gi, "B")
			saveToArray(idNo, newPrice);
			document.getElementById("savechangesbutton").style.visibility = "visible";
			lastNumberTyped = newPrice;
		}

		else if ( newPrice == null || newPrice == "" || newPrice == " ") {
			// do nothing
		}
		else if (isNaN(newPrice)) {
			// do nothing
		}
		else {
//			newPrice = parseInt(newPrice);
//			htmlToWrite = '<a href="javascript:void clickPrice(' + idNo + ')">' + newPrice + '</a>';
//			document.getElementById(idNo).innerHTML = htmlToWrite;
			saveToArray(idNo,newPrice);
			document.getElementById("savechangesbutton").style.visibility = "visible";
			lastNumberTyped = newPrice;
		}
		reWritePage() //for testing arrays have been written to correctly
	}
}

var alertedToSave = "no";
function saveToArray(idNo2, newPrice2) {

	if (alertedToSave == "no") {
		alert("When you have finished updating this page\nyou need to click on the Save Changes\nbutton at the top of the page");
		alertedToSave = "yes";
	}


	if (idNo2 < 100) { arrayOfPrAvFor1[idNo2] = newPrice2; }
	else if (idNo2 < 200 ) { arrayOfPrAvFor2[idNo2 - 100] = newPrice2 }
	else if (idNo2 < 300 ) { arrayOfPrAvFor3[idNo2 - 200] = newPrice2 }
	else if (idNo2 < 400 ) { arrayOfPrAvFor4[idNo2 - 300] = newPrice2 }
	else if (idNo2 < 500 ) { arrayOfPrAvFor5[idNo2 - 400] = newPrice2 }
	else if (idNo2 < 600 ) { arrayOfPrAvFor6[idNo2 - 500] = newPrice2 }
	else if (idNo2 < 700 ) { arrayOfPrAvFor7[idNo2 - 600] = newPrice2 }
	else if (idNo2 < 800 ) { arrayOfPrAvFor8[idNo2 - 700] = newPrice2 }
	else if (idNo2 < 900 ) { arrayOfPrAvFor9[idNo2 - 800] = newPrice2 }
	else if (idNo2 < 1000 ) { arrayOfPrAvFor10[idNo2 - 900] = newPrice2 }


	var tempVar = "";
	for (var i = 0; i < arrayOfPrAvFor1.length; i++ ) {
		tempVar += arrayOfPrAvFor1[i]
		if (i < ( arrayOfPrAvFor1.length - 1 )) {
			tempVar += "endVA";
		}
	}
	document.forms[0].acc1array.value = tempVar;

	tempVar = "";
	for (var i = 0; i < arrayOfPrAvFor2.length; i++ ) {
		tempVar += arrayOfPrAvFor2[i]
		if (i < ( arrayOfPrAvFor2.length - 1 )) {
			tempVar += "endVA";
		}
	}	 
	document.forms[0].acc2array.value = tempVar;
	
	tempVar = "";
	for (var i = 0; i < arrayOfPrAvFor3.length; i++ ) {
		tempVar += arrayOfPrAvFor3[i]
		if (i < ( arrayOfPrAvFor3.length - 1 )) {
			tempVar += "endVA";
		}
	}
	document.forms[0].acc3array.value = tempVar;

	tempVar = "";
	for (var i = 0; i < arrayOfPrAvFor4.length; i++ ) {
		tempVar += arrayOfPrAvFor4[i]
		if (i < ( arrayOfPrAvFor4.length - 1 )) {
			tempVar += "endVA";
		}
	}
	document.forms[0].acc4array.value = tempVar;
	tempVar = "";
	for (var i = 0; i < arrayOfPrAvFor5.length; i++ ) {
		tempVar += arrayOfPrAvFor5[i]
		if (i < ( arrayOfPrAvFor5.length - 1 )) {
			tempVar += "endVA";
		}
	}
	document.forms[0].acc5array.value = tempVar;
	tempVar = "";
	for (var i = 0; i < arrayOfPrAvFor6.length; i++ ) {
		tempVar += arrayOfPrAvFor6[i]
		if (i < ( arrayOfPrAvFor6.length - 1 )) {
			tempVar += "endVA";
		}
	}
	document.forms[0].acc6array.value = tempVar;
	tempVar = "";
	for (var i = 0; i < arrayOfPrAvFor7.length; i++ ) {
		tempVar += arrayOfPrAvFor7[i]
		if (i < ( arrayOfPrAvFor7.length - 1 )) {
			tempVar += "endVA";
		}
	}
	document.forms[0].acc7array.value = tempVar;
	tempVar = "";
	for (var i = 0; i < arrayOfPrAvFor8.length; i++ ) {
		tempVar += arrayOfPrAvFor8[i]
		if (i < ( arrayOfPrAvFor8.length - 1 )) {
			tempVar += "endVA";
		}
	}
	document.forms[0].acc8array.value = tempVar;
	tempVar = "";
	for (var i = 0; i < arrayOfPrAvFor9.length; i++ ) {
		tempVar += arrayOfPrAvFor9[i]
		if (i < ( arrayOfPrAvFor9.length - 1 )) {
			tempVar += "endVA";
		}
	}
	document.forms[0].acc9array.value = tempVar;
	tempVar = "";
	for (var i = 0; i < arrayOfPrAvFor10.length; i++ ) {
		tempVar += arrayOfPrAvFor10[i]
		if (i < ( arrayOfPrAvFor10.length - 1 )) {
			tempVar += "endVA";
		}
	}
	document.forms[0].acc10array.value = tempVar;
}




function checkFormFirst(tF) { //tF = ref to form
	var contOn = "no";

	if (tF.myname.value == "") { alert("Please type in your name"); }
	else if (tF.email.value == "") { alert("Please type in your email address"); }
	else if (tF.dates.value == "") { alert("Please type in the starting date"); }
	else if (tF.cottagename.value == "") { alert("Please type in the cottage name"); }
	else if (tF.noweeks.value == "") { alert("Please select the length of your stay"); }
	else if (tF.noadults.value == "") { alert("Please select the number of adults"); }
	else { contOn = "yes"; }

	if ( contOn == "yes" ) {
	//	document.getElementById("submitbutton2").innerHTML = "<p>Please wait ...</p>";				
		str = new String(tF.myname.value);
		tF.myname.value = replaceSpChars(str);
		str = new String(tF.email.value);
		tF.email.value = replaceSpChars(str);
		str = new String(tF.telephone.value);
		tF.telephone.value = replaceSpChars(str);
		str = new String(tF.address.value);
		tF.address.value = replaceSpChars(str);
		str = new String(tF.dates.value);
		tF.dates.value = replaceSpChars(str);
		str = new String(tF.cottagename.value);
		tF.cottagename.value = replaceSpChars(str);
		str = new String(tF.main.value);

		tF.accNo.value = accountNumber;

		tF.main.value = replaceSpChars(str);
		tF.action = "http://www.holiday-cottages.eu/cgi-bin/holidaycottages_av_enq.pl";
		tF.submit();	
	}			
}
		


function replaceSpChars(str) {
	var re = /=/gi
	str = str.replace(re,"equalsSign")
	re = /&/gi
	str = str.replace(re,"amperSand")
	re = /\+/gi
	str = str.replace(re,"plusSign")
	re = /\n/gi
	str = str.replace(re,"newLineSi")
	return str;
}





function getContentToWrite(nameForFile) {
	var today = new Date();
	var uniqueID = today.getTime();
	uniqueID -= 1007743980440;	
	var htmlToReturn = '<' + 'script type="text\/javascript" src="' + nameForFile + '.js\?' + uniqueID + '"\>\<' + '\/script\>';
	return htmlToReturn;
}


function getContentToWriteOwner(nameForFile) {
	var today = new Date();
	var uniqueID = today.getTime();
	uniqueID -= 1007743980440;	
	var htmlToReturn = '<' + 'script type="text\/javascript" src="../../' + nameForFile + '.js\?' + uniqueID + '"\>\<' + '\/script\>';
	return htmlToReturn;
}




noOfJSLoaded += 1;


