1/** 2 * Booking Module 3 * @type {{getStep1: Function, getStep2: Function, getStep3: Function, getStep4: Function, createSummary: Function, 4 * getSummary: Function, fireData: Function}} 5 */ 6 7var _state = {}; 8 9var Booking = { 10 checkSeason: function() 11 { 12 var data = { 13 date: moment(jQuery('#date').val(), 'DD-MM-YYYY').format('YYYY-MM-DD') 14 }; 15 16 if(data.date != 'dd/mm/yyyy') 17 { 18 jQuery.post('/ajax/checkSeason',data, function(response) 19 { 20 if(response.type == 'Low') 21 { 22 jQuery('.icon-cloud').parent().removeClass('off'); 23 jQuery('.price-table-row').removeClass('off-low-season'); 24 jQuery('.icon-sun').parent().addClass('off'); 25 jQuery('.price-table-row').addClass('off-high-season'); 26 } 27 else 28 { 29 jQuery('.icon-sun').parent().removeClass('off'); 30 jQuery('.price-table-row').removeClass('off-high-season'); 31 jQuery('.icon-cloud').parent().addClass('off'); 32 jQuery('.price-table-row').addClass('off-low-season'); 33 } 34 35 }); 36 } 37 }, 38 39 getStep1: function () 40 { 41 // Helper function to get value from custom selectbox or fallback to native select 42 var getSelectValue = function(containerId, selectName) { 43 var customValue = jQuery(containerId).find('.sbSelector').text(); 44 if (customValue) { 45 return customValue; 46 } 47 // Fallback to native select if custom selectbox not initialized 48 return jQuery('select[name="' + selectName + '"]').val() || ''; 49 }; 50 51 return { 52 duration : jQuery('#rental-days').text(), 53 pickup: { 54 date : moment(jQuery('#pickup_date').val(), 'DD-MM-YYYY').format('YYYY-MM-DD'), 55 time : getSelectValue('#pickup_time', 'pickup_time'), 56 location : getSelectValue('#pickup_location', 'pickup_location') 57 }, 58 dropoff: { 59 date : moment(jQuery('#dropoff_date').val(), 'DD-MM-YYYY').format('YYYY-MM-DD'), 60 time : getSelectValue('#dropoff_time', 'dropoff_time'), 61 location : getSelectValue('#dropoff_location', 'dropoff_location') 62 }, 63 flight: { 64 airline : jQuery('#airline').val() || '', 65 number : jQuery('#flight_number').val() || '' 66 } 67 } 68 }, 69 70 getStep2: function() 71 { 72 return { 73 category: jQuery('#category-pager').find('.active').data('cat-id') 74 } 75 }, 76 77 getStep3: function() 78 { 79 var childSeat, 80 itemID; 81 82 if(jQuery('.form-step-3').find('.custom-checkbox').is(':checked')) 83 { 84 childSeat = { 85 capsule : jQuery('#capsule').text(), 86 babyseat : jQuery('#babyseat').text(), 87 booster : jQuery('#booster').text() 88 } 89 } 90 else 91 { 92 childSeat = false; 93 } 94 95 var itemsObject = {}; 96 var i = 1; 97 98 jQuery.each(jQuery('input[type="checkbox"]:checked'), function() 99 { 100 itemID = $(this).data('id'); 101 102 if(itemID != 6) 103 { 104 itemsObject[i++] = { 105 id: itemID, 106 name: $(this).siblings('span').text() 107 }; 108 } 109 }); 110 111 return { 112 items : itemsObject, 113 message : jQuery('#message').val(), 114 childseat : childSeat 115 } 116 }, 117 118 getStep4: function() 119 { 120 // Get country code from dropdown (defaults to +972 if not found) 121 var countryCode = jQuery('#country_code').val() || '+972'; 122 var phoneNumber = jQuery('#phone_number').val(); 123 124 // Combine country code with phone number 125 var fullPhoneNumber = countryCode + phoneNumber; 126 127 return { 128 clientName : jQuery('#full_name').val(), 129 clientPhone : fullPhoneNumber, 130 clientEmail : jQuery('#email_address').val(), 131 clientNationality : jQuery('#nationality').find('.sbSelector').text(), 132 clientAge : jQuery('#age_range').find('.sbSelector').text() 133 } 134 }, 135 136 createSummary: function() 137 { 138 var step1 = Booking.getStep1(),
139 step2 = Booking.getStep2(), 140 step3 = Booking.getStep3(); 141 142 var pickupText = step1.pickup.date + ', ' + step1.pickup.time + ' , ' + step1.pickup.location, 143 dropoffText = step1.dropoff.date + ', ' + step1.dropoff.time + ', ' + step1.dropoff.location, 144 flightText = (step1.flight.airline ? step1.flight.airline + ' ' : '') + (step1.flight.number ? step1.flight.number : ''), 145 carText = step2.category, 146 accessoriesText = '', 147 childseatText = ''; 148 149 jQuery.each(step3.items, function(index, value) 150 { 151 accessoriesText += value.name; 152 if(index < Object.keys(step3.items).length) accessoriesText += ', '; 153 }); 154 155 if(step3.childseat != false) 156 { 157 var capsule = step3.childseat.capsule > 0 ? step3.childseat.capsule + ' ' + childseat_capsule + ' | ' : '', 158 babyseat = step3.childseat.babyseat > 0 ? step3.childseat.babyseat + ' ' + childseat_babyseat + ' | ' : '', 159 booster = step3.childseat.booster > 0 ? step3.childseat.booster + ' ' + childseat_booster + ' ' : ''; 160 161 childseatText = capsule + babyseat + booster; 162 } 163 164 jQuery('#pickup_text').text(pickupText); 165 jQuery('#dropoff_text').text(dropoffText); 166 jQuery('#car_text').text(carText); 167 168 if(flightText == '') 169 { 170 jQuery('#flight_text').closest('label').hide(); 171 } 172 else 173 { 174 jQuery('#flight_text').text(flightText).closest('label').show(); 175 } 176 177 if(Object.keys(step3.items).length == 0) 178 { 179 jQuery('#accessories_text').closest('label').hide(); 180 } 181 else 182 { 183 jQuery('#accessories_text').text(accessoriesText).closest('label').show(); 184 } 185 186 if(childseatText == '') 187 { 188 jQuery('#childseat_text').closest('label').hide(); 189 } 190 else 191 { 192 jQuery('#childseat_text').text(childseatText).closest('label').show(); 193 } 194 }, 195 196 getSummary: function() 197 { 198 if (!window.__ctm) { 199 window.__ctm = false; 200 } 201 202 return { 203 step1 : Booking.getStep1(),
204 step2 : Booking.getStep2(), 205 step3 : Booking.getStep3(), 206 step4 : Booking.getStep4(), 207 _token : _token, 208 lang : current_lang, 209 dimension : dimensionValue, 210 extra : { 211 cb_sid : hasValue(window.__ctm, 'config.sid') 212 } 213 } 214 }, 215 216 fireData: function() 217 { 218 if (_state.quoteInProgress) return; 219 220 var promise = $.Deferred(); 221 jQuery.ajax('/ajax/fire-quote', { 222 method: 'POST', 223 data: Booking.getSummary(), 224 beforeSend: function() { 225 _state.quoteInProgress = true; 226 }, 227 success: function(response) 228 { 229 _state.quoteInProgress = false; 230 promise.resolve(response); 231 }, 232 error: function(response) 233 { 234 _state.quoteInProgress = false; 235 try { 236 if (response.status == 401) { 237 jQuery('.form-step-5').html('<div class="error-message" style="text-align:center;padding:30px 0;"><h2>' + session_expired_title + '</h2><p>' + session_expired_message + '</p></div>'); 238 jQuery('.sf-controls').hide(); 239 jQuery('.sf-nav').hide(); 240 241 jQuery('#refresh-page-link').on('click', function(e) { 242 e.preventDefault(); 243 location.reload(); 244 }); 245 return; 246 } 247 248 if (response.status == 500) { 249 var reference_number = JSON.parse(response.responseText).reference_number; 250 if (reference_number) { 251 jQuery('.form-step-5').html('<h2>Good news!<br>Your already have an open quote :)</h2>' + 252 '<p><strong>You can check it and reserve your car by clicking <a target="_blank" href="/quotes/print/' + reference_number + '">here</a>.</strong></p>' + 253 '<br>' + 254 '<p>' + 255 'For your convenience, we have notified our representatives and one of them' + 256 'will get back to you to help you get the best quote for you.' + 257 '</p>'); 258 jQuery('.sf-controls').toggle(); 259 jQuery('.sf-nav').toggle(); 260 } 261 } 262 263 promise.reject(response); 264 } catch (e) { 265 _state.quoteInProgress = false; 266 promise.reject(response); 267 } 268 } 269 }); 270 271 return promise; 272 }, 273 274 getPickUpDate: function() 275 { 276 return jQuery('#pickup_date').mobiscroll( "getVal" ); 277 }, 278 279 getDropOffDate: function() 280 { 281 return jQuery('#dropoff_date').mobiscroll( "getVal" ); 282 }, 283 getPickUpDateDesktop: function() 284 { 285 return jQuery('#pickup_date').datepicker( "getDate" ); 286 }, 287 288 getDropOffDateDesktop: function() 289 { 290 return jQuery('#dropoff_date').datepicker( "getDate" ); 291 }, 292 pickupDateChanged: function(pickup_date, dropoff_date) 293 { 294 if (moment(pickup_date).isAfter(dropoff_date) || moment(pickup_date).isSame(dropoff_date)) 295 jQuery('#dropoff_date').mobiscroll('setVal', moment(pickup_date).add(1, 'day').toDate(), true, true); 296 297 jQuery('#dropoff_date').mobiscroll('option', 'minDate', moment(pickup_date).add(1, 'day').toDate()); 298 299 var duration = this.getDaysDifference(this.getPickUpDate(), this.getDropOffDate()) == 0 300 ? 1 301 : this.getDaysDifference(this.getPickUpDate(), this.getDropOffDate()); 302 303 Counter.setDurationText(duration); 304 },pickupDateChangedDesktop: function(pickup_date, dropoff_date) 305 { 306 /******************* 307 * Date Pickers Desktop 308 *******************/ 309 if (moment(pickup_date).isAfter(dropoff_date) || moment(pickup_date).isSame(dropoff_date)) 310 jQuery('#dropoff_date').datepicker("setDate",moment(pickup_date).add(1, 'day').toDate()); 311 312 jQuery('#dropoff_date').datepicker('option', 'minDate', moment(pickup_date).add(1, 'day').toDate()); 313 314 var duration = this.getDaysDifference(this.getPickUpDateDesktop(), this.getDropOffDateDesktop()) == 0 315 ? 1 316 : this.getDaysDifference(this.getPickUpDateDesktop(), this.getDropOffDateDesktop()); 317 Counter.setDurationText(duration); 318 }, 319 dropoffDateChangedDesktop: function(pickup_date, dropoff_date) 320 { 321 /******************* 322 * Date Pickers Desktop 323 *******************/ 324 var duration = this.getDaysDifference(pickup_date, dropoff_date) == 0 325 ? 1 326 : this.getDaysDifference(pickup_date, dropoff_date); 327 328 Counter.setDurationText(duration); 329 }, 330 331 dropoffDateChanged: function(pickup_date, dropoff_date) 332 { 333 var duration = this.getDaysDifference(pickup_date, dropoff_date) == 0 334 ? 1 335 : this.getDaysDifference(pickup_date, dropoff_date); 336 337 Counter.setDurationText(duration); 338 }, 339 setDaysDifferenceDesktop : function(duration){ 340 /******************* 341 * Date Pickers Desktop 342 *******************/ 343 344 //jQuery('#dropoff_date').datepicker("setDate",moment(this.getPickUpDateDesktop()).add(duration, 'day').toDate()); 345 }, 346 getDaysDifference: function(start_date, end_date) 347 { 348 var miliseconds = moment(end_date).diff(moment(start_date)); 349 var duration = moment.duration(miliseconds); 350 return duration.days(); 351 } 352}; 353 354/** 355 * Counter 356 * @type {{Increase: Function, Decrease: Function}} 357 */ 358var Counter = { 359 Increase: function() 360 {
361 var quantity = parseInt(jQuery(this).parent().find('.input-count').text()); 362 jQuery(this).parent().find('.input-count').text(++quantity); 363 Counter.setDurationText(quantity); 364 }, 365 366 Decrease: function() 367 { 368 var quantity = parseInt(jQuery(this).parent().find('.input-count').text()); 369 if(jQuery(this).parent().attr('class') == 'rental-duration') 370 { 371 if(quantity > 1) jQuery(this).parent().find('.input-count').text(--quantity); 372 } 373 else 374 { 375 if(quantity > 0) jQuery(this).parent().find('.input-count').text(--quantity); 376 } 377 Counter.setDurationText(quantity); 378 379 }, 380 getDuration : function(){ 381 return jQuery('#rental-days').text(); 382 }, 383 setDurationText: function(duration) 384 { 385 jQuery('#rental-days').text(duration); 386 387 if(!isMobile()) 388 Booking.setDaysDifferenceDesktop(duration); 389 return duration; 390 } 391}; 392 393/** 394 * Helper object with various helper function 395 * @type {{clearSelection: Function}} 396 */ 397var Helpers = { 398 clearSelection: function() { 399 if(document.selection && document.selection.empty) { 400 document.selection.empty(); 401 } else if(window.getSelection) { 402 var sel = window.getSelection(); 403 sel.removeAllRanges(); 404 } 405 }, 406 setVirtualPageForGA: function(step) { 407 var steps_name = []; 408 steps_name[0] = 'Dates'; 409 steps_name[1] = 'Car Model'; 410 steps_name[2] = 'Additional Services'; 411 steps_name[3] = 'Personal Details'; 412 steps_name[4] = 'Thank you page'; 413 414 var path_names = []; 415 path_names[0] = '/car-rental-form/step1-dates'; 416 path_names[1] = '/car-rental-form/step2-car-model'; 417 path_names[2] = '/car-rental-form/step3-additional-services'; 418 path_names[3] = '/car-rental-form/step4-personal-details'; 419 path_names[4] = '/car-rental-form/step5-thank-you-page'; 420 421 // Get Current Slide 422 var step_number = parseInt(step); 423 if (step_number == 4) return false; 424 425 var current_path_name = (current_lang !== 'en' ? '/'+current_lang : '') + path_names[step_number]; 426 // Create a Title for Google Analytics 427 var title_name_send = "Quote Step #" + (step_number + 1) + ' | ' + steps_name[step_number]; 428 429 window.dataLayer.push({ 430 event: 'pageview', 431 page: current_path_name + '', 432 title: title_name_send 433 }); 434 435 // Send the hit to Google Analytics. 436 if (typeof(ga) != 'undefined') 437 { 438 ga('send', { 439 hitType: 'pageview', 440 page: current_path_name + '', 441 title: title_name_send 442 }); 443 } 444 } 445}; 446function isMobile(){ 447 if(jQuery(document).width() < 700){ 448 return true; 449 }else{ 450 return false; 451 } 452} 453 454jQuery('.img-fluid').on('load', function() { 455 jQuery(this).css('height','auto'); 456}); 457 458function sendGAEvent(object) { 459 if (!object) return; 460 461 window.dataLayer.push({ 462 event: 'event', 463 eventCategory: object.category, 464 eventAction: object.action, 465 eventLabel: object.label, 466 }); 467 468 if (typeof(ga) != 'undefined') { 469 ga('send', { 470 hitType: 'event', 471 eventCategory: object.category, 472 eventAction: object.action, 473 eventLabel: object.label, 474 //eventValue: location.href 475 }); 476 } 477} 478 479function hasValue(root, path) { 480 if (!root) return false; 481 if (!path) return true; 482 var pa = path.split('.'); 483 var ca = root; 484 for (var i = 0, l = pa.length; i < l; i++) { 485 ca = ca[pa[i]]; 486 if (!ca) return false; 487 } 488 return ca; 489} 490 491function findSlideIndexByCatId(catId) { 492 const links = document.querySelectorAll('.booking-category-pager a'); 493 for (let link of links) { 494 if (link.getAttribute('data-cat-id') === catId) { 495 return link.getAttribute('data-slide-index'); 496 } 497 } 498 499 return null; 500} 501 502function addToTamirRentalObject (key, value) { 503 window.TamirRental = window.TamirRental || {}; 504 window.TamirRental[key] = value; 505}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.