PageSourceSearch

https://www.coopenis.it/wp-content/plugins/mybooking/js/mybooking.js?ver=9.3

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

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.