function Trim(StringToTrim) { 
// CONTROLLA CHE IL VALORE IN INPUT SIA DI TIPO STRING
if (typeof(StringToTrim) != "string") { return StringToTrim; }
// CATTURA IL PRIMO CARATTERE DELLA STRINGA PER CONTROLLARE CHE NON SIA UNO SPAZIO VUOTO
var StringBlank = StringToTrim.substring(0, 1);
// ELIMINA LO SPAZIO VUOTO DALLA PRIMA POSIZIONE DELLA STRINGA 
while (StringBlank == " ") { 
StringToTrim = StringToTrim.substring(1, StringToTrim.length); 
StringBlank = StringToTrim.substring(0, 1);
}
// CATTURA L'ULTIMO CARATTERE DELLA STRINGA PER CONTROLLARE CHE NON SIA UNO SPAZIO VUOTO 
StringBlank = StringToTrim.substring(StringToTrim.length - 1, StringToTrim.length);
// ELIMINA LO SPAZIO VUOTO DALL'ULTIMA POSIZIONE DELLA STRINGA 
while (StringBlank == " ") {
StringToTrim = StringToTrim.substring(0, StringToTrim.length-1); 
StringBlank = StringToTrim.substring(StringToTrim.length-1, StringToTrim.length); 
} 
// ELIMINA POTENZIALI SPAZI VUOTI MULTIPLI ALL'INIZIO ED ALLA FINE DI UNA STRINGA 
while (StringToTrim.indexOf(" ") != -1) {
StringToTrim = StringToTrim.substring(0, StringToTrim.indexOf(" ")); 
StringToTrim += StringToTrim.substring(StringToTrim.indexOf(" ") + 1, StringToTrim.length);
}
// RESTITUISCE IL VALORE FINALE SENZA SPAZI VUOTI DI CONTORNO 
return StringToTrim;
}

function OpenPOP_UP(strURL,top,left){
  window.open(strURL,'winpopup','width=400,height=230,status=1,scrollbars=yes');
}



function checkdate(Valuetext){

//	window.onerror=null // for all other strange errors
	var err=0

	//a=document.frm.dat.value
    
	a = Valuetext;
	
	if (a.length != 10) err=1

	b = a.substring(3, 5)// mese

	c = a.substring(2, 3)// '/'

	d = a.substring(0, 2)// giorno

	e = a.substring(5, 6)// '/'

	f = a.substring(9, 10)// anno

	//basic error checking
	if (b<1 || b>12) err = 1

	if (c != '/') err = 1

	if (d<1 || d>31) err = 1

	if (e != '/') err = 1

	if (f<0 || f>99) err = 1


	//advanced error checking

	// months with 30 days

	if (b==4 || b==6 || b==9 || b==11){
		if (d==31) err=1
	}



	// february, leap year
	if (b==2){

		// feb

		var g=parseInt(f/4)

		if (isNaN(g)) {

			err=1

		}



		if (d>29) err=1

		if (d==29 && ((f/4)!=parseInt(f/4))) err=1

	}

	if (err==1){
	   return false;
		//alert('Inserimento Errato');
	}
	else{
	   return true;
		//alert('OK!');
	}

}



function verificaForm(arg){
	if (Trim(arg.c20.value) == "")
	{
	alert("Inserire il Nome e cognome prenotante e primo passeggero")
	arg.c20.focus();
	return false;
	}
	if (Trim(arg.c21.value) == "")
	{
	alert("Inserire l'Indirizzo")
	arg.c21.focus();
	return false;
	}

	if (Trim(arg.c22.value) == "")
	{
	alert("Inserire il cap")
	arg.c22.focus();
	return false;
	}
	if (Trim(arg.c23.value) == "")
	{
	alert("Inserire la cittā")
	arg.c23.focus();
	return false;
	}
	if (Trim(arg.c24.value) == "")
	{
	alert("Inserire la provincia")
	arg.c24.focus();
	return false;
	}
	if (Trim(arg.c25.value) == "")
	{
	alert("Inserire il telefono")
	arg.c25.focus();
	return false;
	}
	if (Trim(arg.c28.value) == "")
	{
	alert("Inserire la mail")
	arg.c28.focus();
	return false;
	}



	//controllo inserimento corretto mail
	var x = arg.c28.value;
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) ;
	else 
	{
		alert("L'indirizzo mail inserito non č corretto");
		return false;
	}
	
	//verifico se l'utente a accettato la legge sulla privacy
	var check = false; 
	//ciclo tutti i radio per verificare se almeno uno č stato selezionato
	for(var i=0; i<arg.c35.length; i++) { 
		if(arg.c35[i].checked){
			// se uno č stato selezionato verifico che sia il si e non il no(0) in que'ultimo caso restituisco un messaggio e blocco le'esecuzione
			check = true; 
			myvar = arg.c35[i].value;
			if (myvar==0){
				alert("L'accettazione allo statuto č obbligatoria");
				return false;
			}
		}
	} 

	if(check==false){ 
	alert("L\'accettazione della legge sulla privacy č obbligatoria"); 
	return false;
	} 



return true;
}


function controllo(arg){
	if (Trim(arg.codice.value)==""){
		alert("Inserire il codice prenotazione")
		arg.codice.focus()
		return false
	}
}

function controllo2(arg){
	var contatore = 0;
	var messaggio = "";
	if (Trim(arg.nominativo.value)!=""){
			  contatore = contatore + 1
			  }
	if (Trim(arg.tel.value)!=""){
			  contatore = contatore + 1
			  }
	if (Trim(arg.mail.value)!=""){
			  
			  	//controllo inserimento corretto mail
				var x = arg.mail.value;
				var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (filter.test(x)){					
					contatore = contatore + 1				
				}else {
					messaggio = messaggio + "L'indirizzo mail inserito non č corretto";
					
				}
	  }
	/*if (Trim(arg.data.value)!=""){
			if (checkdate(arg.data.value) == false){
			   messaggio = messaggio + "\n Non č stata inserita una data partenza valida";
			  } else{
					contatore = contatore + 1  
			  }
		}
	if (Trim(arg.dest.value)!="0"){
			  contatore = contatore + 1
			  }*/
	
	if ((contatore<2 ) && (messaggio=="")){
		alert("Inserire almeno due criteri di ricerca")
		return false
	}else if(messaggio|= ""){
		alert(messaggio)
		return false
	}else{
		return true	
	}
}

function aggiorna(){
	document.form1.submit();
}

function verifica(tipo) {
	if (document.form1.destinazione.value == "0")
	{
	alert("Selezionare la destinazione")
	document.form1.destinazione.focus();
	return false;
	}
	
	/*if (document.form1.localita.value == "0")
	{
	alert("Selezionare la localitā")
	document.form1.localita.focus();
	return false;
	}*/

	if (document.ins.tipo.value == "0")
	{
	alert("Selezionare il tipo viaggio")
	document.ins.tipo.focus();
	return false;
	}

	if (document.ins.titolo.value == "")
	{
	alert("Inserire il titolo dell'offerta")
	document.ins.titolo.focus();
	return false;
	}
	/*entro solo in inserimneto offerta*/
	


document.ins.destinazione.value = document.form1.destinazione.options[document.form1.destinazione.selectedIndex].value
document.ins.localita.value = document.form1.localita.options[document.form1.localita.selectedIndex].value
}

