/* Foglio javascript CONTATTI per KITIRI */
/* ****************************************************** GET ELEMENT BY ID */
function restituisciElemento(id) {
	if (document.getElementById)
		elemento = document.getElementById(id);
	else if (document.all)
		elemento = document.all[id];
	else if (document.layers)
		elemento =  document.layers[id];
	else
		alert("Browser incompatibile!");
	return elemento;
}

/* ****************************************************** CONTROLLO FORM */
function controlloform() {
  var sfondoiniziale = "#FFFFFF";	
  var testoiniziale ="#000000";
  var sfondofinale = "#FF0000";	
  var testofinale ="#FFFFFF";
  var ragione,nome,cognome,citta,provincia,telefono,email,accetto,MsgErrore;
  MsgErrore = restituisciElemento('MsgErrore');
  ragione = restituisciElemento('ragione');
  ragione.style.background=sfondoiniziale;
  ragione.style.color=testoiniziale;
  nome = restituisciElemento('nome');
  nome.style.background=sfondoiniziale;
  nome.style.color=testoiniziale;
  cognome = restituisciElemento('cognome');
  cognome.style.background=sfondoiniziale;
  cognome.style.color=testoiniziale;
  citta = restituisciElemento('citta');
  citta.style.background=sfondoiniziale;
  citta.style.color=testoiniziale;
  provincia = restituisciElemento('provincia');
  provincia.style.background=sfondoiniziale;
  provincia.style.color=testoiniziale;
  telefono = restituisciElemento('telefono');
  telefono.style.background=sfondoiniziale;
  telefono.style.color=testoiniziale;
  accetto = restituisciElemento('accetto');
  accetto.style.background=sfondoiniziale;
  accetto.style.color=testoiniziale;
  email = restituisciElemento('email');	
  email.style.background=sfondoiniziale;
  email.style.color=testoiniziale;	
  MsgErrore.style.display="none";
  if 	(ragione.value=="") {
    /*alert("Ha dimenticato di inserire la Ragione Sociale");*/
    MsgErrore.style.display="block";
    ragione.style.background=sfondofinale;
    ragione.style.color=testofinale;
    ragione.focus();
    return false;
  } else {
    if 	(nome.value=="") {
      //alert("Ha dimenticato di inserire il Nome");
      MsgErrore.style.display="block";
      nome.style.background=sfondofinale;
  	  nome.style.color=testofinale;
  	  nome.focus();
      return false;
    } else {
      if 	(cognome.value=="") {
        //alert("Ha dimenticato di inserire il Cognome");
        MsgErrore.style.display="block";
        cognome.style.background=sfondofinale;
  	    cognome.style.color=testofinale;
  	    cognome.focus();
        return false;
      } else {
        if 	(citta.value=="") {
          //alert("Ha dimenticato di inserire la Cittā");
          MsgErrore.style.display="block";
          citta.style.background=sfondofinale;
  	      citta.style.color=testofinale;
  	      citta.focus();
          return false;
        } else {
          if 	(provincia.value=="") {
            //alert("Ha dimenticato di inserire la Provincia");
            MsgErrore.style.display="block";
            provincia.style.background=sfondofinale;
  	        provincia.style.color=testofinale;
  	        provincia.focus();
            return false;
          } else {
            if 	(!validanumero(telefono.value) || (telefono.value=="")) {
              //alert("Ha dimenticato di inserire il numero di telefono");
              MsgErrore.style.display="block";
              telefono.style.background=sfondofinale;
  	          telefono.style.color=testofinale;
  	          telefono.focus();
              return false;
            } else {
              if (validaEmail(email)) {
                if (accetto.checked) {
                return true;
              } else {
                  alert("Per inviare il messaggio č necessario accettare le condizioni sul trattamento dei dati personali");
                  MsgErrore.style.display="block";
                  accetto.style.background=sfondofinale;
  	              accetto.style.color=testofinale;
  	              accetto.focus();
                  return false;
                }
              } else {
              	MsgErrore.style.display="block";
              	email.style.background=sfondofinale;
  	            email.style.color=testofinale;
  	            email.focus();
                return false;
              }
            }	
          }	
        }	
      }
    }
  }
}	

/* ****************************************************** CONTROLLO MAIL */
function validaEmail(campoEmail) {
	_pattern=/^[\w\-]+(\.?\-?\w+)*@[a-zA-Z0-9]+(\.?\-?[a-zA-Z0-9]+){2,}\.[a-zA-Z]{2,}$/;
	if (campoEmail.value!="") {
		if (_pattern.test(campoEmail.value)==false) {
			alert("Non č stato inserito un indirizzo mail valido");
			return false;
		}
	}	
	return true;
}

function validanumero(campo) {
	_pattern=/^\d+$/;
	if (_pattern.test(campo)==false) {
		alert("Il numero telefonico deve essere costituito da soli numeri");
		return false;
	}
	return true;
}

/* ****************************************************** HISTORY BACK */
function indietro(){
  history.back();
	return false;
}

/* ****************************************************** POP UP INFORMATIVA */
function popupInformativa(info) {
	window.open(info,"informative","width=365,height=490,scrollbars=yes,resizable=yes");
	return false;
}
//Fine Javascript

