
//
// script ElaboGrafica
//

// Controlla la compilazione dei campi
function risultatof(frmAssicurazioni)
{


// Crea le variabili
var campo1 = document.frmAssicurazioni.nome
var campo2 = document.frmAssicurazioni.cognome
var campo3 = document.frmAssicurazioni.indirizzo
var campo4 = document.frmAssicurazioni.citta
var campo5 = document.frmAssicurazioni.cap
var campo6 = document.frmAssicurazioni.telefono
var campo7 = document.frmAssicurazioni.email


//// campo1 = document.frmAssicurazioni.nome -----------------------------------------------

  
  if (campo1.value == "")
  {
    alert("Inserire il nome\.");
    campo1.focus();
    return (false);
  }

  if (campo1.value.length < 4)
  {
    alert("Compilare correttamente il campo Nome\.");
    campo1.focus();
    return (false);
  }

  if (campo1.value.length > 40)
  {
    alert("E' stato superato il massimo dei caratteri consentiti nel campo Nome\.");
    campo1.focus();
    return (false);
  }
  
//// campo2 = document.frmAssicurazioni.cognome -----------------------------------------------
  
  if (campo2.value == "")
  {
    alert("Inserire il Cognome\.");
    campo2.focus();
    return (false);
  }

  if (campo2.value.length < 4)
  {
    alert("Compilare correttamente il campo Cognome\.");
    campo2.focus();
    return (false);
  }

  if (campo2.value.length > 40)
  {
    alert("E' stato superato il massimo dei caratteri consentiti nel campo Cognome\.");
    campo2.focus();
    return (false);
  }
  

//// campo3 = document.frmAssicurazioni.indirizzo -----------------------------------------------
  
  if (campo3.value == "")
  {
    alert("Compilare il campo indirizzo\.");
    campo3.focus();
    return (false);
  }

  if (campo3.value.length < 4)
  {
    alert("Compilare correttamente il campo Indirizzo\.");
    campo3.focus();
    return (false);
  }

  if (campo3.value.length > 60)
  {
    alert("E' stato superato il massimo dei caratteri consentiti nel campo Indirizzo\.");
    campo3.focus();
    return (false);
  }


//// campo4 = document.frmAssicurazioni.citta -------------------------------------
  
    if (campo4.value == "")
  {
    alert("Inserire la città\.");
    campo4.focus();
    return (false);
  }

  if (campo4.value.length < 2)
  {
    alert("Compilare correttamente il campo Città\.");
    campo4.focus();
    return (false);
  }

  if (campo4.value.length > 40)
  {
    alert("E' stato superato il massimo dei caratteri consentiti nel campo Città\.");
    campo4.focus();
    return (false);
  }


//// campo5 = document.frmAssicurazioni.cap -------------------------------------
  
    if (campo5.value == "")
  {
    alert("Inserire il CAP\.");
    campo5.focus();
    return (false);
  }

  if (campo5.value.length < 4)
  {
    alert("Compilare correttamente il campo CAP\.");
    campo5.focus();
    return (false);
  }

  if (campo5.value.length > 6)
  {
    alert("E' stato superato il massimo dei caratteri consentiti nel campo CAP\.");
    campo5.focus();
    return (false);
  }
  
  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-";
  var checkStr = campo5.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("I dati inseriti nel campo non sono validi\.");
    campo5.focus();
    return (false);
  }


//// campo6 = document.frmAssicurazioni.telefono --------------------------------------------
  
   if (campo6.value == "")
  {
    alert("Inserire il numero di telefono\.");
   campo6.focus();
    return (false);
  }

  if (campo6.value.length < 6)
  {
    alert("Compilare correttamente il numero telefonico\.");
    campo6.focus();
    return (false);
  }

  if (campo6.value.length > 20)
  {
    alert("E' stato superato il massimo dei numeri consentiti per il numero telefonico\.");
    campo6.focus();
    return (false);
  }

  var checkOK = "0123456789-";
  var checkStr = campo6.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Inserire prefisso e numero di telefono senza spazi\.");
    campo6.focus();
    return (false);
  }
  
  //// campo7 = document.frmAssicurazioni.email ----------------------------------------

    if (campo7.value == "")
  {
    alert("Inserire la tua E-mail\.");
    campo7.focus();
    return (false);
  }

  if (campo7.value.length < 5)
  {
    alert("Compilare correttamente il campo E-mail\.");
    campo7.focus();
    return (false);
  }

  if (campo7.value.length > 40)
  {
    alert("E' stato superato il massimo dei caratteri consentiti per il campo E-mail\.");
    campo7.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-@_-?!&.";
  var checkStr = campo7.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Compilare correttamente i dati nel campo\.");
    campo7.focus();
    return (false);
  }
  

  return (true);
}  