	var submitcount = 0;
	
	function checkHotel() {
		if (document.form1.id.value == "6") {
			$("#guests").hide();
			$("#guests1").hide();
			$("#guests2").hide();
			$("#guests3").hide();
			$("#guests4").hide();
		} else {
			$("#guests").show();
			$("#guests1").show();
			$("#guests2").show();
			$("#guests3").show();
			$("#guests4").show();
		}
	}
	
	function trackHotel(action,label) {
		//action: 'Bookingbar'
		//label: 'Clicked on booking button - The Devon Valley Hotel' (or similar)
		//   OR
		//action: 'Getaway Page'
		//label: 'Family Getaway - The Devon Valley Hotel' (or similar)
		pageTracker._trackEvent('Book',action,label,85);
		pageTracker._trackPageview('/BookingEngine');
	}
	
	function validForm() {
	
		var msg = "";
		var hotelname = "";
		
		document.form1.guestAdult.value = document.form1.guestAdult1.value;
		document.form1.guestChild.value = document.form1.guestChild1.value;
		
		if (document.form1.id.value == "1") {
			document.form1.louisgroup_select_hotel.name = "louisgroup_devonvalley_book_dates";
			document.form1.guestAdult.name = "numberOfAdults";
			document.form1.guestChild.name = "numberOfChildren";
			document.form1.propertyCode.value = "CPTDV";
			document.form1.action = "https://www.phgsecure.com/IBE/bookingRedirect.ashx";
			hotelname = "The Devon Valley Hotel";
		}
		if (document.form1.id.value == "2") {
			document.form1.louisgroup_select_hotel.name = "louisgroup_erinvale_book_dates";
			document.form1.action = "https://bookings.louisgrouphotels.com/erinvale/book/dates";
			hotelname = "Erinvale Estate Hotel & Spa";
		}
		if (document.form1.id.value == "3") {
			document.form1.louisgroup_select_hotel.name = "louisgroup_placeonthebay_book_dates";
			document.form1.start_date.value = document.form1.arrivalDate.value;
			document.form1.check_in_date.value = document.form1.arrivalDate.value;
			document.form1.check_out_date.value = document.form1.departureDate.value;
			document.form1.number_adults.value = document.form1.guestAdult.value;
			document.form1.number_children.value = document.form1.guestChild.value;
			document.form1.action = "https://www.thebookingbutton.co.uk/properties/FAIRWAYSDIRECT";
			hotelname = "The Fairways on the Bay";
		}
		if (document.form1.id.value == "4") {
			document.form1.louisgroup_select_hotel.name = "louisgroup_placeonthebay_book_dates";
			document.form1.start_date.value = document.form1.arrivalDate.value;
			document.form1.check_in_date.value = document.form1.arrivalDate.value;
			document.form1.check_out_date.value = document.form1.departureDate.value;
			document.form1.number_adults.value = document.form1.guestAdult.value;
			document.form1.number_children.value = document.form1.guestChild.value;
			document.form1.action = "https://www.thebookingbutton.co.uk/properties/PLACEONTHEBAYDIRECT";
			hotelname = "Place on the Bay";
		}
		
		//if (document.form1.id.value == "3" || document.form1.id.value == "4" || document.form1.id.value == "6") {
			//document.form1.louisgroup_select_hotel.name = "louisgroup_placeonthebay_book_dates";
			//document.form1.action = "https://bookings.louisgrouphotels.com/placeonthebay/book/dates";
			//if (document.form1.id.value == "3") {
				//hotelname = "The Fairways on the Bay";
			//}
			//if (document.form1.id.value == "4") {
				//hotelname = "Place on the Bay";
			//}
			//if (document.form1.id.value == "6") {
				//hotelname = "Lobster House";
			//}
		//}
		//if (document.form1.id.value == "6") {
			//document.form1.guestAdult.value = "7";
			//document.form1.guestChild.value = "0";
		//}
		
		if (document.form1.id.value == "") {msg = msg + "Please select a hotel.\n";}
		if (document.form1.depDate.value <= document.form1.arrDate.value) {msg = msg + "Your departure date must be at least 1 day later than your arrival date.\n";}
		if (document.form1.guestAdult.value == "0" && document.form1.guestChild.value == "0") {msg = msg + "You have to book for at least 1 guest.\n";}
	
		if (msg != "") {
			alert(msg);
			if (document.form1.id.value == "") {
				document.form1.id.focus();
			}
			return false;
		}
		if (submitcount == 0) {
			submitcount++;
			$('#bookingbutton').hide();
			$('#invisible').show();
			trackHotel('Bookingbar','Clicked on booking button - '+hotelname); //this function will write the pageTracker._trackEvent and pageTracker._trackPageview lines for a specific hotel 
			return true;
		}
	}
	
	function openWindowHV(theURL) {
	winWidth = screen.width - 100;
	winHeight = screen.height - 100;
	leftPos = 0;
		if (screen) {
			leftPos = (screen.width)/2-(winWidth/2);
		}
	window.open(theURL, "newWin", "scrollbars=yes,resizable=yes,width="+winWidth+",height="+winHeight+",left="+leftPos+",top=0");
	}

