function checkCR(evt) {
    var evt  = (evt) ? evt : ((event) ? event : null);
    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
    if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
  }
document.onkeypress = checkCR;



function trim(stringa) {
		while (stringa.substring(0,1) == ' ') {
			stringa = stringa.substring(1, stringa.length);
		}
		while (stringa.substring(stringa.length-1, stringa.length) == ' ') {
			stringa = stringa.substring(0,stringa.length-1);
		}
	return stringa;
}


function len(StrToLen) {
  return StrToLen.length;
}



function popup(src,nome,w,h) {
  mia_finestra = window.open(src,nome,'scrollbars=no,resizable=no,width='+w+',height='+h+',status=no,location=0,locationBar=0,menuBar=0,resizable=0,toolbar=0');
  mia_finestra.moveTo(0,0);
}



function ControllaCF(cf) {
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return "La lunghezza del codice fiscale non è\n"
		+"corretta: il codice fiscale dovrebbe essere lungo\n"
		+"esattamente 16 caratteri.\n";
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return "Il codice fiscale contiene un carattere non valido `" +
				cf.charAt(i) +
				"'.\nI caratteri validi sono le lettere e le cifre.\n";
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
		return "Il codice fiscale non è corretto:\n"+
			"il codice di controllo non corrisponde.\n";
	return "";
}



function Validator_login() {
	var password  = trim(document.getElementById("password").value);
	
	if ((password == "") || (password == "undefined")) {
	   alert("Inserire la password!!");
		document.getElementById("password").focus();
	} else {
		document.login.submit();
	}
}

function Validator_login_photogallery() {
	var password  = trim(document.getElementById("pass_photo").value);
	
	if ((password == "") || (password == "undefined")) {
	   alert("Inserire la password!!");
		document.getElementById("pass_photo").focus();
	} else {
		document.login_photogallery.submit();
	}
}



function Validator_newsletter() {
	var nome    = trim(document.contatti.nome.value);
	var cognome = trim(document.contatti.cognome.value);
	var email   = trim(document.contatti.email.value);
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if ((nome == "") || (nome == "undefined")) {
	   alert("I campi contrassegnati da * sono obbligatori!!");
	   document.contatti.nome.focus();
	return false;
	}
	
	if ((cognome == "") || (cognome == "undefined")) {
	   alert("I campi contrassegnati da * sono obbligatori!!");
	   document.contatti.cognome.focus();
	return false;
	}
	
	if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
		alert("Inserire un indirizzo email corretto!!");
		document.contatti.email.select();
	return false;
	}

document.contatti.submit();
}

function Validator_accredito(lng) {
  var testata       = trim(document.accredito.testata.value);
  var nome          = trim(document.accredito.nome.value);
	var cognome       = trim(document.accredito.cognome.value);
	var email         = trim(document.accredito.email.value);
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	var checkbox_check = false;
	if (lng == "ita") {
  	var indirizzo  = trim(document.accredito.indirizzo.value);
  	var cap        = trim(document.accredito.cap.value);
  	var citta      = trim(document.accredito.citta.value);
    var provincia  = trim(document.accredito.provincia.value);
  	var stato      = trim(document.accredito.stato.value);
    var telefono   = trim(document.accredito.telefono.value);
    var errore     = "I campi contrassegnati da * sono obbligatori!!"
    var errore2    = "Campo numerico e obbligatorio"
  } else {
    var errore     = "Fields marked by * are mandatory!!"
  }

  
  if ((nome == "") || (nome == "undefined")) {
	   alert(errore);
	   document.accredito.nome.focus();
	return false;
	}
	
	if ((cognome == "") || (cognome == "undefined")) {
	   alert(errore);
	   document.accredito.cognome.focus();
	return false;
	}
	
  if ((testata == "") || (testata == "undefined")) {
	   alert(errore);
	   document.accredito.testata.focus();
	return false;
	}
  
	if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
	   alert(errore);
		 document.accredito.email.select();
	return false;
	}
  
	for (i=1;i<=2;i++) {
		if ((checkbox_check) || (document.accredito["servizio"+i].checked)) {
			checkbox_check=true;
		}
	}
	if (!checkbox_check) {
	   alert(errore);
	return false;
	}
  
	if (lng == "ita") {
  	if ((indirizzo == "") || (indirizzo == "undefined")) {
  	   alert(errore);
  	   document.accredito.indirizzo.focus();
  	return false;
  	}
  	
  	if ((isNaN(cap)) || (cap == "") || (cap == "undefined")) {
  		alert(errore2);
  		document.accredito.cap.value = "";
  		document.accredito.cap.focus();
  	return false;
  	}
  	
  	if ((citta == "") || (citta == "undefined")) {
  	   alert(errore);
  	   document.accredito.citta.focus();
  	return false;
  	}
    
  	if ((provincia == "") || (provincia == "undefined")) {
  	   alert(errore);
  	   document.accredito.provincia.focus();
  	return false;
  	}
  	
  	if ((stato == "") || (stato == "undefined")) {
  	   alert(errore);
  	   document.accredito.stato.focus();
  	return false;
  	}
  	
  	if ((telefono == "") || (telefono == "undefined")) {
  	   alert(errore);
  	   document.accredito.telefono.focus();
  	return false;
  	}
  } 
	
document.accredito.submit();

//disattivato dal 13/10/2009
/*if (lng != "eng") {
  alert ("LA REGISTRAZIONE ON-LINE È CHIUSA.");
} else {
  alert ("THE ON-LINE REGISTRATION IS CLOSED.");
}*/
}

function Validator_contatti() {	
	var referente = trim(document.contatti.referente.value);
	var nome      = trim(document.contatti.nome.value);
	var cognome   = trim(document.contatti.cognome.value);
	var telefono  = trim(document.contatti.telefono.value);
	var email     = trim(document.contatti.email.value);
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

  if ((referente == "") || (referente == "undefined")) {
	   alert("I campi contrassegnati da * sono obbligatori!!");
	   document.contatti.referente.focus();
	return false;
	}
  
  if ((nome == "") || (nome == "undefined")) {
	   alert("I campi contrassegnati da * sono obbligatori!!");
	   document.contatti.nome.focus();
	return false;
	}
	
	if ((cognome == "") || (cognome == "undefined")) {
	   alert("I campi contrassegnati da * sono obbligatori!!");
	   document.contatti.cognome.focus();
	return false;
	}
	
	if ((telefono == "") || (telefono == "undefined")) {
	   alert("I campi contrassegnati da * sono obbligatori!!");
	   document.contatti.telefono.focus();
	return false;
	}
	
	if (email != "") {
		if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
			alert("Inserire un indirizzo email corretto!!");
			document.contatti.email.select();
		return false;
		}
	}

document.contatti.submit();
}

function Validator_hotel(lng) {	
	var nome = trim(document.hotel.nome.value);
	var cognome = trim(document.hotel.cognome.value);
	var email = trim(document.hotel.email.value);
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	
	if (lng != "eng") {
    var ragione_sociale = trim(document.hotel.ragione_sociale.value);
  	var codice_fiscale = trim(document.hotel.codice_fiscale.value);
  	var piva = trim(document.hotel.piva.value);
  }
	
	var myhotel = trim(document.hotel.myhotel.value);
	var checkbox_check = false;	

	if ((nome == "") || (nome == "undefined")) {
	   alert("I campi contrassegnati da * sono obbligatori!!");
	   document.hotel.nome.focus();
	return false;
	}
	
	if ((cognome == "") || (cognome == "undefined")) {
	   alert("I campi contrassegnati da * sono obbligatori!!");
	   document.hotel.cognome.focus();
	return false;
	}
		
	if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
		alert("Inserire un indirizzo email corretto!!");
		document.hotel.email.select();
	return false;
	}
	
	if (lng != "eng") {
  	if (document.getElementById("fattura").checked) {
    	if ((ragione_sociale == "") || (ragione_sociale == "undefined")) {
    	   alert("I campi contrassegnati da * sono obbligatori!!");
    	   document.hotel.ragione_sociale.focus();
    	return false;
    	}
    
    	if ((codice_fiscale == "") || (codice_fiscale == "undefined")) {
    	   alert("I campi contrassegnati da * sono obbligatori!!");
    	   document.hotel.codice_fiscale.focus();
    	return false;
    	}
    
    	if ((piva == "") || (piva == "undefined")) {
    	   alert("I campi contrassegnati da * sono obbligatori!!");
    	   document.hotel.piva.focus();
    	return false;
    	}
    }
  }
  
  if ((myhotel == "") || (myhotel == "undefined")) {
	   alert("I campi contrassegnati da * sono obbligatori!!");
	   document.hotel.myhotel.focus();
	return false;
	}
  
	for (i=1;i<=3;i++) {
		if ((checkbox_check) || (document.hotel["camera"+i].checked)) {
			checkbox_check=true;
		}
	}
	if (!checkbox_check) {
	   alert("I campi contrassegnati da * sono obbligatori!!");
	return false;
	}

document.hotel.submit();
}

function Validator_photogallery() {	
	var nome = trim(document.photogallery.nome.value);
	var cognome = trim(document.photogallery.cognome.value);
	var email = trim(document.photogallery.email.value);
	var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if ((nome == "") || (nome == "undefined")) {
	   alert("Tutti i campi sono obbligatori!!");
	   document.photogallery.nome.focus();
	return false;
	}
	
	if ((cognome == "") || (cognome == "undefined")) {
	   alert("Tutti i campi sono obbligatori!!");
	   document.photogallery.cognome.focus();
	return false;
	}
	
	if (email != "") {
		if (!email_reg_exp.test(email) || (email == "") || (email == "undefined")) {
			alert("Inserire un indirizzo email corretto!!");
			document.photogallery.email.select();
		return false;
		}
	}

document.photogallery.submit();
}

function hotels(quale) {
  /*var aperto = "no";

  if (document.getElementById("dettaglio"+quale).style.display == "block") {
    aperto = "si";
  }  
  
  for (i=1;i<=5;i++) {
    document.getElementById("dettaglio"+i).style.display = 'none';
    document.getElementById("img"+i).src = '../img/info.gif';
  }

  if (aperto != "si") {
    document.getElementById("dettaglio"+quale).style.display = 'block';
    document.getElementById("img"+quale).src = '../img/info_h.gif'; 
  } */
  
  if (document.getElementById("dettaglio"+quale).style.display == "block") {
    document.getElementById("dettaglio"+quale).style.display = 'none';
    document.getElementById("img"+quale).src = '../img/info.gif';
  } else {
    document.getElementById("dettaglio"+quale).style.display = 'block';
    document.getElementById("img"+quale).src = '../img/info_h.gif'; 
  }
}

function mostra() {
  if (document.getElementById("fattura").checked) {
    document.getElementById("nascondi1").style.display = 'block';
  } else {
    document.getElementById("nascondi1").style.display = 'none';
  }
}

function mostra2() {
  if (document.getElementById("corsi").checked) {
    document.getElementById("nascondi").style.display = 'block';
  } else {
    document.getElementById("nascondi").style.display = 'none';
  }
}

function Validator_espositori1() {
	var parola_chiave           = document.ricerca1.parola_chiave.value;
	var elenco_alfabetico       = document.ricerca1.elenco_alfabetico.value;
	var categorie_merceologiche = document.ricerca1.categorie_merceologiche.value;	
	var padiglione              = document.ricerca1.padiglione.value;
	var campi_check             = false;
	
	if (parola_chiave != "") {
    if (parola_chiave.length < 3) {
       alert("Inserire un termine di almeno 3 caratteri!!");
       document.ricerca1.parola_chiave.focus();
    return false;
    } else {
      campi_check = true;
    }
  }
  
  if (elenco_alfabetico != "") {
    campi_check = true;
  }
  
  if (categorie_merceologiche != "") {
    campi_check = true;
  }
  
  if (padiglione != "") {
    campi_check = true;
  }
  
	if (!campi_check) {
		alert("È obbligatorio inserire almeno un parametro per la ricerca");
	return false;
	}
  
document.ricerca1.submit();
}

function Validator_espositori2(lng) {
	var ragione_sociale = document.ricerca2.ragione_sociale.value;
	var nazione         = document.ricerca2.nazione.value;	
	var campi_check     = false;
	
	if (ragione_sociale != "") {
    if (ragione_sociale.length < 3) {
       alert("Inserire un termine di almeno 3 caratteri!!");
       document.ricerca2.ragione_sociale.focus();
    return false;
    } else {
      campi_check = true;
    }
  }
  
  if (nazione != "") {
    campi_check = true;
  }
  
  if (lng != "eng") {
    var provincia = document.ricerca2.provincia.value;
    if (provincia != "") {
      campi_check = true;
    }
  }
  
	if (!campi_check) {
		alert("È obbligatorio inserire almeno un parametro per la ricerca");
	return false;
	}
  
document.ricerca2.submit();
}