
	function checkBooking(pShowDialog, pShowRentalPrice, pCheckUserInput) { 
		
		strError = "";
		iRental = "";
		iVilla = document.getElementById('villa').value;
		iMinStay = document.getElementById('minStay').value;

		getArrAndDepDates();
		isDateArrBeforeToday();

		if (strError == "") {
			isDateDepGreaterThanDateArr();
		}
		if (strError == "") {
			checkDateInterval(dateArr, dateDep, iMinStay);
		}
		if (strError == "") {
			doHttpRequest("/HttpVilla.asp", "villa=" + iVilla + "&dateArr=" + strDateArr + "&dateDep=" + strDateDep); 
		}

		if ( isNumeric(strError) ) {

			iLateAvail = 0;
			iRental = strError;
			
			//do we need to apply late availability ?
			//it applies if the villa is eligible AND the departure date is <= 14 days
			dateToday = new Date();
			dateLateAvailEnds = new Date(document.getElementById('lateAvailEnds').value);
			if ( (dateDep <= dateLateAvailEnds) && (document.getElementById('lateAvail').value != 0) ) {
				iLateAvail = document.getElementById('lateAvail').value;
				iRental = Math.round(iRental * ( (100 - iLateAvail) / 100) );
				document.getElementById('bookLateAvail').value = "Y";
			} else if (dateDep > dateLateAvailEnds)  {
				document.getElementById('bookLateAvail').value = "N";
			}
			
			getTodayPrice();
			
			pButtonBookNextStep = document.getElementById('buttonBookNextStep');
			pButtonBookNextStep.style.display = "none";
			pBookingFormDetails = document.getElementById('bookingFormDetails');
			pBookingFormDetails.style.display = "block";

			setRentalDisplay();
			
			if (pCheckUserInput) {

				strError = "";
				strBookPeople = "";

				strBookName = trim(removeMultipleWhiteSpaces(document.getElementById('bookName').value));
				strBookEmail = trim(removeAllWhiteSpaces(document.getElementById('bookEmail').value));
				strBookTel = trim(removeAllWhiteSpaces(document.getElementById('bookTel').value));
				strBookMob = trim(removeAllWhiteSpaces(document.getElementById('bookMob').value));
				strBookAddress = trim(document.getElementById('bookAddress').value);		
				strBookPostcode = trim(removeAllWhiteSpaces(document.getElementById('bookPostcode').value));
				iMaxPeople = document.getElementById('maxPeople').value;

				document.getElementById('bookName').value = strBookName;
				document.getElementById('bookEmail').value = strBookEmail;
				document.getElementById('bookTel').value = strBookTel;
				document.getElementById('bookMob').value = strBookMob;
				document.getElementById('bookAddress').value = strBookAddress;
				document.getElementById('bookPostcode').value = strBookPostcode;

				if (strBookName == "") {
					strError = strError + "Please enter your name\n"; 
				}
				if (strBookEmail == "") {
					strError = strError + "Please enter your email address\n"; 
				} else if (isEmailValid(strBookEmail) == false) {
					strError = strError + "Please enter a valid email address\n"; 
				}
				if (strBookTel == "") {
					strError = strError + "Please enter your telephone number\n"; 
				}
				if (strBookMob == "") {
					strError = strError + "Please enter your mobile telephone number\n"; 
				}
				if (strBookAddress == "") {
					strError = strError + "Please enter your address\n"; 
				}
				if (strBookPostcode == "") {
					strError = strError + "Please enter your postcode\n"; 
				}
				
				for (i = 1; i <= iMaxPeople; i++) {
				
					strBookGroupName = trim(removeMultipleWhiteSpaces(document.getElementById('bookGroupName' + i).value));
					iBookGroupAge = trim(removeAllWhiteSpaces(document.getElementById('bookGroupAge' + i).value));
					document.getElementById('bookGroupName' + i).value = strBookGroupName;
					document.getElementById('bookGroupAge' + i).value = iBookGroupAge;
					
					if ( (strBookGroupName == "") && (iBookGroupAge != "") ) {
						strError = strError + "People staying at the property : You have entered an age of " + iBookGroupAge + " but there is no name\n"; 
					} else {
					
						if (strBookGroupName != "") {
							strBookPeople = strBookPeople + ", " + strBookGroupName;
							if (iBookGroupAge != "") {
								if (isNumeric(iBookGroupAge)) {
									strBookPeople = strBookPeople + " (" + iBookGroupAge + ")";
								} else {
									strError = strError + "People staying at the property : Age " + iBookGroupAge + " is not a number\n"; 
								}
							}
						}
					}
				}
				
				strBookPeople = strBookPeople.substring(2);
				document.getElementById('bookPeople').value = strBookPeople
				if (strBookPeople == "") {
					strError = strError + "Please enter the people who will be staying at the property\n"; 
				}
			
				if (strError == "") {
					getCaptcha();
				}
				
				if (document.getElementById('Terms').checked == false) {
					strError = strError + "Please read and agree to the Terms and Conditions\n"; 
				}
	
				if (strError != "") {
					setAlert();
				} else {
					//alert("FORM OK");
					document.forms['booking'].submit();
				}
			
			}
			
		} else {
			if (pShowRentalPrice) {
				setRentalDisplay();
			}
			if (pShowDialog) {	
				setAlert();
			}
		}

	}
	

	function setAlert() {
		alert("Sorry, but we cannot process your booking due to the following problems.\n\n" + strError);
	}
