function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function validateContactForm() {
	fullName = document.contact_form.full_name.value;
	phone = document.contact_form.phone.value;
	emailAddress = document.contact_form.email.value;
	query = document.contact_form.query.value;
	
	if (fullName == "") {
		alert("You must enter your full name.");
		document.contact_form.full_name.focus();
		return false;
	}
	if (phone == "" && emailAddress == "") {
		alert("Please provide either your phone number or your email address.");
		document.contact_form.phone.focus();
		return false;
	}
	if (phone != "" && !isNumeric(phone)) {
		alert("Your phone number can only contain numeric characters");
		document.contact_form.phone.focus();
		return false;
	}
	if (emailAddress != "") {
		// E-mail Validation by Henrik Petersen / NetKontoret
		// Explained at www.echoecho.com/jsforms.htm
		// Please do not remove this line and the two lines above.
		apos=emailAddress.indexOf("@"); 
		dotpos=emailAddress.lastIndexOf(".");
		lastpos=emailAddress.length-1;
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
			alert("You must enter a valid email address");
				document.contact_form.email.focus();
			return false;
		}
	}
	
	if (query == "") {
		alert("Please provide some details relating to your query.");
		document.contact_form.query.focus();
		return false;
	}
	
	return true;
}

function isNumeric(strString) {
	var strValidChars = "0123456789 +()";
	var strChar;
	var blnResult = true;

	if (strString.length == 0) return false;
	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++) {
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1) {
			blnResult = false;
		}
	}
	return blnResult;
}

function validateBookingForm() {
	fullName = document.booking_form.full_name.value;
	phone = document.booking_form.phone.value;
	emailAddress = document.booking_form.email.value;
	
	if (fullName == "") {
		alert("You must enter your full name.");
		document.booking_form.full_name.focus();
		return false;
	}
	if (phone == "") {
		alert("You must enter your phone number.");
		document.booking_form.phone.focus();
		return false;
	}
	if (phone != "" && !isNumeric(phone)) {
		alert("Your phone number can only contain numeric characters");
		document.booking_form.phone.focus();
		return false;
	}
	if (emailAddress != "") {
		// E-mail Validation by Henrik Petersen / NetKontoret
		// Explained at www.echoecho.com/jsforms.htm
		// Please do not remove this line and the two lines above.
		apos=emailAddress.indexOf("@"); 
		dotpos=emailAddress.lastIndexOf(".");
		lastpos=emailAddress.length-1;
		if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2) {
			alert("You must enter a valid email address");
				document.booking_form.email.focus();
			return false;
		}
	}
	
	thisDay = document.booking_form.current_day.value;
	thisMonth = document.booking_form.current_month.value;
	thisYear = document.booking_form.current_year.value;
	
	arrivalDay = document.booking_form.arrivalDay.value;	
	arrivalMonth = document.booking_form.arrivalMonth.value;
	arrivalYear = document.booking_form.arrivalYear.value;	
		
	if ((arrivalYear < thisYear) || (arrivalYear == thisYear && arrivalMonth < thisMonth) || (arrivalYear == thisYear && arrivalMonth == thisMonth && arrivalDay < thisDay)) {
		alert("You must provide an arrival date in the future.");
		document.booking_form.arrivalDay.focus();
		return false;
	}
	
	return true;
}

function validatePaymentForm() {
	thisMonth = document.booking_form.current_month.value;
	thisYear = document.booking_form.current_year.value;
	
	ccName = document.booking_form.cc_name.value;
	ccNumber = document.booking_form.cc_number.value;
	ccMonth = document.booking_form.ccMonth.value;
	ccYear = document.booking_form.ccYear.value;	
	
	if (ccName == "") {
	alert("You must enter the name that appears on the credit card.");
	document.booking_form.cc_name.focus();
	return false;
	}
	if (ccNumber == "") {
	alert("You must enter the 16 digit credit card number.");
	document.booking_form.cc_number.focus();
	return false;
	}
	if (ccNumber != "" && !isNumeric(ccNumber)) {
			alert("Your credit card number can only contain numeric characters.");
	document.booking_form.cc_number.focus();
	return false;
	}
	if (ccNumber != "" && ccNumber.length < 16) {
	alert("You must enter the 16 digit credit card number.");
	document.booking_form.cc_number.focus();
	return false;
	}
	var cardSelection = document.booking_form.cc_type.selectedIndex;
	var cardId = document.booking_form.cc_type.options[cardSelection].value;
	
	if (cardId == "-1") {
		alert("You must select a credit card type.");
		document.booking_form.cc_type.focus();
		return false;
	}
		
	if ((ccYear < thisYear) || (ccMonth < thisMonth && ccYear == thisYear)) {
		alert("You must provide an expiry date in the future.");
		document.booking_form.ccMonth.focus();
		return false;
	}
	return true;
}

function getPrice() {
	thisDay = document.booking_form.current_day.value;
	thisMonth = document.booking_form.current_month.value;
	thisYear = document.booking_form.current_year.value;
	
	arrivalDay = document.booking_form.arrivalDay.value;	
	arrivalMonth = document.booking_form.arrivalMonth.value;
	arrivalYear = document.booking_form.arrivalYear.value;	
	
	if ((arrivalYear < thisYear) || (arrivalYear == thisYear && arrivalMonth < thisMonth) || (arrivalYear == thisYear && arrivalMonth == thisMonth && arrivalDay < thisDay)) {
		alert("You must provide an arrival date in the future.");
		document.booking_form.arrivalMonth.focus();
		return false;
	}
	
	document.booking_form.get_price.value = "true";
	document.booking_form.submit();
}

function addBooking() {
	document.booking_form.booking_action.value = "add";
	document.booking_form.submit();
}
function clearBooking() {
	document.booking_form.booking_action.value = "clear";
	document.booking_form.submit();
}
function makeEnquiry() {
    if (validateBookingForm()) {
        document.booking_form.action = "booking_enquiry.php";
    	return true;
    } else {
        return false;
    }
}
function makeBooking() {
    if (validateBookingForm()) {
        document.booking_form.action = "booking_payment.php";
    	return true;
    } else {
        return false;
    }
}