function cancellaSelezioni(formID) {
		var theForm = document.getElementById(formID);
		theForm.action = "";
		theForm.faction.value = "clear";
		theForm.submit();
	}

	function salvaRicerca()

		{
			if (window.document.SRC.FormSearchName.value != '') {
				window.document.SRC.action = '/FrontController.cfm?PAGE=SEARCHBEGIN';
				window.document.SRC.submit();
			}
			else {
				alert("Inserire il nome della ricerca da salvare");
				return false;
			}
		}

	// FUNZIONI PER LA SELEZIONE  MULTIPLA DELLE PROPRIETA'
			function buildMultipleValueText(sourceElement) {
				sourceElementName	= sourceElement.name;
				multipleValueText	= "";

				if (sourceElementName.lastIndexOf("_SOURCE") == -1) {
					baseElement	= sourceElement;
				} else {
					baseElement	= eval("window.document.SRC." + (sourceElement.name).replace("_SOURCE", ""));
				}
				for (i = 0; i < baseElement.options.length; i++) {
					if (multipleValueText == "") {
						multipleValueText 	= baseElement.options[i].text;
					} else {
						multipleValueText 	= multipleValueText + ", " + baseElement.options[i].text;
					}
				}

				eval("window.document.SRC." + baseElement.name.replace("SRC_", "") + "_TEXT").value 	= multipleValueText;
			}
		function buildSingleValueText(sourceElement) {
				signleValueText 	= sourceElement.options[sourceElement.selectedIndex].text;

				eval("window.document.SRC." + sourceElement.name.replace("SRC_", "") + "_TEXT").value 	= signleValueText;
			}
		function selectMultipleValue(sourceElement) {
			
				var formSRC = document.getElementById('SRC');
			
				// Get source element information
				sourceElementValue	= sourceElement.options[sourceElement.selectedIndex].value;
				sourceElementText	= sourceElement.options[sourceElement.selectedIndex].text;

				// Identify the target form (same name without _SOURCE suffix)
				targetElement			= eval("window.document.SRC." + (sourceElement.name).replace("_SOURCE", ""));
				targetText				= eval("window.document.SRC." + (sourceElement.name).replace("_SOURCE", "_TEXT"));

				// Create the new OPTION element to add to target SELECT
				selectedElement	= new Option(sourceElementText, sourceElementValue);
				// Add the element to target SELECT
				targetElement.options[targetElement.options.length] = selectedElement;
				// Remove from SOURCE select
				sourceElement.options[sourceElement.selectedIndex] = null;

				// Create the text
				buildMultipleValueText(sourceElement);
			}

			function unselectMultipleValue(sourceElement) {
				// Get source element information
				sourceElementValue	= sourceElement.options[sourceElement.selectedIndex].value;
				sourceElementText	= sourceElement.options[sourceElement.selectedIndex].text;

				// Identify the target form (same name without _SOURCE suffix)
				targetElement			= eval("window.document.SRC." + (sourceElement.name + "_SOURCE"));
				targetText				= eval("window.document.SRC." + (sourceElement.name.replace("SRC_", "") + "_TEXT"));

				targetText.value	= (targetText.value).replace(sourceElementText + ",", "");
				targetText.value	= (targetText.value).replace(sourceElementText, "");
				// Create the new OPTION element to add to target SELECT
				selectedElement	= new Option(sourceElementText, sourceElementValue);
				// Add the element to target SELECT
				targetElement.options[targetElement.options.length] = selectedElement;
				// Remove from SOURCE select
				sourceElement.options[sourceElement.selectedIndex] = null;

				// Create the text
				buildMultipleValueText(sourceElement);
			}

			function selectMultipleTreeValue(sourceElement, sourceElementValue, sourceElementText) {
				// Identify the target form (same name without _SOURCE suffix)
				targetElement			= eval("window.document.SRC." + (sourceElement.name).replace("_SOURCE", ""));
				targetText				= eval("window.document.SRC." + (sourceElement.name).replace("_SOURCE", "_TEXT"));

				// Remove from SOURCE select
				//sourceElement.options[sourceElement.selectedIndex] = null;

				// Controllo che non sia gia' stato selezionato
				if (checkValueExists(targetElement, sourceElementText)) {
					alert("Non e' possibile selezionare un elemento gia' selezionato in precedenza.");
				} else {
					// Create the new OPTION element to add to target SELECT
					selectedElement	= new Option(sourceElementText, sourceElementValue);
					// Add the element to target SELECT
					targetElement.options[targetElement.options.length] = selectedElement;
					// Create the text
					buildMultipleValueText(sourceElement);
				}
			}

			function checkValueExists(selectedTreeValues, selectElementText) {
				var bCheck = false;
				for (i = 0; i < selectedTreeValues.options.length; i++) {
					if (selectedTreeValues.options[i].text == selectElementText) {
						bCheck = true;
						break;
					}
				}
				return bCheck;
			}

			function unselectMultipleTreeValue(sourceElement) {
				// Get source element information
				sourceElementValue	= sourceElement.options[sourceElement.selectedIndex].value;
				sourceElementText	= sourceElement.options[sourceElement.selectedIndex].text;

				// Identify the target form (same name without _SOURCE suffix)
				targetElement			= eval("window.document.SRC." + (sourceElement.name + "_SOURCE"));
				targetText				= eval("window.document.SRC." + (sourceElement.name.replace("SRC_", "") + "_TEXT"));

				targetText.value	= (targetText.value).replace(sourceElementText + ",", "");
				targetText.value	= (targetText.value).replace(sourceElementText, "");
				// Create the new OPTION element to add to target SELECT
				selectedElement	= new Option(sourceElementText, sourceElementValue);
				// Add the element to target SELECT
				targetElement.value = selectedElement;
				// Remove from SOURCE select
				sourceElement.options[sourceElement.selectedIndex] = null;

				// Create the text
				buildMultipleValueText(sourceElement);
			}

			function selectPrice(item) {
				valoreItem 	= item.options[item.selectedIndex].value;

				if (valoreItem != '') {
					arrayItem	= valoreItem.split(";");
					with (window.document.SRC) {
						SRC_PRICE_DA.value 	= arrayItem[0];
						SRC_PRICE_A.value 	= arrayItem[1];
					}
				} else {
					with (window.document.SRC) {
						SRC_PRICE_DA.value 	= "";
						SRC_PRICE_A.value 	= "";
					}
				}
				insertPriceText();
			}

			function insertPriceText() {
				with (window.document.SRC) {
					if (SRC_PRICE_DA.value != '' && SRC_PRICE_A.value != '')
						prezzoText 	= "da " + SRC_PRICE_DA.value + " a " + SRC_PRICE_A.value;
					else if (SRC_PRICE_DA.value != '')
						prezzoText = "oltre " + SRC_PRICE_DA.value;
					else if (SRC_PRICE_A.value != '')
						prezzoText = "fino a " + SRC_PRICE_A.value;

					if (SRC_PRICE_A.value != '' || SRC_PRICE_DA.value != '') {
						window.document.SRC.PRZ_TEXT.value 	= prezzoText + " Euro";
					} else {
						window.document.SRC.PRZ_TEXT.value 	= "";
					}
				}
			}

			function checkOneSelected() {
				errorString = "";
				numFormField = window.document.SRC.length;
				noOneSelected = true;
				for (i=1; i < numFormField; i++) {
					fieldName = window.document.SRC[i].name;
					strRefName = "SRC_PRP_";
					if (fieldName.substring(0, strRefName.length) == strRefName) {
						if (eval("window.document.SRC." + fieldName + ".selectedIndex > 0")) {
					 		noOneSelected = false;
						 }
					}
					if (fieldName == 'SRC_TO') {
						if (eval("window.document.SRC." + fieldName + ".selectedIndex > 0")) {
					 		noOneSelected = false;
						 }
					}
					if (fieldName == 'SRC_TEXT') {
						if (eval("window.document.SRC." + fieldName + ".value != ''")) {
					 		noOneSelected = false;
						 }
					}
					if (fieldName == 'SRC_PRICE') {
						if (eval("window.document.SRC." + fieldName + "[0].value != ''")) {
					 		noOneSelected = false;
						 }
					}
				}
				if (noOneSelected) {
					errorString = "\r" + "Selezionare almeno un criterio di ricerca";
				}
				return errorString;
			}

			// FUNZIONI PER LA VISUALIZZAZIONE DEI DIV DELLE PROPRIETA'

			 function apriDiv(cod) {
				nomeA 	= "IMG_Div_" + cod;
				closeLayers(nomeA);
				//Metto il DIV delle destinazioni piu' in alto
				if(cod == 'PRP_1') {
					objA 	= imgOffsets("IMG_RIF");
					topRef = -10;
					leftRef = +3;
				} else {
					objA 	= imgOffsets(nomeA);
					topRef 	= +3;
					leftRef = -3;
				}

				posLeft = objA[0];
				posTop 	= objA[1];

				nomeDiv = "DIV_" + cod;
				objDiv 	= document.getElementById(nomeDiv);
				//objPagina = document.getElementById('numberPagina');
				if (objDiv.style.visibility  == 'hidden') {
/*					if (cod == 'PRP_1') {
					    ddmx = new DropDownMenuX('menu1');
					    ddmx.type = "vertical";
					    ddmx.delay.show = 0;
					    ddmx.delay.hide = 5000;
					    ddmx.position.levelX.left = 2;
						if (!MenuJustCreated) {
						    ddmx.init();
							MenuJustCreated = true;
						}
					}*/
					// Posiziono i div vicino all'immagine
					objDiv.style.top = posTop + topRef + "px";
					objDiv.style.left = posLeft + leftRef + "px";
					objDiv.style.visibility = 'visible';
					//objPagina.style.visibility = 'hidden';

				} else {
					objDiv.style.visibility = 'hidden';
					//objPagina.style.visibility = 'visible';
				}
			}

			function closeLayers(currentDiv) {
				var arrayDiv = "";

				strRef = "IMG_Div";
				arrayDiv = document.getElementsByTagName("IMG");

				if (arrayDiv.length) {
				   	for(i=1; i < arrayDiv.length; i++) {
						elementId = arrayDiv[i].id;
						if (elementId != '' && elementId != currentDiv) {
							if(elementId.substring(0, strRef.length) == strRef) {
								nomeDiv = elementId.substring(4);
								nomeDiv = nomeDiv.toUpperCase();
								objDiv 	= document.getElementById(nomeDiv);
								objDiv.style.visibility = 'hidden';
							}
						}
					}
				}
			}

			function imgOffsets(id) {
			  var imgElem = document.getElementById(id);
			  var offsetLeft= -3;
			  var offsetTop= +1;
			  for (var tmpElem = imgElem;tmpElem!=null;tmpElem=tmpElem.offsetParent) {
			    offsetLeft+=tmpElem.offsetLeft;
			    offsetTop+=tmpElem.offsetTop;
			  } return [offsetLeft, offsetTop];
			}
	//Per compatibilit? con il vecchio sistema
	function call_selectMultipleTreeValue(elem) {
		var objSelect = document.getElementById("selDestinazione");
		var pkpropval = elem.info.id;
		var row = myMenu.selectRow(pkpropval);
		var theId = row[0];
		var pklist = row[4];
		var strCaption = row[2];
		selectMultipleTreeValue(objSelect, "|" + theId + ',' + pklist, strCaption, '@TabIndice@');
		return false;
	}

	/**
	 * Ritorna info sulle destinazioni selezionate
	 */
	function getDestinationPreferences(){
		var elDest = document.getElementById("src_prp_1");
		var ar, pkpropval, str, row;
		var pref = {pkpropval:new Array(), preferences:new Array(), company: new Array(),optionNumber: new Array()};
		for (var i = 0; i < elDest.options.length; i++ ) {
	    		ar = elDest.options[i].value.split(",");
	    		str	= ar[0];
	    		pkpropval = str.substring(1,str.length);
	    		row = myMenu.selectRow(pkpropval);
	    		if(row.length > 0) {
	    			pref.optionNumber.push(i);
	    			pref.pkpropval.push(row[0]);
	    			pref.preferences.push(row[5]);
	    			pref.company.push(row[1]);
	    		}
	    }

		return pref;
	}
	//Controlla che tutte le destinazioni selezionate abbiano lo stesso usepre
	//return null, or the usepre
	function checkUsepre() {
		var p = getDestinationPreferences();
		//usepre ITI | CAR
		var preferences = p.preferences;
		//id company
		var company = p.company;

	    //Controlla diversit? negli usepre
	    preferences.sort();
	    for(var i=1; i< preferences.length;i++) {
	      	if(preferences[i] != preferences[i-1]) {
	      		showDialog('open');
	      		return false;
	      		break;
	       	}


	    }
	    //Nel caso di ITI tutte le destinazioni devono avere una sola company altrimenti
	    //l'utente deve decidere.
	    //L'utente ha gi? deciso se il campo src_to ha una sola company
	    var selCompany = getSelectedCompany();
	    var arCp = selCompany.split(",");
	    //if((preferences.length > 1) && (preferences[0] == "ITI") && (arCp.length > 1)) {
	    if((preferences.length > 1) && (preferences[0] == "ITI")) {
	    	for(var i=1;i<company.length;i++){
	    		if(company[i] != company[i-1]) {
	    			showDialogCompany('open');
	    			return false;
	    		}
	    	}
	    }


		var pref = "";
		if(preferences.length > 0 ) {
			pref = preferences[0].replace(/\s+$|^\s+/g,"");
		}
		//ITI | CAR
		return pref;
	}
	/*showDialog per scelta tra ITI e CAR*/

	function showDialog(mode) {
		var crtlButton = document.getElementById("controlButton");
		var elDest = document.getElementById("src_prp_1");
		var dlgPage = document.getElementById("dlgPage");
		//TOBE TESTED
		var overlay = document.getElementById("overlay");
		var elRadio = window.document.SRC.page2go;
		var selDest;

		if(mode == 'open') {
			var offLeft = -25;
			var offTop = 0;
			//Immagine di riferimento per il posizionamento
			var res = imgOffsets("IMG_RIF");

			dlgPage.style.top = res[1] + 'px';
			dlgPage.style.left = (res[0] + offLeft) + 'px';
			dlgPage.style.visibility = 'visible';
			overlay.style.visibility = "visible";
			return;
		}

		if(mode == "close") {
				//Rimuove destinazioni non conformi
				var toRemove = getCheckedValue(elRadio);

				selDest = getDestinationPreferences();
				var ar = selDest.optionNumber;
				for(var i=0;i<ar.length;i++) {
					if(selDest.preferences[i] == "CAR" && toRemove == "CAR") {
						elDest.remove(ar[i]);
					}else if(selDest.preferences[i] == "ITI" && toRemove == "ITI"){
						elDest.remove(ar[i]);
					}
				}

			//reset
			dlgPage.style.visibility = 'hidden';
			overlay.style.visibility = "hidden";

			//Re-invia il form
			checkForm();
			return;
		}
	}

	function showDialogCompany(mode) {
		var dlgDiv = document.getElementById("dlgCompany");
		var crtlButton = document.getElementById("controlButton");
		if(mode == 'open') {
			var offLeft = -25;
			var offTop = 0;
			//Immagine di riferimento per il posizionamento
			var res = imgOffsets("IMG_RIF");
			dlgDiv.style.top = res[1] + 'px';
			dlgDiv.style.left = (res[0] + offLeft) + 'px';
			dlgDiv.style.visibility = 'visible';

			//Rende visibili le company incluse nelle destinazioni selezionate
			var obj = getDestinationPreferences();
			var cp = obj.company.toString();
			var splitted = cp.split(",");
			var firstSelected = false;
			var el;
			for(var i=0;i<splitted.length;i++){
				if(document.getElementById(splitted[i])) {
					el = document.getElementById(splitted[i]);
					el.style.display = "block";
					//First selected by default
					if(!firstSelected) {
						el.checked = true;
					}
				}
			}

		}

		if(mode == 'close') {
			var elRadio = window.document.SRC.toAvailable;
			var toMantain = getCheckedValue(elRadio);
			var tr = dlgDiv.getElementsByTagName("tr");
			var  nrEl = tr.length;


			var srcTo = document.getElementById("src_to");
			//remove unchecked option
			var elOption;
			var found = false;
			for(var i=0;i<srcTo.options.length;i++){
				elOption = srcTo.options[i];
				if(elOption.value != toMantain){
					srcTo.remove(elOption);
				}else{
					found = true;
				}
			}

			//Forza l'aggiunta di una opzione
			if(!found) {
				var src = document.getElementById("src_to_source");
				var opt = src.getElementsByTagName("option");
				for(var i=0;i<opt.length;i++) {
					if(opt[i].getAttribute("value") == toMantain) {
						opt[i].selected = true;
						selectMultipleValue(src);
						break;
					}
				}
			}

			//reset to none tutte le company
			for (var i = 0; i < nrEl; i++){
				if(tr[i].style.display && tr[i].style.display == 'block') {
   				 	tr[i].style.display = "none";
				}
			}

			//reset
			dlgDiv.style.visibility = 'hidden';
			//Prosegue per itinerario
			//apriItinerario();
			//return false;
			//Re-invia il form
			checkForm();
			return;
		}
	}
	/*----------------------------------------------*/
	function apriItinerario() {

		var pkcompany = getSelectedCompany();
		//Forza usando le pkcompany associate alla destinazione nella datatable
		if(pkcompany == "") {
			showDialogCompany('open');
			return false;
		}
		var pkdest 		= "";
		var datapar 	= getVal("src_period_begin_dd") + '/' + getVal("src_period_begin_mm") + '/' +  getVal("src_period_begin_yyyy");
		var datafine 	= getVal("src_period_end_dd") + '/' + getVal("src_period_end_mm") + '/' +  getVal("src_period_end_yyyy");
		var adults 		= getVal("adults");
		var children 	= getVal("children");
		var infants 	= getVal("infants");

		var winParams 	= 'resizable=yes,width=800,height=500,toolbar=no';
		var url 		= "http://magda.openturnet.com/FLEX/ITINERARIOHTL/itinerario.mxml?";
		var itinerario 	= window.open(url + 'pkcompany=' + pkcompany + '&datapar=' + datapar + '&datafine=' + datafine
							+'&adults=' + adults + '&children=' + children + '&infants=' + infants + '&pkdest=' + pkdest,'nome',winParams);

		itinerario.focus();

		function getVal(elId) {
			return document.getElementById(elId).value;
		}
	}
	function getSelectedCompany() {
		var lsSelectedCompany = "";
		var srcTo = document.getElementById("src_to");
		for(var i=0;i<srcTo.options.length;i++){
			if(srcTo.options[i].selected) {
				if(lsSelectedCompany == "") {
					lsSelectedCompany += srcTo.options[i].value;
				}else{
					lsSelectedCompany += "," + srcTo.options[i].value;
				}
			}
		}

		return lsSelectedCompany;
	}

	// return the value of the radio button that is checked
	// return an empty string if none are checked, or
	// there are no radio buttons
	function getCheckedValue(radioObj) {
		if(!radioObj)
			return "";
		var radioLength = radioObj.length;
		if(radioLength == undefined)
			if(radioObj.checked)
				return radioObj.value;
			else
				return "";
		for(var i = 0; i < radioLength; i++) {
			if(radioObj[i].checked) {
				return radioObj[i].value;
			}
		}
		return "";
	}

	// set the radio button with the given value as being checked
	// do nothing if there are no radio buttons
	// if the given value does not exist, all the radio buttons
	// are reset to unchecked
	function setCheckedValue(radioObj, newValue) {
		if(!radioObj)
			return;
		var radioLength = radioObj.length;
		if(radioLength == undefined) {
			radioObj.checked = (radioObj.value == newValue.toString());
			return;
		}
		for(var i = 0; i < radioLength; i++) {
			radioObj[i].checked = false;
			if(radioObj[i].value == newValue.toString()) {
				radioObj[i].checked = true;
			}
		}
	}
	function submitFormForCAR() {
		var myForm = document.getElementById("theForm");
		myForm.action = "FrontController.cfm?PAGE=SEARCHRESULT";
		apriWait('NORM', 300, 150);
		myForm.submit();
	}

		// FUNZIONE DI CONTROLLO DEI CAMPI SELEZIONATI
		function checkForm()
			{
				var lstErrori 		= "ATTENZIONE";
				var oneCriteriaUsed	= false;
				
				with (window.document.SRC) {
					for (i = 0; i < elements.length; i++)
						{
							if (elements[i].name != undefined) 
								{
									elementName = elements[i].name;
									if (elementName.lastIndexOf("_SOURCE") != -1) 
										{
											targetElementName	= elementName.replace("_SOURCE", "");
											if (targetElementName!='SRC_PRP_1')
												{
													elementLenght = eval("window.document.SRC." + targetElementName + ".options.length");
													for (n = 0; n < elementLenght; n++) 
														{
															if (eval("window.document.SRC." + targetElementName + ".options[" + n + "]"))
																{
																	eval("window.document.SRC." + targetElementName + ".options[" + n + "].selected = true");
																	if((targetElementName == 'SRC_PRP_1'))
																		{
																			oneCriteriaUsed = true;
																		}
																}
														}
												}
											else // CONTROLLI PER LA DESTINAZIONE
												{
													if (window.document.SRC.SRC_PRP_1.length) //CONTROLLO CHE SIA UNA SELECT
														{
															for (var j=0;j<window.document.SRC.SRC_PRP_1.length; j++) 
																{
																	if (window.document.SRC.SRC_PRP_1[j].checked!=false) 
																		{
																			oneCriteriaUsed = true;
																		}
																}
														}
													else if (window.document.SRC.SRC_PRP_1.checked!=false) // CONTROLLLO CHE SIA UN CHECK
														{
															oneCriteriaUsed = true;
														}
														
													else	// CONTROLLO CHE SIA UN CAMPO TEXT
														{
															if (window.document.SRC.SRC_PRP_1.value!="") 
																{
																	oneCriteriaUsed = true;
																}
														} 	
													
													}
											}
								}
						}
						
					if (!oneCriteriaUsed) {
						lstErrori += "\nSelezionare almeno una destinazione.";
					}

					// Prendo i dati totali del viaggio
					ddBegin		= SRC_PERIOD_BEGIN_DD.value;
					mmBegin		= SRC_PERIOD_BEGIN_MM.value;
					yyyyBegin	= SRC_PERIOD_BEGIN_YYYY.value;
					ddEnd		= SRC_PERIOD_END_DD.value;
					mmEnd		= SRC_PERIOD_END_MM.value;
					yyyyEnd		= SRC_PERIOD_END_YYYY.value;
	
					// Costruisco le 2 date nel formato inglese
					dateBegin 	= mmBegin + "/" + ddBegin + "/" + yyyyBegin;
					dateEnd 	= mmEnd + "/" + ddEnd + "/" + yyyyEnd;
	
					// Creo le date in formato JS per controllarle
					jsDateBegin = new Date(yyyyBegin, mmBegin, ddBegin);
					jsDateEnd 	= new Date(yyyyEnd, mmEnd, ddEnd);
	
					// Faccio il controllo delle 2 date create
					lstErrori = lstErrori + checkDate(dateBegin, "inizio");
					lstErrori = lstErrori + checkDate(dateEnd, "fine");
	
					// Se le 2 date sono corrette controllo che la data di fine non sia maggiore o uguale alla data di partenza
					if (lstErrori == 'ATTENZIONE') {
						if ((jsDateEnd <=  jsDateBegin)) {
							lstErrori = lstErrori + "\r" + "La data fine periodo non puo' essere minore o uguale alla data di inizio periodo";
						}
					}
	
					// Se non ci sono errori faccio il submit senno' mostro gli errori
					if (lstErrori != 'ATTENZIONE') {
						alert(lstErrori);
						return false;
					} else {
						// Metto le date create nei campi nascosti
						SRC_PERIOD_BEGIN.value 	= dateBegin;
						SRC_PERIOD_END.value 	= dateEnd;
						return true;
					}
				}
			}
			
function refreshEndDate() {
	with (window.document.SRC) {

		ddBegin			= SRC_PERIOD_BEGIN_DD.value;
		mmBegin			= SRC_PERIOD_BEGIN_MM.value;
		yyyyBegin		= SRC_PERIOD_BEGIN_YYYY.value;
		dayPlus			= SRC_PERIOD_DAY.value;
		startDateEn 	= mmBegin + "/" + ddBegin + "/" + yyyyBegin;
		startDate	 	= ddBegin + "/" + mmBegin + "/" + yyyyBegin;
		
		if (checkDate(startDateEn, "inizio") == '') {
			newEndDate 		= dateAdd(startDate, dayPlus );
			splitEndDate 	= newEndDate.split("/");						
			// Inserisco i nuovi valori della data 
			SRC_PERIOD_END_DD.value 	= splitEndDate[0];
			SRC_PERIOD_END_MM.value 	= splitEndDate[1];
			SRC_PERIOD_END_YYYY.value 	= splitEndDate[2];	
		} else {
			alert("ATTENZIONE" + checkDate(startDateEn, "inizio"));
		}
	}	

}			
function checkDate(dateStr, tipo) {
	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" + "La data di " + tipo + " periodo deve essere valida e nel formato gg/mm/aaaa";
		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" + "Il mese deve essere un numero compreso tra 1 e 12";
		return lstErrori;
	}
	
	if (day < 1 || day > 31) {
		lstErrori = lstErrori + "\r" + "Il giorno deve essere un numero compreso tra 1 e 31";
		return lstErrori;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		lstErrori = lstErrori + "\r" + "Il mese " + month+ " non ha 31 giorni!";
		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" + "Febbraio " + year + " non ha " + day + " giorni!";
			return lstErrori;
		}
	}
	return lstErrori; // date is valid
}	
// FUNZIONI PER IL DATE ADD 
function padDigit(digit) {
	if(digit < 10) { 
		return "0" + digit;
	} else { 
		return digit;
	}
}	
function dateAdd(baseStr,days) {
	baseTime = baseStr.split("/");
	time = new Date(baseTime[2],baseTime[1]-1,baseTime[0]);
	time = new Date(time.valueOf()+ (days*1000*3600*24));
	return padDigit(time.getDate())+"/"+padDigit(time.getMonth()+1)+"/"+time.getFullYear();

}			
