PageSourceSearch

https://agtowncars.com/wp-content/plugins/chauffeur-booking-system…/jquery.chauffeurBookingForm.js?ver=7.1.3

js agtowncars.com collected 2026-10-09 21:41:45 UTC 105,267 bytes, 3,639 lines download raw bytes

1/******************************************************************************/
2/******************************************************************************/
3
4;(function($,doc,win)
5{
6	"use strict";
7	
8	var ChauffeurBookingForm=function(object,option)
9	{
10		/**********************************************************************/
11
12		var $this=$(object);
13		
14		var $optionDefault;
15		var $option=$.extend($optionDefault,option);
16		
17		var $marker=[];
18		
19		var $googleMap;
20		
21		var $routeIndex=0;
22		
23		var $directionsRenderer;
24		
25		var $directionsService;
26		var $directionsServiceResponse;
27		
28		var $startLocation;
29		
30		var $googleMapHeightInterval;
31
32		var $self=this;
33
34		var $iti;
35		
36		var $sidebar;
37
38		/**********************************************************************/
39		
40		this.setup=function()
41		{	 
42			var helper=new CHBSHelper();
43			helper.getMessageFromConsole();
44			
45			$self.e('select,input[type="hidden"]').each(function()
46			{
47				if($(this)[0].hasAttribute('data-value'))
48					$(this).val($(this).attr('data-value'));
49			});
50			
51			/***/
52			
53			if(parseInt($option.google_map_option.ask_load_enable,10)===1)
54			{
55				if(isNaN(parseInt($self.e('[name="chbs_google_maps_enable"]').val(),10)))
56				{
57					var url=window.location.href;
58
59					if(url.indexOf('?')===-1) url+='?';
60					else url+='&';
61
62					if(confirm($option.message.google_map_ask_load_confirm)) 
63						window.location.href=url+'chbs_google_maps_enable=1';
64					else window.location.href=url+'chbs_google_maps_enable=-1';
65					
66					return;
67				}
68			}
69			
70			/***/
71			
72			$self.init();
73			
74			if(parseInt($option.icon_field_enable,10)===1)
75			{
76				for(var i=1;i<=3;i++)
77				{
78					$self.e('input[name="chbs_pickup_date_service_type_'+i+'"]').before('<span class="chbs-meta-icon-2 chbs-meta-icon-2-date-1"></span>');
79					$self.e('input[name="chbs_pickup_time_service_type_'+i+'"]').before('<span class="chbs-meta-icon-2 chbs-meta-icon-2-time-1"></span>');
80					$self.e('input[name="chbs_return_date_service_type_'+i+'"]').before('<span class="chbs-meta-icon-2 chbs-meta-icon-2-date-1"></span>');
81					$self.e('input[name="chbs_return_time_service_type_'+i+'"]').before('<span class="chbs-meta-icon-2 chbs-meta-icon-2-time-1"></span>');
82				}
83
84				for(var i=1;i<=2;i++)
85				{
86					$self.e('input[name="chbs_pickup_location_service_type_'+i+'"]').before('<span class="chbs-meta-icon-2 chbs-meta-icon-2-location-1"></span>');
87					$self.e('input[name="chbs_dropoff_location_service_type_'+i+'"]').before('<span class="chbs-meta-icon-2 chbs-meta-icon-2-location-1"></span>');				
88				}
89
90				$self.e('input[name="chbs_passenger_adult_service_type_1"]').before('<span class="chbs-meta-icon-2 chbs-meta-icon-2-passengers-1"></span>');
91				$self.e('input[name="chbs_passenger_adult_service_type_3"]').before('<span class="chbs-meta-icon-2 chbs-meta-icon-2-passengers-1"></span>');
92
93				$self.e('input[name="chbs_passenger_children_service_type_1"]').before('<span class="chbs-meta-icon-2 chbs-meta-icon-2-passengers-1"></span>');
94				$self.e('input[name="chbs_passenger_children_service_type_3"]').before('<span class="chbs-meta-icon-2 chbs-meta-icon-2-passengers-1"></span>');
95			}
96		};
97			
98		/**********************************************************************/
99		
100		this.init=function()
101		{		   
102			var helper=new CHBSHelper();
103			
104			if(helper.isMobile())
105			{
106				$self.e('input[name="chbs_pickup_date_service_type_1"]').prop('readonly',true);
107				$self.e('input[name="chbs_pickup_date_service_type_2"]').prop('readonly',true);
108				$self.e('input[name="chbs_pickup_date_service_type_3"]').prop('readonly',true);
109				$self.e('input[name="chbs_return_date_service_type_1"]').prop('readonly',true);
110				$self.e('input[name="chbs_return_date_service_type_3"]').prop('readonly',true);
111			}
112			
113			$self.createButtonRadio('.chbs-booking-extra');
114			
115			/***/
116			
117			$(window).resize(function() 
118			{
119				try
120				{
121					$self.e('select').selectmenu('close');
122				}
123				catch(e) {}
124				
125				try
126				{
127					$self.e('.chbs-datepicker').datepicker('hide');
128				}
129				catch(e) {}
130				
131				try
132				{
133					$self.e('.chbs-timepicker').timepicker('hide');
134				}
135				catch(e) {}
136				
137				try
138				{
139					$self.e('.ui-timepicker-wrapper').css({opacity:0}
139);
140				}
141				catch(e) {}
142				
143				try
144				{
145					var currCenter=$googleMap.getCenter();
146					google.maps.event.trigger($googleMap,'resize');
147					$googleMap.setCenter(currCenter);
148				}
149				catch(e) {}
150			});
151			
152			$self.setWidthClass();
153			
154			/***/
155			
156			if(parseInt($option.use_my_location_link_enable,10)===1)
157			{
158				if(navigator.geolocation)
159				{
160					$self.e('.chbs-my-location-link').css('display','inline');		
161					navigator.geolocation.getCurrentPosition($self.myLocationSuccess,$self.myLocationError);	
162				}
163			}
164			
165			/***/
166			
167			var active=1;
168			var panel=$self.e('.chbs-tab>ul').children('li[data-id="'+parseInt($self.e('[name="chbs_service_type_id"]').val())+'"]',10);
169			
170			if(panel.length===1) active=panel.index();
171			
172			$self.e('.chbs-tab').tabs(
173			{
174				activate:function(event,ui)
175				{
176					$('.qtip').remove();
177					
178					$self.googleMapReInit();
179					
180					var serviceTypeId=$self.getServiceTypeId();
181					$self.setServiceTypeId(serviceTypeId);
182					
183					$self.googleMapCreate();
184					$self.googleMapCreateRoute();
185				},
186				active:active
187			});
188						  
189			/***/
190			
191			$self.e('.chbs-main-navigation-default a').on('click',function(e)
192			{
193				e.preventDefault();
194				
195				var navigation=parseInt($(this).parent('li').data('step'),10);
196				var step=parseInt($self.e('input[name="chbs_step"]').val(),10);
197				
198				if(navigation-step===0) return;
199				
200				$self.goToStep(navigation-step);
201			});
202			
203			$self.e('.chbs-button-step-next').on('click',function(e)
204			{
205				e.preventDefault();
206				$self.goToStep(1);
207			});
208			
209			$self.e('.chbs-button-step-prev').on('click',function(e)
210			{
211				e.preventDefault();
212				$self.goToStep(-1);
213			});
214			
215			/***/
216			
217			$self.e('.chbs-main-content').on('click','.chbs-form-field',function(e)
218			{
219				e.preventDefault();
220				if(($(e.target).hasClass('chbs-location-add')) || ($(e.target).hasClass('chbs-location-remove'))) return;
221				$(this).find(':input').focus(); 
222				
223				var select=$(this).find('select:not(.chbs-selectmenu-disable)');
224				
225				if(select.length)
226					select.selectmenu('open');
227			});
228			
229			/***/
230			
231			$self.e('.chbs-location-add').on('click',function(e)
232			{
233				e.preventDefault();
234
235				var field=$(this).parent('.chbs-form-field:first');
236				var newField=$self.e('.chbs-form-field-location-autocomplete.chbs-hidden').clone(true,true);
237
238				newField.insertAfter(field);
239				newField.removeClass('chbs-hidden');
240				
241				newField.find(':input').focus();
242				
243				$self.googleMapAutocompleteCreate(newField.find('input[type="text"]'));
244				
245				$self.createLabelTooltip();
246			});
247
248			$self.e('.chbs-location-remove').on('click',function(e)
249			{
250				e.preventDefault();
251				$(this).parent('.chbs-form-field:first').remove();
252
253				$self.googleMapCreate();
254				$self.googleMapCreateRoute();
255			});	   
256
257			$self.e('.chbs-form-field-location-autocomplete input[type="text"]').each(function()
258			{
259				$self.googleMapAutocompleteCreate($(this));
260			});
261					   
262			/***/
263			
264			$self.e('.chbs-payment-form').on('click','.chbs-payment>li>a',function(e)
265			{
266				e.preventDefault();
267				
268				$(this).parents('.chbs-payment').find('li>a').removeClass('chbs-state-selected');
269				$(this).addClass('chbs-state-selected');
270				
271				$self.getGlobalNotice().addClass('chbs-hidden');
272				
273				$self.e('input[name="chbs_payment_id"]').val($(this).attr('data-payment-id'));
274				
275				$self.createSummaryPriceElement();
276			});
277			
278			$self.e('>*').on('click','.chbs-form-checkbox',function(e)
279			{
280				var text=$(this).next('input[type="hidden"]');
281				var value=parseInt(text.val(),10)===1 ? 0 : 1;
282				
283				if(value===1) $(this).addClass('chbs-state-selected');
284				else $(this).removeClass('chbs-state-selected');
285				
286				$(this).next('input[type="hidden"]').on('change',function(e)
287				{ 
288					var value=parseInt($(this).val(),10)===1 ? 1 : 0;
289					var section=$(this).parents('.chbs-clear-fix:first').nextAll('.chbs-panel:first');
290
291					if(value===0) section.addClass('chbs-hidden');
292					else section.removeClass('chbs-hidden');
293
294					$(window).scroll();
295				});
296				
297				text.val(value).trigger('change');
298			});
299			
300			/***/
301			
302			$self.e('.chbs-booking-extra').on('click','.chbs-booking-extra-list .chbs-button.chbs-button-style-2',function(e)
303			{
304				e.preventDefault();
305				
306				var extraNote=$(this).parents('li:first').find('.chbs-booking-form-extra-note');
307				
308				if(!$(this).parent('.chbs-button-radio').length)
309				{
310					$(this).toggleClass('chbs-state-selected'); 
311					
312					if($(this).hasClass('chbs-state-selected'))
313						extraNote.removeClass('chbs-hidden');
314					else extraNote.addClass('chbs-hidden');
315				}
316				else
317				{
318					if(parseInt($(this).attr('data-value'),10)!==0)
319						extraNote.removeClass('chbs-hidden');
320					else extraNote.addClass('chbs-hidden');
321				}
322				
323				var data=[];
324				$self.e('.chbs-booking-extra-list .chbs-button.chbs-button-style-2').each(function()
325				{
326					if($(this).hasClass('chbs-state-selected'))
327						data.push($(this).attr('data-value'));
328				});
329				
330				$self.e('input[name="chbs_booking_extra_id"]').val(data.join(','));
331				
332				$self.createSummaryPriceElement();
333			});
334			
335			/***/
336			
337			$self.e('.chbs-booking-extra').on('blur','.chbs-booking-extra-list input[type="text"]',function(e)
338			{
339			   if(isNaN($(this).val())) $(this).val(1);
340			   $self.createSummaryPriceElement();
341			});
342			
343			$self.e('.chbs-booking-extra').on('click','.chbs-booking-extra-list .chbs-column-2',function()
344			{
345				$(this).find('input[type="text"]').select();
346			});
347			
348			/***/
349			
350			$self.e('.chbs-main-content-step-2').on('click','.chbs-vehicle-list .chbs-button.chbs-button-style-2:not(.chbs-button-on-request)',function(e)
351			{
352				e.preventDefault();
353				
354				if($(this).hasClass('chbs-state-selected')) return;
355
356				$self.e('.chbs-vehicle-list .chbs-button.chbs-button-style-2').removeClass('chbs-state-selected');
357
358				$(this).addClass('chbs-state-selected');
359
360				$self.e('input[name="chbs_vehicle_id"]').val(parseInt($(this).parents('.chbs-vehicle').attr('data-id'),10));
361
362				$self.e('.chbs-vehicle-content-price-bid>div').addClass('chbs-hidden');
363				$self.e('.chbs-vehicle-list [name="chbs_vehicle_bid_price[]"]').val('');
364				$(this).parents('.chbs-vehicle').find('.chbs-vehicle-content-price-bid>div:first-child').removeClass('chbs-hidden');
365
366				$self.getGlobalNotice().addClass('chbs-hidden');
367				
368				$self.calculateBaseLocationDistance(function()
369				{
370					$self.createSummaryPriceElement();
371
372					if(parseInt($option.scroll_to_booking_extra_after_select_vehicle_enable,10)===1)
373					{
374						var header=$self.e('.chbs-booking-extra-header');
375						if(header.length===1) $.scrollTo(header,200,{offset:-50});
376					}
377					
378					$self.manageBookingExtra();
379				});
380			});
381			
382			/***/
383			
384			$self.e('.chbs-main-content-step-2').on('click','.chbs-vehicle .chbs-vehicle-content .chbs-show-more-button a',function(e)
385			{
386				e.preventDefault();
387				
388				$(this).toggleClass('chbs-state-selected');
389				
390				var section=$(this).parents('.chbs-vehicle:first').find('.chbs-vehicle-content-description');
391				
392				var height=parseInt(section.children('div').actual('outerHeight',{includeMargin:true}),10);
393				
394				if(section.hasClass('chbs-state-open'))
395				{
396					section.animate({height:0},150,function()
397					{
398						section.removeClass('chbs-state-open');
399						$(window).scroll();
400					});					  
401				}
402				else
403				{
404					section.animate({height:height},150,function()
405					{
406						section.css('height','auto');
407						section.addClass('chbs-state-open');
408						$(window).scroll();
409					});						
410				}
411			});
412			
413			/***/
414			
415			$self.e('.chbs-main-content-step-2').on('click','.chbs-booking-extra .chbs-booking-extra-header .chbs-show-more-button a',function(e)
416			{
417				e.preventDefault();
418				
419				$(this).toggleClass('chbs-state-selected');
420				
421				var section=$(this).parents('.chbs-booking-extra:first').children('.chbs-booking-extra-header+div');
422				
423				var height=parseInt(section.children('div').actual('outerHeight',{includeMargin:true}),10);
424				
425				if(section.hasClass('chbs-state-open'))
426				{
427					section.animate({height:0},150,function()
428					{
429						section.removeClass('chbs-state-open');
430						$(window).scroll();
431					});					  
432				}
433				else
434				{
435					section.animate({height:height},150,function()
436					{
437						section.css('height','auto');
438						section.addClass('chbs-state-open');
439						$(window).scroll();
440					});						
441				}
442			});
443			
444			/***/
445			
446			$self.e('.chbs-main-content-step-4').on('click','.chbs-summary .chbs-summary-header a',function(e)
447			{
448				e.preventDefault();
449				$self.goToStep(parseInt($(this).attr('data-step'),10)-4);
450			});
451			
452			/***/
453			
454			$self.e('.chbs-main-content-step-4').on('click','.chbs-coupon-code-section a',function(e)
455			{
456				e.preventDefault();
457				
458				$self.setAction('coupon_code_check');
459	   
460				$self.post($self.e('form[name="chbs-form"]').serialize(),function(response)
461				{
462					$self.e('.chbs-summary-price-element').replaceWith(response.html);
463					
464					var object=$self.e('.chbs-coupon-code-section');
465					
466					object.qtip(
467					{
468						show:
469						{ 
470							target:$(this) 
471						},
472						style:
473						{ 
474							classes:(response.error===1 ? 'chbs-qtip chbs-qtip-error' : 'chbs-qtip chbs-qtip-success')
475						},
476						content:
477						{ 
478							text:response.message 
479						},
480						position:
481						{ 
482							my:($option.is_rtl ? 'bottom right' : 'bottom left'),
483							at:($option.is_rtl ? 'top right' : 'top left'),
484							container:object.parent()
485						}
486					}).qtip('show');	
487				});
488			});
489			
490			/***/
491			
492			$self.e('.chbs-main-content-step-4').on('click','.chbs-gratuity-section a',function(e)
493			{
494				e.preventDefault();
495				
496				$self.setAction('gratuity_customer_set');
497	   
498				$self.post($self.e('form[name="chbs-form"]').serialize(),function(response)
499				{  
500					$self.e('.chbs-summary-price-element').replaceWith(response.html);
501					
502					var object=$self.e('.chbs-gratuity-section');
503					
504					object.qtip(
505					{
506						show:
507						{ 
508							target:$(this) 
509						},
510						style:
511								{ 
512							classes:(response.error===1 ? 'chbs-qtip chbs-qtip-error' : 'chbs-qtip chbs-qtip-success')
513						},
514						content:
515								{ 
516							text:response.message 
517						},
518						position:
519						{ 
520							my:($option.is_rtl ? 'bottom right' : 'bottom left'),
521							at:($option.is_rtl ? 'top right' : 'top left'),
522							container:object.parent()
523						}
524					}).qtip('show');
525					
526					object.find('[name="chbs_gratuity_customer_value"]').val(response.gratuity);
527				});
528			});			
529			
530			/***/
531			
532			$self.e('.chbs-datepicker').datepicker(
533			{
534				autoSize:true,
535				minDate:$option.datetime_min_format,
536				maxDate:$option.datetime_max_format,
537				dateFormat:$option.date_format_js,
538				beforeShow:function(date,instance)
539				{
540					var helper=new CHBSHelper();
541					var value=helper.getValueFromClass($(instance.dpDiv),'chbs-booking-form-id-');
542					
543					if(value!==false) $(instance.dpDiv).removeClass('chbs-booking-form-id-'+value);
544					
545					$(instance.dpDiv).addClass('chbs-booking-form-id-'+$option.booking_form_id).addClass('chbs-datepicker');
546					
547					if($(date).attr('name')==='chbs_return_date_service_type_'+$self.getServiceTypeId())
548					{
549						try
550						{
551							var datePickup=$self.e('[name="chbs_pickup_date_service_type_'+$self.getServiceTypeId()+'"]').val();
552							var dateParse=$.datepicker.parseDate($option.date_format_js,datePickup);
553							
554							if(dateParse!==null)
555							{
556								$(this).datepicker('option','minDate',datePickup); 
557							}
558						}
559						catch(e)
560						{
561							
562						}
563					}	
564				},
565				beforeShowDay:function(date)
566				{
567					var helper=new CHBSHelper();
568					
569					var dayWeek=parseInt(date.getDay(),10);
570					if(dayWeek===0) dayWeek=7;
571					
572					date=$.datepicker.formatDate('dd-mm-yy',date);
573					
574					for(var i in $option.date_exclude)
575					{
576						var r=helper.compareDate([date,$option.date_exclude[i].start,$option.date_exclude[i].stop]);
577						if(r) return([false,'','']);
578					}
579					
580					/***/
581					
582					var sDate=date.split('-');
583					var date=new Date(sDate[2],sDate[1]-1,sDate[0]);
584										
585					if((!$option.business_hour[dayWeek].start) || (!$option.business_hour[dayWeek].stop)) 
586						return([false,'','']);
587					
588					/***/
589					
590					return([true,'','']);
591				},
592				onSelect:function(date,object)
593				{
594					var helper=new CHBSHelper();
595					
596					var dateSelected=[object.selectedDay,object.selectedMonth+1,object.selectedYear];
597					
598					for(var i in dateSelected)
599					{
600						if(new String(dateSelected[i]).length===1) dateSelected[i]='0'+dateSelected[i];
601					}
602					
603					dateSelected=dateSelected[0]+'-'+dateSelected[1]+'-'+dateSelected[2];
604					
605					/***/
606					
607					var minTime='';
608					var maxTime='';
609					
610					/***/
611					
612					var dayWeek=parseInt($(this).datepicker('getDate').getDay(),10);
613					if(dayWeek===0) dayWeek=7;
614														
615					/***/
616			 
617					if((helper.isEmpty(minTime)) || (helper.isEmpty(maxTime)))
618					{
619						if(new String(typeof($option.business_hour[dayWeek]))!=='undefined')
620						{
621							minTime=$option.business_hour[dayWeek].start;
622							maxTime=$option.business_hour[dayWeek].stop;
623						}
624					}
625					
626					/***/
627					
628					var t=$option.datetime_min.split(' ');
629					
630					if(dateSelected===t[0])
631					{
632						if(Date.parse('01/01/1970 '+t[1])>Date.parse('01/01/1970 '+minTime))
633							minTime=t[1];
634					}
635					
636					/***/
637					
638					if(!helper.isEmpty($option.datetime_max))
639					{
640						var t=$option.datetime_max.split(' ');
641
642						if(dateSelected===t[0])
643						{
644							if(Date.parse('01/01/1970 '+t[1])<Date.parse('01/01/1970 '+maxTime))
645								maxTime=t[1];
646						}					
647					}
648					
649					/***/
650					
651					var option=
652					{
653						appendTo:$this,
654						showOn:[],
655						showOnFocus:false,
656						timeFormat:$option.time_format,
657						step:$option.timepicker_step,
658						disableTouchKeyboard:true,
659						minTime:minTime,
660						maxTime:maxTime,
661						disableTextInput:parseInt($option.timepicker_field_readonly,10)===1 ? true : false
662					};
663						
664					/***/
665					
666					if(parseInt($option.timepicker_dropdown_list_enable,10)===1)
667					{
668						var prefix=$(this).attr('name').indexOf('pickup')>-1 ? 'pickup' : 'return';
669
670						var timeField=$self.e('input[name="chbs_'+prefix+'_time_service_type_'+$self.getServiceTypeId()+'"]');
671
672						try
673						{
674							timeField.timepicker('remove');
675						}
676						catch(e) {}
677				
678						if(parseInt($self.getServiceTypeId(),10)===3)
679						{
680							var routeField=$self.e('select[name="chbs_route_service_type_3"]>option:selected');
681							
682							try
683							{
684								var timeExclude=JSON.parse(routeField.attr('data-time_exclude'));
685
686								if(timeExclude[dayWeek]!=undefined)
687								{
688									option.step=1;
689									option.disableTextInput=true;
690									option.disableTimeRanges=timeExclude[dayWeek];
691									option.maxTime=timeExclude[dayWeek][timeExclude[dayWeek].length-2][1];
692								}
693							}
694							catch(e) {}
695						}
696					
697						/***/
698					
699						timeField.timepicker(option);
700
701						timeField.val('').timepicker('show');
702						timeField.blur();
703
704						$self.setTimepicker(timeField);
705						
706						if(parseInt($option.timepicker_hour_range_enable,10)===1)
707						{
708							$('.ui-timepicker-list>li').each(function()
709							{
710								var node=[$(this),$(this).next()];
711
712								if(node[1].length===1)
713									node[0].html(node[0].text()+' - '+node[1].text());
714								else node[0].remove();
715							});
716							
717							timeField.on('selectTime',function(obj1,obj2) 
718							{
719								var element=$('.ui-timepicker-list>.ui-timepicker-selected');
720								
721								if(element.length===1)
722								{
723									$(this).val(element.text());
724								}
725							});
726						}
727					}
728				}
729			});
730			
731			$('.ui-datepicker').addClass('notranslate');
732			
733			if(parseInt($option.timepicker_dropdown_list_enable,10)===1)
734			{
735				$this.on('focusin','.chbs-timepicker',function()
736				{
737					var helper=new CHBSHelper();
738
739					var prefix=$(this).attr('name').indexOf('pickup')>-1 ? 'pickup' : 'return';
740
741					var field=$self.e('input[name="chbs_'+prefix+'_date_service_type_'+$self.getServiceTypeId()+'"]');
742
743					if(helper.isEmpty(field.val()))
744					{
745						$(this).timepicker('remove');
746						field.click();
747						return;
748					}
749					else
750					{
751						if(helper.isEmpty($(this).val()))
752							$(this).timepicker('show');
753					}
754				});
755			}
756			
757			/***/
758			
759			$self.createSelectMenu();
760			$self.createFixedLocationAutocomplete();
761			
762			/***/
763			
764			$self.e('.chbs-booking-extra').on('blur','.chbs-booking-extra-list input[type="text"]',function()
765			{
766				if(!$(this)[0].hasAttribute('data-quantity-max')) return;
767				
768				var value=$(this).val();
769				
770				if(isNaN(value)) value=1;
771				
772				value=parseInt(value,10);
773				
774				if(value>parseInt($(this).attr('data-quantity-max'),10))
775					$(this).val($(this).attr('data-quantity-max'));
776				
777				$self.createSummaryPriceElement();
778			});
779			
780			$self.e('.chbs-form-field').has('select').css({cursor:'pointer'});
781			
782			/***/
783			
784			$self.e('.chbs-main-content-step-3').on('click','.chbs-button-sign-up',function(e)
785			{
786				e.preventDefault();
787				
788				$self.e('.chbs-client-form-sign-up').removeClass('chbs-hidden');
789				$self.e('input[name="chbs_client_account"]').val(1);
790			});
791			
792			/***/
793			
794			$self.e('.chbs-main-content').on('click','.chbs-button-widget-submit',function(e)
795			{
796				e.preventDefault();
797			   
798				var helper=new CHBSHelper();
799				
800				var data={};
801				
802				data.service_type_id=$self.getServiceTypeId();
803				
804				data.pickup_date=$self.e('[name="chbs_pickup_date_service_type_'+data.service_type_id+'"]').val();
805				data.pickup_time=$self.e('[name="chbs_pickup_time_service_type_'+data.service_type_id+'"]').val();
806				
807				if($.inArray($self.getServiceTypeId(),[1,2])>-1)
808				{
809					var coordinate=$self.e('[name="chbs_pickup_location_coordinate_service_type_'+data.service_type_id+'"]').val();
810					if(!helper.isEmpty(coordinate))
811					{
812						var json=JSON.parse(coordinate);
813						data.pickup_location_lat=json.lat;
814						data.pickup_location_lng=json.lng;
815						data.pickup_location_zip_code=json.zip_code;
816						data.pickup_location_locality=json.locality;
817						data.pickup_location_address=json.address;
818						data.pickup_location_text=$self.e('[name="chbs_pickup_location_service_type_'+data.service_type_id+'"]').val();  
819					}
820					
821					var coordinate=$self.e('[name="chbs_dropoff_location_coordinate_service_type_'+data.service_type_id+'"]').val();
822					if(!helper.isEmpty(coordinate))
823					{
824						var json=JSON.parse(coordinate);
825						data.dropoff_location_lat=json.lat;
826						data.dropoff_location_lng=json.lng;
827						data.dropoff_location_zip_code=json.zip_code;
828						data.dropoff_location_locality=json.locality;
829						data.dropoff_location_address=json.address;
830						data.dropoff_location_text=$self.e('[name="chbs_dropoff_location_service_type_'+data.service_type_id+'"]').val();
831					}	
832					
833					var pickupLocationId=$self.e('[name="chbs_fixed_location_pickup_service_type_'+data.service_type_id+'"]').val();
834					if(parseInt(pickupLocationId,10)>0)
835						data.fixed_location_pickup_id=pickupLocationId;
836					
837					var dropoffLocationId=$self.e('[name="chbs_fixed_location_dropoff_service_type_'+data.service_type_id+'"]').val();
838					if(parseInt(dropoffLocationId,10)>0)
839						data.fixed_location_dropoff_id=dropoffLocationId;					
840				}
841				else
842				{
843					data.route_id=$self.e('[name="chbs_route_service_type_'+data.service_type_id+'"]').val();	
844				}
845				
846				if($.inArray($self.getServiceTypeId(),[1,3])>-1)
847				{
848					data.extra_time=$self.e('[name="chbs_extra_time_service_type_'+data.service_type_id+'"]').val();
849					data.transfer_type=$self.e('[name="chbs_transfer_type_service_type_'+data.service_type_id+'"]').val(); 
850			  
851					if($.inArray(data.transfer_type,[3]))
852					{
853						data.duration=$self.e('[name="chbs_duration_service_type_'+data.service_type_id+'"]').val();  
854						
855						data.return_date=$self.e('[name="chbs_return_date_service_type_'+data.service_type_id+'"]').val();  
856						data.return_time=$self.e('[name="chbs_return_time_service_type_'+data.service_type_id+'"]').val();  
857					}
858				}
859				
860				if($.inArray($self.getServiceTypeId(),[2])>-1)
861				{
862					data.duration=$self.e('[name="chbs_duration_service_type_'+data.service_type_id+'"]').val();  
863				}
864				
865				var passengerAdult=$self.e('[name="chbs_passenger_adult_service_type_'+data.service_type_id+'"]');
866				if(passengerAdult.length===1) data.passenger_adult=passengerAdult.val();
867				
868				var passengerChildren=$self.e('[name="chbs_passenger_children_service_type_'+data.service_type_id+'"]');
869				if(passengerChildren.length===1) data.passenger_children=passengerChildren.val();
870				
871				data.currency=$self.e('[name="chbs_currency"]').val();
872				
873				data.widget_submit=1;
874                data.widget_second_step=parseInt($self.e('[name="chbs_widget_second_step"]').val(),10);  
875
876				/***/
877				
878				var url=$option.widget.booking_form_url;
879				
880				if(url.indexOf('?')===-1) url+='?';
881				else url+='&';
882				
883				url+=decodeURI($.param(data));
884				
885				var form=$self.e('form[name="chbs-form"]');
886				
887				form.attr('action',url).submit();
888			});
889			
890			/***/
891			
892			$self.e('.chbs-main-content-step-3').on('click','.chbs-button-sign-in',function(e)
893			{
894				e.preventDefault();
895				
896				$self.getGlobalNotice().addClass('chbs-hidden');
897				
898				$self.preloader(true);
899			
900				$self.setAction('user_sign_in');
901	   
902				$self.post($self.e('form[name="chbs-form"]').serialize(),function(response)
903				{
904					if(parseInt(response.user_sign_in,10)===1)
905					{
906						$self.e('.chbs-main-content-step-3 .chbs-client-form').html('');
907				 
908						if(typeof(response.client_form_sign_up)!=='undefined')
909							$self.e('.chbs-main-content-step-3 .chbs-client-form').append(response.client_form_sign_up);  
910	   
911						if(typeof(response.summary)!=='undefined')
912							$self.e('.chbs-main-content-step-3>.chbs-layout-25x75 .chbs-layout-column-left:first').html(response.summary[0]);						
913						
914						$self.createSelectMenu();
915						$self.createFixedLocationAutocomplete();
916					}
917					else
918					{
919						if(typeof(response.error.global[0])!=='undefined')
920							$self.getGlobalNotice().removeClass('chbs-hidden').html(response.error.global[0].message);
921					}
922					
923					$self.preloader(false);
924				});
925			});
926			
927			/***/
928			
929			$self.e('.chbs-main-content-step-3').on('click','.chbs-sign-up-password-generate',function(e)
930			{
931				e.preventDefault();
932				
933				var helper=new CHBSHelper();
934				var password=helper.generatePassword(8);
935				
936				$self.e('input[name="chbs_client_sign_up_password"],input[name="chbs_client_sign_up_password_retype"]').val(password);
937			});
938			
939			$self.e('.chbs-main-content-step-3').on('click','.chbs-sign-up-password-show',function(e)
940			{
941				e.preventDefault();
942				
943				var password=$self.e('input[name="chbs_client_sign_up_password"]');
944				password.attr('type',(password.attr('type')==='password' ? 'text' : 'password'));
945			});
946			
947			/***/
948			
949			$(document).bind('keypress',function(e) 
950			{
951				if(parseInt(e.which,10)===13) 
952				{
953					switch($(e.target).attr('name'))
954					{
955						case 'chbs_client_sign_in_login':
956						case 'chbs_client_sign_in_password':
957						
958							$self.e('.chbs-main-content-step-3 .chbs-button-sign-in').trigger('click');
959						
960						break;
961					}
962				}				   
963			});
964			
965			$(document).unbind('keydown').bind('keydown',function(e) 
966			{
967				switch($(e.target).attr('name'))
968				{
969					case 'chbs_passenger_adult_service_type_1':
970					case 'chbs_passenger_adult_service_type_2':
971					case 'chbs_passenger_adult_service_type_3':
972					case 'chbs_passenger_children_service_type_1':
973					case 'chbs_passenger_children_service_type_2':
974					case 'chbs_passenger_children_service_type_3':	
975
976						if($.inArray(parseInt(e.keyCode,10),[38,40])>-1)
977						{
978							var value=parseInt($(e.target).val(),10);
979							if(isNaN(value)) value=0;
980
981							if(parseInt(e.keyCode,10)===38)
982								value=(value+1)>99 ? 99 : value+1;
983							else if(parseInt(e.keyCode,10)===40)
984								value=(value-1)<0 ? 0 : value-1;
985
986							$(e.target).val(parseInt(value));
987						}
988					
989					break;
990				} 
991			});
992			
993			/***/
994			
995			$self.e('.chbs-main-content-step-2').on('click','.chbs-quantity-section .chbs-quantity-section-button',function(e)
996			{			   
997				var textField=$(this).parent().children('input[type="text"]');
998				if(parseInt(textField.length,10)!==1) return;
999
1000				var step=parseInt($(this).attr('data-step'),10);
1001				var value=parseInt(textField.val(),10);
1002				
1003				var minValue=1;
1004				var maxValue=parseInt(textField.attr('data-quantity-max'),10);
1005				
1006				value+=step;
1007				
1008				if((value<minValue) || (value>maxValue)) return;
1009				
1010				textField.val(value);
1011				
1012				$(this).parents('li:first').find('.chbs-column-3 .chbs-button').removeClass('chbs-state-selected');
1013				$(this).parents('li:first').find('.chbs-column-3 .chbs-button:first').trigger('click');
1014				
1015			});
1016			
1017			/***/
1018			
1019			$self.e('.chbs-main-content-step-2 .chbs-vehicle-list').on('click','.chbs-pagination a',function(e)
1020			{
1021				e.preventDefault();
1022				
1023				var i=0;
1024				
1025				var vehiclePerPage=parseInt($(this).parent('.chbs-pagination').attr('data-vehicle_per_page'),10);
1026				
1027				var vehicleCount=$self.e('.chbs-vehicle-list>ul>li').length;
1028				
1029				/***/
1030				
1031				var vehicleFirst=0;
1032				$self.e('.chbs-vehicle-list>ul>li').each(function()
1033				{
1034					i++;
1035					if((!$(this).hasClass('chbs-hidden')) && (vehicleFirst===0)) vehicleFirst=i;
1036				});
1037				
1038				/***/
1039	   
1040				var step=parseInt($(this).attr('href').substr(1),10);
1041				
1042				var range1=vehicleFirst+(step*vehiclePerPage);
1043				var range2=range1+vehiclePerPage;
1044				
1045				if(range1>vehicleCount)
1046				{
1047					return;
1048				}
1049				
1050				if(range1<=0)
1051				{
1052					return;
1053				}
1054				
1055				/***/
1056				
1057				i=0;
1058				
1059				$self.e('.chbs-vehicle-list>ul>li').each(function()
1060				{
1061					i++;
1062					$(this).addClass('chbs-hidden');
1063					
1064					if((i>=range1) && (i<range2))
1065						$(this).removeClass('chbs-hidden');
1066				});
1067			});
1068					
1069			/***/
1070
1071			$self.createLabelTooltip();
1072			
1073			/***/
1074			
1075			$self.googleMapCreate();
1076			$self.googleMapInit();
1077			
1078			var firstOption=$self.e('[name="chbs_route_service_type_3"]>option:first');
1079			
1080			if(parseInt(firstOption.val(),10)===-1)
1081			{
1082				if(typeof($startLocation)!=='undefined')
1083				{
1084					var data=[{lat:$startLocation.lat(),lng:$startLocation.lng()}];
1085					firstOption.attr('data-coordinate',JSON.stringify(data));
1086				}
1087			}
1088			
1089			$self.googleMapCreateRoute(function()
1090			{
1091				if((parseInt(helper.urlParam('widget_submit'),10)===1) && (parseInt(helper.urlParam('widget_second_step'),10)===1))	
1092				{
1093					$self.goToStep(1,function()
1094					{
1095						$this.removeClass('chbs-hidden');
1096						$self.createStickySidebar();
1097						$(window).scroll();
1098					});
1099                   
1100				}
1101				else $this.removeClass('chbs-hidden');	
1102				$self.googleMapStartCustomizeHeight();  
1103			});
1104			
1105			$self.moveSubmitButton();
1106			$self.setBidPriceVehicle();
1107		};
1108		
1109		/**********************************************************************/
1110		
1111		this.myLocationSuccess=function(position)
1112		{
1113			$self.e('.chbs-my-location-link').on('click',function()
1114			{
1115				var coordinate= 
1116				{
1117					lat: position.coords.latitude,
1118					lng: position.coords.longitude
1119				};
1120			
1121				var field=$self.e('input[name="chbs_pickup_location_coordinate_service_type_'+$self.getServiceTypeId()+'"]');
1122				
1123				field.val(JSON.stringify(coordinate));
1124
1125				$self.googleMapSetAddress(field,function()
1126				{
1127					$self.googleMapCreate();
1128					$self.googleMapCreateRoute();   
1129				},true);
1130			});
1131		};
1132		
1133		/**********************************************************************/
1134		
1135		this.myLocationError=function(error)
1136		{
1137			console.log(error);
1138		};
1139		
1140		/**********************************************************************/
1141		
1142		this.getVehicleSelectedId=function()
1143		{
1144			var vehicleId=parseInt($self.e('.chbs-vehicle .chbs-vehicle-content-header .chbs-button.chbs-state-selected').parents('.chbs-vehicle').attr('data-id'),10);
1145			return(vehicleId);
1146		}
1147		
1148		/**********************************************************************/
1149		
1150		this.setBidPriceVehicle=function()
1151		{
1152			$self.e('.chbs-main-content-step-2')
1153			
1154			$self.e('.chbs-main-content-step-2').on('click','.chbs-vehicle-content-price-bid>div:first-child>a',function(e)
1155			{
1156				e.preventDefault();
1157				
1158				$(this).parent('div').addClass('chbs-hidden');
1159				$(this).parent('div').next('div').removeClass('chbs-hidden');
1160			});
1161			
1162			$self.e('.chbs-main-content-step-2').on('click','.chbs-vehicle-content-price-bid>div+div>input+a',function(e)
1163			{
1164				var input=$(this).prev('input');
1165				
1166				e.preventDefault();
1167				
1168				$self.setAction('vehicle_bid_price_check');
1169	   
1170				$self.preloader(true);
1171				$self.post($self.e('form[name="chbs-form"]').serialize(),function(response)				
1172				{
1173					$self.preloader(false);
1174					if(typeof(response.html)!=='undefined')
1175					{
1176						if(typeof(response.bid_vehicle_min_value)!='undefined')
1177						{
1178							if(confirm(response.bid_question))
1179							{
1180								input.val(response.bid_vehicle_min_value);
1181								
1182								$self.preloader(true);
1183								$self.post($self.e('form[name="chbs-form"]').serialize(),function(response)				
1184								{
1185									$self.preloader(false);
1186									if(typeof(response.html)!=='undefined')
1187									{
1188										$self.e('.chbs-summary-price-element').replaceWith(response.html);
1189									}
1190								});
1191							}
1192							else
1193							{
1194								$self.e('.chbs-summary-price-element').replaceWith(response.html);
1195								if(typeof(response.bid_notice)!='undefined') alert(response.bid_notice);
1196							}
1197						}
1198						else
1199						{
1200							$self.e('.chbs-summary-price-element').replaceWith(response.html);
1201							if(typeof(response.bid_notice)!='undefined') alert(response.bid_notice);
1202						}
1203					}
1204				});
1205			});
1206			
1207			$self.e('.chbs-main-content-step-2').on('click','.chbs-vehicle-content-price-bid>div+div>input+a+a',function(e)
1208			{
1209				e.preventDefault();
1210				
1211				$(this).parent('div').addClass('chbs-hidden');
1212				$(this).parent('div').prev('div').removeClass('chbs-hidden');
1213				
1214				$(this).parent('div').find('input[type="text"]').val('');
1215				
1216				$self.setAction('vehicle_bid_price_check');
1217	   
1218				$self.post($self.e('form[name="chbs-form"]').serialize(),function(response)				
1219				{
1220					if(typeof(response.html)!=='undefined')
1221						$self.e('.chbs-summary-price-element').replaceWith(response.html);
1222				});
1223			});		
1224		};
1225		
1226		/**********************************************************************/
1227		
1228		this.setPayment=function()
1229		{
1230			var paymentId=parseInt($self.e('input[name="chbs_payment_id"]').val(),10);
1231			if(paymentId>0) $self.e('.chbs-payment>li>a[data-payment-id="'+paymentId+'"]').addClass('chbs-state-selected');
1232		};
1233		
1234		/**********************************************************************/
1235		
1236		this.moveSubmitButton=function()
1237		{
1238			if(($this.hasClass('chbs-widget')) && ($this.hasClass('chbs-widget')) && ($this.hasClass('chbs-widget-style-2')))
1239			{
1240				var button=$self.e('.chbs-main-content-step-1 .chbs-button-widget-submit').parent();
1241
1242				button.clone().appendTo($self.e('#panel-1'));
1243				button.clone().appendTo($self.e('#panel-2'));
1244				button.clone().appendTo($self.e('#panel-3'));
1245				
1246				button.remove();
1247			}
1248		};
1249		
1250		/**********************************************************************/
1251		
1252		this.convertTimeToMinute=function(time)
1253		{
1254			time=time.split(':');
1255			return(time[0]*60+time[1]);
1256		};
1257		
1258		/**********************************************************************/
1259		
1260		this.createLabelTooltip=function()
1261		{
1262			$self.e('.chbs-tooltip').qtip(
1263			{
1264				style:
1265				{ 
1266					classes:'chbs-qtip chbs-qtip-success'
1267				},
1268				position:
1269				{ 
1270					my:'bottom left',
1271					at:'top left',
1272					container:$this
1273				}
1274			});
1275		};
1276		
1277		/**********************************************************************/
1278		
1279		this.setTimepicker=function(field)
1280		{
1281			if(parseInt($option.timepicker_dropdown_list_enable,10)===1)
1282				$('.ui-timepicker-wrapper').css({opacity:1,'width':field.parent('div').outerWidth()+1});
1283		};
1284		
1285		/**********************************************************************/
1286		
1287		this.createSelectMenu=function()
1288		{
1289			$self.e('select:not(.chbs-selectmenu-disable)').selectmenu(
1290			{
1291				appendTo:$this,
1292				open:function(event,ui)
1293				{
1294					var select=$(this);
1295					var selectmenu=$('#'+select.attr('id')+'-menu').parent('div');
1296					
1297					var field=select.parents('.chbs-form-field:first');
1298					
1299					var left=parseInt(selectmenu.css('left'),10)-1;
1300					
1301					var borderWidth=parseInt(field.css('border-left-width'),10)+parseInt(field.css('border-right-width'),10);
1302					
1303					var width=field[0].getBoundingClientRect().width-borderWidth;
1304					
1305					selectmenu.css({width:width+2,left:left});
1306				},
1307				change:function(event,ui)
1308				{
1309					var name=$(this).attr('name');
1310					
1311					if(name==='chbs_route_service_type_3')
1312					{
1313						$self.googleMapCreate();
1314						$self.googleMapCreateRoute();
1315					}
1316					
1317					if($.inArray(name,['chbs_transfer_type_service_type_1','chbs_transfer_type_service_type_3'])>-1)
1318					{
1319						var section=$self.e('[name="chbs_return_date_service_type_'+$self.getServiceTypeId()+'"]').parent('div').parent('div');
1320						
1321						if(parseInt($(this).val(),10)===3) section.removeClass('chbs-hidden');
1322						else section.addClass('chbs-hidden');
1323					}
1324					
1325					if($.inArray(name,['chbs_extra_time_service_type_1','chbs_transfer_type_service_type_1','chbs_duration_service_type_2','chbs_extra_time_service_type_3','chbs_transfer_type_service_type_3'])>-1)
1326					{
1327						$self.reCalculateRoute();
1328					}
1329					
1330					if(name==='chbs_navigation_responsive')
1331					{
1332						var navigation=parseInt($(this).val(),10);
1333						
1334						var step=parseInt($self.e('input[name="chbs_step"]').val(),10);	
1335				
1336						if(navigation-step===0) return;
1337
1338						$self.goToStep(navigation-step);
1339					}
1340					
1341					if($.inArray(name,['chbs_vehicle_passenger_count','chbs_vehicle_bag_count','chbs_vehicle_standard','chbs_vehicle_category'])>-1)
1342					{
1343						$self.setAction('vehicle_filter');
1344						
1345						$self.e('.chbs-vehicle-list').children().addClass('chbs-hidden');
1346						$self.e('.chbs-vehicle-list').addClass('chbs-preloader-1');
1347						
1348						$self.post($self.e('form[name="chbs-form"]').serialize(),function(response)
1349						{	   
1350							$self.getGlobalNotice().addClass('chbs-hidden');
1351							
1352							var vehicleList=$self.e('.chbs-vehicle-list');
1353							
1354							vehicleList.html('').removeClass('chbs-preloader-1');
1355							
1356							if((typeof(response.error)!=='undefined') && (typeof(response.error.global)!=='undefined'))
1357							{
1358								$self.getGlobalNotice().removeClass('chbs-hidden').html(response.error.global[0].message);
1359							}
1360							else
1361							{
1362								vehicleList.html(response.html);
1363								$self.recalculateVehiclePrice(response,1);
1364							}
1365							
1366							$self.e('.chbs-vehicle-list').find('.chbs-button.chbs-button-style-2').removeClass('chbs-state-selected');
1367							
1368							$self.preloadVehicleImage();
1369							
1370							$self.e('input[name="chbs_vehicle_id"]').val(0);
1371							$self.createSummaryPriceElement();
1372						});
1373					}
1374					
1375					if($.inArray(name,['chbs_fixed_location_pickup_service_type_1','chbs_fixed_location_dropoff_service_type_1','chbs_fixed_location_pickup_service_type_2','chbs_fixed_location_dropoff_service_type_3']>-1))
1376					{
1377						$self.googleMapSetAddress($(this),function()
1378						{
1379							$self.googleMapCreate();
1380							$self.googleMapCreateRoute();   
1381						});
1382					}
1383					
1384					if($.inArray(name,['chbs_fixed_location_pickup_service_type_1','chbs_fixed_location_pickup_service_type_2']>-1))
1385					{
1386						$self.checkFixedLocationPickup(name);
1387					}					
1388					
1389					if($.inArray(name,['chbs_fixed_location_dropoff_service_type_1']>-1))
1390					{
1391						$self.checkFixedLocationPickup('chbs_fixed_location_pickup_service_type_1');
1392					}  
1393					
1394					if($.inArray(name,['chbs_fixed_location_dropoff_service_type_2']>-1))
1395					{
1396						$self.checkFixedLocationPickup('chbs_fixed_location_pickup_service_type_2');
1397					}	 
1398				}
1399			});
1400						
1401			$self.e('.ui-selectmenu-button .ui-icon.ui-icon-triangle-1-s').attr('class','chbs-meta-icon-arrow-vertical-large'); 
1402			
1403			$self.checkFixedLocationPickup('chbs_fixed_location_pickup_service_type_1');
1404			$self.checkFixedLocationPickup('chbs_fixed_location_pickup_service_type_2');
1405			
1406			var fInedx=[1,3];
1407			
1408			for(var i in fInedx)
1409			{
1410				var transferType=$self.e('[name="chbs_transfer_type_service_type_'+fInedx[i]+'"]');
1411				if(transferType.length===1)
1412				{
1413					if(parseInt(transferType.val(),10)===3)
1414					{
1415						var returnDate=$self.e('[name="chbs_return_date_service_type_'+fInedx[i]+'"]');
1416						returnDate.parents('.chbs-form-field').parent('.chbs-clear-fix').removeClass('chbs-hidden');
1417					}
1418				}	
1419			}
1420		};
1421			
1422		/**********************************************************************/
1423		
1424		this.getFixedLocationSource=function(item)
1425		{
1426			var fixedLocation=[];
1427			$(item).next('select').find('option:not([disabled="disabled"])').each(function(index2,item2)
1428			{
1429				fixedLocation.push({label:item2.text,value:item2.value});
1430			});	  
1431		   
1432			return(fixedLocation);
1433		};
1434		
1435		/**********************************************************************/
1436		
1437		this.createFixedLocationAutocomplete=function()
1438		{
1439			$self.e('.chbs-form-field-location-fixed-autocomplete').each(function(index,item)
1440			{
1441				var fixedLocation=$self.getFixedLocationSource(item);
1442				if(fixedLocation.length)
1443				{
1444					$(item).autocomplete(
1445					{
1446						appendTo:$this,
1447						source:fixedLocation,
1448						minLength:0,
1449						focus:function(event,ui)
1450						{
1451							event.preventDefault();
1452						},
1453						select:$self.handleFixedLocationAutocompleteChange,
1454						change:$self.handleFixedLocationAutocompleteChange
1455					}).focus(function()
1456					{
1457						$(this).autocomplete('search');
1458					});
1459					
1460					$.ui.autocomplete.filter=function(array,term)
1461					{
1462						var matcher=new RegExp('^'+$.ui.autocomplete.escapeRegex(term),'i');
1463						return $.grep(array,function(value) 
1464						{
1465							return(matcher.test(value.label || value.value || value));
1466						});
1467					};
1468				}
1469			});
1470		};
1471		
1472		/**********************************************************************/
1473		
1474		this.handleFixedLocationAutocompleteChange=function(event,ui)
1475		{
1476			event.preventDefault();
1477			var $select=$(event.target).next('select'),
1478				name=$select.attr('name');
1479
1480			if(ui.item==null)
1481			{
1482				$(event.target).val('');
1483				$select.val('');
1484			}
1485			else
1486			{
1487				$(event.target).val(ui.item.label);
1488				$select.val(ui.item.value);
1489			}
1490			
1491			if($.inArray(name,['chbs_fixed_location_pickup_service_type_1','chbs_fixed_location_dropoff_service_type_1','chbs_fixed_location_pickup_service_type_2','chbs_fixed_location_dropoff_service_type_3']>-1))
1492			{
1493				$self.googleMapSetAddress($select,function()
1494				{
1495					$self.googleMapCreate();
1496					$self.googleMapCreateRoute(); 
1497				});
1498			}
1499
1500			if($.inArray(name,['chbs_fixed_location_pickup_service_type_1','chbs_fixed_location_pickup_service_type_2']>-1))
1501			{
1502				$self.checkFixedLocationPickup(name);
1503			}					
1504
1505			if($.inArray(name,['chbs_fixed_location_dropoff_service_type_1']>-1))
1506			{
1507				$self.checkFixedLocationPickup('chbs_fixed_location_pickup_service_type_1');
1508			}  
1509
1510			if($.inArray(name,['chbs_fixed_location_dropoff_service_type_2']>-1))
1511			{
1512				$self.checkFixedLocationPickup('chbs_fixed_location_pickup_service_type_2');
1513			}
1514		};
1515		
1516		/**********************************************************************/
1517		
1518		this.checkFixedLocationPickup=function(pickupLocationFieldName)
1519		{
1520			var dropoffLocationFieldName=pickupLocationFieldName.replace('pickup','dropoff');
1521			
1522			var dropoffLocationField=$self.e('[name="'+dropoffLocationFieldName+'"]');
1523			
1524			dropoffLocationField.children('option').removeAttr('disabled');
1525			
1526			try
1527			{
1528				dropoffLocationField.selectmenu('refresh');
1529			}
1530			catch(e) {}
1531			
1532			/***/
1533			
1534			var dataPickupLocation=$self.e('select[name="'+pickupLocationFieldName+'"]').children('option:selected').attr('data-location');
1535			if(typeof(dataPickupLocation)=='undefined') return;
1536			
1537			dataPickupLocation=JSON.parse(dataPickupLocation);
1538			
1539			if(!dataPickupLocation.dropoff_disable.length) return;
1540			
1541			for(var i in dataPickupLocation.dropoff_disable)
1542				dropoffLocationField.children('option[value="'+dataPickupLocation.dropoff_disable[i]+'"]').attr('disabled','disabled').removeAttr('selected');
1543			
1544			try
1545			{
1546				dropoffLocationField.selectmenu('refresh');
1547			}
1548			catch(e) {}
1549			
1550			$self.e('.chbs-form-field-location-fixed-autocomplete').each(function(index,item)
1551			{
1552				var fixedLocation=$self.getFixedLocationSource(item);
1553				$(item).autocomplete({source:fixedLocation});
1554			});
1555		};
1556		
1557		/**********************************************************************/
1558		/**********************************************************************/
1559		
1560		this.setMainNavigation=function()
1561		{
1562			var step=parseInt($self.e('input[name="chbs_step"]').val(),10);
1563	 
1564			var element=$self.e('.chbs-main-navigation-default').find('li');
1565			
1566			element.removeClass('chbs-state-selected').removeClass('chbs-state-completed');
1567			
1568			element.filter('[data-step="'+step+'"]').addClass('chbs-state-selected');
1569
1570			var i=0;
1571			element.each(function()
1572			{
1573				if((++i)>=step) return;
1574				
1575				$(this).addClass('chbs-state-completed');
1576			});
1577		};
1578		
1579		/**********************************************************************/
1580		
1581		this.getServiceTypeId=function()
1582		{
1583			return(parseInt($self.e('.ui-tabs .ui-tabs-active').attr('data-id'),10));
1584		};
1585		
1586		/**********************************************************************/
1587		
1588		this.setServiceTypeId=function(serviceTypeId)
1589		{
1590			$self.e('input[name="chbs_service_type_id"]').val(serviceTypeId);
1591		};
1592		
1593		/**********************************************************************/
1594		/**********************************************************************/
1595
1596		this.setAction=function(name)
1597		{
1598			$self.e('input[name="action"]').val('chbs_'+name);
1599		};
1600
1601		/**********************************************************************/
1602		
1603		this.e=function(selector)
1604		{
1605			return($this.find(selector));
1606		};
1607
1608		/**********************************************************************/
1609
1610		this.recalculateVehiclePrice=function(response,previousStep)
1611		{
1612			if((parseInt(response.booking_summary_hide_fee,10)===1) && (parseInt(previousStep,10)===1))
1613			{
1614				var vehicle=[];
1615
1616				$self.e('.chbs-vehicle-list>ul>li').each(function()
1617				{
1618					var helper=new CHBSHelper();
1619					var parent=$(this).children('div:first');
1620
1621					if((!helper.isEmpty(parent.attr('data-base_location_cooridnate_lat'))) && (!helper.isEmpty(parent.attr('data-base_location_cooridnate_lng'))))
1622						vehicle.push({id:parent.attr('data-id'),lat:parent.attr('data-base_location_cooridnate_lat'),lng:parent.attr('data-base_location_cooridnate_lng')});
1623				});
1624
1625				if(vehicle.length)
1626				{
1627					$self.e('.chbs-vehicle-list').children().addClass('chbs-hidden');
1628					$self.e('.chbs-vehicle-list').addClass('chbs-preloader-1');
1629					
1630					var j=0;
1631					for(var i in vehicle)
1632					{
1633						$self.calculateBaseLocationDistance(function(baseLocationData)
1634						{
1635							j++;
1636
1637							var vehicleElement=$self.e('.chbs-vehicle-list .chbs-vehicle[data-id="'+baseLocationData.id+'"]');
1638
1639							vehicleElement.find('[name="chbs_base_location_vehicle_distance['+baseLocationData.id+']"]').val(baseLocationData.distance);
1640							vehicleElement.find('[name="chbs_base_location_vehicle_return_distance['+baseLocationData.id+']"]').val(baseLocationData.return_distance);
1641
1642							if(j===vehicle.length)
1643							{
1644								$self.goToStep(0);
1645								return;
1646							}
1647
1648						},vehicle[i]);
1649					}
1650				}
1651			}		 
1652		};
1653
1654		/**********************************************************************/
1655		
1656		this.goToStep=function(stepDelta,callback,useRecaptcha=true)
1657		{   
1658			$self.preloader(true);
1659			
1660			var step=$self.e('input[name="chbs_step"]');
1661			var stepRequest=$self.e('input[name="chbs_step_request"]');
1662			
1663			if(parseInt($option.recaptcha.enable,10)===1)
1664			{
1665				var s=parseInt(step.val(),10)+stepDelta;
1666			
1667				if(s>=1)
1668				{
1669					if(useRecaptcha)
1670					{
1671						var grc=parseInt($option.recaptcha.api_type,10)===1 ? grecaptcha : grecaptcha.enterprise;
1672						
1673						grc.ready(function() 
1674						{
1675							grc.execute($option.recaptcha.site_key).then(function(token)
1676							{
1677								$self.e('[name="chbs_recaptcha_token"]').val(token);
1678								$self.goToStep(stepDelta,callback,false);
1679							});
1680						});
1681						
1682						return;
1683					}
1684				}
1685			}	
1686			
1687			$self.setAction('go_to_step');
1688			
1689			$self.setServiceTypeId($self.getServiceTypeId());
1690			
1691			stepRequest.val(parseInt(step.val(),10)+stepDelta);
1692			
1693			/***/
1694			
1695			var serviceTypeId=$self.getServiceTypeId();
1696			
1697			if(parseInt(stepRequest.val(),10)===2)
1698			{
1699				var sum=parseInt($self.e('[name="chbs_passenger_adult_service_type_'+serviceTypeId+'"]').val(),10)+parseInt($self.e('[name="chbs_passenger_children_service_type_'+serviceTypeId+'"]').val(),10);
1700				if(sum>0) $self.e('[name="chbs_vehicle_passenger_count"]').val(sum);
1701			}
1702			
1703			if(parseInt(stepRequest.val(),10)===4)
1704			{
1705				if($iti)
1706				{
1707					var field=$self.e('input[name="chbs_client_contact_detail_phone_number"]');
1708					var number=$iti.getNumber();
1709
1710					field.val(number);
1711				}
1712			}
1713			
1714			
1715		
1716
1717			
1718			
1719			
1720			$self.post($self.e('form[name="chbs-form"]').serialize(),function(response)
1721			{   
1722				var previousStep=$self.e('input[name="chbs_step"]').val();
1723				
1724				response.step=parseInt(response.step,10);
1725				
1726				$self.getGlobalNotice().addClass('chbs-hidden');
1727				
1728				$self.e('.chbs-main-content>div').css('display','none');
1729				$self.e('.chbs-main-content>div:eq('+(response.step-1)+')').css('display','block');
1730				
1731				$self.e('input[name="chbs_step"]').val(response.step);
1732				
1733				$self.setMainNavigation();
1734				
1735				$self.googleMapDuplicate(-1);
1736				
1737				google.maps.event.trigger($googleMap,'resize');
1738				
1739				$self.e('select[name="chbs_navigation_responsive"]').val(response.step);
1740				$self.e('select[name="chbs_navigation_responsive"]').selectmenu('refresh');
1741				  
1742				if(parseInt(response.step,10)===1)
1743					$self.googleMapStartCustomizeHeight();
1744				else $self.googleMapStopCustomizeHeight();
1745			 
1746				switch(parseInt(response.step,10))
1747				{
1748					case 2:
1749						
1750						if(typeof(response.redirect_to_url_address)!=='undefined')
1751						{
1752							$('body').css({'display':'none'});
1753							window.location.href=response.redirect_to_url_address;
1754							break;
1755						}
1756						
1757						$self.e('.chbs-vehicle-filter>.chbs-form-field:first>select').replaceWith(response.vehicle_passenger_filter_field);
1758						
1759						if(typeof(response.vehicle)!=='undefined')
1760						{
1761							$self.e('.chbs-vehicle-list').removeClass('chbs-preloader-1');
1762							$self.e('.chbs-vehicle-list').html(response.vehicle);
1763							
1764							$self.recalculateVehiclePrice(response,previousStep);
1765						}
1766						
1767						if(typeof(response.booking_extra)!=='undefined')
1768							$self.e('.chbs-booking-extra').html(response.booking_extra);						
1769						
1770						if(typeof(response.summary)!=='undefined')
1771							$self.e('.chbs-main-content-step-2>.chbs-layout-25x75 .chbs-layout-column-left:first').html(response.summary[0]);  
1772						
1773						$self.preloadVehicleImage();
1774						$self.createVehicleGallery();
1775						
1776						$self.createSelectMenu();
1777						$self.createFixedLocationAutocomplete();
1778
1779						$self.manageBookingExtra();
1780
1781					break;
1782						
1783					case 3:
1784						
1785						if((typeof(response.client_form_sign_in)!=='undefined') && (typeof(response.client_form_sign_up)!=='undefined'))
1786						{
1787							$self.e('.chbs-main-content-step-3 .chbs-client-form').html('');
1788
1789							if(typeof(response.client_form_sign_in)!=='undefined')
1790								$self.e('.chbs-main-content-step-3 .chbs-client-form').prepend(response.client_form_sign_in);						
1791
1792							if(typeof(response.client_form_sign_up)!=='undefined')
1793								$self.e('.chbs-main-content-step-3 .chbs-client-form').append(response.client_form_sign_up); 
1794							
1795							if(typeof(response.payment_form)!=='undefined')
1796								$self.e('.chbs-main-content-step-3 .chbs-payment-form').html(response.payment_form); 
1797						}
1798						
1799						if(typeof(response.summary)!=='undefined')
1800							$self.e('.chbs-main-content-step-3>.chbs-layout-25x75 .chbs-layout-column-left:first').html(response.summary[0]);
1801						
1802						$self.setPayment();
1803						$self.createSelectMenu();
1804						$self.createFixedLocationAutocomplete();
1805					   
1806					break;
1807					
1808					case 4:
1809						
1810						if(typeof(response.summary)!=='undefined')
1811						{
1812							$self.e('.chbs-main-content-step-4>.chbs-layout-33x33x33>.chbs-layout-column-left').html(response.summary[0]);
1813						
1814							$self.e('.chbs-main-content-step-4>.chbs-layout-33x33x33>.chbs-layout-column-center').html(response.summary[1]);
1815						
1816							$self.e('.chbs-main-content-step-4>.chbs-layout-33x33x33>.chbs-layout-column-right').html(response.summary[2]);
1817						}
1818						
1819						$self.e('.chbs-agreement-header,.chbs-agreement').remove();
1820						
1821						if(typeof(response.agreement_html)!=='undefined')
1822						{
1823							$self.e('.chbs-main-content-step-4>.chbs-layout-33x33x33').after(response.agreement_html);
1824						}
1825						
1826					break;
1827				}
1828				
1829				$self.createPhoneField();
1830				$self.createLabelTooltip();
1831				
1832				$self.createStickySidebar();
1833				$(window).scroll();
1834				
1835				if($.inArray(response.step,[4])>-1)   
1836					$self.googleMapDuplicate(response.step);
1837				
1838				$('.qtip').remove();
1839				
1840				if(typeof(response.error)!=='undefined')
1841				{
1842					if(typeof(response.error.global[0])!=='undefined')
1843						$self.getGlobalNotice().removeClass('chbs-hidden').html(response.error.global[0].message);
1844					
1845					if(typeof(response.error.local)!=='undefined')
1846					{
1847						for(var index in response.error.local)
1848						{
1849							var selector,object;
1850							
1851							var sName=response.error.local[index].field.split('-');
1852
1853							if(isNaN(sName[1])) selector='[name="'+sName[0]+'"]:eq(0)';
1854							else selector='[name="'+sName[0]+'[]"]:eq('+sName[1]+')';									
1855									
1856							object=$self.e(selector).prevAll('label');
1857								 
1858							object.qtip(
1859							{
1860								show:
1861								{ 
1862									target:$(this) 
1863								},
1864								style:
1865								{ 
1866									classes:(response.error===1 ? 'chbs-qtip chbs-qtip-error' : 'chbs-qtip chbs-qtip-success')
1867								},
1868								content:
1869								{ 
1870									text:response.error.local[index].message 
1871								},
1872								position:
1873								{ 
1874									my:($option.rtl_mode ? 'bottom right' : 'bottom left'),
1875									at:($option.rtl_mode ? 'top right' : 'top left'),
1876									container:object.parents('[name="chbs-form"]')
1877								}
1878							}).qtip('show');	
1879						}
1880					}
1881				}
1882				
1883				if(parseInt(response.step,10)===5)
1884				{
1885					$self.e('.chbs-main-navigation-default').addClass('chbs-hidden');
1886					$self.e('.chbs-main-navigation-responsive').addClass('chbs-hidden');
1887					
1888					if(typeof(response.error)!=='undefined')
1889					{
1890						$self.getGlobalNotice().removeClass('chbs-hidden').html(response.error.global[0].message);	
1891					}
1892					else
1893					{
1894						if($.inArray(parseInt(response.payment_id,10),[1,2,3,4,5])>-1)
1895						{
1896							var helper=new CHBSHelper();
1897
1898							if(!helper.isEmpty(response.payment_info))
1899								$self.e('.chbs-booking-complete-payment-'+response.payment_prefix).append('<p>'+response.payment_info+'</p>');
1900						}
1901
1902						switch(parseInt(response.payment_id,10))
1903						{
1904							case -1:
1905								
1906								if(parseInt(response.thank_you_page_enable,10)!==1)
1907								{
1908									$('body').css('display','none');
1909									window.location.href=response.payment_url;
1910								}
1911								else
1912								{
1913									$self.e('.chbs-booking-complete-payment-woocommerce').css('display','block');
1914									$self.e('.chbs-booking-complete-payment-woocommerce>a').attr('href',response.payment_url);
1915								}
1916
1917							break;
1918
1919							case 1:
1920
1921								$self.e('.chbs-booking-complete-payment-cash').css('display','block');
1922
1923							break;
1924
1925							case 2:
1926
1927								$('body').css('display','none');
1928
1929								$.getScript('https://js.stripe.com/v3/',function() 
1930								{								
1931									var stripe=Stripe(response.stripe_publishable_key);
1932									var section=$self.e('.chbs-booking-complete-payment-stripe');
1933
1934									$self.e('.chbs-booking-complete').on('click','.chbs-booking-complete-payment-stripe a',function(e)
1935									{
1936										e.preventDefault();
1937
1938										stripe.redirectToCheckout(
1939										{
1940											sessionId:response.stripe_session_id
1941										}).then(function(result) 
1942										{
1943
1944										});
1945									});
1946
1947									var counter=parseInt(response.stripe_redirect_duration,10);
1948
1949									if(counter<=0)
1950									{
1951										section.find('a').trigger('click');
1952									}
1953									else
1954									{
1955										$('body').css('display','block');
1956
1957										section.css('display','block');
1958
1959										var interval=setInterval(function()
1960										{
1961											counter--;
1962											section.find('div>span').html(counter);
1963
1964											if(counter===0)
1965											{
1966												clearInterval(interval);
1967												section.find('a').trigger('click');
1968											}
1969
1970										},1000);  
1971									}
1972								});
1973
1974							break;
1975
1976							case 3:
1977
1978								$('body').css('display','none');
1979
1980								var section=$self.e('.chbs-booking-complete-payment-paypal');
1981
1982								$self.e('.chbs-booking-complete').on('click','.chbs-booking-complete-payment-paypal a',function(e)
1983								{
1984									e.preventDefault();
1985
1986									var form=$self.e('form[name="chbs-form-paypal"]');
1987
1988									for(var i in response.form)
1989										form.find('input[name="'+i+'"]').val(response.form[i]);
1990
1991									form.submit();
1992								});
1993
1994								var counter=parseInt(response.payment_paypal_redirect_duration,10);
1995
1996								if(counter<=0)
1997								{
1998									section.find('a').trigger('click');
1999								}
2000								else
2001								{
2002									$('body').css('display','block');
2003
2004									section.css('display','block');
2005
2006									var interval=setInterval(function()
2007									{
2008										counter--;
2009										section.find('div>span').html(counter);
2010
2011										if(counter===0)
2012										{
2013											clearInterval(interval);
2014											section.find('a').trigger('click');
2015										}
2016
2017									},1000);  
2018								}
2019
2020							break;
2021
2022							case 4:
2023
2024								$self.e('.chbs-booking-complete-payment-wire-transfer').css('display','block');
2025
2026							break;
2027
2028							case 5:
2029
2030								$self.e('.chbs-booking-complete-payment-credit-card-pickup').css('display','block');
2031
2032							break;
2033						}
2034					}
2035				}
2036				
2037				var offset=20;
2038				
2039				if($('#wpadminbar').length===1)
2040					offset+=$('#wpadminbar').height();
2041				
2042				$.scrollTo($this,{offset:-1*offset});
2043				
2044				if(typeof(callback)!=='undefined') callback();
2045				
2046				$self.preloader(false);
2047			});
2048		};
2049		
2050		/**********************************************************************/
2051		
2052		this.createPhoneField=function()
2053		{
2054			var field=$self.e('input[name="chbs_client_contact_detail_phone_number"]');
2055			var fieldPlaceholder=$self.e('input[name="chbs_client_contact_detail_phone_number_placeholder"]');
2056			
2057			if(parseInt(fieldPlaceholder.length,10)===1)
2058			{
2059				$iti=window.intlTelInput(fieldPlaceholder[0],
2060				{
2061					initialCountry:$option.client_country_code,
2062					separateDialCode:true
2063				});
2064				
2065				$iti.setNumber(field.val());
2066				
2067				fieldPlaceholder[0].addEventListener('countrychange',function()
2068				{
2069					var number=$iti.getNumber();
2070					
2071					field.val(number);
2072				});
2073			}
2074		};
2075		
2076		/**********************************************************************/
2077		
2078		this.manageBookingExtra=function()
2079		{
2080			var bookingExtraList=$self.e('.chbs-booking-extra-list');
2081			var bookingExtraCategoryList=$self.e('.chbs-booking-extra-category-list');
2082			
2083			if(bookingExtraList.length!==1) return;
2084						
2085			if(parseInt(bookingExtraCategoryList.length)===1)
2086			{
2087				bookingExtraList.addClass('chbs-hidden');
2088
2089				bookingExtraCategoryList.find('>div>a').off('click');
2090
2091				bookingExtraCategoryList.find('>div>a').on('click',function(e)
2092				{
2093					e.preventDefault();
2094
2095					var categoryId=$(this).attr('data-category_id');
2096
2097					bookingExtraList=$self.e('.chbs-booking-extra-list');
2098
2099					if($(this).next('.chbs-booking-extra-list').length===1)
2100					{
2101						if(!$(this).next('.chbs-booking-extra-list').hasClass('chbs-hidden'))
2102						{
2103							$(this).next('.chbs-booking-extra-list').addClass('chbs-hidden');
2104							return;
2105						}
2106					}
2107
2108					bookingExtraList.find('li').each(function()
2109					{
2110						if($.inArray(categoryId,$(this).attr('data-category_id').split(','))>-1)
2111							$(this).removeClass('chbs-hidden-by-category');
2112						else $(this).addClass('chbs-hidden-by-category');
2113					});
2114
2115					$(this).after(bookingExtraList);
2116
2117					bookingExtraList.removeClass('chbs-hidden');
2118				});
2119			}
2120			
2121			var vehicleIdSelected=$self.e('[name="chbs_vehicle_id"]').val();
2122			
2123			bookingExtraList=$self.e('.chbs-booking-extra-list');
2124			
2125			bookingExtraList.find('li:not(.chbs-hidden-by-category)').each(function()
2126			{
2127				var vehicleId=$(this).attr('data-vehicle_id').split(',');
2128				if(($.inArray('-1',vehicleId)>-1) || ($.inArray(vehicleIdSelected,vehicleId)>-1))
2129				{
2130					$(this).removeClass('chbs-hidden');
2131				}
2132				else
2133				{
2134					$(this).addClass('chbs-hidden');
2135					$(this).find('.chbs-button.chbs-button-style-2').removeClass('.chbs-state-selected');
2136				}
2137			});
2138			
2139			bookingExtraList=$self.e('.chbs-booking-extra-list');
2140			
2141			var data=[];
2142			bookingExtraList.find('.chbs-button.chbs-button-style-2').each(function()
2143			{
2144				if($(this).hasClass('chbs-state-selected'))
2145					data.push($(this).attr('data-value'));
2146			});
2147			
2148			var t=[data.join(','),$self.e('input[name="chbs_booking_extra_id"]').val()];
2149			
2150			if(new String(t[0])!==new String(t[1]))
2151			{
2152				$self.e('input[name="chbs_booking_extra_id"]').val(t[0]);
2153				$self.createSummaryPriceElement();
2154			}
2155		};
2156		
2157		/**********************************************************************/
2158		
2159		this.post=function(data,callback)
2160		{
2161			$.post($option.ajax_url,data,function(response)
2162			{ 
2163				callback(response); 
2164			},'json');
2165		};	
2166		
2167		/**********************************************************************/
2168		
2169		this.preloader=function(action)
2170		{
2171			$self.e('#chbs-preloader').css('display',(action ? 'block' : 'none'));
2172		};
2173		
2174		/**********************************************************************/
2175		
2176		this.preloadVehicleImage=function()
2177		{
2178			try
2179			{
2180				$self.e('.chbs-vehicle-list .chbs-vehicle-image img').one('load',function()
2181				{
2182					$(this).parent('.chbs-vehicle-image').animate({'opacity':1},300);
2183				}).each(function() 
2184				{
2185					if(this.complete) $(this).load();
2186				});				
2187			}
2188			catch(e) {}
2189		};
2190		
2191		/**********************************************************************/
2192		
2193		this.createVehicleGallery=function()
2194		{
2195			$self.e('.chbs-main-content-step-2').on('click','.chbs-vehicle-list .chbs-vehicle-image img',function(e)
2196			{
2197				e.preventDefault();
2198				
2199				var gallery=$(this).parents('.chbs-vehicle-image:first').nextAll('.chbs-vehicle-gallery');
2200				
2201				if(parseInt(gallery.length,10)===1)
2202				{
2203					$.fancybox.open(gallery.find('img'));
2204				}
2205			});
2206		};
2207		
2208		/**********************************************************************/
2209		/**********************************************************************/
2210	   
2211		this.googleMapStartCustomizeHeight=function()
2212		{
2213			if(parseInt($option.widget.mode,10)===1) return;
2214			if(parseInt($self.e('input[name="chbs_step"]').val(),10)!==1) return;
2215			
2216			if($googleMapHeightInterval>0) return;
2217			
2218			$googleMapHeightInterval=window.setInterval(function()
2219			{
2220				$self.googleMapCustomizeHeight();
2221			},500);
2222		};
2223		
2224		/**********************************************************************/
2225	   
2226		this.googleMapStopCustomizeHeight=function()
2227		{
2228			if(parseInt($option.widget.mode,10)===1) return;
2229			if(parseInt($self.e('input[name="chbs_step"]').val(),10)!==1) return;
2230			
2231			clearInterval($googleMapHeightInterval);
2232			$self.e('#chbs_google_map').height('420px');
2233			
2234			$googleMapHeightInterval=0;
2235		};		
2236		
2237		/**********************************************************************/
2238	   
2239		this.googleMapCustomizeHeight=function()
2240		{
2241			if(parseInt($option.widget.mode,10)===1) return;
2242			if(parseInt($self.e('input[name="chbs_step"]').val(),10)!==1) return;
2243			
2244			var rideInfo=$self.e('.chbs-ride-info');
2245			var columnLeft=$self.e('.chbs-main-content-step-1>.chbs-layout-50x50>.chbs-layout-column-left');
2246
2247			var helper=new CHBSHelper();
2248			
2249			if(helper.isMobile())
2250			{
2251				$self.e('#chbs_google_map').height('420px');
2252			}
2253			else
2254			{
2255				$self.e('#chbs_google_map').height(parseInt(columnLeft.actual('height'),10)-parseInt(rideInfo.actual('height'),10));
2256			}
2257			
2258			google.maps.event.trigger($googleMap,'resize');
2259		};
2260	   
2261		/**********************************************************************/
2262		/**********************************************************************/
2263	   
2264		this.googleMapDuplicate=function(step)
2265		{
2266			if(step===4)
2267			{
2268				var map=$self.e('.chbs-google-map>#chbs_google_map');
2269				if(map.children('div').length)
2270					$self.e('.chbs-google-map-summary').append(map);			 
2271			}
2272			else
2273			{
2274				
2275				var map=$self.e('.chbs-google-map-summary>#chbs_google_map');
2276				if(map.children('div').length)
2277					$self.e('.chbs-google-map').append(map);
2278			}
2279			
2280			google.maps.event.trigger($googleMap,'resize');
2281			
2282			try
2283			{
2284				$directionsRenderer.setDirections($directionsServiceResponse);
2285				$directionsRenderer.setRouteIndex($self.getRouteIndex());
2286				$googleMap.setCenter($directionsRenderer.getDirections().routes[$self.getRouteIndex()].bounds.getCenter());
2287			}
2288			catch(e)
2289			{
2290		
2291			}
2292		};
2293		
2294		/**********************************************************************/
2295		
2296		this.googleMapSetAddress=function(field,callback,setField=false)
2297		{
2298			var coordinate;
2299			var helper=new CHBSHelper();
2300			
2301			if(field.prop('tagName').toLowerCase()==='select')
2302			{
2303				callback();
2304				return;
2305			}
2306			else coordinate=JSON.parse(field.val());
2307			
2308			if((helper.isEmpty(coordinate.lat)) || (helper.isEmpty(coordinate.lng))) return;
2309			
2310			var geocoder=new google.maps.Geocoder;
2311			
2312			geocoder.geocode({'location':new google.maps.LatLng(coordinate.lat,coordinate.lng)},function(result,status) 
2313			{
2314				if((status==='OK') && (result[0]))
2315				{
2316					coordinate.address=$self.removeDoubleQuote(result[0].formatted_address);
2317						
2318					if(setField)
2319					{
2320                        var textField=field.parent('.chbs-form-field-location-autocomplete').children('input[type="text"]');
2321                        if(textField.length===1) textField.val(coordinate.address);						
2322					}
2323					
2324					field.val(JSON.stringify(coordinate));
2325					callback();
2326				}
2327			});			
2328		};
2329		
2330		/**********************************************************************/
2331		
2332		this.googleMapAutocompleteCreate=function(text)
2333		{
2334			if(text.is('[readonly]')) return;
2335			
2336			var id='chbs_location_'+(new CHBSHelper()).getRandomString(16);
2337				
2338			text.attr('id',id).on('keypress',function(e)
2339			{
2340				if(e.which===13)
2341				{
2342					e.preventDefault();
2343					return(false);
2344				}
2345			});
2346			
2347			text.on('change',function()
2348			{
2349				if(!$.trim($(this).val()).length)
2350				{
2351					text.siblings('input[type="hidden"]').val('');
2352					
2353					$self.googleMapCreate();
2354					$self.googleMapCreateRoute();					
2355				}
2356			});
2357			
2358			var option={};
2359			var helper=new CHBSHelper();
2360			var name=new String(text.attr('name'));
2361			 
2362			if(name.indexOf('pickup')>-1)
2363			{
2364				if(parseInt($option.driving_zone.pickup.enable)===1)
2365				{
2366					if((!helper.isEmpty($option.driving_zone.pickup.area.coordinate.lat)) && (!helper.isEmpty($option.driving_zone.pickup.area.coordinate.lat)) && (parseInt($option.driving_zone.pickup.area.radius,10)>=0))
2367					{
2368						var circle=new google.maps.Circle(
2369						{
2370							center:new google.maps.LatLng($option.driving_zone.pickup.area.coordinate.lat,$option.driving_zone.pickup.area.coordinate.lng),
2371							radius:$option.driving_zone.pickup.area.radius*1000
2372						});
2373						
2374						option.strictBounds=true;
2375						option.bounds=circle.getBounds();
2376					}
2377					
2378					if($option.driving_zone.pickup.country.length)
2379					{
2380						if($.inArray(-1,$option.driving_zone.pickup.country)===-1)
2381						{
2382							option.componentRestrictions={};
2383							option.componentRestrictions.country=$option.driving_zone.pickup.country;
2384						}
2385					}
2386				}				
2387			}
2388			
2389			if(name.indexOf('waypoint')>-1)
2390			{
2391				if(parseInt($option.driving_zone.waypoint.enable)===1)
2392				{
2393					if((!helper.isEmpty($option.driving_zone.waypoint.area.coordinate.lat)) && (!helper.isEmpty($option.driving_zone.waypoint.area.coordinate.lat)) && (parseInt($option.driving_zone.waypoint.area.radius,10)>=0))
2394					{
2395						var circle=new google.maps.Circle(
2396						{
2397							center:new google.maps.LatLng($option.driving_zone.waypoint.area.coordinate.lat,$option.driving_zone.waypoint.area.coordinate.lng),
2398							radius:$option.driving_zone.waypoint.area.radius*1000
2399						});
2400						
2401						option.strictBounds=true;
2402						option.bounds=circle.getBounds();
2403					}
2404					
2405					if($option.driving_zone.waypoint.country.length)
2406					{
2407						if($.inArray(-1,$option.driving_zone.waypoint.country)===-1)
2408						{
2409							option.componentRestrictions={};
2410							option.componentRestrictions.country=$option.driving_zone.waypoint.country;
2411						}
2412					}
2413				}				
2414			}
2415			
2416			if(name.indexOf('dropoff')>-1)
2417			{
2418				if(parseInt($option.driving_zone.dropoff.enable,10)===1)
2419				{
2420					if((!helper.isEmpty($option.driving_zone.dropoff.area.coordinate.lat)) && (!helper.isEmpty($option.driving_zone.dropoff.area.coordinate.lat)) && (parseInt($option.driving_zone.dropoff.area.radius,10)>=0))
2421					{
2422						var circle=new google.maps.Circle(
2423						{
2424							center:new google.maps.LatLng($option.driving_zone.dropoff.area.coordinate.lat,$option.driving_zone.dropoff.area.coordinate.lng),
2425							radius:$option.driving_zone.dropoff.area.radius*1000
2426						});					
2427
2428						option.strictBounds=true;
2429						option.bounds=circle.getBounds();
2430					}
2431					
2432					if($option.driving_zone.dropoff.country.length)
2433					{
2434						if($.inArray(-1,$option.driving_zone.dropoff.country)===-1)
2435						{
2436							option.componentRestrictions={};
2437							option.componentRestrictions.country=$option.driving_zone.dropoff.country;
2438						}
2439					}
2440				}				
2441			}
2442
2443			option.fields=['address_components','geometry'];
2444
2445			var autocomplete=new google.maps.places.Autocomplete(document.getElementById(id),option);
2446			autocomplete.addListener('place_changed',function(id)
2447			{
2448				var place=autocomplete.getPlace();
2449
2450				if(!place.geometry)
2451				{
2452					alert($option.message.place_geometry_error);
2453					text.val('');
2454					return(false);
2455				}
2456				
2457				var placeData=
2458				{
2459					lat:place.geometry.location.lat(),
2460					lng:place.geometry.location.lng(),
2461					address:$self.removeDoubleQuote(text.val()),
2462					zip_code:$self.getZipCode(place)
2463				};
2464			
2465				for(var i in place.address_components)
2466				{
2467					if($.inArray('locality',place.address_components[i].types)>-1)
2468					{
2469						placeData.locality=place.address_components[i].long_name;
2470						break;
2471					}
2472				}
2473
2474				var field=text.siblings('input[type="hidden"]');
2475				
2476				field.val(JSON.stringify(placeData));
2477		 
2478				$self.googleMapCreate();
2479				$self.googleMapCreateRoute();	
2480			});					   
2481		};
2482		
2483		/**********************************************************************/
2484		
2485		this.getZipCode=function(place)
2486		{
2487			for(var i=0;i<place.address_components.length;i++)
2488			{
2489				for(var j=0;j<place.address_components[i].types.length;j++)
2490				{
2491					if(place.address_components[i].types[j]=='postal_code')
2492					{
2493						return(place.address_components[i].long_name);
2494					}
2495				}
2496			}	
2497			
2498			return('');
2499		};
2500		
2501		/**********************************************************************/
2502		/**********************************************************************/		
2503		
2504		this.googleMapInit=function()
2505		{
2506			if(!$self.googleMapExist()) return;
2507			
2508			if(parseInt($option.google_map_option.default_location.type,10)===1)
2509			{
2510				if(navigator.geolocation) 
2511				{
2512					$self.googleMapSetDefaultLocation();
2513					
2514					navigator.geolocation.getCurrentPosition(function(position)
2515					{
2516						try
2517						{
2518							$startLocation=new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
2519							$googleMap.setCenter($startLocation);
2520						}
2521						catch(e) {}
2522					},
2523					function()
2524					{
2525						$self.googleMapSetDefaultLocation();
2526					});
2527				} 
2528				else
2529				{
2530					$self.googleMapSetDefaultLocation();
2531				}
2532			}
2533			else $self.googleMapSetDefaultLocation();
2534		};
2535		
2536		/**********************************************************************/
2537		
2538		this.googleMapSetDefaultLocation=function()
2539		{
2540			if(typeof($startLocation)==='undefined')
2541				$startLocation=new google.maps.LatLng($option.google_map_option.default_location.coordinate.lat,$option.google_map_option.default_location.coordinate.lng);
2542			
2543			if($self.getServiceTypeId()===3) return;
2544			
2545			var helper=new CHBSHelper();
2546					 
2547			var coordinate=[];
2548			
2549			coordinate[0]=$self.e('[name="chbs_pickup_location_coordinate_service_type_'+$self.getServiceTypeId()+'"]').val();
2550			coordinate[1]=$self.e('[name="chbs_dropoff_location_coordinate_service_type_'+$self.getServiceTypeId()+'"]').val();
2551			
2552			if((!helper.isEmpty(coordinate[0])) && (!helper.isEmpty(coordinate[1])))
2553				$startLocation=new google.maps.LatLng(coordinate[0],coordinate[1]);
2554
2555            try
2556            {
2557                $googleMap.setCenter($startLocation); 
2558            }
2559            catch(e) {}
2560		};
2561		
2562		/**********************************************************************/
2563		
2564		this.googleMapCreate=function()
2565		{
2566			if($self.e('#chbs_google_map').length!==1) return;
2567			
2568			$directionsRenderer=new google.maps.DirectionsRenderer();
2569			$directionsService=new google.maps.DirectionsService();
2570								  
2571			var option= 
2572			{
2573				draggable:$option.google_map_option.draggable.enable,
2574				scrollwheel:$option.google_map_option.scrollwheel.enable,
2575				mapTypeId:google.maps.MapTypeId[$option.google_map_option.map_control.id],
2576				mapTypeControl:$option.google_map_option.map_control.enable,
2577				mapTypeControlOptions:
2578				{
2579					style:google.maps.MapTypeControlStyle[$option.google_map_option.map_control.style],
2580					position:google.maps.ControlPosition[$option.google_map_option.map_control.position]
2581				},
2582				zoom:$option.google_map_option.zoom_control.level,
2583				zoomControl:$option.google_map_option.zoom_control.enable,
2584				zoomControlOptions:
2585				{
2586					position:google.maps.ControlPosition[$option.google_map_option.zoom_control.position]
2587				},
2588				streetViewControl:false
2589			};
2590					 
2591			$googleMap=new google.maps.Map($self.e('#chbs_google_map')[0],option);
2592							  
2593			if(parseInt($option.google_map_option.traffic_layer.enable,10)===1)
2594			{
2595				var trafficLayer=new google.maps.TrafficLayer();
2596				trafficLayer.setMap($googleMap);
2597			}
2598			
2599			$directionsRenderer.setMap($googleMap);
2600
2601			if($self.googleMapDraggableLocationAllowed())
2602			{
2603				$directionsRenderer.setOptions(
2604				{
2605					draggable:true,
2606					suppressMarkers:false
2607				});
2608			}
2609			else
2610			{
2611				$directionsRenderer.setOptions(
2612				{
2613					draggable:false,
2614					suppressMarkers:true
2615				});
2616			}
2617			
2618			if($self.googleMapDraggableLocationAllowed())
2619			{
2620				$googleMap.addListener('click',function(event) 
2621				{
2622					var helper=new CHBSHelper();
2623					
2624					var pickupText=$self.e('[name="chbs_pickup_location_service_type_'+$self.getServiceTypeId()+'"]');
2625					var pickupField=pickupText.siblings('input[type="hidden"]');
2626					
2627					var dropoffText=$self.e('[name="chbs_dropoff_location_service_type_'+$self.getServiceTypeId()+'"]');
2628					var dropoffField=dropoffText.siblings('input[type="hidden"]');
2629
2630					if((!helper.isEmpty(pickupField.val())) && (!helper.isEmpty(dropoffField.val()))) return;
2631
2632					var geocoder=new google.maps.Geocoder;
2633					geocoder.geocode({'location':event.latLng},function(result,status) 
2634					{
2635						if((status==='OK') && (result[0]))
2636						{
2637							var locationAddress=$self.removeDoubleQuote(result[0].formatted_address);
2638
2639							var placeData=
2640							{
2641								lat:event.latLng.lat(),
2642								lng:event.latLng.lng(),
2643								address:$self.removeDoubleQuote(result[0].formatted_address)
2644							};
2645
2646							if(helper.isEmpty(pickupField.val()))
2647							{
2648								pickupText.val(locationAddress);
2649								pickupField.val(JSON.stringify(placeData));
2650							}
2651							else if(helper.isEmpty(dropoffField.val()))
2652							{
2653								dropoffText.val(locationAddress);
2654								dropoffField.val(JSON.stringify(placeData));
2655							}
2656
2657							$self.googleMapCreate();
2658							$self.googleMapCreateRoute();
2659						}
2660					});
2661				});
2662
2663				$directionsRenderer.addListener('directions_changed',function()
2664				{
2665					var helper=new CHBSHelper();
2666					
2667					var geocoder=new google.maps.Geocoder;
2668					var directions=$directionsRenderer.getDirections();
2669					var route=directions.routes[$self.getRouteIndex()];
2670					var routePoints=[];
2671					
2672					route.legs.forEach(function(item,index)
2673					{
2674						if(parseInt(index,10)===0)
2675						{
2676							routePoints.push(
2677							{
2678								'lat':item.start_location.lat(),
2679								'lng':item.start_location.lng()
2680							});
2681						}
2682						item.via_waypoints.forEach(function(item2,index2) 
2683						{
2684							routePoints.push(
2685							{
2686								'lat':item2.lat(),
2687								'lng':item2.lng()
2688							});
2689						});
2690						routePoints.push(
2691						{
2692							'lat':item.end_location.lat(),
2693							'lng':item.end_location.lng()
2694						});
2695					});
2696					
2697					var routeLength=routePoints.length;
2698
2699					var waypoints=$self.e('[name="chbs_waypoint_location_service_type_'+$self.getServiceTypeId()+'[]"]');
2700
2701					var locationFields=[];
2702					locationFields.push($self.e('[name="chbs_pickup_location_service_type_'+$self.getServiceTypeId()+'"]'));
2703					
2704					$self.e('[name="chbs_waypoint_location_service_type_'+$self.getServiceTypeId()+'[]"]').each(function(index,waypointField) 
2705					{
2706						if(index>0) locationFields.push($(waypointField));
2707					});
2708					
2709					locationFields.push($self.e('[name="chbs_dropoff_location_service_type_'+$self.getServiceTypeId()+'"]'));
2710					
2711					var locationFieldsLength=locationFields.length;
2712
2713					if(routeLength>locationFieldsLength)
2714					{
2715						var waypointFound;
2716						for(var i=1;i<routeLength-1;i++)
2717						{
2718							waypointFound=false;
2719							waypoints.each(function(j,obj) 
2720							{
2721								if(j>0)
2722								{
2723									var waypointHidden=$(obj).siblings('input[type="hidden"]').val();
2724						 
2725									if(!helper.isEmpty(waypointHidden))
2726									{
2727										var waypointData=JSON.parse(waypointHidden);
2728										if((waypointData.lat==routePoints[i].lat) && (waypointData.lng==routePoints[i].lng))
2729										{
2730											waypointFound=true;
2731											return(false);
2732										}
2733									}
2734								}
2735							});
2736							if(!waypointFound)
2737							{
2738								var pointIndex=i;
2739								
2740								geocoder.geocode({'location':new google.maps.LatLng(routePoints[pointIndex].lat,routePoints[pointIndex].lng)},function(result,status) 
2741								{
2742									if(!((status==='OK') && (result[0]))) return;
2743
2744									var locationAddress=$self.removeDoubleQuote(result[0].formatted_address);
2745
2746									var waypointData=
2747									{
2748										lat:result[0].geometry.location.lat(),
2749										lng:result[0].geometry.location.lng(),
2750										address:$self.removeDoubleQuote(result[0].formatted_address)
2751									};
2752									
2753									$self.e('.chbs-location-add').eq(pointIndex).trigger('click');
2754									
2755									var newWypoint=$self.e('[name="chbs_waypoint_location_service_type_'+$self.getServiceTypeId()+'[]"]').eq(pointIndex);
2756									var newWypointField=newWypoint.siblings('input[type="hidden"]');
2757
2758									newWypoint.val(locationAddress);
2759									newWypointField.val(JSON.stringify(waypointData));
2760
2761									$self.googleMapCreate();
2762									$self.googleMapCreateRoute();
2763								});
2764							}
2765						}
2766					}
2767					else
2768					{
2769						var pointMoved=false;
2770						var routePointsIndex=0;
2771						
2772						locationFields.forEach(function(locationField,index) 
2773						{
2774							var helper=new CHBSHelper();
2775							var locationData=locationField.siblings('input[type="hidden"]').val();
2776
2777							if((helper.isEmpty(locationData)) && (locationFieldsLength===2) && (index===1) && !((routePoints[0].lat==routePoints[1].lat) && (routePoints[0].lng==routePoints[1].lng)))
2778							{
2779								pointMoved=locationField;
2780								var placeData=
2781								{
2782									lat:routePoints[1].lat,
2783									lng:routePoints[1].lng
2784								};
2785								
2786								locationField.siblings('input[type="hidden"]').val(JSON.stringify(placeData));							
2787							}
2788							else if(!helper.isEmpty(locationData))
2789							{
2790								locationData=JSON.parse(locationData);
2791								if(!(locationData.lat==routePoints[routePointsIndex].lat && locationData.lng==routePoints[routePointsIndex].lng))
2792								{
2793									pointMoved=locationField;
2794									locationData.lat=routePoints[routePointsIndex].lat;
2795									locationData.lng=routePoints[routePointsIndex].lng;
2796									locationField.siblings('input[type="hidden"]').val(JSON.stringify(locationData));
2797								}
2798								routePointsIndex++;
2799							}
2800						});
2801
2802						if(pointMoved!=false)
2803						{
2804							var pointDetails=JSON.parse(pointMoved.siblings('input[type="hidden"]').val());
2805							geocoder.geocode({'location':new google.maps.LatLng(pointDetails.lat,pointDetails.lng)},function(result,status) 
2806							{
2807								if((status==='OK') && (result[0]))
2808								{
2809									var locationAddress=$self.removeDoubleQuote(result[0].formatted_address);
2810									pointMoved.val(locationAddress);
2811									pointDetails.address=locationAddress;
2812									pointMoved.siblings('input[type="hidden"]').val(JSON.stringify(pointDetails));
2813								}
2814							});
2815
2816							$self.googleMapCreate();
2817							$self.googleMapCreateRoute();
2818						}
2819					}
2820				});
2821			}			 
2822		};
2823		
2824		/**********************************************************************/
2825		
2826		this.getCoordinate=function(includeDropoffLocation=false)
2827		{
2828			var helper=new CHBSHelper();
2829			var coordinate=new Array();
2830			
2831			var serviceTypeId=$self.getServiceTypeId();
2832			var panelField=$self.e('#panel-'+(serviceTypeId)).children('.chbs-form-field-location-autocomplete,.chbs-form-field-location-fixed');
2833			
2834			if(serviceTypeId===1 || serviceTypeId===2)
2835			{
2836				panelField.each(function()
2837				{
2838					if((serviceTypeId===2) && ($(this).hasClass('chbs-form-field-location-autocomplete')) && (!includeDropoffLocation))
2839					{
2840						if($(this).children('input[name="chbs_dropoff_location_service_type_2"]').length===1) return(true);
2841					}
2842			
2843					var c;
2844					
2845					try
2846					{
2847						if($(this).hasClass('chbs-form-field-location-autocomplete'))
2848							c=JSON.parse($(this).children('input[type="hidden"]').val());
2849						else 
2850						{
2851							if(($(this).find('input.chbs-form-field-location-fixed-autocomplete').length===0) || ($(this).find('input.chbs-form-field-location-fixed-autocomplete').val().length))
2852							{
2853								c=JSON.parse($(this).find('select>option:selected').attr('data-location'));
2854							}
2855							else c={lat:'',lng:''};
2856						}
2857					}
2858					catch(e)
2859					{
2860						c={lat:'',lng:''};
2861					}
2862				
2863					if((!helper.isEmpty(c.lat)) && (!helper.isEmpty(c.lng)))
2864						coordinate.push(new google.maps.LatLng(c.lat,c.lng));
2865				});
2866			}
2867			else
2868			{
2869				var option=$self.e('select[name="chbs_route_service_type_3"]>option:selected');
2870				
2871				if(option.length===1) 
2872				{
2873					var data=JSON.parse(option.attr('data-coordinate'));
2874
2875					for(var i in data)
2876					{
2877						if((!helper.isEmpty(data[i].lat)) && (!helper.isEmpty(data[i].lng)))
2878							coordinate.push(new google.maps.LatLng(data[i].lat,data[i].lng));					
2879					}
2880				}
2881			}	
2882			
2883			return(coordinate);
2884		};
2885		
2886		/**********************************************************************/
2887		
2888		this.googleMapExist=function()
2889		{
2890			return(typeof($googleMap)==='undefined' ? false : true); 
2891		};
2892		
2893		/**********************************************************************/
2894		
2895		this.googleMapDraggableLocationAllowed=function()
2896		{
2897			var serviceTypeId=$self.getServiceTypeId();
2898			
2899			var fixedFieldLength=parseInt($self.e('#panel-'+(serviceTypeId)).children('.chbs-form-field-location-fixed').length,10);
2900			
2901			return((fixedFieldLength===0) && (parseInt($option.google_map_option.draggable_location.enable,10)===1) && (parseInt($self.getServiceTypeId(),10)===1) && ($self.e('[name="chbs_waypoint_location_service_type_'+$self.getServiceTypeId()+'[]"]').length)); 
2902		};
2903	
2904		/**********************************************************************/
2905		
2906		this.googleMapCreateRoute=function(callback)
2907		{ 
2908			var serviceTypeId=$self.getServiceTypeId();
2909			
2910			if(!$self.googleMapExist())
2911			{
2912				if(typeof(callback)!=='undefined') callback();
2913				return;
2914			}
2915			
2916			var request;
2917			
2918			var panelField=$self.e('#panel-'+(serviceTypeId)).children('.chbs-form-field-location-autocomplete');
2919		   
2920			var coordinate=$self.getCoordinate();
2921			var length=coordinate.length;
2922		
2923			if(length===0)
2924			{
2925				$self.googleMapReInit();
2926				
2927				if(typeof(callback)!=='undefined') callback();
2928				return;
2929			}
2930
2931			if(serviceTypeId===2)
2932			{
2933				if(length===2)
2934				{
2935					coordinate=[coordinate[0]];
2936					length=1;
2937				}
2938			}
2939
2940			if(length>2)
2941			{
2942				var waypoint=new Array();
2943				
2944				coordinate.forEach(function(item,i) 
2945				{
2946					if((i>0) && (i<length-1))
2947						waypoint.push({location:item,stopover:true});
2948				});
2949				
2950				request= 
2951				{
2952					origin:coordinate[0],
2953					waypoints:waypoint,
2954					optimizeWaypoints:false,
2955					destination:coordinate[length-1],
2956					travelMode:google.maps.DirectionsTravelMode.DRIVING
2957				};			
2958			}
2959			else if(length===2)
2960			{
2961				request= 
2962				{
2963					origin:coordinate[0],
2964					destination:coordinate[length-1],
2965					travelMode:google.maps.DirectionsTravelMode.DRIVING
2966				};		  
2967			}
2968			else
2969			{
2970				request= 
2971				{
2972					origin:coordinate[length-1],
2973					destination:coordinate[length-1],
2974					travelMode:google.maps.DirectionsTravelMode.DRIVING
2975				};			  
2976			}
2977			
2978			request.avoidTolls=$.inArray('tolls',$option.google_map_option.route_avoid)>-1 ? true : false;
2979			request.avoidFerries=$.inArray('ferries',$option.google_map_option.route_avoid)>-1 ? true : false;
2980			request.avoidHighways=$.inArray('highways',$option.google_map_option.route_avoid)>-1 ? true : false;
2981			
2982			if(parseInt($option.google_map_option.route_type,10)===2)
2983			{
2984				request.provideRouteAlternatives=true;
2985			}
2986			
2987			$directionsService.route(request,function(response,status)
2988			{			  
2989				$self.googleMapClearMarker();
2990				
2991				if(status===google.maps.DirectionsStatus.OK)
2992				{
2993					if($self.googleMapDraggableLocationAllowed())
2994					{
2995						var helper=new CHBSHelper();
2996						var route=response.routes[$self.getRouteIndex()];
2997						var routePoints=[];
2998						
2999						route.legs.forEach(function(item,index) 
3000						{
3001							if(index===0)
3002							{
3003								routePoints.push(
3004								{
3005									'lat':item.start_location.lat(),
3006									'lng':item.start_location.lng(),
3007								});
3008							}
3009							item.via_waypoints.forEach(function(item2,index2) 
3010							{
3011								routePoints.push(
3012								{
3013									'lat':item2.lat(),
3014									'lng':item2.lng()
3015								});
3016							});
3017							routePoints.push(
3018							{
3019								'lat':item.end_location.lat(),
3020								'lng':item.end_location.lng(),
3021							});
3022						});
3023
3024						var locationFields=[];
3025						locationFields.push($self.e('[name="chbs_pickup_location_service_type_'+$self.getServiceTypeId()+'"]'));
3026						$self.e('[name="chbs_waypoint_location_service_type_'+$self.getServiceTypeId()+'[]"]').each(function(index,waypointField)
3027						{
3028							if(index>0) locationFields.push($(waypointField));
3029						});
3030						
3031						locationFields.push($self.e('[name="chbs_dropoff_location_service_type_'+$self.getServiceTypeId()+'"]'));
3032						
3033						var routePointsIndex=0;
3034						locationFields.forEach(function(locationField,index) 
3035						{
3036							var locationData=locationField.siblings('input[type="hidden"]').val();
3037							if(!helper.isEmpty(locationData))
3038							{
3039								locationData=JSON.parse(locationData);
3040								locationData.lat=routePoints[routePointsIndex].lat;
3041								locationData.lng=routePoints[routePointsIndex].lng;
3042								locationField.siblings('input[type="hidden"]').val(JSON.stringify(locationData));
3043								routePointsIndex++;
3044							}
3045						});
3046					}
3047					
3048					if(parseInt($option.google_map_option.route_type,10)===2)
3049					{
3050						var distanceMin=-1;
3051						response.routes.forEach(function(r,index) 
3052						{
3053							if((r.legs[0].distance.value<distanceMin) || (distanceMin===-1)) 
3054							{	
3055								distanceMin=r.legs[0].distance.value;
3056								$routeIndex=index;
3057							}
3058						});
3059					}
3060					
3061					$directionsRenderer.setDirections(response);
3062					$directionsRenderer.setRouteIndex($self.getRouteIndex());
3063					
3064					$directionsServiceResponse=response;
3065 
3066					for(var i in response.routes[$self.getRouteIndex()].legs)
3067					{
3068						var leg=response.routes[$self.getRouteIndex()].legs[i];
3069
3070						$self.googleMapCreateMarker(leg.start_location);
3071						$self.googleMapCreateMarker(leg.end_location); 
3072					}
3073					
3074					/***/
3075					
3076					if(parseInt($option.tax_rate_geofence_enable,10)===1)
3077					{
3078						var routeData=[];
3079
3080						for(var i in response.routes[$self.getRouteIndex()].legs)
3081						{
3082							var leg=response.routes[$self.getRouteIndex()].legs[i];
3083							
3084							for(var j in leg.steps)
3085							{
3086								var step=leg.steps[j];
3087								routeData.push([step.start_location,step.end_location,step.distance.value,step.lat_lngs]);
3088							}
3089						}
3090
3091						$self.e('input[name="chbs_route_data"]').val(JSON.stringify(routeData));
3092					}
3093
3094					try
3095					{
3096						$googleMap.setCenter($directionsRenderer.getDirections().routes[$self.getRouteIndex()].bounds.getCenter());
3097					}
3098					catch(e) {}
3099					
3100					$self.calculateRoute(response,callback);
3101				}
3102				else if(status===google.maps.DirectionsStatus.ZERO_RESULTS)
3103				{
3104					if(serviceTypeId===1)
3105					{
3106						alert($option.message.designate_route_error);
3107						
3108						panelField.each(function()
3109						{
3110							$(this).children('input[type="text"]').val('');
3111							$(this).children('input[type="hidden"]').val('');
3112						}); 
3113						
3114						$self.googleMapReInit();
3115					}
3116				}
3117				
3118				if(typeof(callback)!=='undefined') callback();
3119			});			
3120		};
3121		
3122		/**********************************************************************/
3123		
3124		this.googleMapClearMarker=function()
3125		{
3126			for(var i in $marker)
3127				$marker[i].setMap(null);
3128			
3129			$marker=[];
3130		};
3131		
3132		/**********************************************************************/
3133		
3134		this.googleMapCreateMarker=function(position)
3135		{
3136			if($self.googleMapDraggableLocationAllowed())
3137				return;
3138					
3139			for(var i in $marker)
3140			{
3141				if(typeof($marker[i].position)=='undefined') continue;
3142				if(($marker[i].position.lat()==position.lat()) && ($marker[i].position.lng()==position.lng())) return;
3143			}
3144			
3145			var label=$marker.length+1;
3146			
3147			var marker=new google.maps.Marker(
3148			{
3149				position:position,
3150				map:$googleMap,
3151				label:''+label
3152			});	 
3153			
3154			$marker.push(marker);
3155		};
3156		
3157		/**********************************************************************/
3158		
3159		this.googleMapReInit=function()
3160		{
3161			if(!$self.googleMapExist()) return;
3162			
3163			$directionsRenderer=new google.maps.DirectionsRenderer();
3164			$directionsService=new google.maps.DirectionsService();
3165			
3166			$directionsServiceResponse=null;
3167			
3168			$directionsRenderer.setDirections({routes:[]});
3169			
3170			$googleMap.setZoom($option.google_map_option.zoom_control.level);
3171							
3172			$self.calculateRoute();
3173				
3174			try
3175			{
3176				if($startLocation!==null)
3177					$googleMap.setCenter($startLocation);
3178			}
3179			catch(e) {}
3180		};
3181
3182		/**********************************************************************/
3183		
3184		this.calculateRoute=function(response,callback)
3185		{
3186			var distance=0;
3187			var duration=0;
3188			
3189			if((typeof(response)!=='undefined') && (typeof(response.routes)!=='undefined'))
3190			{
3191				for(var i=0;i<response.routes[$self.getRouteIndex()].legs.length;i++) 
3192				{
3193					distance+=response.routes[$self.getRouteIndex()].legs[i].distance.value;
3194					duration+=response.routes[$self.getRouteIndex()].legs[i].duration.value;
3195				}
3196			}
3197			
3198			distance/=1000;
3199			duration=Math.ceil(duration/60);
3200			
3201			if($option.ride_time_rounding>0.00)
3202			{
3203				duration=Math.ceil(duration/$option.ride_time_rounding)*$option.ride_time_rounding;
3204			}
3205			
3206			$self.e('input[name="chbs_distance_map"]').val(Math.round(distance*10)/10);
3207			$self.e('input[name="chbs_duration_map"]').val(duration*$option.ride_time_multiplier);
3208			
3209			$self.reCalculateRoute(callback);
3210		};
3211		
3212		/**********************************************************************/
3213		
3214		this.reCalculateRoute=function(callback)
3215		{
3216			var duration=0;
3217			var distance=0;
3218			
3219			var serviceTypeId=parseInt($self.e('input[name="chbs_service_type_id"]').val(),10);
3220			
3221			distance=$self.e('input[name="chbs_distance_map"]').val();
3222			
3223			switch(serviceTypeId)
3224			{
3225				case 1:
3226				
3227					duration=$self.e('select[name="chbs_extra_time_service_type_1"]').val();
3228					if(isNaN(duration)) duration=0; 
3229					
3230					duration*=($option.extra_time_unit===2 ? 60 : 1);
3231					
3232				break;
3233				
3234				case 2:
3235					
3236					duration=$self.e('select[name="chbs_duration_service_type_2"]').val();
3237					if(isNaN(duration)) duration=0;
3238					
3239					duration*=60;
3240					
3241				break;
3242				
3243				case 3:
3244					
3245					duration=$self.e('select[name="chbs_extra_time_service_type_3"]').val();
3246					if(isNaN(duration)) duration=0; 
3247					
3248					duration*=($option.extra_time_unit===2 ? 60 : 1);
3249					
3250				break;
3251			}
3252			
3253			if($.inArray(serviceTypeId,[1,3])>-1)
3254			{
3255				var transferType=$self.e('select[name="chbs_transfer_type_service_type_'+serviceTypeId+'"]');
3256				var transferTypeValue=transferType.length===1 ? (parseInt(transferType.val(),10)===1 ? 1 : 2) : 1;
3257				
3258				duration+=(parseInt($self.e('input[name="chbs_duration_map"]').val(),10)*transferTypeValue);
3259				distance*=transferTypeValue;
3260			}
3261			
3262			$self.e('input[name="chbs_distance_sum"]').val(distance);
3263			$self.e('input[name="chbs_duration_sum"]').val(duration);
3264			
3265			var sDuration=$self.splitTime(duration);
3266			
3267			distance=$self.formatLength(distance);
3268				
3269			$self.e('.chbs-ride-info>div:eq(0)>span:eq(2)>span:eq(0)').html(distance);
3270			$self.e('.chbs-ride-info>div:eq(1)>span:eq(2)>span:eq(0)').html(sDuration[0]);
3271			$self.e('.chbs-ride-info>div:eq(1)>span:eq(2)>span:eq(2)').html(sDuration[1]);  
3272			
3273			$self.calculateBaseLocationDistance(callback);
3274		};
3275		
3276		/**********************************************************************/
3277		
3278		this.formatLength=function(length)
3279		{
3280			if($option.length_unit===2)
3281			{   
3282				length/=1.609344;
3283				length=Math.round(length*10)/10;
3284			}
3285			
3286			return(length);
3287		};
3288		
3289		/**********************************************************************/
3290		
3291		this.splitTime=function(time)
3292		{
3293			return([Math.floor(time/60),time%60]);
3294		};
3295		
3296		/**********************************************************************/
3297		
3298		this.setWidthClass=function()
3299		{
3300			if(parseInt($option.widget.mode,10)===1)
3301			{
3302				if($this.hasClass('chbs-widget-style-1')) return;
3303			}
3304			
3305			var width=$this.parent().width();
3306			
3307			var className=null;
3308			var classPrefix='chbs-width-';
3309			
3310			if(width>=1220) className='1220';
3311			else if(width>=960) className='960';
3312			else if(width>=768) className='768';
3313			else if(width>=480) className='480';
3314			else if(width>=300) className='300';
3315			else className='300';
3316			
3317			var oldClassName=$self.getValueFromClass($this,classPrefix);
3318			if(oldClassName!==false) $this.removeClass(classPrefix+oldClassName);
3319			
3320			$this.addClass(classPrefix+className);
3321			
3322			if($self.prevWidth!==width)
3323			{
3324				$self.prevWidth=width;
3325				$(window).resize();
3326				
3327				$self.createStickySidebar();
3328				
3329				if(parseInt($option.widget.mode,10)!==1)
3330				{
3331					if($.inArray(className,['300','480'])>-1)
3332						$self.googleMapStopCustomizeHeight();
3333					else $self.googleMapStartCustomizeHeight();
3334				}
3335			};
3336						
3337			setTimeout($self.setWidthClass,500);
3338		};
3339	   
3340		/**********************************************************************/
3341		
3342		this.getValueFromClass=function(object,pattern)
3343		{
3344			try
3345			{
3346				var reg=new RegExp(pattern);
3347				var className=$(object).attr('class').split(' ');
3348
3349				for(var i in className)
3350				{
3351					if(reg.test(className[i]))
3352						return(className[i].substring(pattern.length));
3353				}
3354			}
3355			catch(e) {}
3356
3357			return(false);		
3358		};
3359		
3360		/**********************************************************************/
3361		
3362		this.createSummaryPriceElement=function()
3363		{
3364			$self.setAction('create_summary_price_element');
3365  
3366			$self.post($self.e('form[name="chbs-form"]').serialize(),function(response)
3367			{	
3368				$self.e('.chbs-summary-price-element').replaceWith(response.html);
3369				$(window).scroll();
3370			});   
3371		};
3372		
3373		/**********************************************************************/
3374		
3375		this.createStickySidebar=function()
3376		{
3377			if(parseInt($option.summary_sidebar_sticky_enable,10)!==1) return;
3378			
3379			var className=$self.getValueFromClass($this,'chbs-width-');
3380			
3381			if($.inArray(className,['300','480','768'])>-1)
3382			{
3383				$self.removeStickySidebar();
3384				return;
3385			}	   
3386			
3387			if($this.hasClass('chbs-hidden')) return;
3388			
3389			var step=parseInt($self.e('input[name="chbs_step"]').val(),10);
3390			
3391			$sidebar=$self.e('.chbs-main-content>.chbs-main-content-step-'+step+'>.chbs-layout-25x75 .chbs-layout-column-left:first').theiaStickySidebar({'additionalMarginTop':40,'additionalMarginBottom':40});
3392		};
3393		
3394		/**********************************************************************/
3395		
3396		this.removeStickySidebar=function()
3397		{
3398			if(parseInt($option.summarySidebarStickyEnable,10)!==1) return;
3399			try
3400			{
3401				$sidebar.destroy();
3402			}
3403			catch(e) {}
3404		};
3405		
3406		/**********************************************************************/
3407		
3408		this.getGlobalNotice=function()
3409		{
3410			var step=parseInt($self.e('input[name="chbs_step"]').val(),10);
3411			return($self.e('.chbs-main-content-step-'+step+' .chbs-notice'));
3412		};
3413		
3414		/**********************************************************************/
3415		
3416		this.calculateBaseLocationDistance=function(callback,coordinate)
3417		{
3418			if(typeof(coordinate)=='undefined') coordinate=false;
3419			
3420			var helper=new CHBSHelper();
3421			
3422			var baseLocation;
3423			var baseLocationData={distance:0,duration:0,return_distance:0,return_duration:0};
3424			
3425			if(coordinate===false)
3426			{
3427				$self.e('input[name="chbs_base_location_distance"]').val(0);
3428				$self.e('input[name="chbs_base_location_duration"]').val(0);
3429				$self.e('input[name="chbs_base_location_return_distance"]').val(0);
3430				$self.e('input[name="chbs_base_location_return_duration"]').val(0);
3431
3432				baseLocation={coordinate:{lat:$option.base_location.coordinate.lat,lng:$option.base_location.coordinate.lng}};
3433
3434				var vehicleId=$self.e('input[name="chbs_vehicle_id"]').val();
3435				var vehicle=$self.e('.chbs-vehicle-list .chbs-vehicle[data-id="'+vehicleId+'"]');
3436
3437				if(vehicle.length===1)
3438				{
3439					if((!helper.isEmpty(vehicle.attr('data-base_location_cooridnate_lat'))) && (!helper.isEmpty(vehicle.attr('data-base_location_cooridnate_lng'))))
3440					{
3441						baseLocation.coordinate.lat=vehicle.attr('data-base_location_cooridnate_lat');
3442						baseLocation.coordinate.lng=vehicle.attr('data-base_location_cooridnate_lng');
3443					}
3444				}
3445			}
3446			else
3447			{
3448				baseLocationData.id=coordinate.id;
3449				
3450				baseLocation={coordinate:{lat:coordinate.lat,lng:coordinate.lng}};
3451			}
3452		   		   
3453			if((helper.isEmpty(baseLocation.coordinate.lat)) || (helper.isEmpty(baseLocation.coordinate.lng)))
3454			{
3455				$self.callback(callback,baseLocationData);
3456				return(baseLocationData);
3457			}
3458			
3459			var request;
3460			var routeCoordinate=$self.getCoordinate(true);
3461			var directionsService=new google.maps.DirectionsService();
3462			
3463			/***/
3464			
3465			if(parseInt(routeCoordinate.length,10)===0)
3466			{
3467				$self.callback(callback,baseLocationData);
3468				return(baseLocationData);
3469			}
3470			
3471			request= 
3472			{
3473				origin:routeCoordinate[0],
3474				optimizeWaypoints:false,
3475				destination:new google.maps.LatLng(baseLocation.coordinate.lat,baseLocation.coordinate.lng),
3476				travelMode:google.maps.DirectionsTravelMode.DRIVING
3477			};   
3478			directionsService.route(request,function(response,status)
3479			{
3480				if(status===google.maps.DirectionsStatus.OK)
3481				{
3482					var distance=0;
3483					var duration=0;
3484					
3485					for(var i=0;i<response.routes[0].legs.length;i++) 
3486					{
3487						distance+=response.routes[0].legs[i].distance.value;
3488						duration+=response.routes[0].legs[i].duration.value;
3489					}
3490					
3491					distance/=1000;
3492					distance=Math.round(distance*10)/10;
3493					
3494					duration=Math.ceil(duration/60);
3495			
3496					if(coordinate===false)
3497					{
3498						$self.e('input[name="chbs_base_location_distance"]').val(distance);
3499						$self.e('input[name="chbs_base_location_duration"]').val(duration);
3500					}
3501					else
3502					{
3503						baseLocationData.distance=distance;
3504						baseLocationData.duration=duration;
3505					}
3506					
3507					if(routeCoordinate.length>1)
3508					{
3509						var transferTypeId=1;
3510						var serviceTypeId=$self.getServiceTypeId();
3511
3512						if($.inArray(serviceTypeId,[1,3])>-1)
3513						{
3514							var transferType=$self.e('select[name="chbs_transfer_type_service_type_'+serviceTypeId+'"]');
3515							transferTypeId=transferType.length===1 ? parseInt(transferType.val(),10) : 1;
3516						}
3517
3518						request= 
3519						{
3520							optimizeWaypoints:false,
3521							origin:$.inArray(transferTypeId,[1,3])>-1 ? routeCoordinate[routeCoordinate.length-1] : routeCoordinate[0],
3522							destination:new google.maps.LatLng(baseLocation.coordinate.lat,baseLocation.coordinate.lng),
3523							travelMode:google.maps.DirectionsTravelMode.DRIVING
3524						};   
3525						directionsService.route(request,function(response,status)
3526						{
3527							if(status===google.maps.DirectionsStatus.OK)
3528							{
3529								var distance=0;
3530								var duration=0;
3531
3532								for(var i=0;i<response.routes[0].legs.length;i++) 
3533								{
3534									distance+=response.routes[0].legs[i].distance.value;
3535									duration+=response.routes[0].legs[i].duration.value;
3536								}
3537
3538								distance/=1000;
3539								distance=Math.round(distance*10)/10;
3540										
3541								duration=Math.ceil(duration/60);
3542
3543								if(coordinate===false)
3544								{
3545									$self.e('input[name="chbs_base_location_return_distance"]').val(distance);
3546									$self.e('input[name="chbs_base_location_return_duration"]').val(duration);
3547								}
3548								else
3549								{
3550									baseLocationData.return_distance=distance;
3551									baseLocationData.return_duration=duration;
3552								}
3553							}
3554							
3555							$self.callback(callback,baseLocationData);
3556						});
3557					}
3558					else $self.callback(callback,baseLocationData);
3559				}
3560				else
3561				{
3562					$self.callback(callback,baseLocationData);
3563				}
3564			});
3565			
3566			return(baseLocationData);
3567			
3568			/***/
3569		};
3570		
3571		/**********************************************************************/
3572		
3573		this.getRouteIndex=function()
3574		{
3575			return(isNaN($routeIndex) ? 0 : $routeIndex);
3576		};
3577		
3578		/**********************************************************************/
3579		
3580		this.removeDoubleQuote=function(value)
3581		{
3582			return(value.replace(/"/g,''));
3583		};
3584		
3585		/**********************************************************************/
3586		
3587		this.callback=function(callback,arg)
3588		{
3589			if(typeof(callback)!=='undefined') callback(arg);
3590		};
3591		
3592		/**********************************************************************/
3593		
3594		this.createButtonRadio=function(selector)
3595		{
3596			$self.e(selector).on('click','.chbs-button-radio a',function(e)
3597			{
3598				e.preventDefault();
3599				
3600				var field=$(this).parent('.chbs-button-radio').find('input[type="hidden"]');
3601				
3602				$(this).siblings('a').removeClass('chbs-state-selected');
3603				
3604				if($(this).hasClass('chbs-state-selected'))
3605				{
3606					field.val(-1);
3607					$(this).removeClass('chbs-state-selected');
3608				}
3609				else 
3610				{	
3611					field.val($(this).attr('data-value'));		 
3612					$(this).addClass('chbs-state-selected');
3613				}
3614			});		  
3615		};
3616				
3617		/**********************************************************************/
3618		/**********************************************************************/
3619	};
3620	
3621	/**************************************************************************/
3622	
3623	$.fn.chauffeurBookingForm=function(option) 
3624	{
3625		console.log('--------------------------------------------------------------------------------------------');
3626		console.log('Chauffer Booking System for WordPress ver. '+option.plugin_version);
3627		console.log('https://1.envato.market/chauffeur-booking-system-for-wordpress-preview');
3628		console.log('--------------------------------------------------------------------------------------------');
3629		
3630		var form=new ChauffeurBookingForm(this,option);
3631		return(form);
3632	};
3633	
3634	/**************************************************************************/
3635
3636})(jQuery,document,window);
3637
3638/******************************************************************************/
3639/******************************************************************************/

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.