function salva() {
         if(!window.confirm("Proseguire nell'operazione?")) { return; }
         document.formDati.actionName.value = "save";
         document.formDati.submit();
}

function elimina() {
            if(!window.confirm("Eliminare il documento e tutti gli allegati?")) { return; }
            document.formElimina.submit();
}

function eliminaAllegato(id, nomefile) {
         if (!window.confirm("Eliminare l'allegato '" + nomefile + "'?")) { return; }
         document.formDati.actionName.value="deleteAllegato";
         document.formDati.idAllegato.value=id;
         document.formDati.submit();
}

function unzipAllegato(id, nomefile) {
         if (!window.confirm("Decomprimere l'allegato '" + nomefile + "'?")) { return; }
         document.formDati.actionName.value="unzipAllegato";
         document.formDati.idAllegato.value=id;
         document.formDati.nomeAllegato.value=nomefile;
         document.formDati.submit();
}

function eliminaFile(campo) {
         if (!window.confirm("Eliminare il file?")) { return; }
         document.formDati.actionName.value="deleteFile";
         document.formDati.campoFile.value=campo;
         document.formDati.submit();
}

function JS_goToURL(p_url, cartella_lingua) {
         if (p_url == "") { return; }
         if(p_url.indexOf("http://") > -1) {
            window.open(p_url);
         }else{
            window.open("../"+cartella_lingua+"/"+p_url);
         }
}

function JS_goToDoc(n) {

         var p_form = window.document.formDati;
         window.open("link_documento.php?indice="+n+"&form="+p_form, "", "width=250,height=220");
}

function visualiFile(percorso, w, h) {
         var box, dim1, dim2;
         dim1 = ((screen.availWidth/2) - (w/2));
         dim2 = ((screen.availHeight/2) - (h/2));
         box = window.open("../ita/preview.php?img="+percorso, "_new", "toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=0, width="+w+", height="+h+", top="+dim1+", left="+dim2);
         box.focus();
}

function JS_openguide(idh) {
         var box, dim1, dim2, w, h;

         w = 850;
         h = 590;

         dim1 = ((screen.availWidth/2) - (w/2));
         dim2 = ((screen.availHeight/2) - (h/2));
         box  = window.open("box_informazioni.php?idh="+idh, "_help", "toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=1, resizable=0, width="+w+", height="+h+", top="+dim1+", left="+dim2);
         box.focus();
}

function JS_visualiPriv(w, h) {
         var box, dim1, dim2;
         if(!w) { w = 600; }
         if(!h) { h = 425; }
         dim1 = ((screen.availWidth/2) - (w/2));
         dim2 = ((screen.availHeight/2) - (h/2));
         box = window.open("privacy.htm", "_new", "toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0, width="+w+", height="+h+", top="+dim1+", left="+dim2);
         box.focus();
}

function JS_visualiCredits(w, h) {
         var box, dim1, dim2;
         if(!w) { w = 600; }
         if(!h) { h = 420; }
         dim1 = ((screen.availWidth/2) - (w/2));
         dim2 = ((screen.availHeight/2) - (h/2));
         box = window.open("mediatech.htm", "_new", "toolbar=0, location=0, directories=0, status=0, menubar=0, scrollbars=0, resizable=0, width="+w+", height="+h+", top="+dim1+", left="+dim2);
         box.focus();
}

function verifica_sintassi(EmailAddr) {
         Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
         if(Filtro.test(EmailAddr)) {
            return true;
         }else{
            return false;
         }
}

function JS_standAloneVsin(EmailAddr) {
         e = EmailAddr.value

         Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
         if(Filtro.test(e)) {
            return true;
         }else{
            alert("Errore nel formato email.\nEsempio corretto: info@mediatechcd.com");
            EmailAddr.value = "";
         }
}

function JS_solonumeriOrdine(e) {
         if (e.which) {
             if(e.which!=46 && e.which!=8 && e.wich!=43 && e.wich!=32 && (e.which<48 || e.which>57))
             return false;
         }else if(e.keyCode) {
             if(e.keyCode!=46 && e.keyCode!=8 && e.keyCode!=43 && e.keyCode!=32 && (e.keyCode<48 || e.keyCode>57))
             return false;
         }
         return true;
}

function JS_partitaIVA(sz_Codice, fie) {
         var n_Val,n_Som1=0,n_Som2=0,lcv;
         if(sz_Codice.length!=11 || isNaN(parseFloat(sz_Codice)) || parseFloat(sz_Codice)<parseFloat(0)) {
            alert("Partita IVA errata.");
            fie.value = "";
            return false;
         }else{
            for(lcv=0;lcv<9;lcv+=2) {
                n_Val=parseInt(sz_Codice.charAt(lcv));
                n_Som1+=n_Val;
                n_Val=parseInt(sz_Codice.charAt(lcv+1));
                n_Som1+=Math.floor(n_Val/5) + (n_Val<<1) % 10;
            }
            n_Som2 = 10 - (n_Som1 % 10);
            n_Val=parseInt(sz_Codice.charAt(10));
            if(n_Som2==n_Val) {
               return true;
            }else{
               alert("Partita IVA errata.");
               fie.value = "";
               return false;
            }
         }
}

function JS_codiceFISCALE(cfins, fie) {
   var cf = cfins.toUpperCase();
   var cfReg = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
   if(!cfReg.test(cf)) {
       alert("Codice fiscale errato.");
       fie.value = "";
       return false;
   }else{
      var set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      var set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
      var setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      var setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
      var s = 0;
      for( i = 1; i <= 13; i += 2 ) {
           s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
      }
      for( i = 0; i <= 14; i += 2 ) {
           s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
      }
      if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) ) {
          alert("Codice fiscale errato.");
          fie.value = "";
          return false;
      }else{
          return true;
      }
   }
}