if(typeof String.prototype.trim !== 'function') { String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); } } if (!Object.keys) { Object.keys = (function () { var hasOwnProperty = Object.prototype.hasOwnProperty, hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'), dontEnums = [ 'toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'constructor' ], dontEnumsLength = dontEnums.length; return function (obj) { if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object'); var result = []; for (var prop in obj) { if (hasOwnProperty.call(obj, prop)) result.push(prop); } if (hasDontEnumBug) { for (var i=0; i < dontEnumsLength; i++) { if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]); } } return result; }; })(); } //special consideration for internet exploder < 8 if (!Date.now) { Date.now = function() { return new Date().valueOf(); }; } window.console = console || { log : function() {} }; function basename(path) { return path.replace(/\\/g,'/').replace( /.*\//, '' ); } /** * ActivityRez Web Booker * * @author Ryan Freeman * @package ActivityRez * @subpackage Web Booker */ //compresses to 21207 B var WebBooker = { bootstrap: {}, showInitLoader: ko.observable(true), wbLoaded: ko.observable(false), show404: ko.observable(false), hasReseller: ko.observable(false), selectedCurrency: ko.observable({}), available_currencies: ko.observableArray([]), thumbnailHeight: wb_global_vars.thumbnailHeight || 125, galleryImageHeight: wb_global_vars.galleryImageHeight || 700, timthumb: 'https://media1.activityrez.com/images/', mediaServer: (wb_global_vars && wb_global_vars.server == 'training') ? '//devmedia.activityrez.com' : '//media.activityrez.com', selectedLanguage: ko.observable(), available_langs: ko.observableArray([]), isOldIE: (function(){ if(navigator.appName != "Microsoft Internet Explorer") return false; return parseInt(/MSIE\s(\d+)/.exec(navigator.appVersion)[1],10) < 9 })(), us_states: [ 'Alabama', 'Alaska', 'American Samoa', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'Delaware', 'District of Columbia', 'Florida', 'Georgia', 'Guam', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Northern Marianas Islands', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Puerto Rico', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Virgin Islands', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming' ], setCurrency: function(val){ WebBooker.selectedCurrency(val); WebBooker.Settings.set('currency',val.title); }, init: function() { var sel_curr = WebBooker.Settings.get('currency')||wb_global_vars.currency, sel_lang = WebBooker.Settings.get('i18n')||wb_global_vars.i18n, ni, elem; for(ni=0; nihere to start accepting payments.'; jQuery('body').addClass('training'); jQuery('body').append(training_div); jQuery('.trainingClose').on('click',function(){ jQuery('.trainingWarning').hide(); }); } createCookie('ACTIVITYREZ3', WebBooker.bootstrap.nonce); WebBooker.Agent.last_key = WebBooker.bootstrap.nonce; jQuery('#wb_bootstrapper').remove(); //lets save some keystrokes var boot = WebBooker.bootstrap; boot.crossDomain = true; boot.privacy = ko.observable(boot.privacy); WebBooker.searchUrl = boot.wb_url + '/#/Search'; // Begin bootstrapping. WebBooker.hasReseller(boot.user_id && boot.user_id > 0); WebBooker.About.content(boot.aboutus); WebBooker.Contact.content(boot.contact); if(boot.user_name){ WebBooker.Agent.name(boot.user_name); } else if(boot.user_display_name){ WebBooker.Agent.name(boot.user_display_name); } // Set the user id. WebBooker.Agent.user_id(boot.user_id); //start the deafult language grab for js __.load(boot.webBookerID,boot.i18n); // Load voucher payment types. var vouch = (boot.vouchers||[]).slice(0); boot.payment_types = []; for(ni = 0; ni < vouch.length; ni++){ boot.payment_types.push(new $ar.VoucherPaymentModel(vouch[ni])); } // Load cc payment type. boot.payment_types.push(new $ar.CreditCardPaymentModel()); for(ni=0; ni b.name() ) { return 1; } if ( a.name() < b.name() ) { return -1; } return 0; }); boot.cats = boot.cats || []; for(ni = 0; ni < boot.cats.length; ni++){ boot.cats[ni] = $ar.Taxonomy(boot.cats[ni]); } boot.tags = boot.tags || []; for(ni = 0; ni < boot.tags.length; ni++){ boot.tags[ni] = $ar.Taxonomy(boot.tags[ni]); } boot.moods = boot.moods || []; for(ni = 0; ni < boot.moods.length; ni++){ boot.moods[ni] = $ar.Taxonomy(boot.moods[ni]); } // init the date pickers jQuery('.datepicker').each(function() { jQuery(this).datepicker({ minDate: 0, numberOfMonths: 2, dateFormat: 'mm/dd/yy', beforeShow: function(a) { if( a.id == 'datepicker-second' && jQuery('#datepicker-first').datepicker('getDate') ) { return { minDate: jQuery('#datepicker-first').datepicker('getDate') }; } var b = new Date(); return { minDate: new Date(b.getFullYear(), b.getMonth(), b.getDate()) }; } }); }); // init the price range slider jQuery('#price-range-slider').noUiSlider({ range: [0,10000], start: [0,10000], step: 10, slide: function() { var values = jQuery(this).val(); WebBooker.Catalog.search_params.price_min( values[0] ); WebBooker.Catalog.search_params.price_max( values[1] ); } }); // init pages. WebBooker.Cart.init(); WebBooker.Catalog.init(); WebBooker.Homepage.init(); WebBooker.ActivityView.init(); // Start cookie listener WebBooker.Agent.cookieInterval = setInterval( WebBooker.Agent.pingCookie, 3000 ); }, hideAllScreens: function() { jQuery('#cart-sidebar .retrieve').show(); //this is dumb WebBooker.Homepage.show(false); WebBooker.Catalog.show(false); WebBooker.ActivityView.show(false); WebBooker.Dashboard.show(false); WebBooker.Dashboard.showMain(true); WebBooker.Dashboard.showReports(false); WebBooker.Dashboard.showSignup(false); WebBooker.CheckoutNav.show(false); WebBooker.CheckoutNav.showConfirmation(false); WebBooker.Itinerary.show(false); WebBooker.Contact.show(false); WebBooker.show404(false); WebBooker.Agent.passwordReset(false); WebBooker.Agent.passwordResetRequest(false); WebBooker.Dashboard.showPasswordResetConfirmation(false); }, successMsg: function(msg) { $ar.Notification(msg,'success'); }, errorMsg: function(msg){ $ar.Notification(msg,'error'); } }; // Agents WebBooker.Agent = { user_id: ko.observable(), user: ko.observable(), name: ko.observable(), email: ko.observable(), password: ko.observable(), key: ko.observable(), isLoggingIn: ko.observable(false), loginError: ko.observable(), loginSuccess: ko.observable(), passwordReset: ko.observable(false), passwordResetRequest: ko.observable(false), signup_fields: { display_name: ko.observable(), email: ko.observable(), arc: ko.observable(), password: ko.observable(), verify_password: ko.observable() }, pw_reset: { username: ko.observable(), old_pw: ko.observable(), new_pw: ko.observable(), new_pw_confirm: ko.observable() }, signup_error: ko.observable(false), last_key: false, cookieInterval: false, login: function() { var email = WebBooker.Agent.email(), password = WebBooker.Agent.password(); if(!email || email === '') { $ar.Notification(__('Please enter a username.'),'error'); return false; } if(!password || password === '') { $ar.Notification(__('Please enter a password.'),'error'); return false; } WebBooker.Agent.loginError(null); WebBooker.Agent.isLoggingIn(true); WebBooker.API.loginAgent({ user: email, pass: password }, function(data) { WebBooker.Agent.isLoggingIn(false); if(data.status <= 0 && data.status != -2){ WebBooker.Agent.loginError(data.msg); return; } if ( data.status == -2 ) { window.location.hash = '#/Dashboard/PasswordReset'; return; } data.display_name = data.display_name||''; WebBooker.bootstrap.reseller2_id = data.company; WebBooker.Agent.user_id(data.uid); if(data.display_name.replace(/\s/g,'').length){ WebBooker.Agent.name(data.display_name); } else { WebBooker.Agent.name(data.name); } // Set the nonce to this new one. WebBooker.bootstrap.nonce = data.nonce; WebBooker.Agent.last_key = data.nonce; // Reload the page so we can get the WP cookie. if(window.location.hash != '/Dashboard/signup'){ location.reload(); } else { window.location.hash = '/Home'; location.reload(); } }); }, logout : function(){ WebBooker.API.logoutAgent(); }, resetPassword: function() { WebBooker.Agent.loginError(false); if ( !WebBooker.Agent.pw_reset.username() ) { WebBooker.errorMsg(__('Please enter your username.')); return false; } if ( !WebBooker.Agent.pw_reset.old_pw() ) { WebBooker.errorMsg(__('Please enter your current password.')); return false; } if ( !WebBooker.Agent.pw_reset.new_pw() ) { WebBooker.errorMsg(__('Please enter a new password.')); return false; } if ( WebBooker.Agent.pw_reset.new_pw() != WebBooker.Agent.pw_reset.new_pw_confirm() ) { WebBooker.errorMsg(__('New passwords do not match.')); return false; } WebBooker.Agent.isLoggingIn(true); WebBooker.API.resetPassword({ username: WebBooker.Agent.pw_reset.username(), old_pw: WebBooker.Agent.pw_reset.old_pw(), new_pw: WebBooker.Agent.pw_reset.new_pw(), new_pw_confirm: WebBooker.Agent.pw_reset.new_pw_confirm() }, function(result) { WebBooker.Agent.isLoggingIn(false); if ( result.status == 1 ) { WebBooker.Agent.password(null); WebBooker.Dashboard.showPasswordReset(false); WebBooker.Dashboard.showPasswordResetConfirmation(true); WebBooker.Agent.loginSuccess(__('Your password has been reset successfully. Please log-in here.')); var sidebar = jQuery('#agents-sidebar'); jQuery('html, body').animate({ scrollTop: sidebar.offset().top }, 500); WebBooker.postMessage('scroll_to=' + sidebar.offset().top); } else { WebBooker.Agent.loginError(result.msg); } }); }, doSignup: function() { if(!WebBooker.Agent.verifySignupFields()) { return false; } var params = { display_name: WebBooker.Agent.signup_fields.display_name(), email: WebBooker.Agent.signup_fields.email(), password: WebBooker.Agent.signup_fields.password(), verify_password: WebBooker.Agent.signup_fields.verify_password(), arc: WebBooker.Agent.signup_fields.arc() }; WebBooker.hideAllScreens(); WebBooker.showInitLoader(true); WebBooker.API.signupAgent(params, function(result) { if(result.status == 1) { WebBooker.Agent.resetSignupFields(); WebBooker.showInitLoader(false); WebBooker.Dashboard.show(true); WebBooker.Dashboard.showMain(false); WebBooker.Dashboard.showReports(false); WebBooker.Dashboard.showSignup(false); WebBooker.Dashboard.signupSuccessMsg(true); var sidebar = jQuery('#agents-sidebar'); jQuery('html, body').animate({ scrollTop: sidebar.offset().top }, 500); WebBooker.postMessage('scroll_to=' + sidebar.offset().top); WebBooker.Agent.loginSuccess(__('Congratulations, your travel agent sign-up is complete! You may log-in now below.')()); } else { WebBooker.showInitLoader(false); WebBooker.Dashboard.show(true); WebBooker.Dashboard.showMain(false); WebBooker.Dashboard.showReports(false); WebBooker.Dashboard.showSignup(true); WebBooker.Agent.signup_error(result.msg); WebBooker.Dashboard.signupSuccessMsg(false); WebBooker.Agent.loginSuccess(false); } }); }, verifySignupFields: function() { var msg = false; WebBooker.Agent.signup_error(false); if(WebBooker.Agent.signup_fields.password() !== WebBooker.Agent.signup_fields.verify_password()) { msg = __('The passwords you entered don\'t match.'); } if(!WebBooker.Agent.signup_fields.verify_password()) { msg = __('You need to enter the password again for verification.'); } if(!WebBooker.Agent.signup_fields.password()) { msg = __('You need to enter a password.'); } if(!WebBooker.Agent.signup_fields.arc()) { msg = __('You need to enter the ARC number.'); } if(!WebBooker.Agent.signup_fields.email()) { msg = __('You need to enter your e-mail address.'); } if(!WebBooker.Agent.signup_fields.display_name()) { msg = __('You need to enter your display name.'); } if(msg) { WebBooker.Agent.signup_error(msg()); return false; } return true; }, resetSignupFields: function() { WebBooker.Agent.signup_fields.password(''); WebBooker.Agent.signup_fields.verify_password(''); WebBooker.Agent.signup_fields.arc(''); WebBooker.Agent.signup_fields.email(''); WebBooker.Agent.signup_fields.display_name(''); WebBooker.Agent.signup_error(false); }, doShowSignup: function() { if(window.location.href != WebBooker.bootstrap.wb_url + '/#/Dashboard/signup') { window.location.href = WebBooker.bootstrap.wb_url + '/#/Dashboard/signup'; return; } if(window.location.hash != '#/Dashboard/signup') { window.location.hash = '#/Dashboard/signup'; } }, PasswordReset: function(login, key) { if ( WebBooker.Agent.pw_reset.new_pw() == WebBooker.Agent.pw_reset.new_pw_confirm() ) { var args = { login: WebBooker.Agent.user(), password: WebBooker.Agent.pw_reset.new_pw(), key: WebBooker.Agent.key() }; WebBooker.API.passwordReset(args, function(json) { if ( json.status == 1 ) { WebBooker.successMsg(json.msg); window.location.hash = '#/Home'; } else if ( json.status == -1 ) { WebBooker.errorMsg(json.msg); } else { WebBooker.errorMsg(json.msg); } } ); } else { WebBooker.errorMsg( __('Passwords do not match!') ); } }, PasswordResetRequest: function() { var args = { user: WebBooker.Agent.user() }; WebBooker.API.passwordResetRequest(args, function(json) { if ( json.status == 1 ) { WebBooker.successMsg(json.msg); } else if ( json.status == -1 ) { WebBooker.errorMsg(json.msg); } else { WebBooker.errorMsg(json.msg); } } ); }, pingCookie: function() { var cookie = readCookie('ACTIVITYREZ3'); if ( cookie && cookie != WebBooker.Agent.last_key ) { WebBooker.bootstrap.nonce = cookie; } return; } }; // Routes function notFound() { WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.show404(true); } Path.map("#/Home").to(function(){ WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.Homepage.show(true); WebBooker.Analytics.trigger({}, 'action_Home'); jQuery('html, body').animate({ scrollTop: 0 }, 500); WebBooker.postMessage('scroll_to=0'); }); Path.map('#/Search').to(function() { if(!WebBooker.Catalog.searchResults().length) { WebBooker.Catalog.hasSearched(false); } WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.Catalog.show(true); setTimeout(function() { jQuery('html, body').animate({ scrollTop: 0 }, 500); WebBooker.postMessage('scroll_to=0'); WebBooker.Catalog.loadWithFilters(); jQuery('#webbooker-search-results .results').focus(); }, 1); }); Path.map('#/Contact').to(function() { WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.Contact.show(true); jQuery('html, body').animate({ scrollTop: 0 }, 500); WebBooker.postMessage('scroll_to=0'); }); Path.map('#/About').to(function() { WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.About.show(true); jQuery('html, body').animate({ scrollTop: 0 }, 500); WebBooker.postMessage('scroll_to=0'); }); Path.map('#/Dashboard').to(function() { WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.Dashboard.showMain(true); WebBooker.Dashboard.showReports(false); WebBooker.Dashboard.showPasswordReset(false); WebBooker.Dashboard.show(true); jQuery('html, body').animate({ scrollTop: 0 }, 500); WebBooker.postMessage('scroll_to=0'); }); Path.map('#/Dashboard/reports').to(function() { WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.Dashboard.show(true); WebBooker.Dashboard.showMain(false); WebBooker.Dashboard.showPasswordReset(false); WebBooker.Dashboard.showReports(true); jQuery('html, body').animate({ scrollTop: 0 }, 500); WebBooker.postMessage('scroll_to=0'); }); Path.map('#/Dashboard/signup').to(function() { WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.Dashboard.show(true); WebBooker.Dashboard.showMain(false); WebBooker.Dashboard.showReports(false); WebBooker.Dashboard.showPasswordReset(false); WebBooker.Dashboard.showSignup(true); jQuery('html, body').animate({ scrollTop: 0 }, 500); WebBooker.postMessage('scroll_to=0'); }); Path.map('#/Dashboard/PasswordReset').to(function() { WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.Dashboard.show(true); WebBooker.Dashboard.showMain(false); WebBooker.Dashboard.showReports(false); WebBooker.Dashboard.showSignup(false); WebBooker.Dashboard.showPasswordReset(true); WebBooker.Agent.pw_reset.username(WebBooker.Agent.email()); jQuery('html, body').animate({ scrollTop: 0 }, 500); WebBooker.postMessage('scroll_to=0'); }); Path.map('#/Checkout').to(function() { WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.Checkout.sale.loadFromCart(); WebBooker.CheckoutNav.show(true); setTimeout(function() { /*var items = []; for ( ni = 0; ni < WebBooker.Cart.items().length; ni += 1 ) { items.push( WebBooker.Cart.items()[ni].processActivityForAnalytics() ); }*/ WebBooker.Analytics.trigger( { cart_items: WebBooker.Cart.items(), subtotal: WebBooker.Checkout.sale.subtotal(), currency: WebBooker.selectedCurrency().title, prev_url: false }, 'action_Checkout'); }, 1000); }); Path.map('#/Confirmation/:saleID/:email').to(function(){ WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.CheckoutNav.showConfirmation(true); WebBooker.CheckoutNav.progress(71); WebBooker.Checkout.sale.id(parseInt(this.params['saleID'],10)); WebBooker.Checkout.sale.leadGuest.email( this.params['email'] ); WebBooker.Checkout.sale.load(function(){ WebBooker.Analytics.trigger( WebBooker.Checkout.sale, 'action_Confirmation' ); }); if(window.addEvent){ window.addEvent('onunload', function(event) { WebBooker.Checkout.newSale(); }); } else if(window.addEventListener){ window.addEventListener('unload', function(event) { WebBooker.Checkout.newSale(); }); } // send confirmation email if(!WebBooker.Sale.get('loadedConfirmation')) { WebBooker.Sale.set('loadedConfirmation', true); WebBooker.API.doItineraryAction({ saleID: WebBooker.Checkout.sale.id(), email: WebBooker.Checkout.sale.leadGuest.email(), output: 'email', subject: __('Itinerary Confirmation')() }); } }); Path.map('#/Confirmation/error/:errorMsg').to(function() { WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.CheckoutNav.showConfirmation(true); WebBooker.Checkout.errorMsg(this.params['errorMsg']); var sale = WebBooker.Sale.get('sale'); if(sale) { WebBooker.Checkout.sale.json(sale); } }); Path.map('#/Itinerary/:saleID/:email').to(function() { WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); jQuery('#cart-sidebar .retrieve').hide(); //dumbness //var sale = WebBooker.Sale.get('sale'); //if(sale) WebBooker.Itinerary.sale = $ar.SaleModel(sale); WebBooker.Itinerary.sale.id(parseInt(this.params['saleID'])); WebBooker.Itinerary.sale.leadGuest.email( this.params['email'] ); WebBooker.Itinerary.load(); WebBooker.Itinerary.show(true); }); Path.map('#/Itinerary').to(function() { WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); jQuery('#cart-sidebar .retrieve').hide(); //dumbness WebBooker.Itinerary.show(true); }); Path.map('#/PasswordResetRequest').to(function(){ WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.Agent.passwordResetRequest(true); jQuery('#passwordResetRequest input').focus(); jQuery('html, body').animate({ scrollTop: 0 }, 500); WebBooker.postMessage('scroll_to=0'); }); Path.map('#/PasswordReset/:login/:key').to(function(){ WebBooker.showInitLoader(false); WebBooker.hideAllScreens(); WebBooker.Agent.passwordReset(true); WebBooker.Agent.user(this.params['login']); WebBooker.Agent.key(this.params['key']); }); // Settings WebBooker.Settings = new Store('WebBooker_Settings_' + wb_global_vars.webBookerID); // Store sale info locally WebBooker.Sale = new Store('WebBooker_Sale_' + wb_global_vars.webBookerID); WebBooker.Contact = { show: ko.observable(false), content: ko.observable('') }; WebBooker.About = { show: ko.observable(false), content: ko.observable('') }; // postMessage for iFrame WebBooker.postMessage = function(message) { if(WebBooker.bootstrap.parent_url) { var matcher = new RegExp(WebBooker.bootstrap.parent_url, 'gi'); if(typeof window.parent !== 'undefined' && typeof window.parent.postMessage == 'function' && matcher.test(window.parent.location.origin)){ window.parent.postMessage(message, WebBooker.bootstrap.parent_url); } } }; jQuery.fn.typeahead.Constructor.prototype.show = function () { var pos = jQuery.extend({}, this.$element.offset(), { height: this.$element[0].offsetHeight }), menu = this.$menu, elem = this.$element; menu.show(function(){ menu.insertAfter(elem); if(pos.top + pos.height + menu.outerHeight() > window.outerHeight && pos.top - menu.outerHeight() > jQuery(window).scrollTop()){ menu.css({ top: 0 - menu[0].offsetHeight + 25 , left: 0 }) }else{ menu.css({ top: pos.height , left: 0 }) } }); this.shown = true; return this; } // Binding Handlers ko.bindingHandlers.collapseSidebarBox = { init: function(element, valueAccessor) { setTimeout(function(){ if(!jQuery(element).siblings('.collapse-me').is(':hidden')){ jQuery(element).children('i').removeClass('icon-chevron-down'); jQuery(element).children('i').addClass('icon-chevron-up'); } }, 2000); jQuery(element).click(function(e) { e.preventDefault(); jQuery(this).siblings('.collapse-me').slideToggle(); jQuery(this).children('i').toggleClass('icon-chevron-down icon-chevron-up'); var title = jQuery(this).attr('title'); title = (title == __('Show')()) ? __('Hide')() : __('Show')(); jQuery(this).attr('title', title); return false; }); } }; ko.bindingHandlers.hotelTypeahead = { init: function(element, valueAccessor) { var option = valueAccessor()['value'], saved_query = '', elem = jQuery(element), no_results; if(WebBooker.bootstrap.agencyID == 1260) return false; jQuery(element).typeahead({ source: function(query,process) { if(query.length < 3 || query == saved_query) { if(!query.length) { option(null); } return []; } saved_query = query; option(null); var searchArgs = { object: 'hotel', property: 'post_title', query: query }; if( WebBooker.Cart.items().length > 0 ){ searchArgs.activities = []; acts = WebBooker.Cart.items(); for( var ne = 0; ne < acts.length; ne++ ){ if( jQuery.inArray( acts[ne].activity, searchArgs.activities ) == -1 ) searchArgs.activities.push( acts[ne].activity ); } } WebBooker.API.request('lookup','liveSearch', searchArgs, function(data){ var names = []; var mappedObjs = jQuery.map(data.items, function(item) { item.name = item.name.trim(); var n = item.name + ' - '; if ( item.hotel_st ) n = n + item.hotel_st + ', '; n += item.hotel_country; names.push(n); return $ar.HotelModel(item); } ); if (data.items.length) { WebBooker.Checkout.hotels(mappedObjs); no_results = false; console.log("Found hotels:",WebBooker.Checkout.hotels(),"Process:",process,"names:",names); process(names); } else { no_results = true; process([]); jQuery(elem).after(''); } }); }, property: 'name', items: 8, updater: function(item) { console.log("Checking hotels updater:",item); option(null); for(var r = 0; r < WebBooker.Checkout.hotels().length; r++){ var hotel = WebBooker.Checkout.hotels()[r]; if(hotel.generatedName == item){ option(hotel); jQuery(element).val(hotel.name); return item.trim(); } } }, matcher: function(item) { // we return true because the ajax livesearch handles the matching. return true; } }); elem.keydown(function(e){ if(e.keyCode == '13' && no_results){ e.preventDefault(); return; } jQuery('.typeahead.dropdown-menu.no-results').remove(); }); elem.on('blur',function(){ jQuery('.typeahead.dropdown-menu.no-results').remove(); }); }, update: function(element, valueAccessor) { var option = valueAccessor()['value']; if(option()) { jQuery(element).val(option().name); } } }; ko.bindingHandlers.processingBtn = { update: function(element, valueAccessor) { if(valueAccessor()) { jQuery(element).prepend(' '); } else { var content = jQuery(element).html(); content.replace(' ', ''); jQuery(element).html(content); } } }; ko.bindingHandlers.scrollTopOnClick = { init: function(element, valueAccessor) { jQuery(element).click(function(e) { jQuery('html, body').animate({ scrollTop: 0 }, 500); WebBooker.postMessage('scroll_to=0'); }); } }; ko.bindingHandlers.scrollTo = { init: function(element, scrollTo) { jQuery(element).click(function(e) { var offset = jQuery(scrollTo()).offset(); jQuery('html, body').animate({ scrollTop: offset.top }, 1000); WebBooker.postMessage('scroll_to=' + offset.top); }); } }; ko.bindingHandlers.fadeOpacity = { init: function(element, valueAccessor) { jQuery(element).css({opacity: 0.2}); }, update: function(element, valueAccessor) { var shouldDisplay = ko.utils.unwrapObservable(valueAccessor()); shouldDisplay ? jQuery(element).fadeTo('slow', 1) : jQuery(element).fadeTo('slow', 0.2); } }; ko.bindingHandlers.fadeVisible = { init: function(element, valueAccessor) { // Start visible/invisible according to initial value var shouldDisplay = ko.utils.unwrapObservable(valueAccessor()); jQuery(element).toggle(shouldDisplay); }, update: function(element, valueAccessor) { // On update, fade in/out var shouldDisplay = ko.utils.unwrapObservable(valueAccessor()); shouldDisplay ? jQuery(element).fadeIn() : jQuery(element).fadeOut(); } }; // Utilities // Calculates the distance between two locations. function getDistance(lat1, lon1, lat2, lon2, unit) { var radlat1 = Math.PI * lat1/180, radlat2 = Math.PI * lat2/180, radlon1 = Math.PI * lon1/180, radlon2 = Math.PI * lon2/180, theta = lon1-lon2, radtheta = Math.PI * theta/180, dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta); dist = Math.acos(dist); dist = dist * 180/Math.PI; dist = dist * 60 * 1.1515; if (unit=="K") { dist = dist * 1.609344 } if (unit=="N") { dist = dist * 0.8684 } return +(Math.round(dist + 'e+2') + 'e-2'); } // Converts numeric degrees to radians function toRad(value) { return value * Math.PI / 180; } function sortNearestDistance(a,b) { return a.distance - b.distance; } function formatTime(date) { var d = new Date(date), hh = d.getHours(), m = d.getMinutes(), s = d.getSeconds(), dd = " am", h = hh; if (h >= 12) { h = hh-12; dd = " pm"; } if (h == 0) { h = 12; } m = m<10?"0"+m:m; s = s<10?"0"+s:s; /* if you want 2 digit hours: */ //h = h<10?"0"+h:h; return h + ':' + m + dd; // var pattern = new RegExp("0?"+hh+":"+m+":"+s); // return date.replace(pattern,h+":"+m+":"+s+" "+dd) } function createTimestamp(now) { var year = "" + now.getFullYear(); var month = "" + (now.getMonth() + 1);if (month.length == 1) {month = "0" + month;} var day = "" + now.getDate();if (day.length == 1) {day = "0" + day;} var hour = "" + now.getHours();if (hour.length == 1) {hour = "0" + hour;} var minute = "" + now.getMinutes();if (minute.length == 1) {minute = "0" + minute;} var second = "" + now.getSeconds();if (second.length == 1) {second = "0" + second;} return year + "/" + month + "/" + day + " " + hour + ":" + minute + ":" + second; } function cleanTimestamp(stamp) { return stamp.replace(/-/g, '/'); } function getDateString(date) { var month = '' + (date.getMonth() + 1); var day = '' + date.getDate(); if (month.length == 1) { month = '0' + month; } if (day.length == 1) { day = '0' + day; } return month + '/' + day + '/' + date.getFullYear(); } function createCookie(name, value, days){ var expires = '', date = new Date(); if(days) { date.setTime(date.getTime()+(days*24*60*60*1000)); expires = '; expires=' + date.toGMTString(); } else { expires = ''; } document.cookie = name + '=' + value + expires + '; path=/;domain=' + window.location.host + "; secure"; } function readCookie(name){ var nameEQ = name + '=', ca = document.cookie.split(';'); for(var i=0; i 1){ _params = Array.prototype.slice.call(arguments,1); } } }); })(arguments); }; ret.load = function(post_id, i18n) { WebBooker.API.getPOFile({ post_id: post_id, i18n: i18n }, function(data) { if(data.status != 1) return false; langFile(data.po); return true; }); }; return ret; })(); var fn_format_money = function() { var val, elem, format; //format comes in as: //{ symbol: string, title: string, rate: number, thousands: string, decimal: string } if(arguments.length < 2){ throw new Error("fn_format_money called with too few parameters"); } if(arguments.length < 3){ val = arguments[0]; format = arguments[1]; elem = {}; } else { elem = arguments[0]; val = arguments[1]; format = arguments[2]; } if(typeof val == 'function') val = ko.utils.unwrapObservable(val()); if(!val || isNaN(val)) val = 0; var pad = function(num,dec,toLeft){ var str = ''+num; while(str.length d[b.name]; } ); if( out.length == 7 ) { return __('Every day')(); } else { return out.join(', '); } }); return that; }; $ar.Taxonomy = function(data){ var that = $ar.Model({ name: '', __name: '', slug: '', term_id: 0 },data); that.selected = ko.observable(false); that.__name = __(that.name); that.name = ko.observable(that.name); return that; }; $ar.Geocoder = (function() { var that = { geocoder: function() { return new google.maps.Geocoder(); }, geocode: function(object, callback) { that.geocoder().geocode( object, function(results, status) { if(status == google.maps.GeocoderStatus.OK) { callback(results); } else { WebBooker.errorMsg('ERROR: Can not geocode address.'); } } ); } }; return that; })(); jQuery(document).ready(function(){ setTimeout(function(){ jQuery('.collapse-me input[type="text"]').each(function(){ if (jQuery(this).val()) jQuery(this).closest('.collapse-me').show(); }); jQuery('.collapse-me select').each(function(){ if (jQuery(this).val()) jQuery(this).closest('.collapse-me').show(); }); jQuery('.collapse-me input:checked').each(function(){ jQuery(this).closest('.collapse-me').show(); }); }, 2000); jQuery("#search-keywords").keypress(function(event){ if(event.keyCode == 13){ jQuery("#searchActivitiesButton").click(); } }); });