// JavaScript Document
	//Variabili js multilingua da mettere dentro all'xml
	msgElaborazione_js		= "Elaborazione in corso ...";
	msgVoli_js				= "Ricerca in corso dei voli sulla base dei 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.";
	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 /><span class="dijitContentPaneLoading">' + msgVoli_js +'</span>';
	
	if(typeof(cfw) == 'undefined') {var cfw = {}};
	
	function viewWApane(idPane, address){
		var TagPane = dijit.byId(idPane);
		var waDate = new Date;
		TagPane.cancel();
		if (address.indexOf('?')!=-1)
			TagPane.setHref(address+'&time='+waDate);
		else
			TagPane.setHref(address+'?time='+waDate);	
			
		//executeScripts();
	}
	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('contentPratica','/booking/pratica_dettaglio.cfm?bkgcode='+bkgcode+'&pkcompany='+pkcompany+'&stato=DB')
				}
		}	

	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 initFromOffer(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 numberOfPax		= 0;
		var iCounter		= 0;
		var dayFieldValue	= "";
		var monthFieldValue	= "";
		var yearFieldValue	= "";
		var checkDateResult	= "";
		var codfisc 		= "";
		var prefixField 	= "";
		var re = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
		
		numberOfPax = dojo.byId('PAXNUMBER').value;
		
		if (typeof(action) != 'undefined')
			prefixField = "mod_";		
		
		for (iCounter = 1; iCounter <= numberOfPax; iCounter++) {
			FirstName		= document.getElementById(prefixField + "passengers_" + iCounter + "__FIRSTNAME").value;				
			LastName		= document.getElementById(prefixField + "passengers_" + iCounter + "__LASTNAME").value;			
			objTitle		= document.getElementById(prefixField + "passengers_" + iCounter + "__TITLE");
			dayFieldValue 	= document.getElementById(prefixField + "passengers_" + iCounter + "__BIRTHDATE_DD").value;
			monthFieldValue	= document.getElementById(prefixField + "passengers_" + iCounter + "__BIRTHDATE_MM").value;
			yearFieldValue	= document.getElementById(prefixField + "passengers_" + iCounter + "__BIRTHDATE_YYYY").value;
			codfisc 		= document.getElementById(prefixField + "passengers_" + iCounter + "__CODFISC").value;
			
			if (objTitle.type == 'select-one') {
				titleName		= objTitle.options[objTitle.selectedIndex].value;	
			} else {
				titleName		= objTitle.value;	
			}
			
			if (((titleName == 'CHD') || (titleName == 'INF')) && ((dayFieldValue == '') && (monthFieldValue == '') && (yearFieldValue == ''))) {
				return alertErrChIfPax_js;
			}
			
			if ((dayFieldValue != '') || (monthFieldValue != '') || (yearFieldValue != '')) {
				checkDateResult	= checkDate(monthFieldValue + "/" + dayFieldValue + "/" + yearFieldValue, iCounter);
				if (checkDateResult != '') {
					return checkDateResult;
				}
			}
			
			if ((FirstName == '' || LastName == '')) {
				return alertErrNomePax_js;
			}
			if (opt.core.trim(codfisc) != "" && 
				opt.core.trim(codfisc) != "NOCF" && 
				! re.test(codfisc.toUpperCase())) {
				return alertCheckCodFisc_js;
			}			
		}
		
		if (document.getElementById("banconista").value=='')
			return alertBanconista_js;
		
		return "ok";
	} 
	
	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 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 gestionePratica(praticaItinerario, pkCompanyItinerario)
		{
			var myTabPane = dijit.byId("mainTab");
			var tabPratiche = dijit.byId("pratiche");
			var dlgPratica = dijit.byId("praticadlg");
			var stkPrenotazione = dijit.byId("myStackContainer");
			var paneStep1 = dijit.byId("step1");
			var waDate = new Date;
			
			if(praticaItinerario != undefined)
				bkgcode = praticaItinerario;
			if(pkCompanyItinerario != undefined)
				pkcompany = pkCompanyItinerario;			
		/*	myTabPane.selectChild('pratiche','booking');
			myWizard.onSelected(myWizard.getPanels()[0]);
			myWizard._onPreviousButtonClick();*/

			// svuoto carrello
			//addCart('cart', 'carrello.cfm?clearCart');
			//CloseTitle();
			if (tabPratiche)
				myTabPane.selectChild(tabPratiche);
				
			stkPrenotazione.selectChild(paneStep1);
			dlgPratica.show();
			viewWApane('praticaContent','/booking/pratica.cfm?BKGCODE='+bkgcode+'&PKCOMPANY='+pkcompany+'&justConfirmed=true&tick='+waDate);
		}

//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 TagPane = dijit.byId('schedaProdottoContent');
			TagPane.cancel();
			TagPane.setHref(address);
			TagPane = dijit.byId('schedaProdotto');
			TagPane.show();
		}	
	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_loginPratiche(response)
		{
	
			var MainPane = dijit.byId("pratiche");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';			
		}
	function submitAjaxForm_loginautofatture(response)
		{
	
			var MainPane = dijit.byId("autofatture");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';			
		}			
	function submitAjaxForm_RisultatoProdottiCarrello(response)
		{
			var MainPane = dijit.byId("step2");			
			MainPane.setContent(response);			
			aggiornaVoli();
			document.body.style.cursor = 'default';
		}

	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_login(response)
		{	
			var MainPane = dijit.byId("boxContainer");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';				
		}
	function submitAjaxForm_login2(response)
		{	
			var MainPane = dijit.byId("formLogin");
			MainPane.setContent(response);
			document.body.style.cursor = 'default';				
		}			
	
	function submitAjaxForm_loginprivati(response)
		{	
			var MainPane = dijit.byId("boxContainer");
			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");
	if (checkSearchForm())
	{
		submitAjaxForm('SRC', submitAjaxForm_RisultatoProdottiCarrello,'step2');
	}
	/*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;
	
	// 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.cancel();	
		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');
}
	
function gotoStep5() {
	var result = checkpasseggeri();
	if (result=='ok') {
		var MainPane = dijit.byId("step5");			
		submitAjaxForm('PASSENGERS', submitAjaxForm_RisultatoBooking,'step5');
		// svuoto carrello
			addCart('cart', 'carrello.cfm?clearCart');

	} else {
		alert(result);
	}
}
	
		
//// 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 myContent = dijit.byId(pane + 'Content');
			var myDivContent = dijit.byId(pane);
			var waDate = new Date;
			var myPane = dijit.byId('carttitle');
			myContent.cancel();			
			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');
		if (arraySelectedDepts.length > 0) {
			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");
			if (classSerIDvalue != null)
				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');
	
	if(objDestSelected && 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')
		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);	
	else
		dijit.byId("next").setDisabled(false);		
}
function organizeStepReg(pageNumber) {		
	prevStep = document.getElementById('currStepIdReg').value;	
	document.getElementById('currStepIdReg').value = pageNumber;
	if (pageNumber == 'reg2')
		if(pageNumber>prevStep) gotoStep2Reg();
	if (pageNumber == 'reg3')
		if(pageNumber>prevStep) gotoStep3Reg();	
	if (pageNumber == 'reg4')
		if(pageNumber>prevStep) gotoStep4Reg();	
		
	dijit.byId("next").setDisabled(false);		
}
function gotoStep2Reg() {
	viewWApane('reg2','/booking/layout/profilo_default_utenteinternet.cfm');
}
function gotoStep3Reg() {
	var sMsg = checkSearchFormReg();
	if (sMsg == 'ok'){
		submitAjaxForm('frmInserisci', submitAjaxForm_RegistrazioneUtenteInternet,'reg3');
	} else 	{						
		var paneStep1 = dijit.byId("reg2");
		dijit.byId('stackContainerReg').selectChild(paneStep1);
		alert(sMsg);		
	}	
}
function gotoStep4Reg() {

}

function checkSearchFormReg() {
	var sNome = opt.core.trim(document.getElementById('USR_NOME').value);
	var sCognome = opt.core.trim(document.getElementById('USR_COGNOME').value);
	var sEmail = opt.core.trim(document.getElementById('USR_EMAIL').value);
	
	if (sNome == '') {
		return 'Inserire il nome'			
	}
	if (sCognome == '') {
		return 'Inserire il cognome'			
	}
	if (sEmail == '') {
		return 'Inserire indirizzo email'			
	}	
	if (! opt.validator.isEmail(sEmail)) {
		return 'indirizzo email non valido'			
	}		
	return 'ok';
}

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

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.value(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 addTabCredito(urlParams){			
	var tc = dijit.byId("praticatabs");
	var objTab = dijit.byId("cc_credito");
	if (objTab != null) {
		dijit.byId("praticatabs").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, 1);
		
	tc.selectChild('cc_credito');
			
}
function selectCercaAgenziaTab(){
	var tc = dijit.byId("praticatabs");
	var objTab = dijit.byId("AgencyContent");
	if (objTab == null) {
		var cp = new dojox.layout.ContentPane({id:"AgencyContent",title: "Cerca l'agenzia",href:"/booking/cerca_agenzia.cfm"});
		var chdIndex= tc.getChildren().length;		
		tc.addChild(cp, chdIndex);
	}	
	tc.selectChild('AgencyContent');
}			
			
function addTabPratiche(){			
	var tc = dijit.byId("mainTab");
	var objTab = dijit.byId("pratiche");
	if (objTab == null) {
		var cp = new dijit.layout.ContentPane({id:"pratiche",title: "PRATICHE",href:"pratiche.cfm"});
		var chdIndex= tc.getChildren().length;		
		tc.addChild(cp, chdIndex);
	}		
}
function chooseConfirmPrevent(opzioni, urlParams) {		
	if(opzioni.closePrevent == 'CC')
		addTabCredito(urlParams);

	if(opzioni.closePrevent == 'BO') 
		viewWApane('contentPratica', '/booking/pratica_dettaglio.cfm?stato=OP&'+urlParams);

	if(opzioni.closePrevent == 'AG')
		selectCercaAgenziaTab();
}		
function confirmFromCC(address) {	
	var tc = dijit.byId("praticatabs");
	tc.selectChild('contentPratica');	
	viewWApane('contentPratica', address);
}
function errorCC(strDecription) {
	//document.getElementById('divMsgErr').innerHTML = "<font color='red'>";
	alert("ATTENZIONE: transazione NON eseguita\nErrore: "+strDecription+"\nSi prega di ripetere l'operazione.");
	dijit.byId("praticatabs").closeChild(dijit.byId('cc_credito'));
	dijit.byId("praticatabs").selectChild(dijit.byId('contentPratica'));
}
function showPratiche() {
	var tc = dijit.byId("mainTab");
	tc.selectChild('pratiche');	
}	
function setNOCF(blnCheck,inputId) {
	var objInput = document.getElementById(inputId);
	if (blnCheck) {
		objInput.style.display = "none";
		objInput.value = "NOCF";		
	} else {		
		objInput.style.display = "";
		objInput.value = "";
	}		
}
function checkMandatoryFields(bErrCodFisc) {		
	if (bErrCodFisc) {
		alert(alertCodFiscNull_js);
		return false;
	}		
	return true;
}	
function doAccetto(bChecked) {
	var objChkAut = window.opener.document.getElementById('aut_trattamento');
	objChkAut.checked = bChecked;
	objChkAut.onclick();
}
