/**
 * @author Beatrice Bartoli
 */
function cambiaArrivo()
{
	var riga=document.getElementById('partenza');
	var parr=document.getElementById('parr');
	var i=riga.selectedIndex;
	if(riga.options[i].value!='')
	{
		parr.style.display="inline";
	}

}

function controllo()
{
	var adulti=document.getElementById('adulti');
	var bambini=document.getElementById('bambini');
	var auto=document.getElementById('auto');
	var rimorchi=document.getElementById('furgoni');
	var moto=document.getElementById('moto');
	var dataa=document.getElementById('dataa');
	var datar=document.getElementById('datar');
	var errore='';
	var roulotte = 0;
	if(auto.value==1 && rimorchi.value==1)
	{
	 roulotte=1;
	}

	try {
			datarList=datar.value.split('/');
			datarD=new Date(datarList[2],(datarList[1]-1),datarList[0]);
		}
		catch (e) {
			datarD = false;
		}

	var data =new Date()
	dataaList=dataa.value.split('/');
	anno = new String(dataaList[2]);
	dataaD=new Date(dataaList[2],(dataaList[1]-1),dataaList[0]);
	if(datarD!==false)
	{
		if(dataaD.getTime()>datarD.getTime())
		{
			errore=errore+"La data ri partenza deve essere inferiore alla data di ritorno\n";
		}
	}
	if(dataaD.getTime()<=data.getTime())
	{
		errore=errore+"La data di pertenza deve essere superiore alla data odierna\n";
	}

	var veicoli=parseInt(parseInt(auto.value)+parseInt(rimorchi.value)+parseInt(moto.value));
	var passeggeri=(parseInt(adulti.value)+parseInt(bambini.value));
	var adul=parseInt(adulti.value);
	if(veicoli>2)
	{
		errore=errore+'Pu\u00F2  essere emesso un biglietto per un totale massimo di 4 passeggeri e 2 veicoli'+"\n";
	}
	if(veicoli>2)
	{
		errore=errore+"I veicoli possono essere massimo 2 \n";
	}
	if(adul<veicoli && roulotte<1)
	{
		errore=errore+"I veicoli inseriti non possono essere in numero maggiore dei passeggeri adulti\n";
	}
	if(passeggeri>4)
	{
		errore=errore+"Pu\u00F2  essere emesso un biglietto per un totale massimo di 4 passeggeri e 2 veicoli\n";
	}
	if (errore == '') {
		return true;
	}
	else
	{
		alert(errore);
		return false;
	}
}

function controlloAuto(lunghezza, tipo)
{
	i=tipo.selectedIndex;
	if(isNaN(lunghezza.value))
	{
		lunghezza.value='0.00';
		alert('La lunghezza dei veicoli deve essere espressa con un valore numerico (es. 4.00)');
	}
	else if((tipo[i].value=='CAR' || tipo[i].value=='FUR') && (lunghezza.value>9 || lunghezza.value<1))
	{
		lunghezza.value='0.00';
		alert('La lunghezza del veicolo deve essere tra 1 m e 9 m');
	}
	else if(tipo[i].value=='CRV' && (lunghezza.value>12 || lunghezza.value<1))
	{
		lunghezza.value='0.00';
		alert('La lunghezza del veicolo deve essere tra 1 m e 12 m');
	}

}

function controlloRimorchi(lunghezza)
{
	i=tipo.selectedIndex;
	if(isNaN(lunghezza.value))
	{
		lunghezza.value='0.00';
		alert('La lunghezza dei veicoli deve essere espressa con un valore numerico (es. 4.00)');
	}
	else if(lunghezza.value>12 || lunghezza.value<1)
	{
		lunghezza.value='0.00';
		alert('La lunghezza del veicolo deve essere tra 1 m e 12 m');
	}

}


function cambiaBambini()
{
	var adulti=document.getElementById('adulti');
	var i=adulti.selectedIndex;

}

function addArrivo()
{
	var riga=document.getElementById('partenza');
	var parr=document.getElementById('parr');
	var i=riga.selectedIndex;
	if(riga.options[i].value!='')
	{
		parr.style.display="inline";
	}
	else
	{
		parr.style.display="none";
	}
}

function addTipo()
{
	var riga=document.getElementById('arrivo');
	var subm=document.getElementById('av');
	var i=riga.selectedIndex;

	if(riga.options[i].value!='')
	{
		
		if (riga.options[i].value.length > 3) {
			location.href = riga.options[i].value;
		}
		else {
			subm.disabled = false;
			subm.src = '../images/avanti.gif';
		}
	}
	else
	{
		subm.disabled=true;
		subm.src='../images/avantiDis.png';
	}
}
function addDate()
{
	var riga=document.getElementById('dataRit');
	riga.style.display="inline";
}
function delDate()
{
	var riga=document.getElementById('dataRit');
	riga.style.display="none";
}