//DIZIONARIO PER LA MULTI LINGUA
var ml_privacy = ['Per inviare il modulo devi consentire il trattamento dei dati personali!',
                  'to send the order you should allow for the processing of personal data'];
var ml_empty = ['Tutti i campi sono da compilare correttamente!',
                'All fields are to be filled correctly'];
var ml_error = ['Le e-mail non coincidono',
                'mails do not match'];
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

function check_submit()
{
  var p = document.getElementById('privacy').checked, a=arguments, lingua=a[0];
  if(p == false)
    window.alert(ml_privacy[lingua]);
  else
  {
    var field, val, label, nome_form=a[1], ck=true, log="", mail1="", mail2="";
    
    for(var i=2; i<a.length; i+=2) //scorro l'array con i parametri in ingresso
    {
      field = a[i]; //nome del campo da controllare
      label = a[i+1] //label è la voce vicino al campo da contrassegnare in caso di errore
      val = document.getElementById(field).value;
      
      if(field == "mail") //spingo l'utente a non sbagliare e-mail
        mail1 = val;
      if(field == "confmail")
        mail2 = val;
        
      if(val == "")
      {
        document.getElementById(label).style.color = "#ff3e3e";
        ck = false;
      }
      else
        document.getElementById(label).style.color = "#ffffff";
    }
      
    if(ck && mail1 == mail2) //se i campi sono completi e corretti
      document.getElementById(nome_form).submit();
    else
    {
      if(!ck)
        log += ml_empty[lingua]+"<br>";
      if(mail1 != mail2)
      {
        log += ml_error[lingua]+"<br>";
        document.getElementById('m').style.color = "#ff3e3e";
        document.getElementById('cm').style.color = "#ff3e3e";
      }
    }
    
    document.getElementById('avvisi').innerHTML = log;
  }
}