Hotel Reservations
// 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
'); dialogStore.get().render(self.YAHOO.util.Dom.get(containerId + 'DialogContainer'));
dialogStore.get().showEvent.subscribe(function() { if (self.YAHOO.env.ua.ie) { // Since we're hiding the table using yui-overlay-hidden, we // want to let the dialog know that the content size has changed, when shown // . dialogStore.get().fireEvent("changeContent"); } }); }
// if there is no calendar yet - create it. if (!calendarStore.get()) {
calendarStore.set(new self.YAHOO.widget.Calendar(containerId + 'ContainerCalendar', options)); // set week layout based on selected locale. for (var key in self.locale.calendarLocale) { if (key != 'START_WEEKDAY') calendarStore.get().cfg.setProperty(key, self.locale.calendarLocale[key]); }
calendarStore.get().render();
// set handler for date selection to call provided callback. calendarStore.get().selectEvent.subscribe(function() { if (calendarStore.get().getSelectedDates().length > 0) { var selDate = calendarStore.get().getSelectedDates()[0]; if (changeCallback) changeCallback(selDate); } else { if (changeCallback) changeCallback(null); } dialogStore.get().hide(); });
calendarStore.get().renderEvent.subscribe(function() { // tell the dialog its' contents have changed, which allows the // container to redraw the underlay (for IE6/Safari2) calendarStore.get().fireEvent("changeContent"); }); if (options.initDate) self.setCalendarDate(calendarStore.get(), options.initDate()); }
var selectedDate = calendarStore.get().getSelectedDates();
if (selectedDate.length > 0) { // Set the pagedate to show the selected date if it exists calendarStore.get().cfg.setProperty("pagedate", selectedDate[0]); calendarStore.get().render(); }
dialogStore.get().show(); } };
// Search widget uses the YAHOO UI. In some rare cases it can conflict with another version of YUI. This helps elminate that problem. // In such case you can do following: // 1) Try to remove searchWidgetYahooUIloader and replace it with 'SearchWidget.init(YAHOO);' to force using your version of YUI. // 2) Try to use YAHOO.util.YUILoader with sandbox (see documentation for YUILoader). // Initiate and configure YUI Loader: var searchWidgetYahooUIloader = new YAHOO.util.YUILoader({ // The YUI Loader will automatically identify any additional dependencies required for the specified components. // . // DataSource required for correct date formating. require: ["event", "calendar", "container", "datasource", "selector"],
// Configures YUI Loader to pull in optional dependencies. // For example, animation is an optional dependency for the slider. loadOptional: true,
// This function is called when all script/css resources have been loaded. onSuccess: function() { // initalize search widget with loaded YUI reference. SearchWidget.init(YAHOO); },
// Configure the Get utility to timeout after 5 seconds for any given node insert timeout: 5000,
// Combine YUI files into a single request (per file type) by using the Yahoo! CDN combo service. combine: false, // Load compressed version. filter: 'min',
base: 'https://www.travelnow.com/templates/264960/static/2/default/js/yui2/' // base: 'https://ajax.googleapis.com/ajax/libs/yui/2.8.1/build/' });
// Load YUI and start widget. if (typeof YAHOO == "undefined" || typeof YAHOO.widget == "undefined" || YAHOO.widget.Calendar == "undefined" || typeof YAHOO.widget.Dialog == "undefined" || typeof YAHOO.util.Date == "undefined") searchWidgetYahooUIloader.insert(); else SearchWidget.init(YAHOO);