// JavaScript Document
	//Variabili js multilingua da mettere dentro all'xml
	msgElaborazione_js		= "Elaborazione in corso ...";
	msgVoli_js				= "Stiamo ricercano le migliori tariffe aeree in base ai dati inseriti...";
	confirmAnnPrev_js 		= "Sei proprio sicuro di voler annullare la pratica in preventivo?";
	confirmPraticaOK_js 	= "Sei proprio sicuro di voler annullare la pratica gia' confermata?";
	confirmPraticaRQ_js 	= "Sei proprio sicuro di voler annullare la pratica in richiesta?";
	confirmPraticaOP_js 	= "Sei proprio sicuro di voler annullare la pratica in opzione?";
	returnRegAccept_js 		= "Occorre accettare prima di continuare";
	alertErrNumeric_js 		= "inserire solo valori numerici";
	alertErrNomePax_js 		= "Inserire il nome e il cognome di tutti i passeggeri.";
	alertErrNomePaxDefault_js 	= "Verificare nome e/o cognome di tutti i passeggeri!";
	alertErrDatePax_js 		= "Inserire la data di nascita di tutti i passeggeri.";
	alertErrChIfPax_js		= "Per tutti i Child e gli Infant e' necessario inserire la data di nascita.";
	alertBanconista_js		= "Il banconista e' obbligatorio";
	alertBirthPaxDate_1_js	= "La data di nascita del ";
	alertBirthPaxDate_2_js	= " passeggero deve essere valida e nel formato gg/mm/aaaa";
	alertBirthPaxMonth_1_js	= "Il mese della data di nascita del ";
	alertBirthPaxMonth_2_js	= " passeggero deve essere un numero compreso tra 1 e 12";
	alertBirthPaxDay_1_js	= "Il giorno della data di nascita del ";
	alertBirthPaxDay_2_js	= " passeggero deve essere un numero compreso tra 1 e 31";
	alertCheckMonth31_1_js	= "Il mese ";
	alertCheckMonth31_2_js	= " della data di nascita del ";
	alertCheckMonth31_3_js	= " passeggero non ha 31 giorni!";	
	alertCheckFeb_1_js		= "Febbraio ";
	alertCheckFeb_2_js		= " non ha ";
	alertCheckFeb_3_js		= " giorni!";
	alertCheckCodFisc_js    = "Codice fiscale non inserito correttamente"
	alertCodFiscNull_js     = "Codice fiscale obbligatorio per primo pax"
	msgAttention			= "ATTENZIONE:";
	
	buttonClicked 		= '';
	step2NoWizardButton = '';
	noWizard 			= true;
	updatedPassengers   = false;
	bkgcode				= '';
	pkcompany			= '';
	//loadingMessage		= '<div style="width:100%; text-align:center; font-size:12px; font-weight:bold;"><br /><br/>' + msgElaborazione_js +'<br /><br/><img src="/booking/images/ajax-loader.gif" style="margin:40px;"></div>';
	//loadingMessageVoli	= '<div style="width:100%; text-align:center; font-size:12px; font-weight:bold;"><br /><br/>' + msgVoli_js +'<br /><br/><img src="/booking/images/ajax-loader.gif" style="margin:40px;"></div>';
	loadingMessage		= '<br /><br /><span class="dijitContentPaneLoading">' + msgElaborazione_js +'</span>';
	loadingMessageVoli	= '<br /><br /><img src="/booking/images/ajax-loader_green1.gif"><br/><br/>' + msgVoli_js;	
	loadingIcon			= '<br /><br /><img src="/booking/images/ajax-loader_green1.gif"><br/><br />';
	
	if(typeof(cfw) == 'undefined') {var cfw = {}};
	
	function viewWApane(idPane, address, theMessage){
		var TagPane = dijit.byId(idPane);
		var waDate = new Date;
		TagPane.cancel();
		if (typeof theMessage == 'undefined')
			theMessage = msgElaborazione_js;
		TagPane.loadingMessage= theMessage;
		TagPane.setContent('<center>' + theMessage + '</center>');
		
		if (address.indexOf('?')!=-1)
			TagPane.setHref(address+'&time='+waDate);
		else
			TagPane.setHref(address+'?time='+waDate);		
	}
	function goToDeleteBooking(bkgcode,pkcompany)
		{			
			if (confirm(confirmAnnPrev_js))
				{
					viewWApane('contentPratica','/booking/pratica_dettaglio.cfm?bkgcode='+bkgcode+'&pkcompany='+pkcompany+'&stato=DP')
				}
		}

	function goToDeleteConfirmBooking(bkgcode,pkcompany,statoPratica)
		{			
			if (statoPratica == 'OK')
				messageConfirm = confirmPraticaOK_js;
			if (statoPratica == 'RQ')
				messageConfirm = confirmPraticaRQ_js;
			if (statoPratica == 'OP')
				messageConfirm = confirmPraticaOP_js;		
				
			if (confirm(messageConfirm)) 
				{
					viewWApane('praticaContent','/booking/pratica_dettaglio.cfm?bkgcode='+bkgcode+'&pkcompany='+pkcompany+'&stato=DB','<center><br /><img src="/booking/images/ajax-loader_green1.gif"><br/><br/>Cancellazione pratica in corso...</center>')
				}
		}	

	function sistemazioni(codice, tipo)
		{
			var campoJs = document.getElementsByName(tipo + "_" + codice);
							
			var i = 0;
			var returnValue = '';			
			for (i=0;i<campoJs.length;i++)
				{
					if(campoJs[0].type == 'select-one')
						returnValue = returnValue + campoJs[i].options[campoJs[i].selectedIndex].value;
					else
						returnValue = returnValue + campoJs[i].value;	
					if (i!=campoJs.length-1)
						returnValue = returnValue + ','
				}
			return returnValue;
		}

	function step2FromHome()
		{
			submitAjaxForm('formStep', submitAjaxForm_RisultatoProdottiCarrello,'step2');
			var stkPrenotazione = dijit.byId("myStackContainer");
			paneStep2 = dijit.byId("step2");
			stkPrenotazione.selectChild(paneStep2);				
		}
	function initFromHome(address)
		{
			var stkPrenotazione = dijit.byId("myStackContainer");
			paneStep2 = dijit.byId("step2");
			stkPrenotazione.selectChild(paneStep2);
			viewWApane('step2',address);
		}

	function showWizardPane(wizard,pane)
		{
			var MainWizard = dijit.byId(wizard);
			var MainPane = dijit.byId(pane);
			MainWizard.onSelected(MainPane);
		}

	function checkpasseggeri(action) {
		var iCounter		= 0;
		var dayFieldValue	= "";
		var monthFieldValue	= "";
		var yearFieldValue	= "";
		var checkDateResult	= "";
		var prefixField 	= "";
		
		if (action == 'confPrn')
			prefixField 	= "conf_";
		
		var bCheckBD = true;
		var objChkBD = document.getElementById('checkBirthDate');
		if (objChkBD)
			bCheckBD = eval(objChkBD.value);
		
		var numberOfPax = dojo.byId(prefixField + 'PAXNUMBER').value;
		
		for (iCounter = 1; iCounter <= numberOfPax; iCounter++) {
			objTitle		= document.getElementById(prefixField + "passengers_" + iCounter + "__TITLE");
			FirstName		= document.getElementById(prefixField + "passengers_" + iCounter + "__FIRSTNAME").value;				
			LastName		= document.getElementById(prefixField + "passengers_" + iCounter + "__LASTNAME").value;			
			
			objDayField 	= document.getElementById(prefixField + "passengers_" + iCounter + "__BIRTHDATE_DD");
			if (objDayField.type == 'select-one')
				dayFieldValue = objDayField.options[objDayField.selectedIndex].value;
			else
				dayFieldValue = objDayField.value;
			
			objMonthField 	= document.getElementById(prefixField + "passengers_" + iCounter + "__BIRTHDATE_MM");
			if (objMonthField.type == 'select-one')
				monthFieldValue = objMonthField.options[objMonthField.selectedIndex].value;
			else
				monthFieldValue = objMonthField.value;
			
			objYearField 	= document.getElementById(prefixField + "passengers_" + iCounter + "__BIRTHDATE_YYYY");
			if (objYearField.type == 'select-one')
				yearFieldValue = objYearField.options[objYearField.selectedIndex].value;
			else
				yearFieldValue = objYearField.value;
			
			if (objTitle.type == 'select-one') {
				titleName		= objTitle.options[objTitle.selectedIndex].value;	
			} else {
				titleName		= objTitle.value;	
			}
			
			if (action == 'confPrn') {
				
				if ((FirstName == '' || LastName == '')) {
					return alertErrNomePax_js;
				}	
				if ((FirstName.toLowerCase().indexOf('nome') > -1 || LastName.toLowerCase().indexOf('passeggero') > -1)) {
					return alertErrNomePaxDefault_js;
				}
				if (bCheckBD && (dayFieldValue == '' || monthFieldValue == '' || yearFieldValue == '')) {
					return alertErrDatePax_js;
				}
			} else {
				if (((titleName == 'CHD') || (titleName == 'INF')) && ((dayFieldValue == '') && (monthFieldValue == '') && (yearFieldValue == ''))) {
					return alertErrChIfPax_js;
				}	
			}
			if ( bCheckBD && (dayFieldValue != '' || monthFieldValue != '' || yearFieldValue != '')) {
				checkDateResult	= checkDate(monthFieldValue + "/" + dayFieldValue + "/" + yearFieldValue, iCounter);
				if (checkDateResult != '') {
					return checkDateResult;
				}
			}
		}
		if (action != 'confPrn') {
			if (document.getElementById("banconista").value=='')
				return alertBanconista_js;
		}		
		
		return "ok";
	} 
	function completaRegistrazione() {
		var bCheckReg = checkRegFields();
		if (! bCheckReg)
			return false;
		
		var result = checkpasseggeri('confPrn');
		if (result == 'ok') 
			submitAjaxForm('frmUsrPrivato',submitAjaxForm_Contatto,'forSbmtAjax2','<center>' + loadingIcon + 'Salvataggio dati utente e passeggeri in corso...</center>');
		else
			alert(result);	
	}
	
	function savePassengersAdv() {
		var result = checkpasseggeri('confPrn');
		if (result == 'ok') 
			submitAjaxForm('frmPassengers',submitAjaxForm_Passengers,'forSbmtAjax5','<center>' + loadingIcon + 'Salvataggio passeggeri in corso...</center>');
		else
			alert(result);	
	}
	
	function checkRegFields(bCheckQuest) {
		var objForm = document.getElementById('frmUsrPrivato');
		
		var sFieldValue = opt.core.trim(objForm.USR_NOME.value);
		if (sFieldValue == '' ) {
			alert('Attenzione:\ninserire il nome per proseguire!');
			objForm.USR_NOME.focus();
			return false;
		} 
		var sFieldValue = opt.core.trim(objForm.USR_COGNOME.value);
		if (sFieldValue == '' ) {
			alert('Attenzione:\ninserire il cognome per proseguire!');
			objForm.USR_COGNOME.focus();
			return false;
		} 
		var sFieldValue = opt.core.trim(objForm.USR_SESSO.value);
		if (sFieldValue == '' ) {
			alert('Attenzione:\ninserire il sesso per proseguire!');
			objForm.USR_SESSO.focus();
			return false;
		}
		
		var dayFieldValue = opt.core.trim(objForm.USR_DD_NASCITA.value);
		var monthFieldValue = opt.core.trim(objForm.USR_MM_NASCITA.value);
		var yearFieldValue = opt.core.trim(objForm.USR_YYYY_NASCITA.value);
		if (dayFieldValue == '' || monthFieldValue == '' || yearFieldValue == '') {
			alert('Attenzione:\ninserire la data di nascita per proseguire!');
			objForm.USR_DD_NASCITA.focus();
			return false;
		} else {	
			var checkDateResult	= checkDate(monthFieldValue + "/" + dayFieldValue + "/" + yearFieldValue, 0);
			if (checkDateResult != '') {
				alert('Attenzione:\ninserire la data di nascita nel formato GG/MM/AAAA per proseguire!');
				objForm.USR_DD_NASCITA.focus();
				return false;
			}
		}
		
		sFieldValue = opt.core.trim(objForm.USR_EMAIL.value);
		if (sFieldValue == '' ) {
			alert('Attenzione:\ninserire email per proseguire!')
			objForm.USR_EMAIL.focus();
			return false;
		} else {
			if (! opt.validator.isEmail(sFieldValue)) {
				alert('Attenzione:\nindirizzo email non valido');
				objForm.USR_EMAIL.focus();
				objForm.USR_EMAIL.select();
				return false;
			}
		}	
		// verifica regexp del codice fiscale
		sFieldValue = opt.core.trim(objForm.USR_CODFISC.value);
		if (sFieldValue == '' ) {
			alert('Attenzione:\ninserire codice fiscale per proseguire!')
			objForm.USR_CODFISC.focus();
			return false;
		} else {
			var reCF = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
			if (! reCF.test(sFieldValue)) {
				alert('Attenzione:\ncodice fiscale non valido');
				objForm.USR_CODFISC.focus();
				objForm.USR_CODFISC.select();
				return false;
			}
		}
		sFieldValue = opt.core.trim(objForm.USR_INDIRIZZO.value);
		if (sFieldValue == '') {
			alert('Attenzione:\ninserire indirizzo per proseguire!')
			objForm.USR_INDIRIZZO.focus();
			return false;
		}
		
		sFieldValue = opt.core.trim(objForm.USR_COMUNE.value);
		if (sFieldValue == '') {
			alert('Attenzione:\ninserire comune per proseguire!')
			objForm.USR_COMUNE.focus();
			return false;
		}
		sFieldValue = opt.core.trim(objForm.USR_CAP.value);
		if (sFieldValue == '' ) {
			alert('Attenzione:\ninserire il C.A.P.!');
			objForm.USR_CAP.focus();
			return false;
		} else {
			if (isNaN(sFieldValue)) {
				alert('Attenzione:\ninserire solo caratteri numerici!');
				objForm.USR_CAP.focus();
				objForm.USR_CAP.select();
				return false;
			} 
		}
		sFieldValue = opt.core.trim(objForm.USR_PROVINCIA.value);
		if (sFieldValue == '') {
			alert('Attenzione:\ninserire provincia per proseguire!')
			objForm.USR_PROVINCIA.focus();
			return false;
		}
		sFieldValue = opt.core.trim(objForm.USR_CELLULARE.value);
		if (sFieldValue == '' ) {
			alert('Attenzione:\ninserire il numero di cellulare!');
			objForm.USR_CELLULARE.focus();
			return false;
		} else {
			if (isNaN(sFieldValue)) {
				alert('Attenzione:\ninserire solo caratteri numerici!');
				objForm.USR_CELLULARE.focus();
				objForm.USR_CELLULARE.select();
				return false;
			} 
		}
		sFieldValue = opt.core.trim(objForm.USR_TELEFONO.value);
		if (sFieldValue != '' ) {
			if (isNaN(sFieldValue)) {
				alert('Attenzione:\ninserire solo caratteri numerici!');
				objForm.USR_TELEFONO.focus();
				objForm.USR_TELEFONO.select();
				return false;
			} 
		}
		
		if (typeof(bCheckQuest) == 'undefined')
			bCheckQuest = true;
			
		if (bCheckQuest) {		
			sFieldValue = opt.form.getCheckboxValues('USR_PROFESSIONE');
			if (sFieldValue == '') {
				alert('Attenzione:\ninserire professione per proseguire!')
				objForm.USR_PROFESSIONE[0].focus();
				return false;
			}
			if (countDestSelected() == 0) {
				alert('Attenzione:\ninserire almeno una destinazione per proseguire!')
				objForm.USR_DESTINAZIONE_VIAGGIO[0].focus();
				return false;
			}
			
			sFieldValue = opt.form.getCheckboxValues('USR_PERIODO_VIAGGIO');
			if (sFieldValue == '') {
				alert('Attenzione:\ninserire periodo del viaggio per proseguire!')
				objForm.USR_PERIODO_VIAGGIO[0].focus();
				return false;
			}
		}
		return true;
	}
	
	function checkDate(dateStr, IdPax) {
		var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
		var matchArray = dateStr.match(datePat); // is the format ok?
		var lstErrori = "";
	
		if (matchArray == null) {
			lstErrori = lstErrori + "\r" + alertBirthPaxDate_1_js +IdPax +alertBirthPaxDate_2_js;
			return lstErrori;
		}
		
		month 	= matchArray[1]; // p@rse date into variables
		day 	= matchArray[3];
		year 	= matchArray[5];
		
		if (month < 1 || month > 12) { // check month range
			lstErrori = lstErrori + "\r" + alertBirthPaxMonth_1_js + IdPax + alertBirthPaxMonth_2_js;
			return lstErrori;
		}
		
		if (day < 1 || day > 31) {
			lstErrori = lstErrori + "\r" + alertBirthPaxDay_1_js + IdPax + alertBirthPaxDay_2_js;
			return lstErrori;
		}
		
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			lstErrori = lstErrori + "\r" + alertCheckMonth31_1_js + month + alertCheckMonth31_2_js + IdPax + alertCheckMonth31_3_js;
			return lstErrori;
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day==29 && !isleap)) {
				lstErrori = lstErrori + "\r" + alertCheckFeb_1_js + year + alertCheckFeb_2_js + day + alertCheckFeb_3_js;
				return lstErrori;
			}
		}
		return lstErrori; // date is valid
	}	
	function checkPaxValue(objPax){
		var sValue = objPax.value.toUpperCase();
		if (sValue.indexOf('PASSEGGERO') >= 0 || sValue.indexOf('NOME') >= 0)
			objPax.value = '';
	}	
	
	function cancPax(keyPax) {
		window.document.cancelForm.KEYPAXTODEL.value = keyPax;
		window.document.cancelForm.submit();
	}



	function openTitlePane(pane)
		{
			var myPane = dijit.byId(pane);
			myPane.toggle();
		}

	function openProdottiTo(pane)
		{
			var myContent = dijit.byId(pane);
			myContent.toggle();			
			/*myContent.setHref(address);

			if (myDivContent.style.display!='none')
				myDivContent.style.display='none';
			else
				myDivContent.style.display='block';*/
		}

	
	function checkUpdatedPassengers(bkgcode,pkcompany)
		{
			//var btn = document.getElementById("closeButtonpratica");
				if (updatedPassengers) 
					{
						updatedPassengers = false;
						viewWApane('pratica_' + bkgcode,'pratiche_syncbooking.cfm?BKGCODE=' + bkgcode + '&PKCOMPANY=' + pkcompany);
					}
			//praticadlg.setCloseControl(btn);
		}
	function showPraticaDetails(bkgcode)
		{
			var dlgPratica = dijit.byId("praticadlg");
			var waDate = new Date;
			dlgPratica.show();
			viewWApane('detailPraticaContent','/booking/pratica_B2C.cfm?BKGCODE='+bkgcode+'&PKCOMPANY='+pkcompany+'&justConfirmed=true&tick='+waDate);
		}
	function gestionePratica(sTab){
		stkPrenotazione = dijit.byId('myStackContainer');
		paneStep1 = dijit.byId('step1');
		// svuoto carrello
		checkPraticaTab();
		addCart('cart', 'carrello.cfm?clearCart');
		stkPrenotazione.selectChild(paneStep1);
		
		if (typeof(sTab) != 'undefined')
			sTab = '&selTab=' + sTab;
		else
			sTab = '';
			
		viewWApane('praticaContent','pratica.cfm?BKGCODE='+bkgcode+'&PKCOMPANY='+pkcompany + sTab);
	}	
	function checkPraticaTab(){
			divPraticaContent = dijit.byId("praticaContent");
			var myTabPane = dijit.byId("mainTab");
			if(!divPraticaContent){
				var cp = new dojox.layout.ContentPane({id:'praticaContent',title:'Pratica'});
				myTabPane.addChild(cp, 1);	
			}else
				cp = dijit.byId('praticaContent');
			myTabPane.selectChild(cp);
		}
//funzione per la scelta del report in layout/booking_report_default.cfm 
	function scegliReport(myRadioButton,myQryString)
		{
			var counter = 0;
			var myvar	= '';
			for (counter = 0; counter < myRadioButton.length; counter++)
				{ 
					if (myRadioButton[counter].checked)
						{ 
							myvar = myRadioButton[counter].value; 
						} 
				} 
			window.open('/booking/pratica_report_show.cfm?'+myQryString+'&ReportType='+myvar);
		}

	

	function submitAjaxFormResultImportaPratica(response)
		{
			var MainPane = dijit.byId("praticheimporta");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';
		}

	

	function submitAjaxFormResultModificaPasseggeri(response)
		{
			var MainPane = dijit.byId("contentPratica");
			MainPane.setContent(response);
			updatedPassengers = true;
			document.body.style.cursor = 'default';
		}
	

	submitAjaxFormmandanota = function(theForm)
		{
			dojo.io.bind({
			   handle: submitAjaxFormResultmandanota,
			   formNode: dijit.byId(theForm)
			});
			var MainPane = dijit.byId("notaContent");
			MainPane.setContent(loadingMessage);
			document.body.style.cursor = 'wait';
		}
	function submitAjaxFormResultmandanota(type, data, evt)
		{
			if (type == 'error')
				{
					alert("Si e' verificato un errore che e' stato segnalato al nostro Staff.\nSi prega di riprovare piu' tardi.");
				}
			else
				{
					var MainPane = dijit.byId("notaContent");
					MainPane.setContent(data);
					document.body.style.cursor = 'default';
				}
		}
	submitAjaxForminseriscinota = function(theForm)
		{
			dojo.io.bind({
			   handle: submitAjaxFormResultinseriscinota,
			   formNode: dijit.byId(theForm)
			});
			var MainPane = dijit.byId("notaContent");
			MainPane.setContent(loadingMessage);
			document.body.style.cursor = 'wait';
		}
		
	function vaiSchedaProdotto(address)
		{
			var dlgPratica = dijit.byId("schedadlg");
			dlgPratica.show();
			viewWApane('SchedaContent',address);

		}	
	function submitAjaxFormResultinseriscinota(type, data, evt)
		{
			if (type == 'error')
				{
					alert(data);
					alert("Si e' verificato un errore che e' stato segnalato al nostro Staff.\nSi prega di riprovare piu' tardi.");
				}
			else
				{
					var MainPane = dijit.byId("notaContent");
					MainPane.setContent(data);
					document.body.style.cursor = 'default';
				}
		}			

	function submitAjaxForm(theForm, handlerFunction, theTarget, theMessage) {
		if (typeof theMessage == 'undefined')
			theMessage = loadingMessage;
			
		dijit.byId(theTarget).setContent(theMessage);
			
		var kw = {		
				form: theForm,
		        load: handlerFunction,
		        error: function(data){
		        		console.error(data);
		                dijit.byId(theTarget).setContent('<br /><span class="dijitContentPaneError">Si &egrave; verificato un errore</span>');
		        }
		        
		};
		dojo.xhrPost(kw);
	}
	
	function submitAjaxForm_Passengers(response) {
		var divResult= dijit.byId("modPaxContent");				
		divResult.setContent(response);		
		document.body.style.cursor = 'default';
	}
		
	function submitAjaxForm_RicercaAdv(response) {
		var divResult= dijit.byId("divAgenzie");				
		divResult.setContent(response);		
		document.body.style.cursor = 'default';
	}	
	function submitAjaxForm_RisultatoProdottiCarrello(response)
		{
			var step2Pane= dijit.byId("step2");				
			step2Pane.setContent(response);		
			document.body.style.cursor = 'default';
			aggiornaVoli();
		}

	function submitAjaxForm_RisultatoPasseggeri(response)
		{			
		var step4Pane = dijit.byId("step4");
		step4Pane.setContent(response);
		document.body.style.cursor = 'default';
				
		}
	function submitAjaxForm_RisultatoBooking(response)
		{								
			var step5Pane = dijit.byId("step5");
			step5Pane.setContent(response);
			document.body.style.cursor = 'default';
		}

		
	function submitAjaxForm_RicercaPratiche(response)
		{
	
			var MainPane = dijit.byId("praticheelenco");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';
				
		}	
				
	function submitAjaxForm_credenziali(response)
		{
	
			var MainPane = dijit.byId("boxAgeContainer");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';			
		}		
			
	function submitAjaxForm_login(response)
		{
	
			var MainPane = dijit.byId("boxContainer");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';
				
		}		
	function submitAjaxForm_loginPratiche(response)
		{
	
			var MainPane = dijit.byId("pratiche");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';
				
		}
	function submitAjaxForm_InviaAmico(response)
		{	
			var MainPane = dijit.byId("sendFriendContent");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';				
		}
	function submitAjaxForm_InviaAmico2(response)
		{	
			var MainPane = dijit.byId("sendFriendContent2");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';				
		}		
	function submitAjaxForm_Contatto(response)
		{	
			var MainPane = dijit.byId("contatto");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';				
		}			

	function submitAjaxForm_Registrazione(response)
		{
			var MainPane = dijit.byId("step2reg");			
			MainPane.setContent(response);			
			document.body.style.cursor = 'default';
		}		
	function submitAjaxForm_ModificaProfilo(response)
		{
			var MainPane = dijit.byId("profilotab1");			
			MainPane.setContent(response);			
			document.body.style.cursor = 'default';
		}		
	function submitAjaxForm_ModificaProfiloAgente(response)
		{
			var MainPane = dijit.byId("agenti");			
			MainPane.setContent(response);			
			document.body.style.cursor = 'default';
		}		
	function submitAjaxForm_InserisiciNota(response)
		{	
			var MainPane = dijit.byId("notaContent");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';
				
		}		
	function submitAjaxForm_InviaNota(response)
		{	
			var MainPane = dijit.byId("notaContent");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';
				
		}
	function searchArrayValue(objArray, lstValore) {
		var bResult = false;

		for(var i=0; i < objArray.length; i++) {		
			arrayValori = lstValore.split(",");
			for(var n=0; n < arrayValori.length; n++) {		
				if(objArray[i].value == arrayValori[n]) {				
					bResult = true;
					break;
				}
			}	
		}
		
		return bResult;
	}
// FUNZIONI GOTO per la NAVIGAZIONE	

function gotoStep2Cart() {
	var MainPane = dijit.byId("step2");
	NumTipo = opt.form.getCheckboxValues('SRC_PT', 'opt:parm1');
	if(NumTipo == 1 || NumTipo == 2)
	if (checkSearchForm()) {
		{
			submitAjaxForm('SRC', submitAjaxForm_RisultatoProdottiCarrello,'step2', '<center>' + loadingIcon +'Ricerca dei prodotti in corso...</center>');
		}
	}	
	/*else 
	{
		alert('selezionare almeno una destinazione');
	}*/
}
	
function gotoStep3Cart() {			
	//goToQPA(); //Prendo tutti i parametri che mi servono per la qpa
	var MainPane = dijit.byId("step3");
	var myCartPane = dijit.byId('carttitle');
	var urlAddress = 'null';
	var returnValue = false;
	var waDate = new Date;
	var arrayTPCarrello = window.document.getElementsByName("TPCarrello");
	var aggregateTPCarrello = window.document.getElementById("aggregateTP").value;
	
	deselectAllTap();
	// Controllo se sia presente il primo valore di aggregateCarrello nel caso ce ne sia uno di quelli da controllare
	if (arrayTPCarrello.length > 0) {
		if(aggregateTPCarrello != '') {
			arrayAggregateTPCarrello = aggregateTPCarrello.split(";");
			// Controllo se c'e' nel carrello il primo valore di controllo (Hotel di solito)
			/*if((searchArrayValue(arrayTPCarrello, arrayAggregateTPCarrello[0])==false) && (searchArrayValue(arrayTPCarrello, arrayAggregateTPCarrello[1])==true)) {
				return "Non e' possibile prenotare un TRASPORTO senza aver selezionato un HOTEL";										
			}*/
		}
		if (myCartPane && myCartPane.open)  
			myCartPane.toggle();
		MainPane.setHref('step3_scelta_servizi.cfm'+'?time='+waDate);
	} else {
		return "Non e' stato inserito nessun prodotto nel carrello.";
	}	
}	

function gotoStep4() {
	var MainPane = dijit.byId("step4");	
	submitAjaxForm('QPA', submitAjaxForm_RisultatoPasseggeri,'step4',loadingIcon);
}
	
function gotoStep5() {
	var objSrcBanconista = document.getElementById('src_banconista');
	if (objSrcBanconista)
		document.getElementById('banconista').value = objSrcBanconista.value; 	
	var result = checkpasseggeri();
	if (result=='ok') {
		var MainPane = dijit.byId("step5");		
		submitAjaxForm('PASSENGERS', submitAjaxForm_RisultatoBooking,'step5','<center>' + loadingIcon + '<br/>Generazione preventivo in corso...</center>');
	}
	else {
		alert(result);
	}
}
	
function doSearchPratiche(){
	submitAjaxForm('SEARCHPRATICHE', submitAjaxForm_RicercaPratiche,'praticheelenco','<center><br /><br /><img src=/booking/images/ajax-loader_green1.gif><br/><br /></center>');
}
		
//// FUNZIONI PER LA GESTIONE DELLE CAMERE MULTIPLE		
	function createRooms(howMany, propertyCode)
		{					
			var mySource 		= document.getElementById('SourceDiv');
			var myDestination 	= document.getElementById('DestinationDIV_' + propertyCode);							
			for(var i=1;i<=howMany;i++) {							
				mySourceCopy = mySource.cloneNode(true);			
				numberElements = (myDestination.childNodes.length);					
				mySourceCopy.removeAttribute("id");						
				//Replico la variabile dinamica con il numero dell'elemento		
				mySourceCopy.innerHTML = mySourceCopy.innerHTML.replace(/@num@/gi, (numberElements+1));
				mySourceCopy.innerHTML = mySourceCopy.innerHTML.replace(/@propCode@/gi, propertyCode);	
				// Rimetto lo stile a visible (togliendolo)
			    mySourceCopy.removeAttribute("style");
			    // Inserisco il nuovo nodo
				myDestination.appendChild(mySourceCopy);			
			}							
		}
	function deleteRooms(howMany, propertyCode)
		{
			var myDestination 	= document.getElementById('DestinationDIV_' + propertyCode);
			for(var n=1;n<=howMany;n++) {
				myDestination.removeChild(myDestination.lastChild);
			}							
		}
	function manageRooms(propertyCode) {		
			var myDestination 	= document.getElementById('DestinationDIV_' + propertyCode);
			var mySelHowMany	= document.getElementById('HowMany_' + propertyCode);
			numberElements = (myDestination.childNodes.length);
			if(mySelHowMany.type== 'radio') 		
				roomSelected = opt.form.getCheckboxValues(mySelHowMany.name); 				
			else 			
				roomSelected = mySelHowMany.options[mySelHowMany.selectedIndex].value;			
			deltaRooms = roomSelected-numberElements;
			// Se seleziono 1 camera li cancello tutti			
			if(roomSelected == 1)
				deltaRooms = -numberElements;
				
			if(deltaRooms > 0) {
				createRooms(deltaRooms, propertyCode); 		
			}
			if(deltaRooms < 0) {
				deleteRooms(Math.abs(deltaRooms), propertyCode);
			}
	}	
	function checkRooms(propertyCode, adults, childs, infants){
			errorMessage = msgAttention;
			bShowMessage = false;
			btoReturn = true;
			var mySelHowMany	= document.getElementById('HowMany_' + propertyCode);
			if (mySelHowMany && mySelHowMany.type=="select-one" && mySelHowMany.selectedIndex != 0){
				numTotalRooms = mySelHowMany.options[mySelHowMany.selectedIndex].value;
				adTotal = sistemazioni(propertyCode, 'ad');
				chTotal = sistemazioni(propertyCode, 'ch');
				inTotal = sistemazioni(propertyCode, 'in');
				
				arrayAd = adTotal.split(',');
				arrayCh = chTotal.split(',');
				arrayIn = inTotal.split(',');
				
				sumAd = 0;
				sumCh = 0;
				sumIn = 0;
				
				for (i=0;i<arrayAd.length;i++) {
					sumAd = parseInt(sumAd) + parseInt(arrayAd[i]);					
				}
				for (i=0;i<arrayCh.length;i++) {
					sumCh = parseInt(sumCh) + parseInt(arrayCh[i]);						
				}
				for (i=0;i<arrayIn.length;i++) {
					sumIn = parseInt(sumIn) + parseInt(arrayIn[i]);					
				}
				
				for (i=1;i<=numTotalRooms;i++) {
					valueField = document.getElementById("values_" + propertyCode + "_" + i);					
					if(valueField.value == 0) {
						errorMessage = errorMessage + "\nLa camera " + i + " non ha selezionato nessun componente, selezionarne o diminuire il numero di camere.";
						bShowMessage = true;						
					}					
				}
							
				if(sumAd != adults) {			
					errorMessage = errorMessage + "\nIl numero degli Adults totali non e' corretto, selezionarne: " + adults;
					bShowMessage = true;
				}	
				if(sumCh != childs) {
					errorMessage = errorMessage + "\nIl numero dei Child totali non e' corretto, selezionarne: " + childs;
					bShowMessage = true;
				}	
				if(sumIn != infants){
					errorMessage = errorMessage + "\nIl numero degli Infants totali non e' corretto, selezionarne: " + infants;
					bShowMessage = true;
				}			
					
				if(bShowMessage) {
					alert(errorMessage);	
					btoReturn = false;
				}			
			}	
			return btoReturn;			
	}
	function setValueRooms(codId) {
		adObj = document.getElementById("ad_" + codId);
		chObj = document.getElementById("ch_" + codId);
		inObj = document.getElementById("in_" + codId);
		
		var totalValue = adObj.options[adObj.selectedIndex].value;
		
		if(chObj.type == 'select-one')
			totalValue = parseInt(totalValue) + parseInt(chObj.options[chObj.selectedIndex].value);
		else
			totalValue = parseInt(totalValue) + parseInt(chObj.value);	
		if(inObj.type == 'select-one')
			totalValue = parseInt(totalValue) + parseInt(inObj.options[inObj.selectedIndex].value);
		else
			totalValue = parseInt(totalValue) + parseInt(inObj.value);
		
		var valueField = document.getElementById("values_" + codId);
		valueField.value = totalValue;		
	}
	
	function addCart(pane, address) {
			var NumTp = document.getElementById('NumTp');
			var UIDTappa = document.getElementById('UIDTappa');
			var myContent = dijit.byId(pane + 'Content');
			var myDivContent = dijit.byId(pane);
			var waDate = new Date;
			
			//if(UIDTappa && NumTp >2){
			if(UIDTappa.value >0 ){
				arrayAddress = address.split('?');
				address = 'tappe.cfm?UIDTappaRel='+UIDTappa.value +"&"+arrayAddress[1]; 
				
			}
			
		
			myContent.setHref(address+'&time='+waDate);	
					
	}

	function showCartLabels() {
			var myPane = dijit.byId('carttitle');
			var testoCarrello = document.getElementById('pulsanteCarrello');
			if (myPane.open)
				testoCarrello.value = 'nascondi carrello';		
			else
				testoCarrello.value = 'visualizza carrello';		
	}

	function showCart() {
			var myPane = dijit.byId('carttitle');
			myPane.toggle();			
	}

	function CloseTitle() {
		var myPane = dijit.byId('carttitle');
		 myPane.toggle()
	}
	

	function changeSelectionLabel(source, destination, objRadio)
		{
			mySource = document.getElementById(source);
			myDestination = document.getElementById(destination);
			mySource.innerHTML  = myDestination.innerHTML ;
			var classSerIDvalue = objRadio.getAttribute("opt:classserID");
			if(classSerIDvalue != null) {			
				setRadioQpaOptions(classSerIDvalue);
				var radioCodSelected = objRadio.getAttribute("opt:codDept");			
				if(radioCodSelected != ''){
					arraySelectedCod = getElementsByAttribute('opt:codSelected', radioCodSelected, 'option');
					if(arraySelectedCod.length >0)
						arraySelectedCod[0].selected=true;
				}		
			}	
		}
	function setQpaOptions(objOptions) {
		valoretoSelect = objOptions.options[objOptions.selectedIndex].getAttribute("opt:codselected");		
		arraySelectedDepts = getElementsByAttribute('opt:codDept', valoretoSelect, 'input');
		var indexSelected = 0;
		for(sel=0;sel<arraySelectedDepts.length; sel++) {
			if(arraySelectedDepts[sel].getAttribute("opt:avail") >0) {					
				indexSelected=sel;	
				break;
			}	
		}
		arraySelectedDepts[indexSelected].click();		
		var classSerIDvalue = arraySelectedDepts[indexSelected].getAttribute("opt:classserID");
		setRadioQpaOptions(classSerIDvalue);	
		
	}
	function setRadioQpaOptions(classSerIDvalue) {
		arraySelectedClass = getElementsByAttribute('opt:classserID', classSerIDvalue, 'input');
		for(sel1=0;sel1<arraySelectedClass.length; sel1++) {
			if(!arraySelectedClass[sel1].checked){
				arraySelectedClass[sel1].click();
				break;
			}	
		}
		
	}

	

function checkSearchForm() {
	var bResult = false;
	objDestSelected = document.getElementById('SRC_PRP_1');
	objDestSelected = document.getElementById('SRC_PRP_1');
	if(objDestSelected.value != '')
		bResult = true;

	return bResult;
}
	
function showBookFromItinerary(pratica, pkCompany) {
	gestionePratica(pratica, pkCompany);
	submitAjaxForm('SEARCHPRATICHE', submitAjaxForm_RicercaPratiche, 'praticheelenco');
}	

function organizeStep(pageNumber) {	
	prevStep = document.getElementById('currentStepId').value;	
	if(pageNumber == 'step2')
		if(pageNumber>prevStep) gotoStep2Cart();
	if(pageNumber == 'step3')
		if(pageNumber>prevStep) gotoStep3Cart();	
	if(pageNumber == 'step4') {
		dijit.byId("next").setLabel('Continua');
		if(pageNumber>prevStep) gotoStep4();	
	}	
	if(pageNumber == 'step5')
		if(pageNumber>prevStep) gotoStep5();		
	if(pageNumber == 'step6')
		if(pageNumber>prevStep) gestionePratica();		
	
	// Se vado in avanti disabilito continua, se torno indietro lo abilito	
	if(pageNumber>prevStep)	{	
		dijit.byId("next").setDisabled(true);	
		istruzione = 'Continua';
	}else{
		dijit.byId("next").setDisabled(false);
		istruzione = 'Indietro';
	}		
	if(prevStep == '')
		prevStep = 'step1';
	
	
	enableLblSteps(pageNumber);	
	setHelp('');	
}

function enableLblSteps(StepNumber){
	for (var ii=1;ii<=20; ii++) {
		var objLabel = document.getElementById('lbl_step' + ii);
		if (objLabel) {
			if ('step'+ii == StepNumber){
				objLabel.className = 'BreadsSelected';	
				highlight(objLabel,'red',3);
				objLabel.style.color = "#003366";
			} else {
				objLabel.className = 'Breads';
			}	
		} else
			break;
	}
}
function showBreadcrumbsType(sType){
	var objBrdcPrev = document.getElementById('brdc_Prev');
	var objBrdcB2b = document.getElementById('brdc_Pren_B2B');
	var objBrdcB2c = document.getElementById('brdc_Pren_B2C');
	
	if (typeof(sType) == 'undefined')
		sType = '';
		
	switch(sType){
		case '':			
			objBrdcPrev.style.display = 'none';
			objBrdcB2b.style.display = 'none';
			objBrdcB2c.style.display = 'none';	
			break;
		case 'Prev':
			objBrdcPrev.style.display = '';
			objBrdcB2b.style.display = 'none';
			objBrdcB2c.style.display = 'none';
			break;
		case 'B2B':
			objBrdcPrev.style.display = 'none';
			objBrdcB2b.style.display = '';
			objBrdcB2c.style.display = 'none';
			break;
		case 'B2C':
			objBrdcPrev.style.display = 'none';
			objBrdcB2b.style.display = 'none';
			objBrdcB2c.style.display = '';	
			break;	
	}
	var arDivB2c = getElementsByAttribute('opt:b2c', 'true', 'div');
	for (var ii=0;ii < arDivB2c.length; ii++) 
		arDivB2c[ii].style.display = 'none';
	
} 

function getOrderDate(idPropCode) {
	objEndDate = dijit.byId(idPropCode+"_dataIn");
	//valore = objEndDate.getValue().getFullYear().toString() + (objEndDate.getValue().getMonth()+1).toString() + objEndDate.getValue().getDate().toString();
	valore = dateFormat(objEndDate.getValue(), 'yyyyMMdd');
	return 	valore;	
}
function getDuration(idPropCode) {
		objStartDate = dijit.byId(idPropCode+"_dataIn");
		objEndDate = dijit.byId(idPropCode+"_dataOut");
		
		var gg = dojo.date.difference(objStartDate.getValue(), objEndDate.getValue(), 'day');

		return gg;
	}
function getStartDate(idPropCode) {
		objStartDate = dijit.byId(idPropCode+"_dataIn");
	
		strStartDate = dateFormat(objStartDate.getValue(), 'dd/MM/yyyy');
		return 	strStartDate;	
	}	
function getEndDate(idPropCode) {
		objEndDate = dijit.byId(idPropCode+"_dataOut");
		strEndDate = dateFormat(objEndDate.getValue(), 'dd/MM/yyyy');

		return 	strEndDate;	
}	

function setProdGG(idPropCode, tipo, fixedGG) {
	if(fixedGG != undefined) {
		objStartDate 	= dijit.byId(idPropCode+"_dataIn");
		objEndDate 		=  dijit.byId(idPropCode+"_dataOut");		
		objEndDate.setValue(dojo.date.add(objStartDate.getValue(), 'day', parseInt(fixedGG-1)));	
		objGG = document.getElementById(idPropCode+"_gg");
		if(fixedGG == 1)
				objGG.innerHTML = fixedGG + " giorno";							
			else
				objGG.innerHTML = fixedGG + " giorni";	
		var gg = parseInt(fixedGG-1);	
	} else {				
		objGG = document.getElementById(idPropCode+"_gg");
		objbtnAdd = document.getElementById(idPropCode+"_btnAdd");
		objbtnAdd.disabled = false;
		var gg = getDuration(idPropCode);
		if( gg<1){
			alert('La data di Out deve essere maggiore della data di In');
			objGG.innerHTML ="";
			objbtnAdd.disabled = true;
		} else {					
			if(gg == 1){
				if(tipo == 'HOTEL') 
					suffix = " notte";
				else 
				 	suffix = " gg";
			}					
			else {
				if(tipo == 'HOTEL') 
					suffix = " notti";
				else 
				 	suffix = " gg";						
			}
			if(tipo != 'HOTEL')
				objGG.innerHTML = parseInt(gg+1) + suffix;
			else					
				objGG.innerHTML = gg + suffix;
		}	
	}		
	colorDays(idPropCode, gg);		
	objGG.style.background= '';
	document.getElementById(idPropCode+'_gg').focus();
}	
function colorDays(idPropCode, numGG) {
	objStartDate = dijit.byId(idPropCode+"_dataIn");
	arrayDate = getElementsByAttribute('idData',idPropCode,'div');
	for (var j=0; j < arrayDate.length; j++){			
		arrayDate[j].style.background = '#F3F3F6';
	}			
	
	for (var i=0; i <= numGG; i++){			
		//divDataId = idPropCode+"_"+dojo.date.strftime(dojo.date.add(objStartDate.getDate(), dojo.date.dateParts.DAY, i) ,"%Y%m%d");					
		divDataId = idPropCode+"_"+ dateFormat(dojo.date.add(objStartDate.getValue(), 'day',i) ,"yyyyMMdd");					
		objDivData = document.getElementById(divDataId);
		if(objDivData)
			objDivData.style.background = 'silver';			
	}	
}
function step2FromTappe(address) {
	var stkPrenotazione = dijit.byId("myStackContainer");	
	viewWApane('step2',address);		
	paneStep2 = dijit.byId("step2");
	stkPrenotazione.selectChild(paneStep2);		
	
}
function doNext(el)
{
	var nextEl = el.form.elements[el.tabIndex+1];
	if (nextEl && nextEl.focus) nextEl.focus();
}

function submitAjaxForm_loginprivati(response)
{	
	var MainPane = dijit.byId("boxContainer");
	MainPane.setContent(response);
	var dlgReg = dijit.byId("Regdlg");
	dlgReg.hide();
	document.body.style.cursor = 'default';
		
}		
function enableCheckButton(objCheck,idButton)
{
	if(objCheck.checked)
		dijit.byId(idButton).setDisabled(false);
	else
		dijit.byId(idButton).setDisabled(true);
}		
function displayDiv(objCheck, idDiv){
	if (objCheck.checked) {
		document.getElementById(idDiv).style.display = '';
		if (dijit.byId('ttpDettaglioPratica').open)
			dijit.byId('ttpDettaglioPratica').toggle();	
	} else {
		document.getElementById(idDiv).style.display = 'none';
		if (! dijit.byId('ttpDettaglioPratica').open)
			dijit.byId('ttpDettaglioPratica').toggle();
	}
		
}
function enableSelectButton(objSelect,idButton)
{
	if(objSelect.selectedIndex != 0)
		dijit.byId(idButton).setDisabled(false);
	else
		dijit.byId(idButton).setDisabled(true);
}			
function addTabPratiche(idTab, titleTab, addressTab){			
	var tc = dijit.byId("praticatabs");
	var objTab = dijit.byId(idTab);
	if (objTab != null) {
		dijit.byId("praticatabs").closeChild(dijit.byId(idTab));
	}	
	var cp = new dojox.layout.ContentPane({id:idTab,title:titleTab,href:addressTab});
	var chdIndex= tc.getChildren().length;		
	tc.addChild(cp, chdIndex);	
	tc.selectChild(idTab);
}
function addTabCredito(urlParams){		
	/*dijit.byId("praticadlg").hide();	
	var tc = dijit.byId("mainTab");
	var objTab = dijit.byId("cc_credito");
	if (objTab != null) {
		tc.closeChild(dijit.byId('cc_credito'));
	}	
	var cp = new dojox.layout.ContentPane({id:"cc_credito",title: "Carta di credito",href:"credit_card.cfm?"+urlParams});
	var chdIndex= tc.getChildren().length;		
	tc.addChild(cp, chdIndex);	
	tc.selectChild('cc_credito');
	*/
	//dijit.byId("praticadlg").hide();
	var c=opt.core.openWin('credit_card.cfm?'+urlParams, 'Carta_Credito', 860, 700, 'alwaysRaised=yes,scrollbars=yes,status=yes,centerscreen');		
	//c.focus();
}
function vaiHelp(address)
{
	var dlgHelp = dijit.byId("helpdlg");
	dlgHelp.show();
	//viewWApane('HelpContent',address);

}	
function vaiReg(address)
{
	var dlgReg = dijit.byId("Regdlg");
	dlgReg.show();
	viewWApane('RegContent',address);

}		
function setHelp(stringa) {
		objHelp = dijit.byId('HelpContent');
		if(objHelp != undefined)
			objHelp.setContent(stringa);
}			
function continueAfterRegAdv() {
	dijit.byId("next").setDisabled(false);		
	viewWApane('divRegAdv','/booking/ajax/continua_adv.cfm');
}
function refreshHeaderBooking() {	
	viewWApane('usrIdentify','/booking/ajax/intestazione_top.cfm');	
}


function checkHome(strResult) {
	if(strResult == ''){
		document.getElementById('divbtnAddSingle').style.display = '';
	} else {
		document.getElementById('divbtnAddSingle').style.display = 'none';	
		alert(strResult);		
	}
}

function checkChiusure(dateStartId, dateEndId, pkpropvalFiled, functionToCall) {
		if(dateStartId == undefined)
			dateStartId = 'SRC_PERIOD_BEGIN';
		if(dateEndId == undefined)
			dateEndId = 'SRC_PERIOD_END';
		if(pkpropvalFiled == undefined)
			pkpropvalFiled = 'PRP_1_pkpropval';	
		if(functionToCall == undefined)
			functionToCall = 'checkHome';			
			
		var startDate = dijit.byId(dateStartId).getValue();
		var endDate = dijit.byId(dateEndId).getValue();
		var bResult = true;
		var strResult = "";
		var pkToCheck = document.getElementById(pkpropvalFiled).value;
		var numTipo = document.getElementById('NumTP').value 
		
		if(numTipo == 4){ //Controllo se e' selezionato il solo Land (n° 4)
			for (i=0;i<arrayChiusure.length;i++){
				strChiusura = arrayChiusure[i];
				if(strChiusura.pkpropval == pkToCheck) {
					for (n=0;n<strChiusura.arrayData.length;n++){
						currentPeriodo = strChiusura.arrayData[n];
						arrayPeriodo = currentPeriodo.split('@');
						arrayDataStart = arrayPeriodo[0].split('/');
						arrayDataEnd = arrayPeriodo[1].split('/');
						
						periodStart = new Date(arrayDataStart[2],arrayDataStart[1]-1,arrayDataStart[0]);
						periodEnd = new Date(arrayDataEnd[2],arrayDataEnd[1]-1,arrayDataEnd[0]);
						//Compare: 0 se Uguale, 1 se a > b; -1 se b<a 
						bCheckLeather = ((startDate < periodStart) && (endDate < periodStart));
						
						
						bCheckGreater = (startDate > periodEnd && endDate > periodEnd);
					
						if (! (bCheckLeather || bCheckGreater)){
							//Se il periodo richiesto sormonta una chiusura esco e visaulizzo la nota
							bResult 	= false;
							strResult 	= strChiusura.nota;
							break;
						}
					}	
				}	
			}
			// Se true abilito il pulsante, altrimenti lo nascondo	
			eval(functionToCall)(strResult);	
		}
}
function showPratiche() {
	var tc = dijit.byId("mainTab");
	tc.selectChild('pratiche');	
}

function countPax(suffix){
	var numAdu = 0;
	var numChd = 0;	
	var sRoomVal = "";
	var arrayOptionPax = getElementsByAttribute('id','RoomType'+suffix, 'select');	
	if (arrayOptionPax.length > 0) {
		for (var i=0;i < arrayOptionPax.length;i++) {
			currentValore = arrayOptionPax[i].options[arrayOptionPax[i].selectedIndex].text;
			numAdu += (arrayOptionPax[i].options[arrayOptionPax[i].selectedIndex].getAttribute('opt_numAdults'))*currentValore;
			numChd += (arrayOptionPax[i].options[arrayOptionPax[i].selectedIndex].getAttribute('opt_numChilds'))*currentValore;
			sRoomVal += arrayOptionPax[i].options[arrayOptionPax[i].selectedIndex].value + ',';
		}
	}else{
		var arrayOptionPax = getElementsByAttribute('name','paxCamereRO','input');
		for (var i=0;i < arrayOptionPax.length;i++) {
			currentValore = arrayOptionPax[i].value;
			numAdu += (arrayOptionPax[i].getAttribute('opt_numAdults'))*currentValore;
			numChd += (arrayOptionPax[i].getAttribute('opt_numChilds'))*currentValore;
			sRoomVal += arrayOptionPax[i].getAttribute('opt_tipocamera') + arrayOptionPax[i].value + ',';
		}		
	}
	
	var objRoomType = document.getElementById('RoomType');	
	objRoomType.value = sRoomVal.substr(0,sRoomVal.length-1);
	document.getElementById('tot_AD' + suffix).innerHTML = numAdu;
	document.getElementById('tot_CH' + suffix).innerHTML = numChd;
	if (suffix == '_iti') {
		document.getElementById('ADULTS' + suffix).value = numAdu;
		document.getElementById('CHILDS' + suffix).value = numChd;	
	}else{
		document.getElementById('ADULTS').value = numAdu;
		document.getElementById('CHILDS').value = numChd;	
	}	
}

function setPaxFromRoomType(suffix){
	var objRoomType = document.getElementById('RoomType')
	if (objRoomType) {
		var arRoomTypeHidden = objRoomType.value.split(','); 
		var arrayRoomType = getElementsByAttribute('id','RoomType'+suffix, 'select');	
		if (arRoomTypeHidden.length > 0 && arrayRoomType.length > 0) {
			for (var kk=0; kk < arrayRoomType.length; kk++) {
				var objSelect = arrayRoomType[kk];
				for (var jj=0; jj < objSelect.length; jj++) {
					for (var ii=0; ii <= arRoomTypeHidden.length; ii++) {
						if (objSelect.options[jj].value == arRoomTypeHidden[ii]) {
							objSelect.options[jj].selected = true;
							break;
						}
					}		
				}
			}		
		}
	}	
}
function moveToStep(stepNumber){
	var stkPrenotazione = dijit.byId("myStackContainer");
	paneStep = dijit.byId("step" + stepNumber);
	stkPrenotazione.selectChild(paneStep);
}

function changePackageDate(dataIn, dataOut,targetPath, pkProdto) {
	/*targetPath = targetPath.replace('@datapar@', dataIn);
	targetPath = targetPath.replace('@datafine@', dataOut);*/
	targetPath = targetPath +"&dataIn="+dataIn+"&dataOut="+dataOut;
	viewWApane('divCambioDate','/booking/cambioDatePackage.cfm?'+targetPath+'&filteredPkProdTo='+pkProdto);
	dijit.byId('dlgCambioData').show();
}	

function openChangeProdDate(dataIn, dataOut, idTab, tipo) {
	viewWApane('divCambioDate','/booking/cambioDate.cfm?dataIn='+dataIn + '&dataOut='+dataOut+'&idTab='+idTab+ '&Tipo='+tipo);
	dijit.byId('dlgCambioData').show();
}
function modifyProdDate(idtab, tipo, dataStart){
	if(tipo == 'PACKAGE'  ){
		if(typeof(dataStart) == 'undefined'){
			strStartDate = dateFormat(dijit.byId('startDate_Change').getValue(), 'yyyy-MM-dd');
			strEndDate = dateFormat(dijit.byId('endDate_Change').getValue(), 'yyyy-MM-dd');
		} else {
			strStartDate = dataStart;
			strEndDate = strStartDate;
		}
		targetPath	= document.getElementById('pathProds').value;
		targetPath = targetPath.replace("@dataBegin@",strStartDate);
		targetPath = targetPath.replace("@dataEnd@",strEndDate);
		step2FromTappe(targetPath);
	} else {
		if(typeof(dataStart) == 'undefined'){
			strStartDate = dateFormat(dijit.byId('startDate_Change').getValue(), 'MM/dd/yyyy');
			strEndDate = dateFormat(dijit.byId('endDate_Change').getValue(), 'MM/dd/yyyy');
		} else {
			strStartDate = dataStart;
			strEndDate = strStartDate;
		}
		targetPath	= document.getElementById('pathProds_'+tipo).value;
		targetPath = targetPath.replace(/@dataBegin@/g,strStartDate);
		targetPath = targetPath.replace(/@dataEnd@/g,strEndDate);
		targetPath = targetPath + '&fromCombo=1';
		viewWApane(idtab, targetPath);		
		}
	chiudiCambioDate();			
}	
function chiudiCambioDate(){
	dijit.byId('dlgCambioData').hide();
}
function showMaps(title, address){
	document.getElementById('hoteltitlemaps').innerHTML=title;
	viewWApane('MappaContent','/booking/iframe_gmaps.cfm?address='+address);
	dijit.byId('mappadlg').show();
}
function loadBackgroundHref(){
	objSourceBackgroundHref = document.getElementById('sourceBackgroundHref');
	eval(objSourceBackgroundHref.value);			
}
function checkEndDateChange(){
	objStartDate 	= dijit.byId("startDate_Change");
	objEndDate 		=  dijit.byId("endDate_Change");	
	objBtnModify = dijit.byId('btnModifyDate');
	if(objEndDate<=objStartDate){
		objBtnModify.setDisabled(true);
		alert("La data di Out non puo' essere uguale o minore a quella di In");
	}else{	
		objBtnModify.setDisabled(false);
	}
}		


function showHelpTlp(objImg,toLeft,over,pixover) {		
	if (typeof(toLeft) == 'undefined')
		toLeft = true;
	if (typeof(over) == 'undefined')
		over = false;	
	if (typeof(pixover) == 'undefined')
		pixover = 0;	
		
	if(typeof(objImg)== 'string')
		var imgElem = document.getElementById(objImg);
	else
		var imgElem = objImg;
		
	var offsetLeft= 5;
	var offsetTop= +10;
	for (var tmpElem = imgElem;tmpElem!=null;tmpElem=tmpElem.offsetParent) {
		offsetLeft+=tmpElem.offsetLeft;
		offsetTop+=tmpElem.offsetTop;
	}	
	
	var sLink = "/booking/help.cfm?helpCode=" + imgElem.getAttribute("opt:helpcode");
	var oDivHelp = document.getElementById('helpAnimDiv');
	
	var posx = offsetLeft;
	var posy = offsetTop;
	
	if (! toLeft) 
		posx = offsetLeft - 220;		
	if (over)
		posy = offsetTop - pixover;
	
    oDivHelp.style.display = '';     
	oDivHelp = dijit.byId('helpAnimDiv')	
	oDivHelp.setHref(sLink);

	var fadeIn = dojo.fadeIn({node: "helpAnimDiv",duration: 1000});
	var wipeIn = dojo.fx.wipeIn({node: "helpAnimDiv",duration: 1000});
	var slideLeft = dojo.fx.slideTo({node: "helpAnimDiv",duration: 1000, left: posx, top:posy});
	var animIn = dojo.fx.combine([fadeIn, wipeIn, slideLeft]);
	var currentAnimation = animIn;
	currentAnimation.play();	
}			

function hideHelp() {
	var fadeOut = dojo.fadeOut({node: "helpAnimDiv",duration: 1000});
    var wipeOut = dojo.fx.wipeOut({node: "helpAnimDiv",duration: 1000});
    var slideRight = dojo.fx.slideTo({node: "helpAnimDiv",duration: 1000, left: (screen.width/2), top: 80});
    var animOut = dojo.fx.combine([fadeOut, wipeOut, slideRight]);
  
	var currentAnimation = animOut;	
	currentAnimation.play();
}
function highlight(theNode,endcolor,times) {
	var sColor = theNode.style.color;
	if (typeof(times) == 'undefined') 
		times=1;
	
	if (times > 0) {
		var anim = dojo.animateProperty({
			node: theNode,
			duration: 600,
			properties: {
				color: { start:endcolor, end: sColor }
			},
			onEnd: function(){ theNode.style.color = sColor; highlight(theNode,endcolor,times-1)}
		});	
		anim.play();
	}	
}

function selectTappa(idTappa){
	deselectAllTap();
	var objTdTappa = document.getElementById('tdTappa_'+idTappa);
	objTdTappa.style.border = '1px solid #E54501';	
	var objTappa = document.getElementById('tappa_'+idTappa);
	if(objTappa)
		objTappa.style.color = '#E54501';	
}
function deselectAllTap(){
	arrayTdTappe = getElementsByAttribute('opt:tdTappa', 'true', 'td');
	for(sel=0;sel<arrayTdTappe.length; sel++) {
		arrayTdTappe[sel].style.border="0px";
		codTappa = 	arrayTdTappe[sel].getAttribute('opt:codTappa');
		divTappa = document.getElementById('tappa_'+codTappa);
		if(divTappa)
			divTappa.style.color="#003399";	
	}
}	
function loginAndSyncBooking(urlParams) {
	if (! confirm("Confermi la selezione dell'agenzia\ndove perfezionare la prenotazione?"))
		return;		
	urlParams = document.getElementById('CCDetails').value + urlParams;
	addTabCredito(urlParams);		
}	
	
function doAccettoClausoleLbl() {
	var objCheck = document.getElementById('chkClausole');
	objCheck.checked = ! objCheck.checked;
	objCheck.onclick();	
}
	
function changeBackClick() {
	document.getElementById('btnGestB2B').style.display='none';
	
	dijit.byId("next").setLabel('Continua');
	dijit.byId("previous").setLabel('Indietro');
	dijit.byId('myStackContainer').selectChild(dijit.byId('step3'));
	dijit.byId("previous").attr("onClick",restoreBackClick);
}
function restoreBackClick() {
	dijit.byId('myStackContainer').back();
}	

function restoreNextClick() {
	dijit.byId('myStackContainer').forward();
}	

function changeNextClickB2B() {
	dijit.byId('myStackContainer').forward();
	pageTracker._trackPageview('/bmm/prenotazione_agenzia');
	showBreadcrumbsType('B2B');
	enableLblSteps('step7');
}

function changeNextClickB2C() {
	dijit.byId('myStackContainer').forward();
	//Inserimento chiamata GOOGLE per BigMouth
	pageTracker._trackPageview('/bmm/prenotazione_utente');
	showBreadcrumbsType('B2C');
	enableLblSteps('step11');
}
function sendRequestMailVoli(bkgCode) {
	var sMess = "Attenzione:\nil preventivo da voi richiesto dovra' essere controllato e completato da un nostro operatore.\n"; 
	sMess += "Desiderate che il nostro ufficio prenotazioni vi ricontatti per gli aggiornamenti?"; 
	if (confirm(sMess)) {
		var sLink = '/booking/mail/mail_richiesta_voli.cfm?bkgcode='+bkgCode;
		viewWApane('requestMailContent',sLink);
	}	
}
