// Search Widget implementation. var SearchWidget = { checkin : null, checkout : null, // Reference to YUI used by search widget. YAHOO: null, yuiLocale: null,
// List of IDs within search widget. // If any of these IDs conflict with IDs already on your page. Change them below and within the form. CHECKIN_ID : "check-in", CHECKIN_ICON_ID : "checkinIcon", CHECKOUT_ID : "check-out", CHECKOUT_ICON_ID : "checkoutIcon", RESET_DATES_ID : "reset-dates", TARGET_ID : "targetId", DESTINATION_ID : "destination", PREDEFINED_DESTINATION_ID : "predefinedDestination", PREDEFINED_TARGETID_ID : "predefinedTargetId", ROOMS_ID : "rooms", ADULTS_ID : "adults", CHILDREN_ID : "children", ADULTS_LABEL_ID : "adults_label", CHILDREN_LABEL_ID : "children_label", SEARCH_ID : "search-btn", HOTEL_CHAINS_ID : "hotel-chains", STAR_CATEGORY_ID : "star-rating", ROOMS_MAX_COUNT : "maxcount",
// Current locale code. localeCode : "en",
// Fields to store calendar instances. checkinCalendar : null, checkoutCalendar : null,
// Fields to store calendar dialogs. checkinCalendarDialog : null, checkoutCalendarDialog : null,
today : new Date(), checkInDateSelected: new Date(), checkOutDateSelected: new Date(),
// Locale object loaded from JS file. locale: null,
// Main initialization function. Should be called once. Argument reference to YUI main object. init : function(YAHOO_LIBRARY_REF) { var self = this; self.YAHOO = YAHOO_LIBRARY_REF; self.loadLocaleFromTemplates(); self.decorateDatelessCheckbox(); self.setInitialCheckinCheckoutDates(); self.decorateCalendars(); self.decorateDates(); self.decoratePredefinedDestinations(); self.decorateRooms(); self.decorateSearch(); },
// Applies current calendar locale. loadLocaleFromTemplates : function() { var self = this; if (typeof yuiLocales == "undefined") { // This inserts the default locale if one is not specified. self.YAHOO.log("locale was not loaded. Possible reason - incorrect home url in CP", "error"); self.locale = {}; self.locale.calendarLocale = self.YAHOO.util.DateLocale; } else { self.locale = yuiLocales; var dateLocale = null; var loadLocale = function(postfix) { if (!dateLocale) { self.localeCode = "en" + postfix; dateLocale = yuiLocales.dateLocales[self.localeCode]; if (!dateLocale) dateLocale = yuiLocales.calendarLocales[self.localeCode]; } }; // This checks for variations on the new locale (for example fr could be fr_CA). loadLocale("");loadLocale("_SA");loadLocale("_CA");loadLocale("_PL");loadLocale("_TW");
var originDateLocale = self.YAHOO.lang.merge(dateLocale); self.locale.calendarLocale = self.locale.calendarLocales[self.localeCode]; // Required for some languages like Hindi. self.locale.calendarLocale["DATE_RANGE_DELIMITER"] = "--"; if (!self.locale.calendarLocale.YEAR_OFFSET) self.locale.calendarLocale.YEAR_OFFSET = 0;
self.YAHOO.util.DateLocale[self.localeCode] = self.YAHOO.lang.merge(self.YAHOO.util.DateLocale, dateLocale); self.YAHOO.util.DateLocale[self.localeCode + "_origin"] = self.YAHOO.lang.merge(self.YAHOO.util.DateLocale, originDateLocale); } },
// Save entered dates in case of switching to dateless mode. updateSavedDates : function() { var self = this; self.checkin = self.YAHOO.util.Dom.get(self.CHECKIN_ID).value; self.checkout = self.YAHOO.util.Dom.get(self.CHECKOUT_ID).value; },
// Restore saved dates in case of switching back to calendar mode. restoreSavedDates : function() { var self = this; self.YAHOO.util.Dom.get(self.CHECKIN_ID).value = self.checkin; self.YAHOO.util.Dom.get(self.CHECKOUT_ID).value = self.checkout; },
// Set checkin and checkout 'disabled' property. setCheckinCheckoutDisable : function (value) { var self = this; self.YAHOO.util.Dom.get(self.CHECKIN_ID).disabled = self.YAHOO.util.Dom.get(self.CHECKOUT_ID).disabled = value; },
// Set handler for dateless checkbox. decorateDatelessCheckbox : function() { var self = this; var datelessCheckBox = self.YAHOO.util.Dom.get(self.RESET_DATES_ID); if (datelessCheckBox) { self.updateSavedDates(); self.YAHOO.util.Event.on(datelessCheckBox, "click", function() { if (datelessCheckBox.checked) { // if dateless self.updateSavedDates(); // save dates entered // clear fields self.YAHOO.util.Dom.get(self.CHECKIN_ID).value = self.YAHOO.util.Dom.get(self.CHECKOUT_ID).value = ""; // disable fields self.setCheckinCheckoutDisable(true); } else { // if calendar mode - enable fields and restore dates self.setCheckinCheckoutDisable(false); self.restoreSavedDates(); } }) } },
// Utility functions - adds day to date. addDays : function(date, days) { var result = new Date(); result.setTime(date.getTime() + (1000*3600*24)*days); return result; },
// Utility function - formats date according to current locale. formatDate : function(date) { var self = this; return self.YAHOO.util.Date.format(date, { format: "%x" }, self.localeCode); },
// Utility function - parses date according current locale. parseDate : function(sDate) { var self = this; var aDate = sDate.split(self.locale.calendarLocale.DATE_FIELD_DELIMITER); var rArray;
if (aDate.length == 2) { rArray = [aDate[self.locale.calendarLocale.MD_MONTH_POSITION-1],aDate[self.locale.calendarLocale.MD_DAY_POSITION-1]]; rArray.type = self.YAHOO.widget.Calendar.MONTH_DAY; } else { rArray = [aDate[self.locale.calendarLocale.MDY_YEAR_POSITION-1] - self.locale.calendarLocale.YEAR_OFFSET, aDate[self.locale.calendarLocale.MDY_MONTH_POSITION-1],aDate[self.locale.calendarLocale.MDY_DAY_POSITION-1]]; rArray.type = self.YAHOO.widget.Calendar.DATE; }
for (var i=0;i