// JavaScript Document
function evid (mio_elemento, classe, ultimo) {
  var elemento = document.getElementById(mio_elemento);

  if (ultimo == "l") {
	 elemento.className = classe+' last';
  } else {
	 elemento.className = classe;  
  }
}

function devid (mio_elemento, ultimo) {
  var elemento = document.getElementById(mio_elemento);

  if (ultimo == "l") {
	 elemento.className = 'last';
  } else {
	 elemento.className = '';  
  }
}

function linka (id1,id2,id3){
  document.location.href = 'scheda.asp?id1='+id1+'&id2='+id2;
}

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;
}

// controli del form contatti in lingua
function Validator() {
	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,})+$/; 
	var sito          = trim(document.contatti.sito.value);
  var lng           = document.contatti.lng.value;
  
  //selezione dei messaggi in base alla lingua attuale
  switch (lng) {
    case "eng" :
      var msg1 = "I campi contrassegnati da * sono obbligatori!!";
      var msg2 = "Inserire un indirizzo email corretto!!";
      var msg3 = "Il campo \"Sito\" deve cominciare con http://!!";
      break;
    case "fra" :
      var msg1 = "I campi contrassegnati da * sono obbligatori!!";
      var msg2 = "Inserire un indirizzo email corretto!!";
      var msg3 = "Il campo \"Sito\" deve cominciare con http://!!";
      break;
    case "deu" :
      var msg1 = "I campi contrassegnati da * sono obbligatori!!";
      var msg2 = "Inserire un indirizzo email corretto!!";
      var msg3 = "Il campo \"Sito\" deve cominciare con http://!!";
      break;
    case "esp" :
      var msg1 = "I campi contrassegnati da * sono obbligatori!!";
      var msg2 = "Inserire un indirizzo email corretto!!";
      var msg3 = "Il campo \"Sito\" deve cominciare con http://!!";
      break;
    default :
      var msg1 = "I campi contrassegnati da * sono obbligatori!!";
      var msg2 = "Inserire un indirizzo email corretto!!";
      var msg3 = "Il campo \"Sito\" deve cominciare con http://!!";
  }	

	if ((nome == "") || (nome == "undefined")) {
	   alert(msg1);
	   document.contatti.nome.focus();
	return false;
	}
	
	if ((cognome == "") || (cognome == "undefined")) {
	   alert(msg1);
	   document.contatti.cognome.focus();
	return false;
	}
	
	if ((telefono == "") || (telefono == "undefined")) {
	   alert(msg1);
	   document.contatti.telefono.focus();
	return false;
	}

	if (email != "") {
    if (!email_reg_exp.test(email)) {
  		alert(msg2);
  		document.contatti.email.select();
  	return false;
  	}
  }
  
  if (sito != "") {
  	if (sito.indexOf("http://") == (-1)) {
  		alert(msg3);
  		document.contatti.sito.value = "http://";
  		document.contatti.sito.select();
  	return false;
  	}
  }
	
return (true);
}
