function validate() { if (document.schedule_form.frID.value == document.schedule_form.dsID.value) { alert("The destination city cannot be the same as the departure city!"); return false; } //check if valid dates have been picked ... flag an error if not var intDate = document.schedule_form.dayCMB.value; var intMonth = document.schedule_form.monthCMB.value; var intYear = document.schedule_form.yearCMB.value; var errorFlag = 0; if (!validateMonth(intDate, intMonth)) { alert("Please enter a valid date!"); return false; } // check if departure date is not before today var now = new Date(); var today = new Date(now.getYear(),now.getMonth(),now.getDate()); departureDate = new Date(intYear,intMonth-1,intDate); if (departureDate.getTime() < today.getTime()) { alert ("Please pick the correct date for your departure!"); return false; } if (document.schedule_form.displayReturn.checked) { var intDate2 = document.schedule_form.dayCMB2.value; var intMonth2 = document.schedule_form.monthCMB2.value; var intYear2 = document.schedule_form.yearCMB2.value; if (!validateMonth(intDate2, intMonth2)) { alert ("Please pick the correct date for your return!"); return false; } returnDate = new Date(intYear2,intMonth2-1,intDate2); if (document.schedule_form.dayCMB2.value < today.getDate()) { if (returnDate < departureDate) { alert ("Your return date cannot be before the departure date! \n Correct your return details."); return false; } } } return true; } function validateMonth(intDate, intMonth) { if (intMonth == 2 && intDate > 29 ) { return false; } if (intMonth == 4 && intDate > 30) { return false; } if (intMonth == 6 && intDate > 30) { return false; } if (intMonth == 9 && intDate > 30) { return false; } if (intMonth == 11 && intDate > 30) { return false; } return true; }