function OKCancel(question) {
	if (confirm(question)) {
		return true;
	} else {
		return false;
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function addBookmark() {
bookmarkURL = "http://www.newhols.com"
bookmarkTitle = "Newmans Holiday Homes"

if (document.all) {
	window.external.AddFavorite(bookmarkURL,bookmarkTitle)
	}
}

function buildeDC(x, linkwords, classname) {
	var e, dom, td;
	dom = 'newhols';
	td = 'com';
	e = x + '@' + dom + '.' + td;
	if (linkwords != '') {
		document.write('<a href="mailto:' + e + '?subject=Enquiry from Newhols Website" class="' + classname + '">' + linkwords + '</a>');
	} else {
		document.write('<a href="mailto:' + e + '?subject=Enquiry from Newhols Website" class="' + classname + '">' + e + '</a>');
	}
}

function buildeBS(x, linkwords, classname) {
	var e, dom, td;
	dom = 'breansandscaravans';
	td = 'com';
	e = x + '@' + dom + '.' + td;
	if (linkwords != '') {
		document.write('<a href="mailto:' + e + '?subject=Enquiry from Brean Sands Caravans Website" class="' + classname + '">' + linkwords + '</a>');
	} else {
		document.write('<a href="mailto:' + e + '?subject=Enquiry from Brean Sands Caravans Website" class="' + classname + '">' + e + '</a>');
	}
}

function left(str, n) {
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else
		return String(str).substring(0, n);
}

function right(str, n) {
	if (n <= 0)
		return "";
	else if (n > String(str).length)
		return str;
	else {
		var iLen = String(str).length;
		return String(str).substring(iLen, iLen - n);
	}
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit)
		field.value = field.value.substring(0, maxlimit);
	else
		cntfield.value = maxlimit - field.value.length;
}

function UpdateDeposit() {
	document.frmBook1.DepositChanged.value = '1';
//	document.frmBook1.action = 'book-1.asp';
	document.frmBook1.submit();
}

function DiscountShowAll() {
	document.frmDiscountBrowse.submit();
}

function confirmThis(i, gotoPage) {
	var message=new Array();
	message[0]="Are you sure you want to delete this record?";
	message[1]="Suspending this Owner\'s logon works by erasing their password.\n\nTo allow them back on to the system again at a later date, you will need to send the Owner a new password.\n\nDo you want to continue?";
	message[2]="Are you sure you want to email these job details to this contractor?";

	var r=confirm(message[i]);
	if (r==true) {
		window.location = gotoPage;
	} else {
		return false;
	}
}

function calcExtraSubTotal(formNo) {
	var productId, thePrice, qty, depositAmountReqd, freeInd;
	var stringLength, depositSubtotal, subtotal, total, totalDeposit, totalExtrasAndDeposits;

	total = 0;
	totalDeposit = 0;
	totalExtrasAndDeposits = 0;
	for (i = 0; i < document.forms[formNo].elements.length; i++) {
		if (left(document.forms[formNo].elements[i].name, 3) == 'Qty') {
			
			stringLength = document.forms[formNo].elements[i].name.length;
			productId = right(document.forms[formNo].elements[i].name, (stringLength - 3));
			qty = document.getElementById('Qty' + productId).value;
			thePrice = document.getElementById('ThePrice' + productId).value;
			depositAmountReqd = document.getElementById('DepositAmountReqd' + productId).value;
			freeInd = document.getElementById('FreeInd' + productId).value;
			
			if (!(isNaN(qty))){
				subtotal = thePrice * qty;
				depositSubtotal = depositAmountReqd * qty;
				total = total + subtotal;
				totalDeposit = totalDeposit + depositSubtotal;
				totalExtrasAndDeposits = totalExtrasAndDeposits + subtotal + depositSubtotal;
				if (subtotal != 0) {
					document.getElementById('SubTotal' + productId).innerHTML='Subtotal<br />&pound;' + subtotal.toFixed(2);
				} else {
					document.getElementById('SubTotal' + productId).innerHTML='';
				}
			}
		}
	}
	document.getElementById('Total').innerHTML='Extras Total <strong>&pound;' + total.toFixed(2) + '</strong><br />plus refundable damage/security deposit of <strong>&pound;' + totalDeposit.toFixed(2) + '</strong>';
	document.getElementById('TotalExtrasAndDeposits').innerHTML='TOTAL EXTRAS AND DEPOSITS <strong>&pound;' + totalExtrasAndDeposits.toFixed(2) + '</strong>';
}

function priceWeek() {
	var m1, m2, dailyPrice, priceWeek
	
	m1 = '<strong>&pound;'
	m2 = '</strong> per week'
	
	dailyPrice = document.getElementById('Price').value;
	if (!(isNaN(dailyPrice))){
		priceWeek = dailyPrice * 7.00;
		document.getElementById('WeekPriceText').innerHTML = m1 + priceWeek.toFixed(2) + m2;
	} else {
		document.getElementById('WeekPriceText').innerHTML = 'Cannot calculate weekly price';
	}
}

function price3Day() {
	var m1, m2, dailyPrice, price3Day
	
	m1 = '<strong>&pound;'
	m2 = '</strong> for Friday to Monday'
	
	dailyPrice = document.getElementById('Price3Day').value;
	if (!(isNaN(dailyPrice))){
		price3Day = dailyPrice * 3.00;
		document.getElementById('Price3DayText').innerHTML = m1 + price3Day.toFixed(2) + m2;
	} else {
		document.getElementById('price3DayText').innerHTML = 'Cannot calculate 3 Day price';
	}
}

function price4Day() {
	var m1, m2, dailyPrice, price4Day
	
	m1 = '<strong>&pound;'
	m2 = '</strong> for Monday to Friday'
	
	dailyPrice = document.getElementById('Price4Day').value;
	if (!(isNaN(dailyPrice))){
		price4Day = dailyPrice * 4.00;
		document.getElementById('Price4DayText').innerHTML = m1 + price4Day.toFixed(2) + m2;
	} else {
		document.getElementById('price4DayText').innerHTML = 'Cannot calculate 4 Day price';
	}
}

function date1Initialise(date1Field, theDate) {
	var date1Value = document.getElementById(date1Field).value;
	
	if (date1Value == '') {
		document.getElementById(date1Field).value =  theDate
	}
}

function date2Initialise(date1Field, date2Field) {
	var dayfield1, monthfield1, yearfield1, dd1, mm1, dayobj1, validDate1
	var dayfield2, monthfield2, yearfield2, dd2, mm2, dayobj2, validDate2
	
	var date1Value = document.getElementById(date1Field).value;
	var date2Value = document.getElementById(date2Field).value;
	
	validDate1 = false;
	validDate2 = false;

	if (date1Value != '') {
		if (checkdate(document.getElementById(date1Field)) == true) {
			validDate1 = true;
			dayfield1 = date1Value.split("/")[0];
			monthfield1 = date1Value.split("/")[1];
			yearfield1 = date1Value.split("/")[2];
			dayobj1 = new Date(yearfield1, monthfield1-1, dayfield1);
		}
	}
	
	if (date2Value != '') {
		if (checkdate(document.getElementById(date2Field)) == true) {
			validDate2 = true;
			dayfield2 = date2Value.split("/")[0];
			monthfield2 = date2Value.split("/")[1];
			yearfield2 = date2Value.split("/")[2];
			dayobj2 = new Date(yearfield2, monthfield2-1, dayfield2);
		}
	}
	
	if (validDate1 == true) {
		if (validDate2 == true) {
			if (dayobj2 <= dayobj1) {
				dayobj1.setDate(dayobj1.getDate() + 7);
				dd1 = dayobj1.getDate();
				dd1 = (dd1 < 10) ? '0' + dd1 : dd1;
				mm1 = dayobj1.getMonth()+1;
				mm1 = (mm1 < 10) ? '0' + mm1 : mm1;
				document.getElementById(date2Field).value = dd1 + '/' + mm1 + '/' + dayobj1.getFullYear();
			}
		} else {
			dayobj1.setDate(dayobj1.getDate() + 7);
			dd1 = dayobj1.getDate();
			dd1 = (dd1 < 10) ? '0' + dd1 : dd1;
			mm1 = dayobj1.getMonth()+1;
			mm1 = (mm1 < 10) ? '0' + mm1 : mm1;
			document.getElementById(date2Field).value = dd1 + '/' + mm1 + '/' + dayobj1.getFullYear();
		}
	}
}

function checkdate(input) {
	var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
	var returnval=false
	
	if (!validformat.test(input.value)) {
		alert("Invalid Date Format. Please correct and submit again.")
	}	else { //Detailed check for valid date ranges
		var dayfield=input.value.split("/")[0];
		var monthfield=input.value.split("/")[1];
		var yearfield=input.value.split("/")[2];
		var dayobj = new Date(yearfield, monthfield-1, dayfield);
		if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield)) {
			alert("Invalid Day, Month, or Year range detected. Please correct and submit again.");
		} else {
			returnval=true;
		}
	}
	if (returnval==false){
		input.select();
	}
	return returnval;
}

