function Calcola(){
	
	var msgstr = ""
	var varTrattamento = ""
	date1 = new Date();
	dateArrivo = new Date();
	dateApertura = new Date();
	datePartenza = new Date();
	dateChiusura = new Date();
	date2 = new Date();
	diff  = new Date();
	
	VarProsegui = "OK"
	
	document.forms['Preventivo'].Arrivo.value = document.forms['Preventivo'].GiornoArrivo.options[document.forms['Preventivo'].GiornoArrivo.selectedIndex].value;
	document.forms['Preventivo'].Partenza.value = document.forms['Preventivo'].GiornoPartenza.options[document.forms['Preventivo'].GiornoPartenza.selectedIndex].value
		
	//Controllo che le date rientrino nelle aperture
	dateArrivoTemp = new Date(document.forms['Preventivo'].Arrivo.value + " 00:00:00");
	dateArrivo.setTime(dateArrivoTemp.getTime());
	
	
	datePartenzaTemp = new Date(document.forms['Preventivo'].Partenza.value + " 00:00:00");
	datePartenza.setTime(datePartenzaTemp.getTime());
	
	if (dateArrivo < datePartenza )
	{

	}
	else
	{
		msgstr = msgstr + "ERRORE!!!  LA DATA DI PARTENZA RISULTA PRECEDENTE A QUELLA DI ARRIVO, VERIFICARE E RIPROVARE.\n";
		VarProsegui = "NO";
	}
	//Controllo il trattamento ed i periodi 
	
	document.forms['Preventivo'].TrattamentoC.value = document.forms['Preventivo'].Tiposoggiorno.options[document.forms['Preventivo'].Tiposoggiorno.selectedIndex].text;
	
	TipoTrattamento = document.forms['Preventivo'].TrattamentoC.value;
	//periodi eccezione DOVE NON SI FA DORMIRE E COLAZIONE CONTROLLARE STARTPERIODO E FINEPERIODO (praticamente quelli nei quali non si fa B&B)
	date1temp = new Date(document.forms['Preventivo'].fineperiodo6.value);
	date1 = new Date(document.forms['Preventivo'].startperiodo4.value);
	
	if (TipoTrattamento != 'Dormire e colazione')
	{

	}
	else
	{
		if ((dateArrivo > date1temp) || (datePartenza<=date1))
		{
		
		}
		else
		{
		msgstr = msgstr + "IN UNO O PIU' GIORNI SCELTI NON SI PRESTA IL SERVIZIO DORMIRE E COLAZIONE. NON č POSSIBILE DARE UN RISULTATO. VERIFICARE e RIPROVARE.\n";
		VarProsegui = "NO";
		}
	}




//Inizializzazione variabili preventivo

	document.forms['Preventivo'].da1.value = "";
	document.forms['Preventivo'].da2.value = "";
	document.forms['Preventivo'].da3.value = "";
	document.forms['Preventivo'].da4.value = "";
	document.forms['Preventivo'].da5.value = "";
	document.forms['Preventivo'].da6.value = "";
	document.forms['Preventivo'].da7.value = "";
	document.forms['Preventivo'].da8.value = "";
	document.forms['Preventivo'].da9.value = "";
	document.forms['Preventivo'].a1.value = "";
	document.forms['Preventivo'].a2.value = "";
	document.forms['Preventivo'].a3.value = "";
	document.forms['Preventivo'].a4.value = "";
	document.forms['Preventivo'].a5.value = "";
	document.forms['Preventivo'].a6.value = "";
	document.forms['Preventivo'].a7.value = "";
	document.forms['Preventivo'].a8.value = "";
	document.forms['Preventivo'].a9.value = "";
	document.forms['Preventivo'].giorni1.value = "";
	document.forms['Preventivo'].giorni2.value = "";
	document.forms['Preventivo'].giorni3.value = "";
	document.forms['Preventivo'].giorni4.value = "";
	document.forms['Preventivo'].giorni5.value = "";
	document.forms['Preventivo'].giorni6.value = "";
	document.forms['Preventivo'].giorni7.value = "";
	document.forms['Preventivo'].giorni8.value = "";
	document.forms['Preventivo'].giorni9.value = "";


// Fine inizializzazione


	if (VarProsegui == "NO"){
		alert (msgstr);
	}
	else
	{


// Controllo periodi - devono essere presenti tutti i periodi di preventivo
// Controllo data Arrivo
	
		date1temp = new Date(document.forms['Preventivo'].Arrivo.value + " 00:00:00");
		date1.setTime(date1temp.getTime());
		
			date1temp = new Date(document.forms['Preventivo'].fineperiodo1.value);
			datebtemp = new Date(document.forms['Preventivo'].startperiodo1.value);
			
			if (date1 <= date1temp ){
					document.forms['Preventivo'].da1.value = document.forms['Preventivo'].Arrivo.value + " 00:00:00";
			}
			else {
				date1temp = new Date(document.forms['Preventivo'].fineperiodo2.value)
				if (date1 <= date1temp){
					document.forms['Preventivo'].da2.value = document.forms['Preventivo'].Arrivo.value + " 00:00:00";
				}
				else {
					date1temp = new Date(document.forms['Preventivo'].fineperiodo3.value);
					if (date1 <= date1temp){
						document.forms['Preventivo'].da3.value = document.forms['Preventivo'].Arrivo.value + " 00:00:00";
					}
					else {
						date1temp = new Date(document.forms['Preventivo'].fineperiodo4.value);
						if (date1 <= date1temp){
							document.forms['Preventivo'].da4.value = document.forms['Preventivo'].Arrivo.value + " 00:00:00";
						}
						else {
							date1temp = new Date(document.forms['Preventivo'].fineperiodo5.value);
							if (date1 <= date1temp){
								document.forms['Preventivo'].da5.value = document.forms['Preventivo'].Arrivo.value + " 00:00:00";
							}
							else {
								date1temp = new Date(document.forms['Preventivo'].fineperiodo6.value);
								if (date1 <= date1temp){
									document.forms['Preventivo'].da6.value = document.forms['Preventivo'].Arrivo.value + " 00:00:00";
								}
								else {
									date1temp = new Date(document.forms['Preventivo'].fineperiodo7.value);
									if (date1 <= date1temp){
										document.forms['Preventivo'].da7.value = document.forms['Preventivo'].Arrivo.value + " 00:00:00";
									}
									else {
										date1temp = new Date(document.forms['Preventivo'].fineperiodo8.value);
										if (date1 <= date1temp){
											document.forms['Preventivo'].da8.value = document.forms['Preventivo'].Arrivo.value + " 00:00:00";
										}
										else {
											date1temp = new Date(document.forms['Preventivo'].fineperiodo9.value);
											if (date1 <= date1temp){
												document.forms['Preventivo'].da9.value = document.forms['Preventivo'].Arrivo.value + " 00:00:00";
											}
											else {
												//alert("Data di inizio non valida");
											}	
										}
									}
								}
							}
						}
					}
				}
			}
			


// Fine Controllo data Arrivo

// Inizio Controllo Data Partenza
			
			
			date2temp = new Date(document.forms['Preventivo'].Partenza.value + " 00:00:00");
			date2.setTime(date2temp.getTime());
		
//  1° periodo

			date1temp = new Date(document.forms['Preventivo'].fineperiodo1.value);
			if (date2 <= date1temp){
				document.forms['Preventivo'].a1.value = document.forms['Preventivo'].Partenza.value+ " 00:00:00";
				if (document.forms['Preventivo'].da1.value == "")
				{
					document.forms['Preventivo'].da1.value = document.forms['Preventivo'].startperiodo1.value;
			 	}
			}
			else 
			{

// 2° periodo
				date1temp = new Date(document.forms['Preventivo'].fineperiodo2.value)
				if (date2 <= date1temp)
				{
					document.forms['Preventivo'].a2.value = document.forms['Preventivo'].Partenza.value+ " 00:00:00";
					if (document.forms['Preventivo'].da2.value == "")
					{
						document.forms['Preventivo'].da2.value = document.forms['Preventivo'].startperiodo2.value;
					 	document.forms['Preventivo'].a1.value = document.forms['Preventivo'].fineperiodo1.value;
					}
				}
				else 
				{

// 3° periodo
					date1temp = new Date(document.forms['Preventivo'].fineperiodo3.value);
					if (date2 <= date1temp)
					{
						document.forms['Preventivo'].a3.value = document.forms['Preventivo'].Partenza.value+ " 00:00:00";
						if (document.forms['Preventivo'].da3.value == "")
						{
							document.forms['Preventivo'].da3.value = document.forms['Preventivo'].startperiodo3.value;
						 	if (document.forms['Preventivo'].da2.value == ""){
								document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
								document.forms['Preventivo'].da2.value = document.forms['Preventivo'].startperiodo2.value;
								document.forms['Preventivo'].a1.value = document.forms['Preventivo'].fineperiodo1.value;
								}
								else
								{
								document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
						 	}
						}
					}
					else {

// 4° periodo
						date1temp = new Date(document.forms['Preventivo'].fineperiodo4.value);
						if (date2 <= date1temp){
							document.forms['Preventivo'].a4.value = document.forms['Preventivo'].Partenza.value+ " 00:00:00";
							if (document.forms['Preventivo'].da4.value == ""){
								document.forms['Preventivo'].da4.value = document.forms['Preventivo'].startperiodo4.value;
								if (document.forms['Preventivo'].da3.value == ""){
									document.forms['Preventivo'].a3.value = document.forms['Preventivo'].fineperiodo3.value;
									document.forms['Preventivo'].da3.value = document.forms['Preventivo'].startperiodo3.value;
									if (document.forms['Preventivo'].da2.value == ""){
										document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
										document.forms['Preventivo'].da2.value = document.forms['Preventivo'].startperiodo2.value;
										document.forms['Preventivo'].a1.value = document.forms['Preventivo'].fineperiodo1.value;
									}
									else
									{
										document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
						 			}
								}
								else
								{
									document.forms['Preventivo'].a3.value = document.forms['Preventivo'].fineperiodo3.value;
						 		}
							}
						}
						else {

// 5° periodo
							date1temp = new Date(document.forms['Preventivo'].fineperiodo5.value);
							if (date2 <= date1temp){
								document.forms['Preventivo'].a5.value = document.forms['Preventivo'].Partenza.value+ " 00:00:00";
								if (document.forms['Preventivo'].da5.value == ""){
									document.forms['Preventivo'].da5.value = document.forms['Preventivo'].startperiodo5.value;
									if (document.forms['Preventivo'].da4.value == ""){
										document.forms['Preventivo'].da4.value = document.forms['Preventivo'].startperiodo4.value;
										document.forms['Preventivo'].a4.value = document.forms['Preventivo'].fineperiodo4.value;
										if (document.forms['Preventivo'].da3.value == ""){
											document.forms['Preventivo'].a3.value = document.forms['Preventivo'].fineperiodo3.value;
											document.forms['Preventivo'].da3.value = document.forms['Preventivo'].startperiodo3.value;
											if (document.forms['Preventivo'].da2.value == ""){
												document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
												document.forms['Preventivo'].da2.value = document.forms['Preventivo'].startperiodo2.value;
												document.forms['Preventivo'].a1.value = document.forms['Preventivo'].fineperiodo1.value;
											}
											else
											{
												document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
								 			}
										}
										else
										{
											document.forms['Preventivo'].a3.value = document.forms['Preventivo'].fineperiodo3.value;
								 		}
									}
									else
									{
										document.forms['Preventivo'].a4.value = document.forms['Preventivo'].fineperiodo4.value;
							 		}
								}
							}
							else {

// 6° periodo
								date1temp = new Date(document.forms['Preventivo'].fineperiodo6.value);
								if (date2 <= date1temp){
									document.forms['Preventivo'].a6.value = document.forms['Preventivo'].Partenza.value+ " 00:00:00";
									if (document.forms['Preventivo'].da6.value == ""){
										document.forms['Preventivo'].da6.value = document.forms['Preventivo'].startperiodo6.value ;
										if (document.forms['Preventivo'].da5.value == ""){
											document.forms['Preventivo'].da5.value = document.forms['Preventivo'].startperiodo5.value;
											document.forms['Preventivo'].a5.value = document.forms['Preventivo'].fineperiodo5.value;
											if (document.forms['Preventivo'].da4.value == ""){
												document.forms['Preventivo'].da4.value = document.forms['Preventivo'].startperiodo4.value;
												document.forms['Preventivo'].a4.value = document.forms['Preventivo'].fineperiodo4.value;
												if (document.forms['Preventivo'].da3.value == ""){
													document.forms['Preventivo'].a3.value = document.forms['Preventivo'].fineperiodo3.value;
													document.forms['Preventivo'].da3.value = document.forms['Preventivo'].startperiodo3.value;
													if (document.forms['Preventivo'].da2.value == ""){
														document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
														document.forms['Preventivo'].da2.value = document.forms['Preventivo'].startperiodo2.value;
														document.forms['Preventivo'].a1.value = document.forms['Preventivo'].fineperiodo1.value;
													}
													else
													{
														document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
										 			}
												}
												else
												{
													document.forms['Preventivo'].a3.value = document.forms['Preventivo'].fineperiodo3.value;
										 		}
											}
											else
											{
												document.forms['Preventivo'].a4.value = document.forms['Preventivo'].fineperiodo4.value;
									 		}
										}
										else
										{
											document.forms['Preventivo'].a5.value = document.forms['Preventivo'].fineperiodo5.value;
								 		}
									}
								}
								else {

// 7° periodo
									date1temp = new Date(document.forms['Preventivo'].fineperiodo7.value);
									if (date2 <= date1temp){
										document.forms['Preventivo'].a7.value = document.forms['Preventivo'].Partenza.value+ " 00:00:00";
										if (document.forms['Preventivo'].da7.value == ""){
											document.forms['Preventivo'].da7.value = document.forms['Preventivo'].startperiodo7.value ;
											if (document.forms['Preventivo'].da6.value == ""){
												document.forms['Preventivo'].da6.value = document.forms['Preventivo'].startperiodo6.value ;
												document.forms['Preventivo'].a6.value = document.forms['Preventivo'].fineperiodo6.value ;
												if (document.forms['Preventivo'].da5.value == ""){
													document.forms['Preventivo'].da5.value = document.forms['Preventivo'].startperiodo5.value;
													document.forms['Preventivo'].a5.value = document.forms['Preventivo'].fineperiodo5.value;
													if (document.forms['Preventivo'].da4.value == ""){
														document.forms['Preventivo'].da4.value = document.forms['Preventivo'].startperiodo4.value;
														document.forms['Preventivo'].a4.value = document.forms['Preventivo'].fineperiodo4.value;
														if (document.forms['Preventivo'].da3.value == ""){
															document.forms['Preventivo'].a3.value = document.forms['Preventivo'].fineperiodo3.value;
															document.forms['Preventivo'].da3.value = document.forms['Preventivo'].startperiodo3.value;
															if (document.forms['Preventivo'].da2.value == ""){
																document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
																document.forms['Preventivo'].da2.value = document.forms['Preventivo'].startperiodo2.value;
																document.forms['Preventivo'].a1.value = document.forms['Preventivo'].fineperiodo1.value;
															}
															else
															{
																document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
												 			}
														}
														else
														{
															document.forms['Preventivo'].a3.value = document.forms['Preventivo'].fineperiodo3.value;
												 		}
													}
													else
													{
														document.forms['Preventivo'].a4.value = document.forms['Preventivo'].fineperiodo4.value;
											 		}
												}
												else
												{
													document.forms['Preventivo'].a5.value = document.forms['Preventivo'].fineperiodo5.value;
										 		}
											}
											else
											{
												document.forms['Preventivo'].a6.value = document.forms['Preventivo'].fineperiodo6.value;
									 		}
										}
									}
									else {
										
										date1temp = new Date(document.forms['Preventivo'].fineperiodo8.value);
										if (date2 <= date1temp){
											document.forms['Preventivo'].a8.value = document.forms['Preventivo'].Partenza.value+ " 00:00:00";
											if (document.forms['Preventivo'].da8.value == ""){
												document.forms['Preventivo'].da8.value = document.forms['Preventivo'].startperiodo8.value ;
												if (document.forms['Preventivo'].da7.value == ""){
													document.forms['Preventivo'].da7.value = document.forms['Preventivo'].startperiodo7.value ;
													document.forms['Preventivo'].a7.value = document.forms['Preventivo'].fineperiodo7.value ;
													if (document.forms['Preventivo'].da6.value == ""){
														document.forms['Preventivo'].da6.value = document.forms['Preventivo'].startperiodo6.value ;
														document.forms['Preventivo'].a6.value = document.forms['Preventivo'].fineperiodo6.value ;
														if (document.forms['Preventivo'].da5.value == ""){
															document.forms['Preventivo'].da5.value = document.forms['Preventivo'].startperiodo5.value;
															document.forms['Preventivo'].a5.value = document.forms['Preventivo'].fineperiodo5.value;
															if (document.forms['Preventivo'].da4.value == ""){
																document.forms['Preventivo'].da4.value = document.forms['Preventivo'].startperiodo4.value;
																document.forms['Preventivo'].a4.value = document.forms['Preventivo'].fineperiodo4.value;
																if (document.forms['Preventivo'].da3.value == ""){
																	document.forms['Preventivo'].a3.value = document.forms['Preventivo'].fineperiodo3.value;
																	document.forms['Preventivo'].da3.value = document.forms['Preventivo'].startperiodo3.value;
																	if (document.forms['Preventivo'].da2.value == ""){
																		document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
																		document.forms['Preventivo'].da2.value = document.forms['Preventivo'].startperiodo2.value;
																		document.forms['Preventivo'].a1.value = document.forms['Preventivo'].fineperiodo1.value;
																	}
																	else
																	{
																		document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
																	}
																}
																else
																{
																	document.forms['Preventivo'].a3.value = document.forms['Preventivo'].fineperiodo3.value;
																}
															}
															else
															{
																document.forms['Preventivo'].a4.value = document.forms['Preventivo'].fineperiodo4.value;
															}
														}
														else
														{
															document.forms['Preventivo'].a5.value = document.forms['Preventivo'].fineperiodo5.value;
														}
													}
													else
													{
														document.forms['Preventivo'].a6.value = document.forms['Preventivo'].fineperiodo6.value;
													}
												}
												else
												{
													document.forms['Preventivo'].a7.value = document.forms['Preventivo'].fineperiodo7.value;
												}
											}
										}
										else {
										
										date1temp = new Date(document.forms['Preventivo'].fineperiodo9.value);
										if (date2 <= date1temp){
											document.forms['Preventivo'].a9.value = document.forms['Preventivo'].Partenza.value+ " 00:00:00";
											if (document.forms['Preventivo'].da9.value == ""){
												document.forms['Preventivo'].da9.value = document.forms['Preventivo'].startperiodo9.value ;
												if (document.forms['Preventivo'].da8.value == ""){
													document.forms['Preventivo'].da8.value = document.forms['Preventivo'].startperiodo8.value ;
														document.forms['Preventivo'].a8.value = document.forms['Preventivo'].fineperiodo8.value ;
													if (document.forms['Preventivo'].da7.value == ""){
														document.forms['Preventivo'].da7.value = document.forms['Preventivo'].startperiodo7.value ;
															document.forms['Preventivo'].a7.value = document.forms['Preventivo'].fineperiodo7.value ;
														if (document.forms['Preventivo'].da6.value == ""){
															document.forms['Preventivo'].da6.value = document.forms['Preventivo'].startperiodo6.value ;
															document.forms['Preventivo'].a6.value = document.forms['Preventivo'].fineperiodo6.value ;
															if (document.forms['Preventivo'].da5.value == ""){
																document.forms['Preventivo'].da5.value = document.forms['Preventivo'].startperiodo5.value;
																document.forms['Preventivo'].a5.value = document.forms['Preventivo'].fineperiodo5.value;
																if (document.forms['Preventivo'].da4.value == ""){
																	document.forms['Preventivo'].da4.value = document.forms['Preventivo'].startperiodo4.value;
																	document.forms['Preventivo'].a4.value = document.forms['Preventivo'].fineperiodo4.value;
																	if (document.forms['Preventivo'].da3.value == ""){
																		document.forms['Preventivo'].a3.value = document.forms['Preventivo'].fineperiodo3.value;
																		document.forms['Preventivo'].da3.value = document.forms['Preventivo'].startperiodo3.value;
																		if (document.forms['Preventivo'].da2.value == ""){
																			document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
																			document.forms['Preventivo'].da2.value = document.forms['Preventivo'].startperiodo2.value;
																			document.forms['Preventivo'].a1.value = document.forms['Preventivo'].fineperiodo1.value;
																		}
																		else
																		{
																			document.forms['Preventivo'].a2.value = document.forms['Preventivo'].fineperiodo2.value;
																		}
																	}
																	else
																	{
																		document.forms['Preventivo'].a3.value = document.forms['Preventivo'].fineperiodo3.value;
																	}
																}
																else
																{
																	document.forms['Preventivo'].a4.value = document.forms['Preventivo'].fineperiodo4.value;
																}
															}
															else
															{
																document.forms['Preventivo'].a5.value = document.forms['Preventivo'].fineperiodo5.value;
															}
														}
														else
														{
															document.forms['Preventivo'].a6.value = document.forms['Preventivo'].fineperiodo6.value;
														}
													}
													else
													{
														document.forms['Preventivo'].a7.value = document.forms['Preventivo'].fineperiodo7.value;
													}
												}
												else
													{
														document.forms['Preventivo'].a8.value = document.forms['Preventivo'].fineperiodo8.value;
													}
												}
										
												else
												{

// eventuali altri periodi da aggiungere con la stessa logica

// alla chiusura di tutto mantenere perņ else{//alert("Data di Fine non valida");}

										//alert("Data di Fine non valida");
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		
// controllare che tutti i periodi siano presenti			
		
			if (!(document.forms['Preventivo'].da1.value =="")){
				date1temp = new Date(document.forms['Preventivo'].a1.value)
				date2temp = new Date(document.forms['Preventivo'].da1.value)
				diff.setTime(Math.abs(date1temp.getTime() - date2temp.getTime()));
				timediff = diff.getTime();
				days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
				document.forms['Preventivo'].giorni1.value = days
			}
			else
			{
				document.forms['Preventivo'].giorni1.value = 0;
			}
			
			if (!(document.forms['Preventivo'].da2.value =="")){
				date1temp = new Date(document.forms['Preventivo'].a2.value)
				date2temp = new Date(document.forms['Preventivo'].da2.value)
				diff.setTime(Math.abs(date1temp.getTime() - date2temp.getTime()));
				timediff = diff.getTime();
				days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
				document.forms['Preventivo'].giorni2.value = days
				if (!(document.forms['Preventivo'].da1.value ==""))
				{
					days = parseInt(document.forms['Preventivo'].giorni1.value);
					days = days + 1;
					document.forms['Preventivo'].giorni1.value = days;
				}
			}
			else
			{
				document.forms['Preventivo'].giorni2.value = 0;
			}				
			if (!(document.forms['Preventivo'].da3.value =="")){
				date1temp = new Date(document.forms['Preventivo'].a3.value)
				date2temp = new Date(document.forms['Preventivo'].da3.value)
				diff.setTime(Math.abs(date1temp.getTime() - date2temp.getTime()));
				timediff = diff.getTime();
				days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
				document.forms['Preventivo'].giorni3.value = days
	
				if (!(document.forms['Preventivo'].da2.value ==""))
				{
					days = parseInt(document.forms['Preventivo'].giorni2.value);
					days = days + 1;
					document.forms['Preventivo'].giorni2.value = days;
				}
			}
			else
			{
				document.forms['Preventivo'].giorni3.value = 0;
			}				
			if (!(document.forms['Preventivo'].da4.value =="")){
				date1temp = new Date(document.forms['Preventivo'].a4.value)
				date2temp = new Date(document.forms['Preventivo'].da4.value)
				diff.setTime(Math.abs(date1temp.getTime() - date2temp.getTime()));
				timediff = diff.getTime();
				days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
				document.forms['Preventivo'].giorni4.value = days
				if (!(document.forms['Preventivo'].da3.value ==""))
				{
					days = parseInt(document.forms['Preventivo'].giorni3.value);
					days = days + 1;
					document.forms['Preventivo'].giorni3.value = days;
				}
			}
			else
			{
				document.forms['Preventivo'].giorni4.value = 0;
			}				
			if (!(document.forms['Preventivo'].da5.value =="")){
				date1temp = new Date(document.forms['Preventivo'].a5.value)
				date2temp = new Date(document.forms['Preventivo'].da5.value)
				diff.setTime(Math.abs(date1temp.getTime() - date2temp.getTime()));
				timediff = diff.getTime();
				days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
				document.forms['Preventivo'].giorni5.value = days
				if (!(document.forms['Preventivo'].da4.value ==""))
				{
					days = parseInt(document.forms['Preventivo'].giorni4.value);
					days = days + 1;
					document.forms['Preventivo'].giorni4.value = days;
				}
			}
			else
			{
			document.forms['Preventivo'].giorni5.value = 0;
			}				
			if (!(document.forms['Preventivo'].da6.value =="")){
				date1temp = new Date(document.forms['Preventivo'].a6.value)
				date2temp = new Date(document.forms['Preventivo'].da6.value)
				diff.setTime(Math.abs(date1temp.getTime() - date2temp.getTime()));
				timediff = diff.getTime();
				days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
				document.forms['Preventivo'].giorni6.value = days
				if (!(document.forms['Preventivo'].da5.value ==""))
				{
					days = parseInt(document.forms['Preventivo'].giorni5.value);
					days = days + 1;
					document.forms['Preventivo'].giorni5.value = days;
				}
			}
			else
			{
				document.forms['Preventivo'].giorni6.value = 0;
			}				
			if (!(document.forms['Preventivo'].da7.value =="")){
				date1temp = new Date(document.forms['Preventivo'].a7.value)
				date2temp = new Date(document.forms['Preventivo'].da7.value)
				diff.setTime(Math.abs(date1temp.getTime() - date2temp.getTime()));
				timediff = diff.getTime();
				days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
				document.forms['Preventivo'].giorni7.value = days
				if (!(document.forms['Preventivo'].da6.value ==""))
				{
					days = parseInt(document.forms['Preventivo'].giorni6.value);
					days = days + 1;
					document.forms['Preventivo'].giorni6.value = days;
				}
			}
			else
			{
				document.forms['Preventivo'].giorni7.value = 0;
			}
			
			if (!(document.forms['Preventivo'].da8.value =="")){
				date1temp = new Date(document.forms['Preventivo'].a8.value)
				date2temp = new Date(document.forms['Preventivo'].da8.value)
				diff.setTime(Math.abs(date1temp.getTime() - date2temp.getTime()));
				timediff = diff.getTime();
				days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
				document.forms['Preventivo'].giorni8.value = days
				if (!(document.forms['Preventivo'].da7.value ==""))
				{
					days = parseInt(document.forms['Preventivo'].giorni7.value);
					days = days + 1;
					document.forms['Preventivo'].giorni7.value = days;
				}
			}
			else
			{
				document.forms['Preventivo'].giorni8.value = 0;
			}
			if (!(document.forms['Preventivo'].da9.value =="")){
				date1temp = new Date(document.forms['Preventivo'].a9.value)
				date2temp = new Date(document.forms['Preventivo'].da9.value)
				diff.setTime(Math.abs(date1temp.getTime() - date2temp.getTime()));
				timediff = diff.getTime();
				days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
				document.forms['Preventivo'].giorni9.value = days
				if (!(document.forms['Preventivo'].da8.value ==""))
				{
					days = parseInt(document.forms['Preventivo'].giorni8.value);
					days = days + 1;
					document.forms['Preventivo'].giorni8.value = days;
				}
			}
			else
			{
				document.forms['Preventivo'].giorni9.value = 0;
			}
			document.forms['Preventivo'].submit();
		}
							
	}