var dates = function () { //private shorthand references to YUI utilities: var messageResources = new Object(); return { init: function () { messageResources.missingCheckInDate = "Please enter a check-in date."; messageResources.missingCheckOutDate = "Please enter a check-out date."; messageResources.invalidCheckInDate = "Your Check-in date is invalid. Please check the date."; messageResources.invalidCheckOutDate = "Your Check-out date is invalid. Please check the date."; messageResources.pastCheckInDate = "Your Check-in date cannot be less than minDate"; messageResources.pastCheckOutDate = "Your Check-out date cannot be less than minDate"; messageResources.futureCheckInDate = "Your Check-in date cannot be more than maxDate"; messageResources.futureCheckOutDate = "Your Check-out date cannot be more than maxDate"; messageResources.checkOutDateBeforeCheckInDate = "Your check-out date must be after your check-in date. Please verify your dates."; }, validateDates: function(section,fromDtFldNm,toDtFldNm,formIdx) { var section = section ; var fromDateFldName = "fromDate"; var toDateFldName = "toDate" ; var yud = YAHOO.util.Dom ; var fromDateObj = null ; var toDateObj = null ; var formIndex = formIdx+'' ; var dateFormatPattern = YAHOO.calendarUtil.module.getDateFormatPattern() ; if(fromDtFldNm != null && fromDtFldNm.length > 0){ if(formIndex != null && formIndex.length > 0 ){ fromDateFldName = fromDtFldNm+formIndex; }else{ fromDateFldName = fromDtFldNm; } } if(toDtFldNm != null && toDtFldNm.length > 0){ if(formIndex != null && formIndex.length > 0 ){ toDateFldName = toDtFldNm+formIndex; }else{ toDateFldName = toDtFldNm; } } fromDateObj = yud.get(fromDateFldName) ; toDateObj = yud.get(toDateFldName); var minDate = yud.get("minDate").value ; var maxDate = yud.get("maxDate").value ; var fromDate = ''; var toDate = ''; var errMessage = "" ; //Check-in date validation if(fromDateObj != null){ fromDate = fromDateObj.value; //If the validation is invoked from the availability form, make sure the check in and //check out dates are not empty if(section == "availability" || section == "futureRates" ){ if(fromDate == null || fromDate == '' ){ errMessage = messageResources.missingCheckInDate ; alert(errMessage); fromDateObj.focus() ; return false ; } } if(fromDate != null && fromDate.length > 0){ //is check-in date valid? if (!isDateValid(fromDate, dateFormatPattern)) { errMessage = messageResources.invalidCheckInDate ; alert(errMessage); fromDateObj.focus() ; return false ; } //Validate that Check-in is not less than the min date if(isDateLessThanDate1(fromDateObj.value,formatDate(minDate,dateFormatPattern),dateFormatPattern)){ errMessage = messageResources.pastCheckInDate ; errMessage = errMessage.replace("minDate",formatDate(minDate,dateFormatPattern)) alert(errMessage); fromDateObj.focus() ; return false; } //Validate that fromDate is not greater than the max date if(isDateGreaterThanDate1(fromDateObj.value,formatDate(maxDate,dateFormatPattern),dateFormatPattern)){ errMessage = messageResources.futureCheckInDate ; errMessage = errMessage.replace("maxDate",formatDate(maxDate,dateFormatPattern)) alert(errMessage); fromDateObj.focus() ; return false; } //The check is made for availabilility on top already if(section != "availability"){ if(toDateObj != null && (toDateObj.value == null || toDateObj.value == "") ){ errMessage = messageResources.missingCheckOutDate ; alert(errMessage); toDateObj.focus() ; return false ; } } } } if(section != "futureRates"){ //Check-out date validation if(toDateObj != null){ toDate = toDateObj.value; if(section == "availability"){ if(toDate == null || toDate == '' ){ errMessage = messageResources.missingCheckOutDate ; alert(errMessage); toDateObj.focus() ; return false ; } } if(toDate != null && toDate.length > 0){ //is check in date valid? if (!isDateValid(toDate, dateFormatPattern)) { errMessage = messageResources.invalidCheckOutDate ; alert(errMessage); toDateObj.focus() ; return false ; } //Validate that check-out is not less than the min date if(isDateLessThanDate1(toDateObj.value,datePlusOne(minDate,dateFormatPattern),dateFormatPattern)){ errMessage = messageResources.pastCheckOutDate ; errMessage = errMessage.replace("minDate",datePlusOne(minDate,dateFormatPattern)) alert(errMessage); toDateObj.focus() ; return false; } //Validate that check-out is not greater than the max date if(isDateGreaterThanDate1(toDateObj.value,formatDate(maxDate,dateFormatPattern),dateFormatPattern)){ errMessage = messageResources.futureCheckOutDate ; errMessage = errMessage.replace("maxDate",formatDate(maxDate,dateFormatPattern)) alert(errMessage); toDateObj.focus() ; return false; } if(section != "availability"){ if(fromDateObj != null && (fromDateObj.value == null || fromDateObj.value == "") ){ errMessage = messageResources.missingCheckInDate ; alert(errMessage); fromDateObj.focus() ; return false ; } } } } //Validate that Check-in date is before Check-out date if((fromDateObj != null && (fromDateObj.value != null && fromDateObj.value != "")) && (toDateObj != null && (toDateObj.value != null && toDateObj.value != ""))){ if(isDateLessThanOrEqualToDate1(toDateObj.value,fromDateObj.value,dateFormatPattern)) { errMessage = messageResources.checkOutDateBeforeCheckInDate ; alert(errMessage); toDateObj.focus() ; return false; } } } return true; }, validateEandMDates: function(section,fromDtFldNm,toDtFldNm,formIdx) { var fromDateObj = null ; var toDateObj = null ; var yud = YAHOO.util.Dom ; var dateFormatPattern = YAHOO.calendarUtil.module.getDateFormatPattern() ; fromDateObj = yud.get(fromDtFldNm) ; toDateObj = yud.get(toDtFldNm); var minDate = yud.get("minDate").value ; var maxDate = yud.get("maxDate").value ; var fromDate = ''; var toDate = ''; var errMessage = "" ; //Check-in date validation if(fromDateObj != null && (fromDateObj.value != null && fromDateObj.value != "") ){ fromDate = fromDateObj.value; //is Arrival date valid? if (!isDateValid(fromDate, dateFormatPattern)) { errMessage = "Your arrival date is invalid. Verify your date." ; alert(errMessage); return false ; } //Validate that Arrival is not equal to the current date if(isDateEqualsCurrentDate(fromDate,dateFormatPattern)){ errMessage = "For same-day bookings, please contact the hotel directly or call our National Group Desk directly at 1800-831-4004." ; alert(errMessage); return false; } //Validate that Arrival is not less than the min date if(isDateLessThanDate1(fromDate,formatDate(minDate,dateFormatPattern),dateFormatPattern)){ errMessage = "Your arrival date occur in the past. Verify your dates" ; alert(errMessage); return false; } //Validate that Arrival is not greater than the max date if(isDateGreaterThanDate1(fromDate,formatDate(maxDate,dateFormatPattern),dateFormatPattern)){ errMessage = "Your arrival date occur in the future. Verify your dates" ; alert(errMessage); return false; } if(toDateObj.value == null || toDateObj.value == '' ){ errMessage = "Please enter a departure date." ; alert(errMessage); return false ; } } //Departure date validation if(toDateObj != null && (toDateObj.value != null && toDateObj.value != "") ){ toDate = toDateObj.value; //is Departure date valid? if (!isDateValid(toDate, dateFormatPattern)) { errMessage = "Your departure date is invalid. Verify your date." ; alert(errMessage); return false ; } //Validate that check-out is not less than the min date if(isDateLessThanDate1(toDate,datePlusOne(minDate,dateFormatPattern),dateFormatPattern)){ errMessage = "Your departure date occurs in the past. Verify your date. "; alert(errMessage); return false; } //Validate that check-out is not greater than the max date if(isDateGreaterThanDate1(toDate,formatDate(maxDate,dateFormatPattern),dateFormatPattern)){ errMessage = "Your departure date occurs in the future. Verify your date."; alert(errMessage); return false; } if(fromDateObj.value == null || fromDateObj.value == '' ){ errMessage = "Please enter an arrival date"; alert(errMessage); return false ; } } //Validate that Check-in date is before Check-out date if((fromDateObj != null && (fromDateObj.value != null && fromDateObj.value != "")) && (toDateObj != null && (toDateObj.value != null && toDateObj.value != ""))){ if(isDateEqualsDate1(fromDateObj.value,toDateObj.value,dateFormatPattern)) { errMessage = "For same-day bookings, please contact the hotel directly or call our National Group Desk directly at 1800-831-4004. " alert(errMessage); return false; }else if(isDateGreaterThanDate1(fromDateObj.value,toDateObj.value,dateFormatPattern)) { alert("Please enter a departure date that is after your arrival date"); return false; } var daysDiff = calculateNoOfNights(new Date(fromDateObj.value), new Date(toDateObj.value)); if (daysDiff > 10) { alert("For events lasting more than 10 nights, please contact our National Group Desk directly at 1-800-831-4004."); return false; } } return true; }, calculateNoOfNights: function (checkInDate, checkOutDate) { var daysDifference = 0; if (checkInDate != null && checkOutDate != null) { var difference = checkOutDate.getTime() - checkInDate.getTime(); daysDifference = Math.floor(difference/1000/60/60/24); } return daysDifference; } }; }(); addLoadEvent(dates.init);