PageSourceSearch

https://jordan-travel.com/wp-content/plugins/tourmaster/tour/tourmaster-tour.js?ver=7.1.2

js jordan-travel.com collected 2026-10-02 11:05:17 UTC 61,878 bytes, 1,698 lines download raw bytes

1(function($){
2	"use strict";
3
4	// Detect Screen
5	var tourmaster_display = 'desktop';
6	if( typeof(window.matchMedia) == 'function' ){
7		$(window).on('resize tourmaster-set-display', function(){
8			if( window.matchMedia('(max-width: 419px)').matches ){
9				tourmaster_display = 'mobile-portrait';
10			}else if( window.matchMedia('(max-width: 767px)').matches ){
11				tourmaster_display = 'mobile-landscape'
12			}else if( window.matchMedia('(max-width: 999px)').matches ){
13				tourmaster_display = 'tablet'
14			}else{
15				tourmaster_display = 'desktop';
16			}
17		});
18		$(window).trigger('tourmaster-set-display');
19	}else{
20		$(window).on('resize tourmaster-set-display', function(){
21			if( $(window).innerWidth() <= 419 ){
22				tourmaster_display = 'mobile-portrait';
23			}else if( $(window).innerWidth() <= 767 ){
24				tourmaster_display = 'mobile-landscape'
25			}else if( $(window).innerWidth() <= 999 ){
26				tourmaster_display = 'tablet'
27			}else{
28				tourmaster_display = 'desktop';
29			}
30		});
31		$(window).trigger('tourmaster-set-display');
32	}	
33
34    // datepicker
35	$.fn.tourmaster_datepicker = function(){
36
37		$(this).each(function(){
38			var date_input = $(this);
39			var datepicker_wrap = $(this).closest('.tourmaster-datepicker-wrap');
40			var alternate_field = $(this).siblings('.tourmaster-datepicker-alt');
41			var date_format = $(this).attr('data-date-format');
42
43			if( !$(this).attr('data-tour-date') ){
44				if( date_input.val() ){
45					datepicker_wrap.addClass('tourmaster-with-date');
46				}
47
48				$(this).datepicker({
49					dateFormat: date_format,
50					altFormat: 'yy-mm-dd',
51					altField: alternate_field,
52					changeMonth: true,
53					changeYear: true,
54					minDate: new Date(),
55					onSelect: function(){
56						datepicker_wrap.addClass('tourmaster-with-date');
57					}
58				});
59
60				datepicker_wrap.on('click', '.tourmaster-clear-date', function(){
61					date_input.val('');
62					alternate_field.val('');
63					datepicker_wrap.removeClass('tourmaster-with-date');
64				});
65			}else{
66				var date_range = $(this).attr('data-tour-range');
67				var available_date = JSON.parse($(this).attr('data-tour-date'));	
68				var current_date = $(this).val();
69				var selected_date = current_date;
70
71				$(this).datepicker({
72					dateFormat: date_format,
73					altFormat: 'yy-mm-dd',
74					altField: alternate_field,
75					changeMonth: true,
76					changeYear: true,
77					minDate: new Date(available_date[0]),
78					maxDate: new Date(available_date[ available_date.length - 1 ]),
79
80					// determine selectable date
81					beforeShowDay: function( date ){
82						current_date  = date.getFullYear() + '-';
83						current_date += ('0' +(date.getMonth() + 1)).slice(-2) + '-';
84						current_date += ('0' + date.getDate()).slice(-2);
85
86						var extra_class = '';
87						var date_diff = tourmaster_date_diff(selected_date, current_date);
88						if( date_diff >= 0 && date_diff < date_range ){
89							extra_class = 'tourmaster-highlight';
90						}
91
92						if( available_date.indexOf(current_date) >= 0 ){
93							return [true, extra_class, ''];
94						}else{
95							return [false, extra_class, ''];
96						}
97					},
98
99					// for date range
100					onSelect: function( dateText, inst ){
101						selected_date  = inst.selectedYear + '-';
102						selected_date += ('0' +(inst.selectedMonth + 1)).slice(-2) + '-';
103						selected_date += ('0' + inst.selectedDay).slice(-2);
104
105						alternate_field.trigger('change');
106					},
107
108					// datepicker position right
109				 	beforeShow: function(input, inst){
110				        var widget = $(inst).datepicker('widget');
111				        if( $("body").hasClass("rtl") ){
112							widget.css('margin-left', widget.outerWidth() - $(input).outerWidth() );
113						}else{
114							widget.css('margin-left', $(input).outerWidth() - widget.outerWidth());
115						}
116				        widget.css('margin-top', -2);
117				    },
118
119					// for localization
120					closeText: TMi18n.closeText,
121					currentText: TMi18n.currentText,
122					monthNames: TMi18n.monthNames,
123					monthNamesShort: TMi18n.monthNamesShort,
124					dayNames: TMi18n.dayNames,
125					dayNamesShort: TMi18n.dayNamesShort,
126					dayNamesMin: TMi18n.dayNamesMin,
127					firstDay: TMi18n.firstDay
128				});
129				
130				var initial_date = new Date(current_date + 'T00:00:00+00:00');
131				initial_date = new Date(initial_date.getTime() + (initial_date.getTimezoneOffset() * 60000));
132				$(this).datepicker('setDate', initial_date);
133			}
134		});
135
136	} // tourmaster_datepicker
137
138    function tourmaster_date_diff(date1, date2){
139		var dt1 = new Date(date1);
140		var dt2 = new Date(date2);
141		return Math.floor((Date.UTC(dt2.getFullYear(), dt2.getMonth(), dt2.getDate()) - Date.UTC(dt1.getFullYear(), dt1.getMonth(), dt1.getDate()) ) /(1000 * 60 * 60 * 24));
142	}
143
144	// tour booking bar
145	function tourmaster_tour_booking_ajax( ajax_url, ajax_settings, ajax_data ){
146
147		var ajax_settings = $.extend({
148			beforeSend: function( jqXHR, settings ){},
149			error: function( jqXHR, textStatus, errorThrown ){
150
151				// print error message for debug purpose
152				console.log(jqXHR, textStatus, errorThrown);
153			},
154			success: function( data ){ 
155				// console.log('success', data); 
156			}
157		}, ajax_settings);
158
159		var ajax_data = $.extend({
160			action: 'tourmaster_tour_booking',
161		}, ajax_data);
162
163		$.ajax({
164			type: 'POST',
165			url: ajax_url,
166			data: ajax_data,
167			dataType: 'json',
168			beforeSend: ajax_settings.beforeSend,
169			error: ajax_settings.error,
170			success: ajax_settings.success
171		});
172	}
173	function tourmaster_tour_input( form ){
174		var ret = {};
175
176		form.find('input[name], select[name], textarea[name]').each(function(){
177			var key = $(this).attr('name');
178			if( (key.lastIndexOf('[]') == (key.length - 2)) ){
179				key = key.substr(0, key.length - 2);
180				if( typeof(ret[key]) != 'object' ){
181					ret[key] = []
182				}
183
184				ret[key].push($(this).val());
185			}else{	
186				ret[key] = $(this).val();
187			}
188		});
189
190		return ret;
191	}
192	function tourmaster_get_booking_detail( form ){
193		var booking_detail = {};
194
195		form.find('input[name], select[name], textarea[name]').each(function(){
196			var key = $(this).attr('name');
197			var value;
198
199			if( $(this).is('[type="checkbox"]') ){
200				var value = $(this).is(':checked')? $(this).val(): 0;
201			}else if( $(this).is('[type="radio"]') ){
202				if( $(this).is(':checked') ){
203					var value = $(this).val();
204				}else{
205					return;
206				}
207			}else{
208				var value = $(this).val();
209			}
210
211			if( (key.lastIndexOf('[]') == (key.length - 2)) ){
212				key = key.substr(0, key.length - 2);
213				if( typeof(booking_detail[key]) != 'object' ){
214					booking_detail[key] = []
215				}
216
217				booking_detail[key].push(value);
218			}else{	
219				booking_detail[$(this).attr('name')] = value;
220			}
221		});	
222
223		// console.log(booking_detail);
224
225		return booking_detail;
226	}
227	$.fn.tourmaster_tour_booking = function(){
228
229		var form = $(this);
230		var ajax_url = $(this).attr('data-ajax-url');
231
232		// step 1
233		$(this).on('change', 'input[name="tour-date"], select[name="tour-date"]', function(){
234
235			var sent_data = tourmaster_tour_input(form);
236			sent_data['step'] = 1;
237
238			// remove unrelated input
239			form.find('[data-step]').each(function(){
240				if( $(this).attr('data-step') > 1 ){
241					$(this).slideUp(200, function(){ $(this).remove(); });
242				}
243			});
244
245			// get new input
246			tourmaster_tour_booking_ajax(ajax_url, {
247				success: function( data ){
248					if( typeof(data.content) != 'undefined' ){
249
250						// remove unrelated input once again
251						form.find('[data-step]').each(function(){
252							if( $(this).attr('data-step') > 1 ){
253								$(this).slideUp(200, function(){ $(this).remove(); });
254							}
255						});
256
257						var content = $(data.content).hide();
258						form.append(content);
259						content.find('.tourmaster-datepicker').tourmaster_datepicker();
260						content.slideDown(200);
261					}
262				}
263			}, {
264				data: sent_data
265			});
266		});
267
268		// step 2
269		$(this).on('change', 'input[name="package"]', function(){
270
271			var sent_data = tourmaster_tour_input(form);
272			sent_data['step'] = 2;
273
274			// remove unrelated input
275			form.find('[data-step]').each(function(){
276				if( $(this).attr('data-step') > 2 ){
277					$(this).slideUp(200, function(){ $(this).remove(); });
278				}
279			});
280
281			// get new input
282			tourmaster_tour_booking_ajax(ajax_url, {
283				success: function( data ){
284					if( typeof(data.content) != 'undefined' ){
285						var content = $(data.content).hide();
286						form.append(content);
287						content.find('.tourmaster-datepicker').tourmaster_datepicker();
288						content.slideDown(200);
289
290						// update header price
291						content.find('select').first().trigger('change');
292					}
293				}
294			}, {
295				data: sent_data
296			});
297		});
298
299		// step 3
300		$(this).on('change', 'select[name="tour-room"]', function(){
301			var wrap = $(this).closest('.tourmaster-tour-booking-room');
302			var template = wrap.siblings('.tourmaster-tour-booking-room-template').children();
303			var container = wrap.siblings('.tourmaster-tour-booking-people-container');
304			var container_animate = false;
305
306			if( $(this).val() && container.length == 0 ){
307				var container = $('<div class="tourmaster-tour-booking-people-container" data-step="999" ></div>').hide();
308				container.insertAfter(wrap);
309				container_animate = true;
310			}
311
312			if( $(this).val() ){
313				var count = parseInt($(this).val()) - container.children().length;
314
315				// add template fields
316				if( count > 0 ){
317					for( var i = 0; i < count; i++ ){
318						var clone = template.clone();
319						clone.attr('data-step', 4);
320						clone.find('.tourmaster-tour-booking-room-text > span').html((container.children().length + 1));
321
322						container.append(clone);
323						if( !container_animate ){
324							clone.hide();
325							clone.slideDown(200);
326						}
327					} 
328
329				// remove excess fields
330				}else if( count < 0 ){
331					container.children('div').slice(count).slideUp(200, function(){ $(this).remove(); });	
332				}
333
334				if( container_animate ){
335					container.slideDown(200);
336				}
337			
338			}else{
339				// remove container out
340				if( container.length > 0 ){
341					container.slideUp(200, function(){ $(this).remove(); });
342				}
343			}
344		});
345		// $(this).find('select[name="tour-room"]').trigger('change');
346
347		// for updating the head price
348		var orig_price = '';
349		if( $(this).hasClass('tourmaster-update-header-price') ){
350			$(this).on('change', 'input, select', function(){
351
352				var header_price = $('.tourmaster-header-price');
353				var booking_data = tourmaster_get_booking_detail(form);
354				if( !orig_price ){
355					orig_price  = header_price.html();
356				}
357				
358				// if( $(this).is('[name="package"]') ){
359				// 	booking_data['tour-people'] = 0;
360				// 	booking_data['tour-adult'] = 0;
361				// 	booking_data['tour-male'] = 0;
362				// 	booking_data['tour-female'] = 0;
363				// 	booking_data['tour-children'] = 0;
364				// 	booking_data['tour-student'] = 0;
365				// 	booking_data['tour-infant'] = 0;
366				// }
367				
368				tourmaster_tour_booking_ajax(ajax_url, {
369					success: function( data ){
370						
371						if( typeof(data.price) != 'undefined' ){
372							header_price.data('original-price', header_price.html());
373							header_price.find('.tourmaster-tour-discount-price').remove();
374							header_price.find('.tourmaster-tour-price-wrap').removeClass('tourmaster-discount');
375							header_price.addClass('tourmaster-price-updated').find('.tourmaster-tour-price .tourmaster-tail').html(data.price);
376							$(window).trigger('resize');
377						}else if( orig_price ){
378							header_price.html(orig_price).removeClass('tourmaster-price-updated');
379							if( $(document.body).hasClass("rtl") ){
380								header_price.find('[data-rel=tipsy]').tipsy({fade: true, gravity: 'sw'});
381							}else {
382								header_price.find('[data-rel=tipsy]').tipsy({fade: true, gravity: 'se'});
383							}
384						}
385					}
386				}, {
387					action: 'tourmaster_update_head_price',
388					data: booking_data
389				});
390			});		
391		}
392
393		// validate input before submitting
394		$(this).on('click', 'input[type="submit"]', function(){
395
396			var submit_button = $(this);
397			var error_message = $(this).siblings('.tourmaster-tour-booking-submit-error');
398
399			// validate extra fields
400			var validate = true;
401			form.find('input[data-required], select[data-required], textarea[data-required]').each(function(){
402				if( !$(this).val() ){
403					validate = false;
404				}
405			});
406			if( !validate ){
407				error_message.slideDown(200);
408				return false;
409			}
410			
411			var extra_booking_info = {};
412			form.find('.tourmaster-extra-booking-field').find('input, select, textarea').each(function(){
413				extra_booking_info[$(this).attr('name')] = $(this).val();
414			});
415
416			// validate booking fields
417			var submit = true;
418			var tour_package = '';
419			var traveller_amount = 0;
420			var adult_amount = 0;
421			var male_amount = 0;
422			var female_amount = 0;
423			var max_traveller_per_room = 0;
424			error_message.filter('.tourmaster-temp').slideUp(200, function(){ $(this).remove() });
425
426			form.find('[data-step]').each(function(){
427				var step = $(this).attr('data-step');
428				if( step == 1 || step == 2 || step == 3 ){
429					$(this).find('input[name], select[name]').each(function(){
430						if( $(this).val() == "" ){
431							submit = false;
432						}else if( $(this).attr('name') == 'package' ){
433							tour_package = $(this).val();
434						}
435					});
436				}else if( step == 4 ){
437					var num_people = 0;
438					var room_people = 0;
439					$(this).find('select[name], input[name]').each(function(){
440						if( $(this).attr('name') == 'group' ){
441							traveller_amount = 'group';
442							adult_amount = 'group';
443						}else if( $(this).val() != "" ){
444							room_people += parseInt($(this).val());
445
446							if( $(this).is('[name^="tour-adult"], [name^="tour-people"]') ){
447								adult_amount += room_people;
448							}else if( $(this).is('[name^="tour-male"]') ){
449								male_amount += room_people;
450								adult_amount += room_people;
451							}else if( $(this).is('[name^="tour-female"]') ){
452								female_amount += room_people;
453								adult_amount += room_people;
454							}
455						}
456					});
457
458					num_people += room_people;
459					if( room_people > max_traveller_per_room ){
460						max_traveller_per_room = room_people;
461					}
462
463					if( traveller_amount != 'group' ){
464						if( num_people <= 0 ){
465							submit = false;
466						}else{
467							traveller_amount += num_people;
468						}
469					}
470				}
471			});
472
473			if( !submit ){
474				error_message.slideDown(200);
475			}else{
476				error_message.slideUp(200);
477
478				submit_button.animate({ opacity: 0.5 });
479				tourmaster_tour_booking_ajax(ajax_url, {
480					success: function( data ){
481						
482						if( data.status == 'success' ){
483							if( submit && submit_button.attr('data-ask-login') ){
484								
485								// get lightbox content
486								var content = submit_button.siblings('[data-tmlb-id="' + submit_button.attr('data-ask-login') + '"]');
487								if( content.length == 0 ){
488									content = form.closest('form').siblings('[data-tmlb-id="' + submit_button.attr('data-ask-login') + '"]');
489								}
490								var lb_content = content.clone();
491								
492								// check for social login plugin
493								if( lb_content.find('.nsl-container-block').length > 0 ){
494									lb_content.find('.nsl-container-block').replaceWith(content.find('.nsl-container-block').clone(true));
495								}
496								
497								tourmaster_lightbox(lb_content);
498
499								var booking_detail = tourmaster_get_booking_detail(form);
500								tourmaster_set_cookie('tourmaster-booking-detail', JSON.stringify(booking_detail), 0);
501							}else{
502								var booking_detail = tourmaster_get_booking_detail(form);
503								tourmaster_set_cookie('tourmaster-booking-detail', JSON.stringify(booking_detail), 0);
504								
505								form.submit();
506							}
507						}else if( typeof(data.message) != 'undefined' ){
508							var temp_error = $('<div class="tourmaster-tour-booking-submit-error tourmaster-temp" ></div>').html(data.message);
509							temp_error.insertAfter(submit_button);
510							temp_error.slideDown(200);
511						}
512						submit_button.animate({ opacity: 1 });
513					}
514				}, {
515					action: 'tourmaster_tour_booking_amount_check',
516					tid: form.find('[name="tid"]').val(),
517					tour_id: form.find('[name="tour-id"]').val(),
518					tour_date: form.find('[name="tour-date"]').val(),
519					traveller: traveller_amount,
520					'adult_amount': adult_amount,
521					'male_amount': male_amount,
522					'female_amount': female_amount,
523					'package': tour_package,
524					'max_traveller_per_room': max_traveller_per_room,
525					'extra_booking_info': extra_booking_info
526				});
527			}
528
529			return false;
530		});
531		
532	}
533
534	$.fn.tourmaster_tour_booking_sticky = function(){
535
536		// animate sidebar
537		$(this).each(function(){
538			var page_wrap = $(this).closest('.tourmaster-page-wrapper');
539			var template_wrap = page_wrap.children('.tourmaster-template-wrapper');
540			var booking_bar_wrap = $(this);
541			var booking_bar_anchor = $(this).siblings('.tourmaster-tour-booking-bar-anchor');
542			var top_offset = parseInt($('html').css('margin-top'));
543			var left_offset = parseInt(booking_bar_anchor.css('margin-left'));
544			var right_offset = parseInt(booking_bar_anchor.css('margin-right'));
545
546			// hide header price and replace with header price in the booking bar
547			if( page_wrap.hasClass('tourmaster-tour-style-1') ){ 
548				$(this).addClass('tourmaster-start-script');
549				page_wrap.siblings('.tourmaster-single-header').addClass('tourmaster-start-script');
550				
551				var header_price = $(this).children('.tourmaster-tour-booking-bar-outer').children('.tourmaster-header-price');
552				booking_bar_wrap.css('margin-top', -header_price.outerHeight());
553				booking_bar_anchor.css('margin-top', -header_price.outerHeight());
554				page_wrap.css('min-height', booking_bar_wrap.height() - header_price.outerHeight());
555				$(window).resize(function(){
556					booking_bar_wrap.css('margin-top', -header_price.outerHeight());
557					booking_bar_anchor.css('margin-top', -header_price.outerHeight());
558					page_wrap.css('min-height', booking_bar_wrap.height() - header_price.outerHeight())
559
560					if( $("body").hasClass("rtl") ){
561						booking_bar_wrap.css({ 
562							'position': '', 
563							'top': '', 
564							'right': '',
565							'margin-top': booking_bar_anchor.css('margin-top')
566						});
567					}else {
568						booking_bar_wrap.css({ 
569							'position': '', 
570							'top': '', 
571							'left': '',
572							'margin-top': booking_bar_anchor.css('margin-top')
573						});
574					}
575					booking_bar_wrap.removeClass('tourmaster-fixed tourmaster-top tourmaster-bottom tourmaster-lock');
576				}); 
577			}
578
579			// scroll action
580			var top_padding = 0;
581			var prev_scroll = 0;
582			$(window).on('scroll resize', function(){
583				if( !booking_bar_anchor.length ) return;
584
585				var animate_on_scroll = true;
586				if( tourmaster_display == 'mobile-landscape' || tourmaster_display == 'mobile-portrait' || tourmaster_display == 'tablet' ){
587					animate_on_scroll = false;
588				}
589
590				var scroll_direction = (prev_scroll > $(window).scrollTop())? 'up': 'down';
591				prev_scroll = $(window).scrollTop();
592
593				// fixed nav bar
594				if( animate_on_scroll && $(window).scrollTop() + top_offset + top_padding > booking_bar_anchor.offset().top ){
595
596					// bar smaller than screensize
597					if( $(window).height() > booking_bar_wrap.outerHeight() + top_padding ){
598						
599						if( $(window).scrollTop() + booking_bar_wrap.outerHeight() + top_offset + (top_padding * 2) > page_wrap.offset().top + page_wrap.outerHeight() ){
600								
601								if( !booking_bar_wrap.hasClass('tourmaster-fixed-lock') ){
602									if( $("body").hasClass("rtl") ){
603										booking_bar_wrap.css({
604											'position': 'absolute',
605											'top': template_wrap.outerHeight() - booking_bar_wrap.outerHeight() - top_padding,
606											'right': 'auto',
607											'margin-top': 0
608										});
609									}else{
610										booking_bar_wrap.css({
611											'position': 'absolute',
612											'top': template_wrap.outerHeight() - booking_bar_wrap.outerHeight() - top_padding,
613											'left': 'auto',
614											'margin-top': 0
615										});
616									}
617
618									booking_bar_wrap.removeClass('tourmaster-fixed');
619									booking_bar_wrap.addClass('tourmaster-fixed-lock');
620								}
621							
622						}else if( !booking_bar_wrap.hasClass('tourmaster-fixed') ){
623							if( $("body").hasClass("rtl") ){
624								booking_bar_wrap.css({ 
625									'position': 'fixed', 
626									'top': top_padding + top_offset, 
627									'right': $(window).width() - (booking_bar_anchor.offset().left + booking_bar_anchor.outerWidth() ) - right_offset, 
628									'margin-top': 0 
629								});		
630							}else {
631								booking_bar_wrap.css({ 
632									'position': 'fixed', 
633									'top': top_padding + top_offset, 
634									'left': booking_bar_anchor.offset().left - left_offset, 
635									'margin-top': 0 
636								});
637							}
638
639							booking_bar_wrap.removeClass('tourmaster-fixed-lock');
640							booking_bar_wrap.addClass('tourmaster-fixed');
641						}else{
642							if( booking_bar_wrap.hasClass('tourmaster-fixed') ){
643								if( $("body").hasClass("rtl") ){
644									booking_bar_wrap.css({ 
645										'right': $(window).width() - (booking_bar_anchor.offset().left + booking_bar_anchor.outerWidth() ) - right_offset, 
646									});		
647								}else {
648									booking_bar_wrap.css({ 
649										'left': booking_bar_anchor.offset().left - left_offset, 
650									});
651								}
652							}	
653						}
654
655					// bar larger than screensize
656					}else{
657
658						// scroll down
659						if( scroll_direction == 'down' ){
660							
661							if( booking_bar_wrap.hasClass('tourmaster-top') ){
662								if( $("body").hasClass("rtl") ){
663									booking_bar_wrap.css({
664										'position': 'absolute',
665										'top': $(window).scrollTop() + top_padding + top_offset - booking_bar_wrap.parent().offset().top,
666										'right': 'auto',
667										'margin-top': 0
668									});	
669								}else {
670									booking_bar_wrap.css({
671										'position': 'absolute',
672										'top': $(window).scrollTop() + top_padding + top_offset - booking_bar_wrap.parent().offset().top,
673										'left': 'auto',
674										'margin-top': 0
675									});
676								}
677
678								booking_bar_wrap.removeClass('tourmaster-top');
679								booking_bar_wrap.addClass('tourmaster-lock');
680							
681							}else if( $(window).scrollTop() + $(window).height() > page_wrap.offset().top + page_wrap.outerHeight() ){
682
683								if( !booking_bar_wrap.hasClass('tourmaster-lock') ){
684									if( $("body").hasClass("rtl") ){ 
685										booking_bar_wrap.css({
686											'position': 'absolute',
687											'top': template_wrap.outerHeight() - booking_bar_wrap.outerHeight(),
688											'right': 'auto',
689											'margin-top': 0
690										});
691									}else {
692										booking_bar_wrap.css({
693											'position': 'absolute',
694											'top': template_wrap.outerHeight() - booking_bar_wrap.outerHeight(),
695											'left': 'auto',
696											'margin-top': 0
697										});
698									}
699
700									booking_bar_wrap.removeClass('tourmaster-bottom');
701									booking_bar_wrap.addClass('tourmaster-lock');
702								}
703							
704							}else if( $(window).scrollTop() + $(window).height() > booking_bar_wrap.offset().top + booking_bar_wrap.outerHeight() ){	
705								if( !booking_bar_wrap.hasClass('tourmaster-bottom') ){
706									if( $("body").hasClass("rtl") ){
707										booking_bar_wrap.css({ 
708											'position': 'fixed', 
709											'top': $(window).height() - booking_bar_wrap.outerHeight(),
710											'right': $(window).width() - (booking_bar_anchor.offset().left + booking_bar_anchor.outerWidth() ) - right_offset, 
711											'margin-top': 0 
712										});
713									}else {
714										booking_bar_wrap.css({ 
715											'position': 'fixed', 
716											'top': $(window).height() - booking_bar_wrap.outerHeight(),
717											'left': booking_bar_anchor.offset().left - left_offset, 
718											'margin-top': 0 
719										});
720									}
721
722									booking_bar_wrap.removeClass('tourmaster-top tourmaster-lock');
723									booking_bar_wrap.addClass('tourmaster-bottom');
724								}
725							}else{
726								if( booking_bar_wrap.hasClass('tourmaster-bottom') ){
727									if( $("body").hasClass("rtl") ){
728										booking_bar_wrap.css({ 
729											'right': $(window).width() - (booking_bar_anchor.offset().left + booking_bar_anchor.outerWidth() ) - right_offset, 
730										});
731									}else{
732										booking_bar_wrap.css({ 
733											'left': booking_bar_anchor.offset().left - left_offset
734										});
735									}
736								}
737							}
738
739						// scroll up
740						}else{
741							if( booking_bar_wrap.hasClass('tourmaster-bottom') ){
742								if( $("body").hasClass("rtl") ){
743									booking_bar_wrap.css({
744										'position': 'absolute',
745										'top': $(window).scrollTop() + $(window).height() - booking_bar_wrap.outerHeight() - booking_bar_wrap.parent().offset().top,
746										'right': 'auto',
747										'margin-top': 0
748									});
749								}else {
750									booking_bar_wrap.css({
751										'position': 'absolute',
752										'top': $(window).scrollTop() + $(window).height() - booking_bar_wrap.outerHeight() - booking_bar_wrap.parent().offset().top,
753										'left': 'auto',
754										'margin-top': 0
755									});
756								}
757
758								booking_bar_wrap.removeClass('tourmaster-bottom');
759								booking_bar_wrap.addClass('tourmaster-lock');
760							}else if( booking_bar_wrap.hasClass('tourmaster-lock') && $(window).scrollTop() + top_offset + top_padding < booking_bar_wrap.offset().top ){
761								if( $("body").hasClass("rtl") ){ 
762									booking_bar_wrap.css({ 
763										'position': 'fixed', 
764										'top': top_padding + top_offset,
765										'right': $(window).width() - (booking_bar_anchor.offset().left + booking_bar_anchor.outerWidth() ) - right_offset, 
766										'margin-top': 0 
767									});
768								}else {
769									booking_bar_wrap.css({ 
770										'position': 'fixed', 
771										'top': top_padding + top_offset,
772										'left': booking_bar_anchor.offset().left - left_offset, 
773										'margin-top': 0 
774									});
775								}
776
777								booking_bar_wrap.removeClass('tourmaster-bottom tourmaster-lock');
778								booking_bar_wrap.addClass('tourmaster-top');
779							}
780						}
781					}
782
783				// retun nav bar to original position
784				}else{
785
786					if( booking_bar_wrap.hasClass('tourmaster-fixed') || booking_bar_wrap.hasClass('tourmaster-top') ||
787						booking_bar_wrap.hasClass('tourmaster-bottom') ||booking_bar_wrap.hasClass('tourmaster-lock') ){
788
789						if( $("body").hasClass("rtl") ){
790							booking_bar_wrap.css({ 
791								'position': '', 
792								'top': '', 
793								'right': '',
794								'margin-top': booking_bar_anchor.css('margin-top')
795							});
796						}else {
797							booking_bar_wrap.css({ 
798								'position': '', 
799								'top': '', 
800								'left': '',
801								'margin-top': booking_bar_anchor.css('margin-top')
802							});
803						}
804						booking_bar_wrap.removeClass('tourmaster-fixed tourmaster-top tourmaster-bottom tourmaster-lock');
805					}
806				}
807
808			});
809		});
810
811	} // tourmaster_tour_booking_sticky 
812
813    var tourmaster_payment_template = function(){
814
815		var t = this;
816		t.form = $('#tourmaster-payment-template-wrapper');
817		t.sidebar = t.form.find('#tourmaster-tour-booking-bar-inner');
818		t.content = t.form.find('#tourmaster-tour-payment-content');
819
820		t.payment_step = $('#tourmaster-payment-step-wrap');
821		t.payment_template = $('#tourmaster-page-wrapper');
822		t.init();
823	}
824	tourmaster_payment_template.prototype = {
825
826		init: function(){
827			
828			var t = this;
829
830			t.bind_script();
831			t.bind_script_recurring();
832
833			// bind the next state button
834			t.form.on('click', '.tourmaster-payment-step', function(){
835				
836				var booking_detail_data = t.get_booking_detail();
837				if( $(this).attr('data-name') ){
838					booking_detail_data[$(this).attr('data-name')] = $(this).attr('data-value');
839				}
840				if( $(this).attr('data-step') ){
841					booking_detail_data['step'] = $(this).attr('data-step');
842				}
843
844				if( t.check_required_field(booking_detail_data['step']) ){
845					t.change_step({
846						booking_detail: booking_detail_data
847					});
848				}
849				
850			});
851
852			// bind the change state button
853			t.payment_step.on('click', '.tourmaster-payment-step-item', function(){
854				if( $(this).hasClass('tourmaster-enable') ){
855					var booking_detail_data = t.get_booking_detail();
856					if( $(this).attr('data-step') ){
857						booking_detail_data['step'] = $(this).attr('data-step');
858					}
859
860					if( t.check_required_field(booking_detail_data['step']) ){
861						t.change_step({
862							booking_detail: booking_detail_data
863						});
864					}
865				}
866			});
867
868			// additional service ajax
869			t.form.on('change input', '.tourmaster-payment-service-form-wrap input', tourmaster_debounce(function(e){
870				if( e.type == 'change' && $(e.target).is('input[type="text"]') ) return;
871
872				var booking_detail_data = t.get_booking_detail();
873
874				if( $(this).attr('data-step') ){
875					booking_detail_data['step'] = 3;
876				}
877
878				t.change_step({
879					booking_detail: booking_detail_data,
880					sub_action: 'update_sidebar'
881				});
882
883			}, 1000));
884
885			// bind the deposit button
886			t.form.on('change', 'input[name="payment-type"]', function(){
887
888				var total_price_wrap = $(this).closest('.tourmaster-tour-booking-bar-total-price-wrap');
889				var deposit_price_wrap = total_price_wrap.siblings('.tourmaster-tour-booking-bar-deposit-text');
890
891				if( deposit_price_wrap.length == 0 ){
892					deposit_price_wrap = total_price_wrap.children('.tourmaster-tour-booking-bar-deposit-text');
893				}
894				
895				if( $(this).is(':checked') ){
896					if( $(this).val() == 'full' ){
897						total_price_wrap.removeClass('tourmaster-deposit');
898						deposit_price_wrap.slideUp(200);
899						if( typeof(window.tourmaster_payment_type) !== 'undefined' ){
900							window.tourmaster_payment_type = 'full';
901							window.tourmaster_paypal_pay_amount = window.tourmaster_paypal_full_amount;
902						}
903					}else if( $(this).val() == 'partial' ){
904						total_price_wrap.addClass('tourmaster-deposit');
905						deposit_price_wrap.slideDown(200);
906						if( typeof(window.tourmaster_payment_type) !== 'undefined' ){
907							window.tourmaster_payment_type = 'partial';
908							window.tourmaster_paypal_pay_amount = window.tourmaster_paypal_deposit_amount;
909						}
910					}
911				}
912				
913			});
914
915		},
916
917		animate_content: function(element, content){
918
919			var orig_height = element.outerHeight();
920			element.html(content);
921			var new_height = element.outerHeight();
922
923			// animate
924			element.css({height: orig_height});
925			element.animate({height: new_height}, function(){
926				element.css({height: 'auto'}, 1000)
927			});
928		},
929
930		// bind general script
931		bind_script_recurring: function(){
932
933			var t = this;
934
935			// or divider
936			t.content.find('#tourmaster-payment-method-or').each(function(){
937				var divider_width = ($(this).width() - $(this).children('.tourmaster-middle').width() - 40) / 2;
938				$(this).children('.tourmaster-left, .tourmaster-right').css('width', divider_width);
939			});
940			$(window).resize(function(){
941				t.content.find('#tourmaster-payment-method-or').each(function(){
942					var divider_width = ($(this).width() - $(this).children('.tourmaster-middle').width() - 40) / 2;
943					$(this).children('.tourmaster-left, .tourmaster-right').css('width', divider_width);
944				});
945			});
946
947			// paypal button
948			t.paypal_jssdk_payment();
949
950		}, 
951
952		bind_script: function(){
953
954			var t = this;
955
956			// max unit
957			t.form.on('change input', '[data-max-unit]', function(){
958				if( parseInt($(this).val()) > parseInt($(this).attr('data-max-unit')) ){
959					$(this).val($(this).attr('data-max-unit'));
960				}
961
962			});
963
964			// view price breakdown
965			t.sidebar.on('click', '#tourmaster-tour-booking-bar-price-breakdown-link', function(){
966				$(this).siblings('.tourmaster-price-breakdown').slideToggle(200);
967			});
968
969			// edit date
970			t.sidebar.on('click', '.tourmaster-tour-booking-bar-date-edit', function(){
971				var temp_form = $(this).siblings('form');
972				var booking_detail = t.get_booking_detail();
973				temp_form.append($('<input name="tour_temp" />').val(JSON.stringify(booking_detail)));
974				temp_form.submit();
975			});
976
977			// coupon
978			t.sidebar.on('click', '.tourmaster-tour-booking-bar-coupon-validate', function(){
979
980				var coupon_code = $(this).siblings('[name="coupon-code"]');
981				var coupon_message = $(this).siblings('.tourmaster-tour-booking-coupon-message');
982
983				$.ajax({
984					type: 'POST',
985					url: $(this).attr('data-ajax-url'),
986					data: { 'coupon_code': coupon_code.val(), 'tour_id': $(this).attr('data-tour-id'), 'action': 'tourmaster_validate_coupon_code', 'tid': $(this).attr('data-tid') },
987					dataType: 'json',
988					beforeSend: function(){
989						coupon_code.animate({opacity: 0.3});
990						coupon_message.slideUp(150);
991						coupon_message.removeClass('tourmaster-success tourmaster-failed');
992					},
993					error: function( jqXHR, textStatus, errorThrown ){
994
995						// print error message for debug purpose
996						console.log(jqXHR, textStatus, errorThrown);
997					},
998					success: function( data ){
999						coupon_code.animate({opacity: 1});
1000
1001						if( data.status == 'success' ){
1002							var booking_detail_data = t.get_booking_detail();
1003							t.change_step({ booking_detail: booking_detail_data, sub_action: 'update_sidebar' });
1004						}else{
1005							coupon_message.addClass('tourmaster-' + data.status);
1006							coupon_message.html(data.message);
1007							coupon_message.slideDown(150);
1008						}
1009					}
1010				});
1011				
1012
1013			});
1014
1015			// payment billing
1016			t.content.on('click', '#tourmaster-payment-billing-copy', function(){
1017				if( $(this).is(':checked') ){
1018					var billing_info = $(this).closest('.tourmaster-payment-billing-wrap');
1019					var contact_info = billing_info.siblings('.tourmaster-payment-contact-wrap');
1020
1021					billing_info.find('[data-contact-detail]').each(function(){
1022						var contact_field = contact_info.find('[name="' + $(this).attr('data-contact-detail') + '"]');
1023						$(this).val(contact_field.val());
1024					});
1025				}
1026			});
1027
1028			// lightbox popup
1029			t.content.on('click', '[data-tmlb]', function(){
1030				var lb_content = $(this).siblings('[data-tmlb-id="' + $(this).attr('data-tmlb') + '"]');
1031				tourmaster_lightbox(lb_content.clone());
1032			});
1033
1034			// payment button
1035			t.content.on('click', '[data-method]', function(){
1036				if( t.check_required_field(4) ){
1037					var action = $(this).attr('data-action');
1038					var type = $(this).attr('data-action-type');
1039
1040					if( $(this).attr('data-method') == 'ajax' ){
1041						var booking_detail_data = t.get_booking_detail();
1042						t.change_step({
1043							'action': action, 
1044							'type': type, 
1045							'booking_detail': booking_detail_data
1046						});
1047					}
1048				}
1049			});
1050			t.content.on('click', '.goodlayers-payment-plugin-complete', function(){
1051				t.change_step({
1052					'action': 'tourmaster_payment_plugin_complete',
1053					'step': 4
1054				});
1055			});
1056			
1057			// payment style 2
1058			t.sidebar.on('click', '.tourmaster-pay-now, .tourmaster-pay-woocommerce', function(){
1059				if( t.check_required_field(4) ){
1060					var action = 'tourmaster_payment_selected';
1061
1062					if( $(this).is('.tourmaster-pay-now') ){
1063						var type = $(this).closest('.tourmaster-tour-booking-side-payment-wrap').find('.tourmaster-payment-selection').val();
1064					}else{
1065						var type = 'woocommerce';
1066					}
1067					
1068					var booking_detail_data = t.get_booking_detail();
1069					t.change_step({
1070						'action': action, 
1071						'type': type, 
1072						'booking_detail': booking_detail_data
1073					});
1074				}
1075			});
1076		},
1077
1078		// paypal jssdk
1079		paypal_jssdk_payment: function(){
1080			
1081			var t = this;
1082
1083			var paypal_container = $('#paypal-button-container').empty();
1084			
1085			if( paypal_container.length && typeof(paypal) !== 'undefined' ){		
1086				paypal.Buttons({
1087					createOrder: (data, actions) => {
1088						if( t.check_required_field(4) ){
1089							return actions.order.create({
1090								purchase_units: [{
1091									amount: {
1092										currency_code: window.tourmaster_paypal_currency_code,
1093										value: window.tourmaster_paypal_pay_amount
1094									}
1095								}]
1096							});
1097						}
1098						return false;
1099					},
1100					onApprove: (data, actions) => {
1101						return actions.order.capture().then(function(orderData) {
1102							t.change_step({
1103								'action': 'tourmaster_payment_selected', 
1104								'type': 'paypal',
1105								'paypal_type': 'js-sdk',
1106								'order_data': orderData,
1107								'booking_detail': t.get_booking_detail()
1108							},{
1109								complete: function(data){
1110									// console.log(data, actions);
1111								}
1112							});
1113						});
1114					}
1115				}).render('#paypal-button-container');
1116			}
1117
1118		},
1119
1120		// check required input field
1121		check_required_field: function(step){
1122
1123			var t = this;
1124			var error = false;
1125
1126			var error_box = t.form.find('.tourmaster-tour-booking-required-error');
1127			if( error_box.length ){
1128				error_box.slideUp(200);
1129
1130				if( step == 3 ){
1131					t.form.find('input[data-required], select[data-required], textarea[data-required]').each(function(){
1132						if( !$(this).val() ){ 	
1133							$(this).addClass('tourmaster-validate-error');
1134							error = 'default';
1135						}else if( $(this).is('[type="email"]') ){
1136							var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
1137    						if( !re.test($(this).val().toLowerCase()) ){
1138    							$(this).addClass('tourmaster-validate-error');
1139    							error = 'email';
1140    						}
1141						}else if( $(this).is('[name="phone"], [name="billing_phone"]') ){
1142							var re = /^[\d\+\-\s\(\)\.]*$/;
1143    						if( !re.test($(this).val().toLowerCase()) ){
1144    							$(this).addClass('tourmaster-validate-error');
1145    							error = 'phone';
1146    						}
1147						}
1148
1149						if( !error ){
1150							$(this).removeClass('tourmaster-validate-error');
1151						}
1152					});
1153					if( error ){
1154						error_box.html(error_box.data(error));
1155						error_box.slideDown(200);
1156
1157						var scrollPos = error_box.offset().top - $(window).height() + 200;
1158						if( scrollPos > 0 ){
1159							$('html, body').animate({scrollTop: scrollPos}, 600, 'easeOutQuad');
1160						}
1161					}
1162				}
1163
1164				if( step == 4 ){
1165					t.form.find('[name="term-and-service"]').each(function(){
1166						if( !$(this).prop('checked') ){
1167							error = 'default'; 
1168							error_box.html(error_box.data(error));
1169							error_box.slideDown(200);
1170						}
1171					});
1172				}
1173			}
1174			
1175			return (error === false);
1176		},
1177
1178		// get the input field
1179		get_booking_detail: function(){
1180			var t = this;
1181			var booking_detail = {};
1182			if( t.form.attr('data-booking-detail') ){
1183				booking_detail = JSON.parse(t.form.attr('data-booking-detail'));
1184			}
1185
1186			var booking_detail_new = tourmaster_get_booking_detail(t.form);
1187
1188			// assign value back
1189			for( var slug in booking_detail_new ){ booking_detail[slug] = booking_detail_new[slug]; }
1190			t.form.attr('data-booking-detail', JSON.stringify(booking_detail));
1191
1192			return booking_detail;
1193		},
1194
1195		change_step: function(ajax_data, ajax_settings){
1196
1197			var t = this;
1198
1199			var ajax_data = $.extend({
1200				action: 'tourmaster_payment_template',
1201			}, ajax_data);
1202
1203			var ajax_settings = $.extend({
1204				beforeSend: function(){
1205
1206					// loading animation
1207					if( typeof(ajax_data.sub_action) == 'undefined' || ajax_data.sub_action != 'update_sidebar' ){
1208						t.content.animate({opacity: 0.1});
1209
1210						// animate to the top
1211						$('html, body').animate({scrollTop: t.payment_template.offset().top}, 600, 'easeOutQuad');
1212					}
1213
1214					t.sidebar.animate({opacity: 0.1});
1215
1216				},
1217				error: function( jqXHR, textStatus, errorThrown ){
1218
1219					// print error message for debug purpose
1220					console.log(jqXHR, textStatus, errorThrown);
1221				},
1222				success: function( data ){
1223
1224					if( data.status == 'failed' ){
1225						if( data.message ){
1226							t.sidebar.children('.tourmaster-tour-booking-submit-error').remove();
1227							
1228							var error = $('<div class="tourmaster-tour-booking-submit-error" style="display: block" >' + data.message + '</div>');
1229							t.sidebar.append(error);
1230						}
1231						console.log(data);
1232					}
1233
1234					// assign content
1235					if( typeof(data.content) != 'undefined' ){
1236						t.animate_content(t.content, data.content);
1237					}
1238
1239					// assign sidebar
1240					if( typeof(data.sidebar) != 'undefined' ){
1241						t.animate_content(t.sidebar, data.sidebar);
1242					}
1243
1244					// update cookie
1245					if( typeof(data.cookie) != 'undefined' ){
1246						var new_booking_detail = JSON.stringify(data.cookie);
1247						tourmaster_set_cookie('tourmaster-booking-detail', new_booking_detail, 0);
1248						t.form.attr('data-booking-detail', new_booking_detail);
1249					}
1250
1251					// set the step bar
1252					if( typeof(ajax_data.booking_detail) != 'undefined' || typeof(ajax_data.step) != 'undefined' ){
1253						if( typeof(ajax_data.step) != 'undefined' ){
1254							var booking_step = ajax_data.step;
1255						}else{
1256							var booking_step = ajax_data.booking_detail.step;
1257						}
1258
1259						t.payment_step.find('.tourmaster-payment-step-item').each(function(){
1260							if( booking_step == 4 ){
1261								$(this).addClass('tourmaster-checked').removeClass('tourmaster-current tourmaster-en
1261able')
1262							}else{
1263								if( $(this).attr('data-step') == 1 ){
1264									$(this).addClass('tourmaster-checked').removeClass('tourmaster-current tourmaster-enable');
1265								}else if( $(this).attr('data-step') == booking_step ){
1266									$(this).addClass('tourmaster-current').removeClass('tourmaster-checked tourmaster-enable');
1267								}else if( $(this).attr('data-step') < booking_step ){
1268									$(this).addClass('tourmaster-enable').removeClass('tourmaster-checked tourmaster-current');
1269								}else{
1270									$(this).removeClass('tourmaster-checked tourmaster-current tourmaster-enable');
1271								}
1272							}
1273						});
1274					}
1275
1276					t.content.animate({opacity: 1});
1277					t.sidebar.animate({opacity: 1});
1278
1279					t.bind_script_recurring();
1280
1281					if( typeof(ajax_settings.complete) == 'function' ){
1282						ajax_settings.complete(data);
1283					}
1284				}
1285			}, ajax_settings);
1286
1287			$.ajax({
1288				type: 'POST',
1289				url: t.form.attr('data-ajax-url'),
1290				data: ajax_data,
1291				dataType: 'json',
1292				beforeSend: ajax_settings.beforeSend,
1293				error: ajax_settings.error,
1294				success: ajax_settings.success
1295			});
1296		},
1297	};
1298
1299    // single review
1300    $.fn.tourmaster_single_review = function(){
1301        var review_section = $(this);
1302        var review_filter = $(this).find('#tourmaster-single-review-filter');
1303        var review_content = $(this).find('#tourmaster-single-review-content');
1304
1305        // bind the filter
1306        var sort_by = review_filter.find('[data-sort-by]');
1307        var filter_by = review_filter.find('#tourmaster-filter-by');
1308
1309        sort_by.on('click', function(){
1310            if( $(this).hasClass('tourmaster-active') ) return false;
1311
1312            $(this).addClass('tourmaster-active').siblings('[data-sort-by]').removeClass('tourmaster-active');
1313            tourmaster_get_review_ajax({
1314                'action': 'get_single_tour_review',
1315                'tour_id': review_content.attr('data-tour-id'),
1316                'sort_by': $(this).attr('data-sort-by'),
1317                'filter_by': filter_by.val()
1318            }, review_content);
1319        });
1320        filter_by.on('change', function(){
1321            tourmaster_get_review_ajax({
1322                'action': 'get_single_tour_review',
1323                'tour_id': review_content.attr('data-tour-id'),
1324                'sort_by': sort_by.filter('.tourmaster-active').attr('data-sort-by'),
1325                'filter_by': $(this).val()
1326            }, review_content);
1327        });
1328
1329        review_content.on('click', '[data-paged]', function(){
1330            tourmaster_get_review_ajax({
1331                'action': 'get_single_tour_review',
1332                'tour_id': review_content.attr('data-tour-id'),
1333                'paged': $(this).attr('data-paged'),
1334                'sort_by': sort_by.filter('.tourmaster-active').attr('data-sort-by'),
1335                'filter_by': filter_by.val()
1336            }, review_content, review_section);
1337        });
1338
1339    }
1340    function tourmaster_get_review_ajax( ajax_data, content_section, scroll_to = null ){
1341        content_section.animate({opacity: 0.2}, 200);
1342
1343        $.ajax({
1344            type: 'POST',
1345            url: content_section.attr('data-ajax-url'),
1346            data: ajax_data,
1347            dataType: 'json',
1348            error: function( jqXHR, textStatus, errorThrown ){
1349
1350                content_section.animate({opacity: 1}, 200);
1351
1352                // print error message for debug purpose
1353                console.log(jqXHR, textStatus, errorThrown);
1354            },
1355            success: function( data ){
1356
1357                if( typeof(data.content) != 'undefined' ){
1358                    var old_height = content_section.outerHeight();
1359                    content_section.html(data.content);
1360
1361                    var new_height = content_section.outerHeight();
1362                    content_section.css({'height': old_height});
1363                    content_section.animate({height: new_height}, 200 , function(){
1364                        content_section.css({height: 'auto'});
1365                    });
1366                }	
1367
1368                content_section.animate({opacity: 1}, 200);
1369
1370                if( scroll_to != null ){
1371                    $('body, html').animate({'scrollTop': scroll_to.offset().top - 150 });
1372                }
1373
1374            }
1375        });
1376    }	
1377
1378	// on document ready
1379	$(document).ready(function(){
1380
1381        var body = $('body');
1382
1383		body.find('.tourmaster-tour-search-filter-clear').on('click', function(){
1384
1385			var form = $(this).closest('form');
1386			form.find('.tourmaster-rating-select[data-rating-score="0"]').trigger('click');
1387			form.find('input[type="text"], select, input[name="rating"], input[type="hidden"]').val('');
1388			form.find('input[type="checkbox"]').removeAttr('checked');
1389
1390			return false;
1391		});
1392
1393        // tipsy
1394		if( body.hasClass("rtl") ){
1395			$('[data-rel=tipsy]').tipsy({fade: true, gravity: 'sw'});
1396		}else {
1397			$('[data-rel=tipsy]').tipsy({fade: true, gravity: 'se'});
1398		}
1399
1400        // sync grid content height
1401		new gdlr_core_sync_height( $('body'), $('.tourmaster-tour-content-wrap.gdlr-core-js') );
1402		/*
1403		$('.tourmaster-tour-item-style-grid').each(function(){
1404			var max_height = 0;
1405			var default_padding = 8;
1406			var sync_item = $(this).find('.tourmaster-tour-grid.tourmaster-tour-frame .tourmaster-tour-content-wrap');
1407			
1408			sync_item.each(function(){
1409				if( $(this).outerHeight() > max_height ){	
1410					max_height = $(this).outerHeight();
1411				}
1412			});
1413			sync_item.each(function(){
1414				var bottom_padding = max_height - $(this).outerHeight() + parseInt($(this).css('padding-bottom'));
1415				$(this).css('padding-bottom', bottom_padding);
1416			});
1417
1418
1419			$(window).resize(function(){
1420				max_height = 0;
1421				sync_item.css('padding-bottom', default_padding);
1422				sync_item.each(function(){
1423					if( $(this).outerHeight() > max_height ){	
1424						max_height = $(this).outerHeight();
1425					}
1426				});
1427				sync_item.each(function(){
1428					var bottom_padding = max_height - $(this).outerHeight() + parseInt($(this).css('padding-bottom'));
1429					$(this).css('padding-bottom', bottom_padding);
1430				});
1431			});
1432		});
1433		*/
1434
1435		// center right content
1436		$('.tourmaster-center-tour-content').each(function(){
1437			var left_height = $(this).siblings('.tourmaster-content-left').outerHeight();
1438			$(this).css({'padding-top': 0, 'padding-bottom': 0});
1439			var padding = (left_height - $(this).outerHeight()) / 2;
1440			padding = (padding > 0)? padding: 0;
1441			$(this).css({'padding-top': padding, 'padding-bottom': padding });
1442
1443			$(window).resize(function(){
1444				var left_height = $(this).siblings('.tourmaster-content-left').outerHeight();
1445				$(this).css({'padding-top': 0, 'padding-bottom': 0});
1446				var padding = (left_height - $(this).outerHeight()) / 2;
1447				padding = (padding > 0)? padding: 0;
1448				$(this).css({'padding-top': padding, 'padding-bottom': padding });
1449			});
1450		});
1451
1452        // search rating
1453		var search_item = $('.tourmaster-tour-search-item');
1454		if( search_item.length ){
1455			tourmaster_rating(search_item);
1456
1457			search_item.find('.tourmaster-type-filter-title i').click(function(){
1458				var filter_content = $(this).parent().siblings('.tourmaster-type-filter-item-wrap');
1459
1460				if( $(this).hasClass('tourmaster-active') ){
1461					$(this).removeClass('tourmaster-active');
1462					filter_content.slideUp(200);
1463				}else{
1464					$(this).addClass('tourmaster-active');
1465					filter_content.slideDown(200);
1466				}
1467			});
1468		}
1469
1470		// trigger the datepicker
1471		$('.tourmaster-datepicker').tourmaster_datepicker();
1472
1473        // on user template
1474		if( body.hasClass('single-tour')){
1475
1476			// read more content button
1477			$('.tourmaster-single-tour-read-more-wrap .tourmaster-button').on('click', function(){
1478				var scrollPos = $(window).scrollTop();
1479
1480				$(this).hide();
1481				$(this).parent().parent().siblings('.tourmaster-single-tour-read-more-gradient').hide();
1482				$(this).closest('.tourmaster-single-tour-content-wrap').css({'max-height': 'none', 'margin-bottom': 0});
1483
1484				$('html, body').scrollTop(scrollPos);
1485
1486				return false;
1487			});
1488
1489			// tour booking bar
1490			$('#tourmaster-single-tour-booking-fields').tourmaster_tour_booking();
1491			$('#tourmaster-tour-booking-bar-wrap').tourmaster_tour_booking_sticky();
1492
1493			// submit booking form
1494			$('#tourmaster-enquiry-form').find('input[type="submit"]').click(function(){
1495				if( $(this).hasClass('tourmaster-now-loading') ){ return false; }
1496
1497				var form = $(this).closest('form');
1498				var form_button = $(this);
1499				var message_box = form.find('.tourmaster-enquiry-form-message').not('.tourmaster-enquiry-term-message');
1500
1501				var condition_accepted_input = form.find('[name="tourmaster-require-acceptance"]');
1502                if( condition_accepted_input.length && !condition_accepted_input.is(':checked') ){
1503                    condition_accepted_input.siblings('.tourmaster-enquiry-form-message').slideDown(150);
1504                    return false;
1505                }else{
1506                    condition_accepted_input.siblings('.tourmaster-enquiry-form-message').slideUp(1
150650);
1507                }
1508
1509				var validate = true;
1510				form.find('input[data-required], select[data-required], textarea[data-required]').each(function(){
1511					if( !$(this).val() ){
1512						validate = false;
1513					}
1514				});
1515
1516				if( !validate ){
1517					if( form.attr('data-validate-error') ){
1518						message_box.removeClass('tourmaster-success').addClass('tourmaster-failed');
1519						message_box.html(form.attr('data-validate-error'));
1520						message_box.slideDown(300);
1521					}
1522				}else{
1523
1524					message_box.slideUp(300);
1525					form_button.addClass('tourmaster-now-loading');
1526
1527					$.ajax({
1528						type: 'POST',
1529						url: form.attr('data-ajax-url'),
1530						data: { action: form.attr('data-action'), data: tourmaster_get_booking_detail(form) },
1531						dataType: 'json',
1532						error: function( jqXHR, textStatus, errorThrown ){
1533							// print error message for debug purpose
1534							console.log(jqXHR, textStatus, errorThrown);
1535						},
1536						success: function( data ){
1537							if( typeof(grecaptcha) != 'undefined' ){
1538								form.find('#g-recaptcha-response').val('gdlr-verfied');
1539							}
1540							
1541							form_button.removeClass('tourmaster-now-loading');
1542
1543							if( typeof(data.message) != 'undefined' ){
1544								if( data.status == 'success' ){
1545									form.find('input[name], textarea[name], select[name]').not('[name="tour-id"]').val('');
1546									message_box.removeClass('tourmaster-failed').addClass('tourmaster-success');
1547								}else{
1548									message_box.removeClass('tourmaster-success').addClass('tourmaster-failed');
1549								}
1550
1551								message_box.html(data.message);
1552								message_box.slideDown(300);
1553							}
1554							
1555						}
1556					});
1557				}
1558
1559				return false;
1560			});
1561
1562			// save wishlist
1563			$('#tourmaster-save-wish-list').click(function(){
1564				if( $(this).hasClass('tourmaster-active') ) return;
1565				$(this).addClass('tourmaster-active');
1566				
1567				$.ajax({
1568					type: 'POST',
1569					url: $(this).attr('data-ajax-url'),
1570					data: { action: 'tourmaster_add_wish_list', 'tour-id': $(this).attr('data-tour-id') },
1571					dataType: 'json'
1572				});		
1573			});
1574
1575			// single review
1576			$('#tourmaster-single-review').tourmaster_single_review();
1577
1578			// urgency message
1579			$('#tourmaster-urgency-message').click(function(){
1580				var expire_time = $(this).attr('data-expire');
1581				if( !expire_time ){ expire_time = 3600; }
1582				tourmaster_set_cookie('tourmaster-urgency-message', '1', expire_time);
1583
1584				$(this).fadeOut(200, function(){ $(this).remove(); });
1585			});
1586
1587			// combobox list
1588			$('.tourmaster-single-tour-booking-fields').on('click', '.tourmaster-combobox-list-display', function(){
1589				$(this).siblings('ul').fadeToggle(200);
1590			});
1591			$('.tourmaster-single-tour-booking-fields').on('click', '.tourmaster-combobox-list-wrap ul li', function(){
1592				var value = $(this).attr('data-value');
1593
1594				$(this).closest('ul').fadeOut(200);
1595				$(this).closest('ul').siblings('input').val(value).trigger('change');
1596				$(this).closest('ul').siblings('.tourmaster-combobox-list-display').children('span').html(value);
1597			});
1598			$(document).mouseup(function(e){
1599			    var container = $('.tourmaster-combobox-list-wrap');
1600
1601			    // if the target of the click isn't the container nor a descendant of the container
1602			    if( container.length && !container.is(e.target) && container.has(e.target).length === 0 ) {
1603			        container.find('ul').fadeOut(200);
1604			    }
1605			});
1606
1607			// booking form tab
1608			$('#tourmaster-booking-tab-title').children().click(function(){
1609				if( $(this).hasClass('tourmaster-active') ){
1610					return false;
1611				}else{
1612					$(this).addClass('tourmaster-active').siblings().removeClass('tourmaster-active');
1613				}
1614
1615				var selected_tab = $(this).attr('data-tourmaster-tab');
1616				$(this).parent().siblings('.tourmaster-booking-tab-content').each(function(){
1617					if( $(this).is('[data-tourmaster-tab="' + selected_tab + '"]') ){
1618						$(this).fadeIn(200, function(){ $(this).addClass('tourmaster-active'); });
1619					}else{
1620						$(this).removeClass('tourmaster-active').hide();
1621					}
1622				});
1623			});
1624
1625		// on payment template
1626		}else if( body.hasClass('tourmaster-template-payment') ){
1627
1628			new tourmaster_payment_template();
1629
1630		}
1631
1632    });
1633
1634    $(window).on('load', function(){
1635
1636        var body = $('body');
1637
1638        // content navigation
1639		var content_nav = $('#tourmaster-content-navigation-item-outer');
1640
1641		if( !body.is('.wp-admin') && content_nav.length ){
1642            
1643			window.traveltour_anchor_offset	= content_nav.height();
1644
1645			var content_nav_container = content_nav.parent();
1646			var offset = parseInt($('html').css('margin-top'));
1647
1648			// slidebar
1649			var slidebar = content_nav.find('.tourmaster-content-navigation-slider');
1650			content_nav.find('.tourmaster-active').each(function(){
1651				slidebar.css({width: $(this).outerWidth(), left: $(this).position().left});
1652			});
1653			content_nav.on('tourmaster-change', function(){
1654				var active_slidebar = $(this).find('.tourmaster-active');
1655				if( !active_slidebar.hasClass('tourmaster-slidebar-active') ){
1656					active_slidebar.addClass('tourmaster-slidebar-active');
1657					slidebar.animate({width: active_slidebar.outerWidth(), left: active_slidebar.position().left}, { queue: false, duration: 200 });
1658				}
1659			});
1660			$(window).resize(function(){ content_nav.trigger('tourmaster-change'); });
1661			content_nav.each(function(){
1662				$(this).find('.tourmaster-content-navigation-tab').hover(function(){
1663					slidebar.animate({ width: $(this).outerWidth(), left: $(this).position().left }, { queue: false, duration: 150 });
1664				}, function(){
1665					var active_slidebar = $(this).parent().children('.tourmaster-slidebar-active');
1666					if( active_slidebar.length ){
1667						slidebar.animate({ width: active_slidebar.outerWidth(), left: active_slidebar.position().left }, { queue: false, duration: 150 });
1668					}
1669				});
1670			});
1671
1672			// sticky scroll
1673			$(window).scroll(function(){
1674				if( tourmaster_display == 'mobile-landscape' || tourmaster_display == 'mobile-portrait' || tourmaster_display == 'tablet' ) return;
1675
1676				if( $(this).scrollTop() + offset > content_nav_container.offset().top ){
1677					if( !content_nav.hasClass('tourmaster-fixed') ){
1678						content_nav.parent().css('height', content_nav.parent().height());
1679						content_nav.addClass('tourmaster-fixed');
1680
1681						window.traveltour_anchor_offset	= content_nav.height();
1682					}
1683				}else{
1684					if( content_nav.hasClass('tourmaster-fixed') ){
1685						content_nav.parent().css('height', 'auto');
1686						content_nav.removeClass('tourmaster-fixed');
1687					}
1688
1689				}
1690			});
1691		}
1692        
1693    });
1694
1695})(jQuery);
1696
1697// https://github.com/jaz303/tipsy
1698!function(a){function b(a,b){return"function"==typeof a?a.call(b):a}function c(a){for(;a=a.parentNode;)if(a==document)return!0;return!1}function d(b,c){this.$element=a(b),this.options=c,this.enabled=!0,this.fixTitle()}d.prototype={show:function(){var c=this.getTitle();if(c&&this.enabled){var d=this.tip();d.find(".tipsy-inner")[this.options.html?"html":"text"](c),d[0].className="tipsy",d.remove().css({top:0,left:0,visibility:"hidden",display:"block"}).prependTo(document.body);var i,e=a.extend({},this.$element.offset(),{width:this.$element[0].offsetWidth,height:this.$element[0].offsetHeight}),f=d[0].offsetWidth,g=d[0].offsetHeight,h=b(this.options.gravity,this.$element[0]);switch(h.charAt(0)){case"n":i={top:e.top+e.height+this.options.offset,left:e.left+e.width/2-f/2};break;case"s":i={top:e.top-g-this.options.offset,left:e.left+e.width/2-f/2};break;case"e":i={top:e.top+e.height/2-g/2,left:e.left-f-this.options.offset};break;case"w":i={top:e.top+e.height/2-g/2,left:e.left+e.width+this.options.offset}}2==h.length&&("w"==h.charAt(1)?i.left=e.left+e.width/2-15:i.left=e.left+e.width/2-f+15),d.css(i).addClass("tipsy-"+h),d.find(".tipsy-arrow")[0].className="tipsy-arrow tipsy-arrow-"+h.charAt(0),this.options.className&&d.addClass(b(this.options.className,this.$element[0])),this.options.fade?d.stop().css({opacity:0,display:"block",visibility:"visible"}).animate({opacity:this.options.opacity}):d.css({visibility:"visible",opacity:this.options.opacity})}},hide:function(){this.options.fade?this.tip().stop().fadeOut(function(){a(this).remove()}):this.tip().remove()},fixTitle:function(){var a=this.$element;(a.attr("title")||"string"!=typeof a.attr("original-title"))&&a.attr("original-title",a.attr("title")||"").removeAttr("title")},getTitle:function(){var a,b=this.$element,c=this.options;this.fixTitle();var a,c=this.options;return"string"==typeof c.title?a=b.attr("title"==c.title?"original-title":c.title):"function"==typeof c.title&&(a=c.title.call(b[0])),a=(""+a).replace(/(^\s*|\s*$)/,""),a||c.fallback},tip:function(){return this.$tip||(this.$tip=a('<div class="tipsy"></div>').html('<div class="tipsy-arrow"></div><div class="tipsy-inner"></div>'),this.$tip.data("tipsy-pointee",this.$element[0])),this.$tip},validate:function(){this.$element[0].parentNode||(this.hide(),this.$element=null,this.options=null)},enable:function(){this.enabled=!0},disable:function(){this.enabled=!1},toggleEnabled:function(){this.enabled=!this.enabled}},a.fn.tipsy=function(b){function e(c){var e=a.data(c,"tipsy");return e||(e=new d(c,a.fn.tipsy.elementOptions(c,b)),a.data(c,"tipsy",e)),e}function f(){var a=e(this);a.hoverState="in",0==b.delayIn?a.show():(a.fixTitle(),setTimeout(function(){"in"==a.hoverState&&a.show()},b.delayIn))}function g(){var a=e(this);a.hoverState="out",0==b.delayOut?a.hide():setTimeout(function(){"out"==a.hoverState&&a.hide()},b.delayOut)}if(b===!0)return this.data("tipsy");if("string"==typeof b){var c=this.data("tipsy");return c&&c[b](),this}if(b=a.extend({},a.fn.tipsy.defaults,b),b.live||this.each(function(){e(this)}),"manual"!=b.trigger){var h=b.live?"live":"bind",i="hover"==b.trigger?"mouseenter":"focus",j="hover"==b.trigger?"mouseleave":"blur";this[h](i,f)[h](j,g)}return this},a.fn.tipsy.defaults={className:null,delayIn:0,delayOut:0,fade:!1,fallback:"",gravity:"n",html:!1,live:!1,offset:0,opacity:.8,title:"title",trigger:"hover"},a.fn.tipsy.revalidate=function(){a(".tipsy").each(function(){var b=a.data(this,"tipsy-pointee");b&&c(b)||a(this).remove()})},a.fn.tipsy.elementOptions=function(b,c){return a.metadata?a.extend({},c,a(b).metadata()):c},a.fn.tipsy.autoNS=function(){return a(this).offset().top>a(document).scrollTop()+a(window).height()/2?"s":"n"},a.fn.tipsy.autoWE=function(){return a(this).offset().left>a(document).scrollLeft()+a(window).width()/2?"e":"w"},a.fn.tipsy.autoBounds=function(b,c){return function(){var d={ns:c[0],ew:c.length>1&&c[1]},e=a(document).scrollTop()+b,f=a(document).scrollLeft()+b,g=a(this);return g.offset().top<e&&(d.ns="n"),g.offset().left<f&&(d.ew="w"),a(window).width()+a(document).scrollLeft()-g.offset().left<b&&(d.ew="e"),a(window).height()+a(document).scrollTop()-g.offset().top<b&&(d.ns="s"),d.ns+(d.ew?d.ew:"")}}}(jQuery);

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.