   function changeColor(id){
      document.getElementById(id).style.background = '#FFFFAA';
      if(id=="civico" || id=="cap"){
        document.getElementById(id).style.width = 80+'px'
      }else if(id=="note"){
        document.getElementById(id).style.width = 400+'px';
        document.getElementById(id).style.height = 400+'px';
      }else{
        document.getElementById(id).style.width = 200+'px';
      }
      document.getElementById(id).style.color = '#0000FF'
   }
   function restoreColor(id){
      document.getElementById(id).style.background = '#FFFFFF'
      if(id=="civico" || id=="cap"){
        document.getElementById(id).style.width = 30+'px';
      }else if(id=="note"){
        document.getElementById(id).style.width = 200+'px';
        document.getElementById(id).style.height = 100+'px';
      }else{
        document.getElementById(id).style.width = 100+'px';
      }
      document.getElementById(id).style.color = '#000000'
   }

   function popUp(p, n, w, h) {
      window.open(p,n,'width='+w+',height='+h+',scrollbars=yes');
   }

   function popUp(p, n, w, h) {
      window.open(p,n,'width='+w+',height='+h+',scrollbars=yes');
   }


   
  function controllo_iva(iva){
     piva = iva; //document.getElementById('piva').value;
     
     if(piva.length==11){
         dispari1 = parseInt(piva.charAt(0));
         dispari2 = parseInt(piva.charAt(2));
         dispari3 = parseInt(piva.charAt(4));
         dispari4 = parseInt(piva.charAt(6));
         dispari5 = parseInt(piva.charAt(8));
         pari1    = parseInt(piva.charAt(1));
         pari2    = parseInt(piva.charAt(3));
         pari3    = parseInt(piva.charAt(5));
         pari4    = parseInt(piva.charAt(7));
         pari5    = parseInt(piva.charAt(9));

         pari1    = ((pari1*2)>9)? (pari1*2)-9:(pari1*2);
         pari2    = ((pari2*2)>9)? (pari2*2)-9:(pari2*2);  
         pari3    = ((pari3*2)>9)? (pari3*2)-9:(pari3*2);  
         pari4    = ((pari4*2)>9)? (pari4*2)-9:(pari4*2);  
         pari5    = ((pari5*2)>9)? (pari5*2)-9:(pari5*2);

         somma_tmp1 = (dispari1+dispari2+dispari3+dispari4+dispari5+pari1+pari2+pari3+pari4+pari5);
         somma_tmp2 = somma_tmp1/10;
         
         s = somma_tmp1 - (Math.floor(somma_tmp2)*10);

         somma = 10-s;


         if(somma == parseInt(piva.charAt(10))){
           return true;
         }else{
           return false;
         }
     }else{
         return false;
     }
  }




   function controllo(){
      iva = document.getElementById('piva').value;
      iva_ok = controllo_iva(iva);
      document.getElementById("ok").disabled = true;
      state = document.getElementById("state").value;

      var errore = 0;
      var mex_errore = "Mancano i seguenti campi:\n\n";
      
      if(!(document.getElementById('ViSo').checked||document.getElementById('Sentinel').checked||document.getElementById('Other').checked)){
          document.getElementById('prodotto').style.color = '#FF0000';
          errore = 1; mex_errore+="- missing product Type\n";
      }else{
          document.getElementById('prodotto').style.color = '#000000';
      }
      if(!(document.getElementById('Utente_finale').checked||document.getElementById('Rivenditore').checked||document.getElementById('Agente').checked)){
          document.getElementById('motivo').style.color = '#FF0000';
          errore = 1; mex_errore+="- Motivo del contatto\n";
      }else{
          document.getElementById('motivo').style.color = '#000000';
      }


      if (document.getElementById('nome').value == ""){ errore = 1; document.getElementById('nome').style.background = '#FF0000';mex_errore+="- missing Name\n";}
      if (document.getElementById('cognome').value == ""){ errore = 1; document.getElementById('cognome').style.background = '#FF0000';mex_errore+="- missing Surname\n";}
      if (document.getElementById('company').value == ""){ errore = 1; document.getElementById('company').style.background = '#FF0000';mex_errore+="- missing company\n";}
      if (document.getElementById('Rivenditore').checked || document.getElementById('Agente').checked){
         if (iva == ""){
           errore = 1; document.getElementById('piva').style.background = '#FF0000';mex_errore+="- missing VAT number\n";
         }else{
           if(!(iva_ok) && state == "Italy"){
             errore = 1; document.getElementById('piva').style.background = '#FF0000';mex_errore+="- incorrect VAT number\n";
           }
         }

      }
      if (document.getElementById('business').value == ""){ errore = 1; document.getElementById('business').style.background = '#FF0000';mex_errore+="- missing Business\n";}

      if (document.getElementById("state").value == "0") { errore = 1; document.getElementById('state').style.background = '#FF0000';mex_errore+="- missing state\n";}
      if (document.getElementById('indirizzo').value == ""){ errore = 1; document.getElementById('indirizzo').style.background = '#FF0000';mex_errore+="- missing address\n";}
      if (document.getElementById('civico').value == ""){ errore = 1; document.getElementById('civico').style.background = '#FF0000';mex_errore+="- missing address number\n";}
      if (document.getElementById('cap').value == ""){ errore = 1; document.getElementById('cap').style.background = '#FF0000';mex_errore+="- missing ZIP code\n";}
      if (document.getElementById('citta').value == ""){ errore = 1; document.getElementById('citta').style.background = '#FF0000';mex_errore+="- missing city\n";}
      if (state == "Italy"){
        if (document.getElementById('country').value == ""){ errore = 1; document.getElementById('country').style.background = '#FF0000';mex_errore+="- missing Regione\n";}
      }
      if (document.getElementById('tel_1').value == ""){ errore = 1; document.getElementById('tel_1').style.background = '#FF0000';mex_errore+="- missing telephone number\n";}

      if(document.getElementById('ml').checked){
          if (document.getElementById('e-mail').value == ""){ errore = 1; document.getElementById('e-mail').style.background = '#FF0000';mex_errore+="- missing e-mail\n";}
      }


      if (!(document.getElementById('autorizzazione').checked)){
        errore = 1; document.getElementById('privacy_label').style.color = '#FF0000'; mex_errore+="- missing Privacy\n";
      }else{
        document.getElementById('privacy_label').style.color = '#000000';
      }


      if(errore==0){
        document.getElementById("ok").disabled = false;
        document.getElementById("modulo").submit();
      }else{
        alert(mex_errore);
        document.getElementById("ok").disabled = false;
      }

   }