PageSourceSearch

https://www.lafavoritahotel.com/wp-content/plugins/mybooking/js/mybooking.js?ver=11.2

js lafavoritahotel.com collected 2026-10-06 12:18:41 UTC 51,947 bytes, 1,814 lines download raw bytes

1/* global calendaryear, periods, periodsDays, mgc_idvendor, _gaq, mgc_searchintovendor_enabled, mbWsUser, minimumStayCheckin */
2
3LOCAL_STORAGE_ACC_KEY = 'accomodation';
4
5//--------------------------Library functions--------------------------
6function getFormParameters(formSelector) {
7	var parameters = {};
8	jQuery(formSelector).find('input,select,textarea').each(function () {
9		var dis = jQuery(this).attr('disabled');
10		if ((!dis || dis != true) && (jQuery(this).attr('type') != 'radio' && jQuery(this).attr('type') != 'checkbox' || jQuery(this).attr('checked')))
11			parameters[jQuery(this).attr('name')] = jQuery(this).val();
12	});
13	return parameters;
14}
15language = 'it';
16icl_lang = 'it';
17
18function bindOutDatePicker(selettore) {
19	jQuery(selettore).datepicker({
20		onSelect: function (dateText, inst) {
21			var date = jQuery(this).datepicker("getDate");
22			var attr = jQuery(this).attr('datein');
23			if (typeof attr !== 'undefined' && attr !== false) {
24				var valueDOut = jQuery('#' + jQuery(this).attr('datein')).val();
25				if (valueDOut != '') {
26					var dateDOut = jQuery('#' + jQuery(this).attr('datein')).datepicker("getDate");
27					if (dateDOut > date)
28						jQuery('#' + jQuery(this).attr('datein')).val(jQuery(this).val());
29				} else {
30					jQuery('#' + jQuery(this).attr('datein')).val(jQuery(this).val());
31				}
32			}
33		}
34	});
35}
36
37function bindInDatePicker(selettore) {
38	jQuery(selettore).datepicker({
39		onSelect: function (dateText, inst) {
40			var date = jQuery(this).datepicker("getDate");
41			var attr = jQuery(this).attr('dateout');
42			if (typeof attr !== 'undefined' && attr !== false) {
43				var valueDOut = jQuery('#' + jQuery(this).attr('dateout')).val();
44				if (valueDOut != '') {
45					var dateDOut = jQuery('#' + jQuery(this).attr('dateout')).datepicker("getDate");
46					if (dateDOut < date) {
47						jQuery('#' + jQuery(this).attr('dateout')).val(jQuery(this).val());
48					}
49				} else {
50					jQuery('#' + jQuery(this).attr('dateout')).val(jQuery(this).val());
51				}
52			}
53		}
54	});
55}
56
57/**
58 * Classe Period, rappresentazione in javascript di wsPeriod del webservice
59 * @argument {Date} init
60 * @argument {Date} end
61 * @argument {Boolean} canCheckinBitmask
62 */
63function Period(init, end, canCheckinBitmask) {
64	this.init = init;
65	this.end = end;
66	this.canCheckinBitmask = canCheckinBitmask;
67
68	this.isInPeriod = function (date) {
69		return date >= init && date <= end;
70	};
71
72	this.getInitFormatted = function () {
73		return this.init.toString('dd/MM/yyyy');
74	};
75
76	this.getEndFormatted = function () {
77		return this.end.toString('dd/MM/yyyy');
78	};
79
80	this.isCheckinValid = function (date) {
81		if (!this.isInPeriod(date))
82			return false;
83
84		var dayOfWeek = date.getDay();
85
86		//Per javascript i giorni iniziano da domenica ma a me mi servono che inizino da lunedi
87		if (dayOfWeek === 0) {
88			dayOfWeek = 6;
89		} else {
90			dayOfWeek = dayOfWeek - 1;
91		}
92
93		dayOfWeek = Math.pow(2, dayOfWeek);
94
95		return (this.canCheckinBitmask & dayOfWeek) > 0;
96	};
97
98	this.isCheckOutDate = function (date) {
99		var tomorrow = new Date();
100		tomorrow.setTime(this.end.getTime());
101		tomorrow.setDate(this.end.getDate() + 1);
102		tomorrow.setHours(0);
103		tomorrow.setMilliseconds(0);
104		tomorrow.setMinutes(0);
105		tomorrow.setSeconds(0);
106		return tomorrow.getTime() === date.getTime();
107	};
108}
109
110/*
111function bindBalloon(){
112	jQuery(".balloon").tooltip({
113		delay: 0,
114		track: true,
115		showURL: false,
116		extraClass: "cont-balloon",
117	  bodyHandler: function() {
118			return jQuery('#' + jQuery(this).attr('rel')).html();
119		}
120	});
121}
122*/
123
124//Array in cui vengono inseriti i vari periodi
125periods = new Array();
126periodsDays = new Array();
127
128jQuery(function () {
129
130	jQuery.validator.addMethod(
131		"italianDate",
132		function (value, element) {
133			if (value === '')
134				return true;
135
136			return value.match(/^\d\d?\/\d\d?\/\d\d\d\d$/);
137		},
138		"Inserire una data in formato dd/mm/yyyy"
139	);
140
141	jQuery('form.validate').each(function () {
142		jQuery(this).validate();
143	});
144
145	//bindInDatePicker('.datein');
146	//bindOutDatePicker('.dateout');
147
148
149	jQuery('.dateout').datepicker({
150		onSelect: function (dateText, inst) {
151			return false;
152		}
153	});
154
155	comboYear = '2015:2022';
156	if (typeof calendaryear !== 'undefined') {
157		prevYear = calendaryear - 1;
158		comboYear = prevYear + ':' + calendaryear;
159	}
160
161	//console.log('year cal ' + comboYear);
162
163	jQuery.datepicker.setDefaults(jQuery.extend(
164		jQuery.datepicker.regional[icl_lang], {
165			changeMonth: true
166		}, {
167			changeYear: true
168		}, {
169			yearRange: comboYear
170		}, {
171			dateFormat: 'dd/mm/yy'
172		}, {
173			minDate: new Date()
174		}, {
175			showOn: 'both'
176		}, {
177			buttonImageOnly: true
178		}, {
179			buttonText: ''
180		}
181	));
182
183	calManager = new CalendarManager('arrivo', 'partenza');
184	calManager.init();
185
186
187	//L'aggiornamento del motorino lo faccio solo se il motorino esiste
188	if (jQuery('#corpoboxricerca').length > 0) {
189		jQuery("#plusrooms a").click(function () {
190
191			var newStanze = jQuery('#stanze').val() * 1 + 1;
192			jQuery('#stanze').val(newStanze);
193
194			var i;
195			for (i = 1; i <= maxStanze; i = i + 1) {
196				if (i <= jQuery('#stanze').val())
197					jQuery("#stanza" + i).show();
198				else
199					jQuery("#stanza" + i).hide();
200				//alert( i );
201			}
202			return false;
203		});
204
205		jQuery('body').on("change",'#stanze',function () {
206
207			var i;
208			for (i = 1; i <= maxStanze; i = i + 1) {
209				if (i <= jQuery('#stanze').val())
210					jQuery("#stanza" + i).show();
211				else
212					jQuery("#stanza" + i).hide();
213				//alert( i );
214			}
215			return false;
216		});
217
218		var i;
219		for (i = 1; i <= maxStanze; i = i + 1) {
220			jQuery("body").on("change","#bambini" + i,function () {
221				var indexBb = jQuery(this).attr('id').replace('bambini', '');
222				if (jQuery(this).val() == 0)
223					jQuery("#containBambini" + indexBb).hide();
224				else {
225					jQuery("#containBambini" + indexBb).show();
226				}
227				var j;
228				for (j = 1; j <= maxBambini; j = j + 1) {
229					if (j <= jQuery(this).val()) {
230						jQuery("#etabambino" + indexBb + j).show();
231						jQuery("#etabambino" + indexBb + j).attr("disabled", false);
232					} else {
233						jQuery("#etabambino" + indexBb + j).hide();
234						jQuery("#etabambino" + indexBb + j).attr("disabled", true);
235
236						//alert( indexBb + " . " + j );
237					}
238				}
239			});
240
241			if (jQuery("#stanze").length > 0 && jQuery('#stanze').val() >= i)
242				jQuery("#stanza" + i).show();
243			else if (i > 1)
244				jQuery("#stanza" + i).hide();
245
246			if (jQuery("#bambini" + i).length > 0 && jQuery("#bambini" + i).val() > 0) {
247				var indexBb = jQuery("#bambini" + i).attr('id').replace('bambini', '');
248				if (jQuery("#bambini" + i).val() == 0)
249					jQuery("#containBambini" + indexBb).hide();
250				else {
251					jQuery("#containBambini" + indexBb).show();
252				}
253				var j;
254				for (j = 1; j <= maxBambini; j = j + 1) {
255					if (j <= jQuery("#bambini" + i).val()) {
256						jQuery("#etabambino" + indexBb + j).show();
257						jQuery("#etabambino" + indexBb + j).attr("disabled", false);
258					} else {
259						jQuery("#etabambino" + indexBb + j).hide();
260						jQuery("#etabambino" + indexBb + j).attr("disabled", true);
261					}
262				}
263			}
264		}
265
266		jQuery("a.minusrooms").click(function () {
267			var newStanze = jQuery('#stanze').val() * 1 - 1;
268			jQuery('#stanze').val(newStanze);
269
270			var contStanza = jQuery(this).parents('fieldset.stanze');
271			contStanza.hide();
272			// contStanza.find('.cchildn').hide();
273			// contStanza.find('select.etabambini').hide().attr("disabled",true);
274
275			return false;
276		});
277
278		jQuery('body').on('mouseenter', '.stanze', function () {
279			jQuery(this).addClass('active');
280		});
281		jQuery('body').on('mouseleave', '.stanze', function () {
282			jQuery(this).removeClass('active');
283		});
284
285
286		//Precarico i campi del motorino di ricerca con eventuali valori presi dal localStorage
287		if(jQuery("[data-elementor-type='popup'] #corpoboxricerca").length == 0){
288			fillBookingEngineFromLocalStorage();
289		}
290		if (typeof mgc_idvendor !== 'undefined' && mgc_idvendor !== null && typeof mgc_searchintovendor_enabled !== 'undefined') {
291			var accJson = sessionStorage.getItem(LOCAL_STORAGE_ACC_KEY);
292			if (accJson !== null) {
293				searchResultIntoVendor();
294			} else {
295				//Non ho una ricerca preventivo. Carico le condizioni di default
296				jQuery("[data-mb_prid] .mbdefault").show();
297				jQuery("[data-mb_changerqbutton]").hide();
298				jQuery("[data-mb_pridbutton]").hide();
299			}
300		}
301	}
302
303
304	
305
306	//Aggiunta del preventivo da backoffice
307	jQuery('#scontrino-actions').on('click', '.mybooking-addquote', function () {
308		//metto i parametri del form nella variabile data
309		var parameters = getFormParameters('#mybooking-searchform');
310		parameters['action'] = 'mybooking-addquote';
311		jQuery.post(ajaxurl, parameters,
312			function (data) {
313				jQuery('#scontrino-actions').html(data);
314			});
315		return false;
316	});
317
318	//Quando clicco in un radio del prodotto controllo se sono in backoffice. In tal caso cancello l'eventuale messaggio di un salvataggio precedente e
319	//rifaccio vedere il bottone per il salvataggio
320	if (jQuery('#mybooking-bsearch.addquote').length > 0) {
321		jQuery('#mybooking-searchform').find('input:radio').click(function () {
322			jQuery('#mybooking-bsearch.addquote').find('input').show();
323			jQuery('#mybooking-bsearch.addquote').find('p.message').remove();
324		});
325	}
326
327
328	/*------------------Gestione scontrino--------------------------------------------*/
329
330
331
332	jQuery("body").on('mouseover', '.accomitems', function () {
333		jQuery(this).addClass('hover');
334	});
335	jQuery("body").on('mouseleave', '.accomitems', function () {
336		jQuery(this).removeClass('hover');
337	});
338
339	jQuery("body").on('click', '.accomitems', function () {
340
341		jQuery(this).parent('.listresults').find('.accomitems').removeClass('active').find('input.checkproduct').attr('checked', false);
342		jQuery(this).addClass('active').find('input.checkproduct').attr('checked', true);
343		loadLoader('scontrino');
344		//metto i parametri del form nella variabile data
345		var parameters = getFormParameters('#mybooking-searchform');
346		parameters['action'] = 'mybooking-scontrino';
347		jQuery.post(ajaxurl, parameters,
348			function (data) {
349				jQuery('#scontrino').html(data);
350			});
351
352		//Registro l'azione scontrino su google analitycs
353		if (_gaq != undefined) {
354			var lang = '';
355			if (language && language != 'it')
356				lang = language + '/';
357
358			if (typeof _gaq != 'undefined') {
359				_gaq.push(['_trackPageview', '/' + lang + 'mybooking-scontrino?idvendor=' + parameters['idvendor']]);
360			}
361		}
362	});
363
364	jQuery('#summarycontent').on('change', ' #summary-selpagamento', function () {
365
366		loadLoader('scontrino');
367		//metto i parametri del form nella variabile data
368		var parameters = getFormParameters('#formoptrequest');
369		parameters['action'] = 'mybooking-scontrino';
370
371		var paymentBalanceTime = jQuery(this).find('option:selected').attr('rel');
372		parameters['paymentbalancetime'] = paymentBalanceTime;
373		parameters['hidePrenota'] = '1';
374		parameters['showDaPagare'] = '1';
375		jQuery('#mybooking-paymentbalance').val(paymentBalanceTime);
376		if (paymentBalanceTime == 2) {
377			jQuery('#formpren .daticartacredito').show();
378		} else {
379			jQuery('#formpren .daticartacredito').hide();
380		}
381
382		jQuery.post(ajaxurl, parameters,
383			function (data) {
384				jQuery('#scontrino').html(data);
385			});
386	});
387
388
389
390	jQuery('body').on('click', 'input.spfcltv', function () {
391		//metto i parametri del form nella variabile data
392		var parameters = getFormParameters('#mybooking-searchform');
393		parameters['action'] = 'mybooking-scontrino';
394		loadLoader('scontrino');
395		jQuery.post(ajaxurl, parameters,
396			function (data) {
397				jQuery('#scontrino').html(data);
398			});
399	});
400
401	/*------------------Gestione result strutture ajax--------------------------------------------*/
402	jQuery('#corpoboxricerca form.struttura').submit(function (e) {
403		e.preventDefault();
404		//Sto facendo una richiesta informazioni
405		if (jQuery('#corpoboxricerca form.struttura #mbrichinfo').is(':checked'))
406			return true;
407
408		if (validateRicercaEsperienza(this)) {
409			setAccomodationInLocalStorage();
410			var idV = 0;
411			if (typeof mgc_idvendor !== 'undefined' && mgc_idvendor !== null && typeof mgc_searchintovendor_enabled !== 'undefined') {
412				searchResultIntoVendor();
413				idV = mgc_idvendor;
414				jQuery(this).closest('.modal').modal('hide');
415			} else {
416				idV = searchStrutturaIntoVendor();
417			}
418			//Registro l'azione result strutture su google analitycs
419			if (typeof _gaq !== 'undefined') {
420				var lang = '';
421				if (language && language !== 'it') {
422					lang = language + '/';
423				}
424
425				_gaq.push(['_trackPageview', '/' + lang + 'mybooking-result-strutture?idvendor=' + idV]);
426			}
427		}
428
429		return false;
430	});
431
432	jQuery('body').on('submit','#corpoboxricerca form',function (e) {
433		if (!jQuery(this).hasClass('struttura')) {
434			if (!validateRicercaEsperienza(this)) {
435				e.preventDefault();
436			}
437		}
438		setAccomodationInLocalStorage();
439	});
440
441
442	jQuery('#scegprenota').click(searchStrutturaIntoVendor);
443
444
445
446	jQuery('body').on('click', 'a.trgspcollpse', function () {
447
448		var SpLocoTrigger = jQuery(this);
449		idCurr = jQuery(this).attr('id');
450
451		jQuery('tr.spcollpse').each(function () {
452			if (jQuery(this).hasClass(idCurr)) {
453				if (jQuery(this).css('display') != 'none') {
454					jQuery(this).hide();
455					SpLocoTrigger.css('background-image', 'url("' + rootTheme + '/images/nav-blue-small-bx.png"');
456
457				} else {
458					jQuery(this).show();
459					SpLocoTrigger.css('background-image', 'url("' + rootTheme + '/images/nav-blue-small-tx.png"');
460				}
461			}
462		});
463		return false;
464	});
465
466	jQuery('body').on('click','#corpoboxricerca #chooseform .radio,#corpoboxricerca #btnmbrichinfo,#corpoboxricerca #btnmbrichpren',function (e) {
467
468		var link = jQuery(this).attr('lnk');
469		
470		if(jQuery(this).attr('id')!= 'btnmbrichpren'){
471			var selectVendor = jQuery('#formulaidvendor');
472
473			if(typeof mgcVendorsData !== 'undefined' && selectVendor.length > 0){
474				var selectedVendorId = selectVendor.val();
475				if(selectedVendorId == ''){
476					selectedVendorId = 0;
477				}
478
479				var reqAvailUrl = mgcVendorsData[selectedVendorId]['requestAvailUrl'];
480				if(typeof reqAvailUrl !== 'undefined' && reqAvailUrl != null){
481					link = reqAvailUrl;
482				}
483			}
484		}
485
486
487		jQuery('#ricercaEsperienza').attr('action', link);
488		var method = jQuery(this).attr('data-method');
489		if (typeof method != 'undefined') {
490			jQuery('#ricercaEsperienza').attr('method', method);
491		}
492	});
493
494	jQuery('body').on('change','#formulaidvendor',function (e) {
495
496		jQuery.getJSON(lnkDaysStatus + jQuery(this).val() + ".json", function(json) {
497			periodsDays = json;
498			periodsDays.forEach(function(el){el.date = new Date(el.date * 1000); el.date.setHours(0,0,0,0);});
499			calManager.periodDaysMap = null;
500		}).fail(function(e) {
501			console.log( e );
502		  });
503	});
504
505
506
507	jQuery('#corpoboxricerca #chooseformula').change(function () {
508		try {
509			var ad_bb = jQuery(this).find('option:selected').attr('rel');
510			ad_bb = ad_bb.split("-");
511			if (ad_bb.length == 2) {
512				jQuery('.cadlts select option').each(function () {
513					if (jQuery(this).val() > ad_bb[0])
514						jQuery(this).hide();
515					else
516						jQuery(this).show();
517				});
518
519				jQuery('.cchildn select option').each(function () {
520					if (jQuery(this).val() > ad_bb[1])
521						jQuery(this).hide();
522					else
523						jQuery(this).show();
524				});
525
526
527			}
528		} catch (e) {}
529	});
530
531	/*
532	jQuery('body').on("click", 'a.trgspcollpse', (function(){
533		idCurr = jQuery(this).attr('id');
534
535		alert(idCurr);
536
537		jQuery('tr.spcollpse').each(function(){
538			if(jQuery(this).hasClass(idCurr)){
539				if(jQuery(this).css('display') != 'none')
540					jQuery(this).hide();
541				else
542					jQuery(this).show();
543			}
544		});
545		return false;
546	});
547	*/
548
549	/*
550	jQuery('a.trgspcollpsepren').click(function(){
551		jQuery('tr.spcollpsepren').each(function(){
552			if(jQuery(this).is(':visible'))
553				jQuery(this).hide();
554			else
555				jQuery(this).show();
556		});
557		return false;
558	});
559	*/
560
561	/*
562	bindBalloon();
563
564	jQuery(document).ajaxComplete(
565			function(){
566				bindBalloon();
567			}
568		);
569	*/
570
571
572	/*
573	 * Hotel + Nave
574	 */
575	// change IBE to "Hotel + Nave"
576	jQuery('body').on( 'click', '.tabhotelnave', function (e) {
577		var divCorpoBoxRicerca = jQuery(this).parents('#corpoboxricerca');
578
579		divCorpoBoxRicerca.find('.tab').removeClass('active');
580		jQuery(this).addClass('active');
581
582		divCorpoBoxRicerca.find('.mybooking_action').val('comparepricesships');
583
584		divCorpoBoxRicerca.find('form').removeClass('form-accom').removeClass('form-flight').addClass('form-ferry');
585		/*  replaced with css styles
586		divCorpoBoxRicerca.find('#plusrooms').hide();
587		divCorpoBoxRicerca.find('#chooseform').hide();
588		divCorpoBoxRicerca.find('#chooseroute').show();
589		divCorpoBoxRicerca.find('legend').show();
590		*/
591
592		var formAction = divCorpoBoxRicerca.find('#ricercaEsperienza');
593		if (divCorpoBoxRicerca.find('#mbrichpren').length > 0) {
594			formAction.attr('action', divCorpoBoxRicerca.find('#mbrichpren').attr('lnk'));
595		}
596
597		formAction.data('originaltarget', formAction.attr('target'));
598		var action = formAction.attr('action');
599		if (!mybooking_endsWith(action, '&compareships=1')) {
600			formAction.data('originalaction', formAction.attr('action'));
601			formAction.attr('action', action + '&compareships=1')
602		}
603		formAction.attr('target', '');
604
605		e.preventDefault();
606	});
607
608	jQuery('body').on( 'click', '.tabhotelaereo', function (e) {
609		var divCorpoBoxRicerca = jQuery(this).parents('#corpoboxricerca');
610
611		divCorpoBoxRicerca.find('.tab').removeClass('active');
612		jQuery(this).addClass('active');
613
614		divCorpoBoxRicerca.find('.mybooking_action').val('findflight');
615
616		divCorpoBoxRicerca.find('form').removeClass('form-accom').removeClass('form-ferry').addClass('form-flight');
617		/*  replaced with css styles
618		divCorpoBoxRicerca.find('#plusrooms').hide();
619		divCorpoBoxRicerca.find('#chooseform').hide();
620		divCorpoBoxRicerca.find('#chooseroute').show();
621		divCorpoBoxRicerca.find('legend').show();
622		*/
623
624		var formAction = divCorpoBoxRicerca.find('#ricercaEsperienza');
625		if (divCorpoBoxRicerca.find('#mbrichpren').length > 0) {
626			formAction.attr('action', divCorpoBoxRicerca.find('#mbrichpren').attr('lnk'));
627		}
628
629		formAction.data('originaltarget', formAction.attr('target'));
630		var action = formAction.attr('action');
631		if (!mybooking_endsWith(action, '&compareships=1')) {
632			formAction.data('originalaction', formAction.attr('action'));
633			formAction.attr('action', action + '&findflight=1')
634		}
635		formAction.attr('target', '');
636
637		e.preventDefault();
638	});
639
640	// change IBE to "Hotel" (only)
641
642	jQuery('body').on( 'click', '.tabhotel', function (e) {
643		var divCorpoBoxRicerca = jQuery(this).parents('#corpoboxricerca');
644
645		divCorpoBoxRicerca.find('.tab').removeClass('active');
646		jQuery(this).addClass('active');
647
648		divCorpoBoxRicerca.find('.mybooking_action').val('result-strutture');
649
650		divCorpoBoxRicerca.find('form').removeClass('form-ferry').removeClass('form-flight').addClass('form-accom');
651		/* replaced with css styles
652		divCorpoBoxRicerca.find('#chooseroute').hide();
653		divCorpoBoxRicerca.find('legend').hide();
654		divCorpoBoxRicerca.find('#plusrooms').show();
655		divCorpoBoxRicerca.find('#chooseform').show();
656		*/
657
658		var formAction = divCorpoBoxRicerca.find('#ricercaEsperienza');
659		if (divCorpoBoxRicerca.find('#mbrichpren').length > 0) {
660			if (divCorpoBoxRicerca.find('#mbrichpren').is(':checked')) {
661				formAction.attr('action', divCorpoBoxRicerca.find('#mbrichpren').attr('lnk'));
662			} else if (divCorpoBoxRicerca.find('#mbrichinfo').is(':checked')) {
663				formAction.attr('action', divCorpoBoxRicerca.find('#mbrichinfo').attr('lnk'));
664			}
665		}
666
667		var origTarget = formAction.data('originaltarget');
668		if (origTarget)
669			formAction.attr('target', origTarget);
670
671		var origAction = formAction.data('originalaction');
672		if (origAction)
673			formAction.attr('action', origAction);
674
675		e.preventDefault();
676	});
677
678	jQuery('body').on('submit', '#ricercaEsperienza.form-ferry,#ricercaEsperienza.form-flight', function () {
679		jQuery('#mb-waitingwrapper').show().removeClass('hidden');
680		return true;
681	});
682
683	jQuery('#mb-waitingwrapper').on('click', '.close', function (e) {
684		jQuery('#mb-waitingwrapper ').fadeOut(300).addClass('hidden');
685		e.preventDefault();
686	});
687
688	//----immagine track newslettet
689	mgcpp = mb_getUrlParameter('mgcpp');
690	if (mgcpp != null) {
691		var params = "&idcliente=" + idCliente + "&mgcpp=" + mgcpp;
692		//alert(params);
693		jQuery('body').append('<img id="voidImg" src="' + rootUrl + '/file?action=setAnalyticsId' + params + '"  />');
694	}
695
696	// ----- autocomplete del modulo hotel+voli
697	/*
698	var availableTags = [
699	     #foreach ($entry in $airportMap.entrySet())
700	     	{"id":"$entry.key","value":"$entry.value"},
701	     #end
702    ];
703    $( "#departureAirport" ).autocomplete({
704        source: availableTags,
705        select: function( event, ui ) {
706        	$(this).val(ui.item.value);
707        	var v_id = ui.item.id;
708        	$("#fromCode").val(v_id);
709        		return false;
710        }
711    });
712	*/
713	if (typeof aeroporti != 'undefined') {
714		jQuery("#aeroportopartenza").autocomplete({
715			source: aeroporti,
716			select: function (event, ui) {
717				jQuery(this).val(ui.item.value);
718				var v_id = ui.item.id;
719				jQuery("#fromFlightCode").val(v_id);
720				return false;
721			}
722		});
723	}
724
725	var searchLang = '';
726	if (typeof language != 'undefined') {
727		searchLang = '&lang=' + language;
728	}
729
730	//Gestione autocompletamento località e zone
731	if (jQuery('#mgc-locality-autocomplete').length > 0) {
732		jQuery('#mgc-locality-autocomplete').autocomplete({
733			source: '/wp-content/plugins/mybooking/autocompletelocality.php?exczones=1' + searchLang,
734			//source: '/admin-ajax.php?action=mybooking-ajax-showlocality',
735			//source: "search.php",
736			minLength: 2,
737			select: function (event, ui) {
738				if (ui.item.type == 1) { //località
739					jQuery('#autocompletelocality').val(ui.item.id);
740					jQuery('#autocompletevendor').val('');
741				} else if (ui.item.type == 2) { //vendor
742					jQuery('#autocompletevendor').val(ui.item.id);
743					jQuery('#autocompletelocality').val('');
744				}
745			}
746			/* source: function (request, callback) {
747            jQuery.ajax({
748                type: "POST",
749                url: ajaxurl + '?callback=?&action=mybooking-ajax-showlocality',
750                data: "{'cityname':'" + request.term + "'}",
751                contentType: "application/json; charset=utf-8",
752                dataType: "json",
753                success: function (data) {
754				   alert('aaaaaa');
755                }
756            })},
757			*/
758		}).off('blur').on('blur', function (e) {
759
760		}).data("ui-autocomplete")._renderItem = function (ul, item) {
761
762			var listItem = jQuery("<li></li>").data("item.autocomplete", item).appendTo(ul);
763			if (item.type != 4) {
764				listItem.append('<span>' + item.label + '</span>');
765			} else {
766				listItem.addClass('ui-state-disabled');
767				listItem.append(item.label);
768			}
769
770			if (item.type == 1) {
771				listItem.addClass("item-locality");
772			} else if (item.type == 2) {
773				listItem.addClass("item-accommodation");
774			} else if (item.type == 3) {
775				listItem.addClass("item-zone");
776			} else if (item.type == 4) {
777				listItem.addClass("item-label");
778			}
779			return listItem;
780		};
781		jQuery('body').click(function () {
782			jQuery('#mgc-locality-autocomplete').autocomplete('close');
783		});
784	}
785
786	// ** Nando: corregge bug focus tastiera su Android
787	if (/android/i.test(navigator.userAgent || navigator.vendor || window.opera)) {
788		var clickTargetId = "";
789		jQuery(document).click(function (e) {
790			clickTargetId = e.target.id;
791		});
792		jQuery(window).on('resize', function (e) {
793			if (clickTargetId === "mgc-locality-autocomplete") {
794				e.preventDefault();
795				e.stopImmediatePropagation();
796				jQuery("#mgc-locality-autocomplete").focus();
797			}
798		});
799	}
800
801	jQuery( document ).on( 'elementor/popup/show', () => {
802		calManager.datePickerArrivoCreated = false;
803		fillBookingEngineFromLocalStorage();
804		calManager.datePickerArrivoCreated = false;
805		let dataArrivo = calManager.initDataArrivo(jQuery("#" + calManager.idArrivo));
806		if(dataArrivo !== null){
807			calManager.selezionaDataPartenza(dataArrivo,true);
808		}
809		setTimeout(() => {
810			console.log("Delayed for 1 second.");
811		}, "1000");		
812	} );
813
814
815});
816
817
818jQuery(window).load(function () {
819	if (typeof customUserId !== "undefined") {
820		var srcAttr = jQuery("#voidImg").attr('src');
821		srcAttr = srcAttr + "&analyticId=" + customUserId;
822		jQuery("#voidImg").attr('src', srcAttr);
823	}
824});
825
826function mb_getUrlParameter(sParam) {
827	var sPageURL = window.location.search.substring(1);
828	var sURLVariables = sPageURL.split('&');
829	for (var i = 0; i < sURLVariables.length; i++) {
830		var sParameterName = sURLVariables[i].split('=');
831		if (sParameterName[0] == sParam) {
832			return sParameterName[1];
833		}
834	}
835}
836
837/**
838 * Ritorna il vendor_id così lo posso usare
839 * @returns {Boolean}
840 */
841function searchStrutturaIntoVendor() {
842	jQuery('#pricesummary').hide();
843	//metto i parametri del form nella variabile data
844	var parameters = getFormParameters('#ricercaEsperienza');
845	parameters['action'] = 'mybooking-ajax-result-strutture';
846	loadLoader('mybooking-ajax-result-strutture');
847	jQuery.post(ajaxurl, parameters,
848		function (data) {
849			jQuery('#mybooking-ajax-result-strutture').html(data);
850		}
851	);
852	return parameters['idvendor'];
853}
854
855function validateRicercaEsperienza(formRicercaEsperienza) {
856	try {
857		jQuery(formRicercaEsperienza).validate();
858		var isValid = jQuery(formRicercaEsperienza).valid();
859		if (!isValid) {
860			textError = '';
861			jQuery(formRicercaEsperienza).find('label.error').each(function () {
862				textError = textError + jQuery(this).html() + '\n';
863			});
864			//alert(textError);
865			return false;
866		} else {
867			if (jQuery('#partenza').val().length === 0) {
868				return true;
869			}
870
871			var dateDOut = jQuery('#partenza').datepicker("getDate");
872			var dateIn = jQuery('#arrivo').datepicker("getDate");
873			if (dateIn!=null && dateDOut!=null && dateIn >= dateDOut) {
874				jQuery('#partenza').addClass('error');
875				jQuery('#arrivo').addClass('error');
876				var lang = 'it';
877				var msg = {
878					it: 'Inserisci una data di partenza posteriore alla data di arrivo',
879					en: 'Insert a departure date subsequent to the date of arrival',
880					fr: 'Entrez une date de départ à la suite de la date d\'arrivée',
881					de: 'Geben Sie eine Start Zeitpunkt nach dem Datum der Ankunft',
882					es: 'Introduzca una fecha de salida posterior a la fecha de llegada',
883					ru: 'Введите даты вылета после даты заезда'
884				}
885				if (language && language != 'it')
886					lang = language;
887
888
889
890				//alert(msg[lang]);
891				return false;
892			}
893
894			return true;
895		}
896	} catch (e) {
897		alert(e.message);
898	}
899}
900
901function loadLoader(id) {
902	jQuery('#' + id).html('<p class="loader">' + jQuery('#loader').html() + '</p>');
903}
904
905window.onload = function () {
906	if (typeof Piwik != 'undefined' && typeof Piwik.getAsyncTracker === 'function') {
907		var piwikTracker = Piwik.getAsyncTracker();
908		if (piwikTracker) {
909			var visitorId = piwikTracker.getVisitorId();
910			if (visitorId != null && visitorId.length > 0) {
911				if (jQuery('#ricercaEsperienza #visitorid').length == 0) {
912					jQuery('#ricercaEsperienza').append('<input type="hidden" id="visitorid" name="visitor_id" value="" />');
913				}
914				jQuery('#ricercaEsperienza #visitorid').val(visitorId);
915			}
916		}
917	}
918}
919
920function trackGaEvent(category, action, message) {
921	//alert('cat: ' + category +  ' - action: ' + action + ' - message: ' + message );
922	try {
923		//analitycs
924		if (typeof _gaq != 'undefined') {
925			_gaq.push(['_trackEvent', category, action, message]);
926		}
927		//Analitycs universal
928		else if (typeof ga != 'undefined') {
929			ga('send', 'event', category, action, message);
930		}
931	} catch (e) {
932		//alert(e.message);
933	}
934}
935
936function mybooking_checkEmail(emailAddress) {
937	var sQtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]';
938	var sDtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]';
939	var sAtom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+';
940	var sQuotedPair = '\\x5c[\\x00-\\x7f]';
941	var sDomainLiteral = '\\x5b(' + sDtext + '|' + sQuotedPair + ')*\\x5d';
942	var sQuotedString = '\\x22(' + sQtext + '|' + sQuotedPair + ')*\\x22';
943	var sDomain_ref = sAtom;
944	var sSubDomain = '(' + sDomain_ref + '|' + sDomainLiteral + ')';
945	var sWord = '(' + sAtom + '|' + sQuotedString + ')';
946	var sDomain = sSubDomain + '(\\x2e' + sSubDomain + ')*';
947	var sLocalPart = sWord + '(\\x2e' + sWord + ')*';
948	var sAddrSpec = sLocalPart + '\\x40' + sDomain; // complete RFC822 email address spec
949	var sValidEmail = '^' + sAddrSpec + '$'; // as whole string
950
951	var reValidEmail = new RegExp(sValidEmail);
952
953	if (reValidEmail.test(emailAddress)) {
954		return true;
955	}
956
957	return false;
958}
959
960function mybooking_endsWith(str, suffix) {
961	return str.indexOf(suffix, str.length - suffix.length) !== -1;
962}
963
964/**
965 * Classe DayStatus, rappresentazione dello stato nel giorno, checkin valido, checkout valido, min stay, data aperta, sleeping day
966 *
967 */
968function DayMgcStatus(date, canCheckin, canCheckOut, open, minStay, sleepingDay) {
969	this.date = date;
970	this.canCheckin = canCheckin;
971	this.canCheckOut = canCheckOut;
972	this.open = open;
973	this.minStay = minStay;
974	this.sleepingDay = sleepingDay;
975
976	this.getDateFormatted = function () {
977		return this.date.toString('dd/MM/yyyy');
978	}
979}
980
981
982
983function CalendarManager(idArrivo, idPartenza) {
984	this.idArrivo = idArrivo;
985	this.idPartenza = idPartenza;
986
987	this.padTo2Digits = function(num) {
988		return num.toString().padStart(2, '0');
989	  }
990	  
991	this.formatDate = function(date) {
992		return [
993			this.padTo2Digits(date.getDate()),
994			this.padTo2Digits(date.getMonth() + 1),
995			date.getFullYear(),
996		].join('/');
997	}
998
999	this.init = function () {
1000		var calendarManager = this;
1001
1002		jQuery('body').on('focus',"#" + this.idArrivo, function(){
1003			calendarManager.createDatePickerArrivo();
1004		});
1005	 
1006	
1007		jQuery('body').on('focus',"#" + idPartenza, function(){
1008			if(!jQuery(this).hasClass('hasDatepicker')){
1009				calendarManager.createDatePickerPartenza();
1010			}		
1011		});
1012		
1013		let dataArrivo = this.initDataArrivo(jQuery("#" + calendarManager.idArrivo));
1014		if(dataArrivo !== null){
1015			let dataPartenza = new Date();
1016			dataPartenza.setDate(dataArrivo.getDate() + 1);
1017			jQuery("#" + calendarManager.idPartenza).val(this.formatDate(dataPartenza));
1018		}
1019	}
1020
1021	this.initDataArrivo = function(jqInput) {
1022		if (
1023			(typeof periods == 'undefined' || periods == null || periods.length == 0) &&
1024			(typeof periodsDays == 'undefined' || periodsDays == null || periodsDays.length == 0)
1025		)
1026			return null;
1027
1028		var arrivoDate = jQuery('#' + this.idArrivo).val();
1029		if (arrivoDate === '' || typeof arrivoDate === 'undefined') {
1030			if (typeof periodsDays !== 'undefined' && periodsDays !== null && periodsDays.length > 0) {
1031				var tmpDate = new Date();
1032				tmpDate.setHours(0, 0, 0, 0);
1033				var i = 0;
1034				for (i = 0; i < 365; i++) {
1035					var periodDay = this.searchPeriodDay(tmpDate);
1036					if (periodDay != null && periodDay.canCheckin && periodDay.open && periodDay.sleepingDay) {
1037						arrivoDate = tmpDate;
1038						// jqInput.datepicker('setDate', tmpDate);
1039						jqInput.val(this.formatDate(tmpDate));
1040						return tmpDate;
1041					}
1042					tmpDate.setDate(tmpDate.getDate() + 1);
1043				}
1044			} else {
1045				arrivoDate = periods[0].getInitFormatted();
1046				jqInput.val(this.formatDate(periods[0].init));
1047				return periods[0].init;
1048			}
1049		}
1050
1051		return null;
1052	}
1053
1054	this.createDatePickerArrivo = function() {
1055		var calendarManager = this;
1056		if(!calendarManager.datePickerArrivoCreated){
1057			calendarManager.datePickerArrivoCreated = true;
1058			jQuery("#" + calendarManager.idArrivo).datepicker({
1059				onSelect: function (dateText, inst) {
1060					if(!calendarManager.datePickerPartenzaCreated){
1061						calendarManager.createDatePickerPartenza();
1062					}
1063					calendarManager.selezionaDataPartenza(dateText);
1064				},
1065				beforeShowDay: function (date) {
1066					//Così abilito solo martedì e sabato
1067					var day = date.getDay();
1068					var defaultResult = [true];
1069
1070					if (typeof periodsDays != 'undefined' && periodsDays != null && periodsDays.length > 0) {
1071						//Nuova gestione giornaliera
1072						var periodDay = calendarManager.searchPeriodDay(date);
1073						if (periodDay != null && periodDay.canCheckin && periodDay.open && periodDay.sleepingDay)
1074							return [true];
1075						else
1076							return [false];
1077					} else if (typeof periods == 'undefined' || periods == null || periods.length == 0)
1078						return defaultResult;
1079					else {
1080						var i = 0;
1081						for (i = 0; i < periods.length; i = i + 1) {
1082							var period = periods[i];
1083							if (period.isInPeriod(date)) {
1084								if (period.isCheckinValid(date))
1085									return [true];
1086							}
1087						}
1088						return [false];
1089					}
1090				}
1091			});
1092
1093			
1094		}
1095	}
1096
1097	this.createDatePickerPartenza = function(){
1098		var calendarManager = this;
1099		jQuery("#" + idPartenza).datepicker({
1100			onSelect: function (dateText, inst) {
1101				return calendarManager.selezionaDataArrivo(dateText);
1102			},
1103			beforeShowDay: function (date) {
1104				//Così abilito solo martedì e sabato
1105				var day = date.getDay();
1106				var defaultResult = [true];
1107
1108				if (typeof periodsDays != 'undefined' && periodsDays != null && periodsDays.length > 0) {
1109					//Nuova gestione giornaliera
1110					if (calendarManager.canCheckOut(date))
1111						return [true];
1112					else
1113						return [false];
1114				} else if (periods == undefined || periods == null || periods.length == 0) {
1115					return defaultResult;
1116				} else {
1117					var i = 0;
1118					var noPeriods = true;
1119					for (i = 0; i < periods.length; i = i + 1) {
1120						var period = periods[i];
1121						if (period.isInPeriod(date)) {
1122							if (period.isCheckinValid(date))
1123								return [true];
1124							noPeriods = false;
1125						}
1126					}
1127
1128					//Se non ho nessun periodo controllo che non sia in un giorno successivo al periodo (in tal caso ho un true perchè sono in checkout)
1129					if (noPeriods) {
1130						for (i = 0; i < periods.length; i = i + 1) {
1131							var period = periods[i];
1132							if (period.isCheckOutDate(date)) {
1133								return [true];
1134							}
1135						}
1136					}
1137					return [false];
1138				}
1139			}
1140		});
1141
1142		
1143	};
1144
1145	this.periodDaysMap = null;
1146
1147
1148	var self = this;
1149
1150	this.getPeriodsDayMap = function () {
1151		if (periodsDays === null) {
1152			return null;
1153		}
1154		if (self.periodDaysMap === null) {
1155			self.periodDaysMap = periodsDays.reduce(function (map, obj) {
1156				map[obj.date.getTime()] = obj;
1157				return map;
1158			}, {});
1159			//console.log(self.periodDaysMap);
1160		}
1161		return self.periodDaysMap;
1162	}
1163	/**
1164	 * return DayMgcStatus
1165	 */
1166	this.searchPeriodDay = function (date) {
1167		if (periodsDays === null)
1168			return null;
1169
1170
1171		var perDayMap = self.getPeriodsDayMap();
1172
1173		return perDayMap[date.getTime()];
1174
1175		// var i =0;
1176		// for(i == 0 ; i < periodsDays.length;i++){
1177		//	if(periodsDays[i].date.getTime() == date.getTime())
1178		//		return periodsDays[i];
1179		//}
1180		// return null;
1181	}
1182
1183	this.canCheckOut = function (date) {
1184		var dataArrivo = this.getDataArrivo();
1185		if (date <= dataArrivo)
1186			return false;
1187
1188		dayPeriod = this.searchPeriodDay(date);
1189		if (dayPeriod == null || !dayPeriod.canCheckOut && dayPeriod.open) {
1190			return false;
1191		}
1192
1193		maxStay = 365;
1194		var currentMinStay = 1;
1195
1196
1197		var oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
1198
1199		var diffDays = Math.round(Math.abs((dataArrivo.getTime() - date.getTime()) / (oneDay)));
1200
1201		//Se oggi non è aperto controllo che ieri non fosse aperto
1202		if (!dayPeriod.open) {
1203			var tmpDate = new Date(date);
1204			tmpDate.setDate(tmpDate.getDate() - 1);
1205			dayPeriodTmp = this.searchPeriodDay(tmpDate);
1206			if (dayPeriodTmp == null || !dayPeriodTmp.open)
1207				return false;
1208		}
1209
1210		//Controllo che tutte le date dalla data arrivo sino ad oggi abbiano sleepingDay > 0 altrimenti non posso dormire
1211
1212		var minStayPeriodCheckin = typeof minimumStayCheckin !== 'undefined' && minimumStayCheckin === true;
1213
1214		var tmpDate = new Date(dataArrivo);
1215		var firstDate = true;
1216		for (var tmpDate = dataArrivo; tmpDate < date; tmpDate.setDate(tmpDate.getDate() + 1)) {
1217			dayPeriod = this.searchPeriodDay(tmpDate);
1218			if (dayPeriod === null || !dayPeriod.sleepingDay) {
1219				return false;
1220			}
1221
1222			if (!minStayPeriodCheckin || firstDate) {
1223				if (currentMinStay < dayPeriod.minStay) {
1224					currentMinStay = dayPeriod.minStay;
1225				}
1226			}
1227
1228			firstDate = false;
1229		}
1230
1231		if (currentMinStay > diffDays) {
1232			return false;
1233		}
1234		return true;
1235	}
1236
1237	this.getDataArrivo = function () {
1238		//	var arrivo = $('#arrivo').val();
1239		//	var arrivSp = arrivo.split('/');
1240		//
1241		//	if(arrivo.length == 0)
1242		//		return null;
1243		//
1244		//	var arrivoDate = new Date(arrivSp[2],arrivSp[1] - 1,arrivSp[0]);
1245		//	return arrivoDate;
1246		var arrivoDate = jQuery('#' + this.idArrivo).datepicker("getDate");
1247		if(arrivoDate == null){
1248			var arrivoDateText = jQuery('#' + this.idArrivo).val();
1249			if(arrivoDateText!==null && arrivoDateText.length > 0){
1250				return jQuery.datepicker.parseDate('dd/mm/yy',arrivoDateText);
1251			}
1252		}
1253		return arrivoDate;
1254	};
1255
1256
1257	/**
1258	 *
1259	 * @param isDown true se sto diminuendo false se sto aumentando
1260	 * @param incr true se sono in incremento usando il touchspin
1261	 * @return true se ho trovato, false altrimenti
1262	 *
1263	 */
1264	this.updatePartenza = function (addTextDate) {
1265
1266		var addDay = 1;
1267		var initVal = 1;
1268
1269
1270		packetMaxStay = 365;
1271		var maxLength = 30;
1272
1273		var dataArrivo = this.getDataArrivo();
1274		var dataPartenza = this.getDataArrivo();
1275		dataPartenza.setDate(dataArrivo.getDate() + initVal * 1);
1276
1277		var found = this.canCheckOut(dataPartenza);
1278
1279		if (!found) {
1280			var i = 0;
1281			for (i = 0; i < maxLength; i = i + 1) {
1282				dataPartenza.setDate(dataPartenza.getDate() + addDay);
1283				initVal = initVal * 1 + addDay;
1284				if (this.canCheckOut(dataPartenza)) {
1285					found = true;
1286					break;
1287				}
1288			}
1289		} else {
1290			found = true;
1291		}
1292
1293		if (initVal > packetMaxStay) {
1294			found = false;
1295		}
1296
1297
1298		if (dataPartenza <= dataArrivo)
1299			found = false;
1300
1301		if (dataPartenza != null && found) {
1302
1303			jQuery('#' + this.idPartenza).datepicker('setDate', dataPartenza);
1304			if(addTextDate) {
1305				jQuery('#' + calManager.idPartenza).val(jQuery.datepicker.formatDate('dd/mm/yy', dataPartenza));
1306			}
1307		}
1308
1309
1310		return found;
1311	}
1312
1313
1314	//-----Fine jQuery.ready Inizio funzioni
1315	this.selezionaDataPartenza = function (dateText,addTextDate) {
1316
1317		if (typeof periodsDays !== 'undefined' && periodsDays !== null && periodsDays.length > 0) {
1318			this.updatePartenza(addTextDate);
1319		} else if (jQuery('#' + this.idPartenza).val() || jQuery('#' + this.idPartenza).val() === '') {
1320			var d = dateText.substr(0, 2) * 1;
1321			var m = dateText.substr(3, 2) * 1 - 1;
1322			var y = dateText.substr(6, 4) * 1;
1323			var dataArrivo = new Date(y, m, d, 0, 0, 0);
1324
1325			var check = /^([0-9]{2})([\/]{1})([0-9]{2})([\/]{1})([0-9]{4})$/;
1326			var result = check.test(jQuery('#' + this.idPartenza).val());
1327			if (result) {
1328				var textDPart = jQuery('#' + this.idPartenza).val();
1329				var mPar = textDPart.substr(3, 2) * 1 - 1;
1330				var dataPartenza = new Date(textDPart.substr(6, 4), mPar, textDPart.substr(0, 2), 0, 0, 0);
1331				if (dataPartenza.getTime() > dataArrivo.getTime())
1332					return false;
1333			}
1334
1335			dataArrivo.setDate(dataArrivo.getDate());
1336
1337			d = dataArrivo.getDate();
1338			m = dataArrivo.getMonth() + 1;
1339			y = dataArrivo.getYear();
1340
1341			if (y < 1900)
1342				y = 1900 + y;
1343			if (m < 10)
1344				m = '0' + m;
1345			if (d < 10)
1346				d = '0' + d;
1347
1348			var parText = d + '/' + m +
1349				'/' + y;
1350			jQuery('#' + this.idPartenza).val(parText);
1351		}
1352		return false;
1353	};
1354
1355
1356	this.selezionaDataArrivo = function (dateText) {
1357		if (jQuery('#' + this.idArrivo).val() || jQuery('#' + this.idArrivo).val() === '') {
1358			var d = dateText.substr(0, 2) * 1;
1359			var m = dateText.substr(3, 2) * 1 - 1;
1360			var y = dateText.substr(6, 4) * 1;
1361			var dataPartenza = new Date(y, m, d, 0, 0, 0);
1362
1363			var check = /^([0-9]{2})([\/]{1})([0-9]{2})([\/]{1})([0-9]{4})$/;
1364			var result = check.test(jQuery('#' + this.idArrivo).val());
1365			if (result) {
1366				var textDPart = jQuery('#' + this.idArrivo).val();
1367				var mPar = textDPart.substr(3, 2) * 1 - 1;
1368				var dataArrivo = new Date(textDPart.substr(6, 4), mPar, textDPart.substr(0, 2), 0, 0, 0);
1369				if (dataPartenza.getTime() > dataArrivo.getTime())
1370					return false;
1371			}
1372
1373			dataPartenza.setDate(dataPartenza.getDate());
1374
1375			d = dataPartenza.getDate();
1376			m = dataPartenza.getMonth() + 1;
1377			y = dataPartenza.getYear();
1378
1379			if (y < 1900)
1380				y = 1900 + y;
1381			if (m < 10)
1382				m = '0' + m;
1383			if (d < 10)
1384				d = '0' + d;
1385
1386
1387			var parText = d + '/' + m +
1388				'/' + y;
1389			jQuery('#' + this.idArrivo).val(parText);
1390		}
1391
1392
1393		return false;
1394	};
1395}
1396
1397function setAccomodationInLocalStorage() {
1398	var camere = jQuery('#stanze').val();
1399	var fullProducts = new Array();
1400
1401	var i = 0;
1402	for (i = 1; i <= camere; i = i + 1) {
1403		var numBambini = jQuery('#bambini' + i).val();
1404		var numAdulti = jQuery('#adulti' + i).val();
1405		var arrayBb = new Array();
1406
1407		var bb = 0;
1408		for (bb = 0; bb < numBambini; bb = bb + 1) {
1409			var idxBbHtml = bb + 1;
1410			arrayBb.push(jQuery('#etabambino' + i + idxBbHtml).val());
1411		}
1412
1413		fullProducts.push(new FullProduct(numAdulti, arrayBb, 0));
1414	}
1415
1416	var acc = null;
1417	if (jQuery('#arrivo').val().length > 0) {
1418		var arriveDate = jQuery('#arrivo').datepicker("getDate");
1419		var partenzaDate = jQuery('#partenza').datepicker("getDate");
1420		if(arriveDate && partenzaDate) {
1421			acc = new Accomodation(arriveDate.getTime(),partenzaDate.getTime() , fullProducts);
1422			sessionStorage.setItem(LOCAL_STORAGE_ACC_KEY, JSON.stringify(acc));
1423		}
1424	}
1425
1426	return acc;
1427}
1428
1429function fillBookingEngineFromLocalStorage() {
1430	try {
1431		var accJson = sessionStorage.getItem(LOCAL_STORAGE_ACC_KEY);
1432		if (accJson !== null) {
1433			var acc = JSON.parse(accJson);
1434			calManager.createDatePickerArrivo();
1435			calManager.createDatePickerPartenza();
1436			jQuery('#arrivo').val(jQuery.datepicker.formatDate('dd/mm/yy', new Date(acc.checkin)));
1437			jQuery('#partenza').val(jQuery.datepicker.formatDate('dd/mm/yy', new Date(acc.checkout)));
1438			jQuery('#stanze').val(acc.wsFullProduct.length);
1439			var i = 0;
1440			for (i = 0; i < acc.wsFullProduct.length; i = i + 1) {
1441				var idxHtml = i + 1;
1442				jQuery('#adulti' + idxHtml).val(acc.wsFullProduct[i].adults);
1443				jQuery('#bambini' + idxHtml).val(acc.wsFullProduct[i].ageOfChildren.length);
1444				jQuery('#stanza' + idxHtml).show();
1445				if (acc.wsFullProduct[i].ageOfChildren.length > 0) {
1446					jQuery('#containBambini' + idxHtml).show();
1447				}
1448				for (var j = 1; j <= acc.wsFullProduct[i].ageOfChildren.length; j = j + 1) {
1449					jQuery('#etabambino' + idxHtml + j).show().val(acc.wsFullProduct[i].ageOfChildren[j - 1]);
1450				}
1451			}
1452		}
1453	} catch (e) {
1454		console.log(e);
1455	}
1456}
1457
1458
1459
1460function searchResultIntoVendor(callBack) {
1461
1462	if (typeof callBack === 'undefined') {
1463		callBack = null;
1464	}
1465
1466	var accJson = sessionStorage.getItem(LOCAL_STORAGE_ACC_KEY);
1467	var acc = JSON.parse(accJson);
1468	acc.idVendor = mgc_idvendor;
1469	acc.idLanguage = mbGetIdLanguage();
1470	var searchRequest = new SearchRequest(acc, getWSUser());
1471
1472	jQuery.ajax({
1473		type: 'POST',
1474		url: '/rest/mybooking/searchintovendor',
1475		data: JSON.stringify(searchRequest),
1476		success: function (wsAccRes) {
1477			if (callBack !== null)
1478				callBack(acc, wsAccRes);
1479			else {
1480				var wsFullProductFound = Array();
1481				if (typeof wsAccRes.wsFullProduct !== 'undefined') {
1482					wsFullProductFound = wsAccRes.wsFullProduct[0].wsFullProductFound;
1483				}
1484
1485				renderProductWithResults(acc, wsFullProductFound, wsAccRes.wsErrorCause);
1486			}
1487		},
1488		error: function (a, b, wsAccRes) {
1489			if (callBack !== null)
1490				callBack(acc, wsAccRes);
1491			else {
1492				var wsFullProductFound = Array();
1493				renderProductWithResults(acc, wsFullProductFound, wsAccRes.wsErrorCause);
1494			}
1495		},
1496		contentType: "application/json",
1497		dataType: 'json'
1498	});
1499}
1500
1501
1502function mbGetIdLanguage() {
1503	if (typeof (language) !== 'undefined') {
1504		switch (language) {
1505			case 'it':
1506				return 1;
1507			case 'en':
1508				return 2;
1509			case 'fr':
1510				return 3;
1511			case 'de':
1512				return 4;
1513			case 'es':
1514				return 5;
1515			case 'nl':
1516				return 6;
1517		}
1518	}
1519	return 0;
1520}
1521
1522function mbSearchResult(callBackFnc, treatment) {
1523
1524	if (typeof treatment === 'undefined') {
1525		treatment = 0;
1526	}
1527	var accJson = sessionStorage.getItem(LOCAL_STORAGE_ACC_KEY);
1528	var acc = JSON.parse(accJson);
1529
1530	acc.idLanguage = mbGetIdLanguage();
1531	if (treatment > 0) {
1532		acc.wsFullProduct.forEach(function (element) {
1533			element.treatment = treatment;
1534		});
1535	}
1536
1537	var searchRequest = new SearchRequest(acc, getWSUser());
1538	jQuery.ajax({
1539		type: 'POST',
1540		url: '/rest/mybooking/search',
1541		data: JSON.stringify(searchRequest),
1542		success: function (wsAccRes) {
1543			callBackFnc(wsAccRes, acc);
1544		},
1545		contentType: "application/json",
1546		dataType: 'json'
1547	});
1548}
1549
1550
1551function mbShowDetailAccomodation(callBackFnc, acc) {
1552
1553	var searchRequest = new SearchRequest(acc, getWSUser());
1554	jQuery.ajax({
1555		type: 'POST',
1556		url: '/rest/mybooking/showDetailsAccomodation',
1557		data: JSON.stringify(searchRequest),
1558		success: function (wsAccRes) {
1559			callBackFnc(wsAccRes, acc);
1560		},
1561		contentType: "application/json",
1562		dataType: 'json'
1563	});
1564}
1565
1566function mbBook(callBackFnc, wsQuote, wsContact) {
1567
1568	var quoteRequest = new Object();
1569	quoteRequest.wsQuote = wsQuote;
1570	quoteRequest.wsContact = wsContact;
1571	quoteRequest.noSendEmailToCustomer = false;
1572	quoteRequest.test = false;
1573	quoteRequest.wsUser = getWSUser();
1574
1575
1576	jQuery.ajax({
1577		type: 'POST',
1578		url: '/rest/mybooking/book',
1579		data: JSON.stringify(quoteRequest),
1580		success: function (res) {
1581			callBackFnc(res, quoteRequest);
1582		},
1583		contentType: "application/json",
1584		dataType: 'json'
1585	});
1586}
1587
1588function mbViewQuote(callBackFnc, quote_id, code) {
1589	var quoteRequest = new Object();
1590	quoteRequest.quote_id = quote_id;
1591	quoteRequest.key_code = code;
1592	quoteRequest.wsUser = getWSUser();
1593
1594	jQuery.ajax({
1595		type: 'POST',
1596		url: '/rest/mybooking/viewQuote',
1597		data: JSON.stringify(quoteRequest),
1598		success: function (res) {
1599			callBackFnc(res, quoteRequest);
1600		},
1601		contentType: "application/json",
1602		dataType: 'json'
1603	});
1604}
1605
1606function mbPenalties(callBackFnc, vendor_id, idLang) {
1607	var vendorRequest = new Object();
1608	vendorRequest.idVendor = vendor_id;
1609	vendorRequest.idLanguage = idLang;
1610	vendorRequest.onlyPenalties = true;
1611	vendorRequest.wsUser = getWSUser();
1612
1613	jQuery.ajax({
1614		type: 'POST',
1615		url: '/rest/mybooking/getVendorDescription',
1616		data: JSON.stringify(vendorRequest),
1617		success: function (res) {
1618			callBackFnc(res, vendorRequest);
1619		},
1620		contentType: "application/json",
1621		dataType: 'json'
1622	});
1623}
1624
1625
1626function mbGetBeLink(checkin, checkout, initLnk, acc) {
1627	var beLnk = initLnk + '&arrivo=' + checkin + '&partenza=' + checkout + '&stanze=' + acc.wsFullProduct.length;
1628
1629	var j = 0;
1630	for (j = 0; j < acc.wsFullProduct.length; j = j + 1) {
1631		var idxlnk = j + 1;
1632		var wfp = acc.wsFullProduct[j];
1633		beLnk = beLnk + '&adulti' + idxlnk + '=' + wfp.adults;
1634		beLnk = beLnk + '&bambini' + idxlnk + '=' + wfp.ageOfChildren.length;
1635		if (wfp.ageOfChildren.length > 0) {
1636			for (var bb = 0, bb = 0; bb < wfp.ageOfChildren.length; bb++) {
1637				var idxbb = bb + 1;
1638				beLnk = beLnk + '&etabambino' + idxlnk + idxbb + '=' + wfp.ageOfChildren[bb];
1639			}
1640		}
1641
1642		if (wfp.treatment > 0) {
1643			beLnk = beLnk + '&treatment' + idxlnk + '=' + wfp.treatment;
1644		}
1645
1646		if (wfp.treatment > 0) {
1647			beLnk = beLnk + '&product_id' + idxlnk + '=' + wfp.product_id;
1648		}
1649	}
1650
1651	return beLnk;
1652}
1653
1654
1655function mbFindGetParameter(parameterName) {
1656	var result = null,
1657		tmp = [];
1658	location.search
1659		.substr(1)
1660		.split("&")
1661		.forEach(function (item) {
1662			tmp = item.split("=");
1663			if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
1664		});
1665	return result;
1666}
1667
1668function mbGetAccomodationFromLink() {
1669	var arrivo = mbFindGetParameter('arrivo');
1670	var partenza = mbFindGetParameter('partenza');
1671	var stanze = mbFindGetParameter('stanze');
1672
1673	var acc = new Accomodation();
1674	acc.checkin = jQuery.datepicker.parseDate('dd/mm/yy', arrivo);
1675	acc.checkout = jQuery.datepicker.parseDate('dd/mm/yy', partenza);
1676
1677	var idxStanza = 0;
1678
1679	var fullProducts = new Array();
1680	acc.wsFullProduct = fullProducts;
1681	for (idxStanza = 0; idxStanza < stanze; idxStanza = idxStanza + 1) {
1682		var stanza = idxStanza + 1;
1683
1684		var tratt = mbFindGetParameter('treatment' + stanza);
1685
1686		var product_id = mbFindGetParameter('product_id' + stanza);
1687
1688		var adulti = mbFindGetParameter('adulti' + stanza);
1689		var bambini = 1 * mbFindGetParameter('bambini' + stanza);
1690
1691		var idxBb = 0;
1692		var ageOfChildren = new Array();
1693		for (idxBb = 0; idxBb < bambini; idxBb = idxBb + 1) {
1694			var bb = idxBb + 1;
1695			var age = mbFindGetParameter('etabambino' + stanza + bb);
1696			ageOfChildren.push(age);
1697		}
1698
1699		var facilitiesChoix = mbFindGetParameter('accopt' + stanza);
1700		if (facilitiesChoix !== null) {
1701			facilitiesChoix = facilitiesChoix.split(',').map(function (id) {
1702				fpObj = new Object();
1703				fpObj.fpfId = id.split('-')[0];
1704				fpObj.quantity = id.split('-')[1];
1705				return fpObj;
1706			});
1707		}
1708
1709		var fpRes = new FullProduct(adulti, ageOfChildren, tratt, product_id);
1710		fpRes.wsFPFacilitiesOptionalToPayOnSite = facilitiesChoix;
1711		fullProducts.push(fpRes);
1712	}
1713
1714	return acc;
1715}
1716
1717function renderProductWithResults(acc, wsFullProductFound, wsErrorCause) {
1718
1719	var i = i;
1720	var persons = 0;
1721	for (i = 0; i < acc.wsFullProduct.length; i = i + 1) {
1722
1723		var wp = acc.wsFullProduct[i];
1724		persons += 1 * wp.adults + 1 * wp.ageOfChildren.length;
1725	}
1726
1727	var checkin = jQuery.datepicker.formatDate('dd/mm/yy', new Date(acc.checkin));
1728	var checkout = jQuery.datepicker.formatDate('dd/mm/yy', new Date(acc.checkout));
1729
1730	jQuery("[data-mb_prid]").fadeOut(300);
1731	jQuery("[data-mb_prid]").each(function () {
1732		var product_id = 1 * jQuery(this).attr('data-mb_prid');
1733		var i = 0;
1734
1735		var elButton = jQuery('[data-mb_pridbutton="' + product_id + '"]');
1736		var initLnk = elButton.attr('data-mb_be_href');
1737		var beLink = mbGetBeLink(checkin, checkout, initLnk, acc);
1738
1739		elButton.attr('href', beLink);
1740		jQuery('[data-mb_prnotfound="' + product_id + '"] a').attr('href', beLink);
1741
1742
1743		var resultFound = false;
1744		for (i = 0; i < wsFullProductFound.length; i = i + 1) {
1745			var wsFound = wsFullProductFound[i];
1746			if (wsFound.product_id === product_id || wsFound.product_parent_id === product_id) {
1747				jQuery(this).find('[data-mb_print="price"]').html(wsFound.totalPrice);
1748				jQuery(this).find('[data-mb_print="persons"]').html(persons);
1749				jQuery(this).find('[data-mb_print="checkin"]').html(checkin);
1750				jQuery(this).find('[data-mb_print="checkout"]').html(checkout);
1751				jQuery(this).find('.mbdefault').hide();
1752				jQuery(this).find('.mbwithquote').show();
1753				resultFound = true;
1754				break;
1755			}
1756		}
1757		if (!resultFound) {
1758			//Non ho una ricerca preventivo. Carico le condizioni di default
1759			jQuery('[data-mb_changerqbutton="' + product_id + '"]').show();
1760			jQuery('[data-mb_pridbutton="' + product_id + '"]').hide();
1761			jQuery('[data-mb_verbutton="' + product_id + '"]').hide();
1762			jQuery('[data-mb_prnotfound="' + product_id + '"]').show();
1763			jQuery('[data-mb_prnotfound="' + product_id + '"] [data-mb_type]').hide();
1764			if (wsErrorCause !== null && typeof wsErrorCause !== 'undefined' && wsErrorCause.length > 0) {
1765				var typeSpan = jQuery('[data-mb_prnotfound="' + product_id + '"] [data-mb_type="' + wsErrorCause[0].type);
1766				if (typeSpan !== null && typeSpan.length > 0) {
1767					typeSpan.show();
1768					jQuery('[data-mb_prnotfound="' + product_id + '"] [data-mb_default]').hide();
1769				}
1770			}
1771		} else {
1772			jQuery('[data-mb_changerqbutton="' + product_id + '"]').show();
1773			jQuery('[data-mb_pridbutton="' + product_id + '"]').show();
1774			jQuery('[data-mb_verbutton="' + product_id + '"]').hide();
1775			jQuery('[data-mb_prnotfound="' + product_id + '"]').hide();
1776		}
1777
1778		jQuery("[data-mb_prid]").fadeIn(300);
1779	});
1780}
1781
1782function SearchRequest(accomodation, wsUser) {
1783	this.wsUser = wsUser;
1784	this.wsAccomodation = accomodation;
1785}
1786
1787function Accomodation(checkin, checkout, wsFullProduct) {
1788	this.checkin = checkin;
1789	this.checkout = checkout;
1790	this.wsFullProduct = wsFullProduct;
1791	this.idLanguage = 0;
1792}
1793
1794function mbFormatNumber(number, locale) {
1795	return number.toLocaleString(locale, {
1796		minimumFractionDigits: 2,
1797		maximumFractionDigits: 2
1798	});
1799}
1800
1801function FullProduct(adults, ageOfChildren, treatment, product_id) {
1802	if (typeof product_id === 'undefined') {
1803		product_id = 0;
1804	}
1805	this.adults = adults;
1806	this.ageOfChildren = ageOfChildren;
1807	this.treatment = treatment;
1808	this.product_id = product_id;
1809	this.wsFPFacilitiesOptionalToPayOnSite = Array();
1810}
1811
1812function getWSUser() {
1813	return mbWsUser;
1814}

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.