/* ------------------------------------------------------------------------------------------------
   Tooltip
   ------------------------------------------------------------------------------------------------ */
function ShowInf(aTipo)
         {
         var aTxt = "";
         switch (aTipo)
                {
                case 'VACP':
                     { aTxt = "Se attivato visualizza solo gli articoli contenuti nel catalogo predefinito;<br>" +
                              "se disattivato visualizza tutti gli articoli.";
                       break; }

                case 'DOCONLINE':
                     { aTxt = "Se attivato permette l'accesso a DocumentiOnLine.";
                       break; }

                case 'VOMAIL':
                     { aTxt = "Invia una mail segnalando il problema riscontrato.";
                       break; }

                case 'VOCONF':
                     { aTxt = "Conferma l'ordine.";
                       break; }

                case 'VONONE':
                     { aTxt = "Nessuna operazione.";
                       break; }

                case 'GSTPAG':
                     { aTxt = "Cambia pagina";
                       break; }

                case 'RAGSOC':
                     { aTxt = "Denominazione dell'utente, se utente interno;<br>" +
                              "Ragione sociale, se ditta esterna (Dato obbligatorio)";
                       break; }
                case 'CONTO':
                     { aTxt = "Codice che identifica l'anagrafica dell'Utente nel gestionale;<br>" +
                              "Il valore predefinito è il codice del Cliente (Dato obbligatorio)";
                       break; }
                case 'PASSWD':
                     { aTxt = "Genera una password casuale di 6 caratteri.";
                       break; }
                case 'FIDO_DIS':
                     { aTxt = "Funzione non abilitata.";
                       break; }
                case 'FIDO_CLI':
                     { aTxt = "Se attivato gli ordinativi dell'utente saranno<br>verificati prima dell'emissione del documento.";
                       break; }
                case 'FIDO_MAN':
                     { aTxt = "Se attivato gli ordinativi dell'utente devono essere<br>verificati prima dell'invio.<br><br>(Impostazione tipo verifica: Manuale).";
                       break; }
                case 'FIDO_AUTO':
                     { aTxt = "Se attivato gli ordinativi dell'utente devono essere<br>verificati prima dell'invio.<br><br>(Impostazione tipo verifica: Automatica).";
                       break; }
                case 'BROK':
                     { aTxt = "Se attivato l'utente potrà effettuare solo ordinativi<br>" +
                              "speciali (non vengono eseguiti i controlli sulla disponibilità.)";
                       break; }
                case 'CFPORD':
                     { aTxt = "Se attivato permette all’utente di confermare e inviare i propri ordini,<br>" +
                              "se disattivato dovrà essere il Cliente a confermare e inviare gli ordini.";
                       break; }
                case 'CFAORD':
                     { aTxt = "Se attivato permette all’utente di confermare e inviare gli ordini,<br>" +
                              "di qualsiasi altro utente.";
                       break; }
                case 'VISPRE':
                     { aTxt = "Se attivato vengono visualizzati i prezzi.";
                       break; }
                case 'BLOCAR':
                     { aTxt = "Se attivato blocca il carrello; l'utente non potrà fare nessuna<br>" +
                              "operazione che cambi il contenuto del carrello.";
                       break; }
                       
                case 'CHGPWD':
                     { aTxt = "Se attivato permette all'utente di cambiare la<br>" +
                              "propria password.";
                       break; }

                case 'CLASSE':
                     { aTxt = "Definisce quale Classe applicare all'Utente.<br>" +
                              "Se non esistono Classi applicabili vengono utilizzati<br>" +
                              "i parametri del Cliente.";
                       break; }
                case 'CATPER':
                     { aTxt = "Se attivato l'utente potrà utilizzare la gestione completa<br>" +
                              "dei Cataloghi personalizzati.";
                       break; }
                case 'DESPRO':
                     { aTxt = "Se attivato permette all\’utente di inserire nuove destinazioni.";
                       break; }
                case 'CHGDES':
                     { aTxt = "Se attivato dà la possibilità all'Utente di cambiare la destinazione<br>predefinita.";
                       break; }
                case 'BUDGET':
                     { aTxt = "Se attivato consente la gestione annuale del budget di spesa.";
                       break; }
                }
         if (aTxt == "") { aTxt = aTipo + " - Info non definite"; }
         Tip(aTxt, BGCOLOR,'#FFFFCE', BORDERCOLOR,'#000000', FONTCOLOR,'#000000');
         }

/* ------------------------------------------------------------------------------------------------
   Maxlength per TextArea
   ------------------------------------------------------------------------------------------------ */
    function ismaxlength(obj)
             {
             var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "";
             if (obj.getAttribute && obj.value.length>mlength) { obj.value=obj.value.substring(0,mlength); }
             }
/* ------------------------------------------------------------------------------------------------
   Cambia il colore di sfondo dell'elemento passato
   ------------------------------------------------------------------------------------------------ */
function BCol(aEle, aOnOff)
         {
         if (aOnOff==1)
            { aEle.style.backgroundColor="#FFFACD"; }            
         else
            { aEle.style.backgroundColor="white"; }
         return true;
         }

/* -------------------------------------------------------------------------------------------------
   Visualizza/nasconde un DIV
   ------------------------------------------------------------------------------------------------- */
function UTL_ShowHideDiv(id)
         {
	      	 if (document.getElementById)
            {
            if (document.getElementById(id).style.display == "none")
               { document.getElementById(id).style.display = 'block'; }
            else
               { document.getElementById(id).style.display = 'none'; }
            }
         else
            {
            if (document.layers)
               {
               if (document.id.display == "none")
                  { document.id.display = 'block'; }
               else
                  { document.id.display = 'none'; }
               }
            else
               {
               if (document.all.id.style.visibility == "none")
                  { document.all.id.style.display = 'block'; }
               else
                  { document.all.id.style.display = 'none'; }
               }
            }
         return true;
         }

/* -------------------------------------------------------------------------------------------------
   Visualizza un DIV
   ------------------------------------------------------------------------------------------------- */
function UTL_ShowDiv(id)
         {
	      	 if (document.getElementById)
            { document.getElementById(id).style.display = 'block'; }
         else
            {
            if (document.layers)
               { document.id.display = 'block'; }
            else
               { document.all.id.style.display = 'block'; }
            }
         return true;
         }

/* -------------------------------------------------------------------------------------------------
   Nasconde un DIV
   ------------------------------------------------------------------------------------------------- */
function UTL_HideDiv(id)
         {
	      	 if (document.getElementById)
            { document.getElementById(id).style.display = 'none'; }
         else
            {
            if (document.layers)
               { document.id.display = 'none'; }
            else
               { document.all.id.style.display = 'none'; }
            }
         return true;
         }

function UTL_Trim(aStr)
         {
         return aStr;
         }

function Left(str, n)
         {
	        if (n <= 0)
	           return "";
	        else if (n > String(str).length)
	                return str;
	             else
	                return String(str).substring(0,n);
         }

function Right(str, n)
         {
         if (n <= 0)
            return "";
         else if (n > String(str).length)
                 return str;
              else {
                   var iLen = String(str).length;
                   return String(str).substring(iLen, iLen - n);
                   }
         }

function UTL_IsDate(dateStr)
         {
         var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
         var matchArray = dateStr.match(datePat);
         if (matchArray == null) { return false; }
         day = matchArray[1];
         month = matchArray[3];
         year = matchArray[5];
         if (month < 1 || month > 12) { return false; }
         if (day < 1 || day > 31) { return false; }
         if ((month==4 || month==6 || month==9 || month==11) && day==31) { return false; }
         if (month == 2) 
            { 
            var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
            if (day > 29 || (day==29 && !isleap)) { return false; }
            }
         return true;
         }

function UTL_IsNumeric(sText)
         {
         var ValidChars = "0123456789,";
         var IsNumber=true;
         var Char;
         for (i = 0; i < sText.length && IsNumber == true; i++) 
             { 
             Char = sText.charAt(i); 
             if (ValidChars.indexOf(Char) == -1) 
                {
                IsNumber = false;
                }
             }
         return IsNumber;   
         }
function UTL_formatCurrency(num) 
         {
         num = num.toString().replace(/[,]/gi,'.');
         num = num.toString().replace(/\€\,/g,'');
         if (isNaN(num))
            num = "0";
         sign = (num == (num = Math.abs(num)));
         num = Math.floor(num*100+0.50000000001);
         cents = num%100;
         num = Math.floor(num/100).toString();
         if (cents<10)
            cents = "0" + cents;
         for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
             num = num.substring(0,num.length-(4*i+3))+','+
                   num.substring(num.length-(4*i+3));
         var num1 = num.replace(/,/g,'.');
         return (((sign)?'':'-') + '€ ' + num1 + ',' + cents);
         }

function UTL_currencyToNumber(num) 
         {
         num = num.toString().replace(/[€]/gi,'');
         num = num.toString().replace(/[ ]/gi,'');
         num = num.toString().replace(/[.]/gi,'');
         return num;
         }

function UTL_ControllaPI(pi)
         {
         if( pi == '' )  return '';
         if( pi.length != 11 ) return "La lunghezza della partita IVA non è\n" +
                                      "corretta: la partita IVA dovrebbe essere lunga\n" +
                                      "esattamente 11 caratteri.\n";
         validi = "0123456789";
         for( i = 0; i < 11; i++ )
            {
            if( validi.indexOf( pi.charAt(i) ) == -1 ) return "La partita IVA contiene un carattere non valido `" +
                                                              pi.charAt(i) + "'.\nI caratteri validi sono le cifre.\n";
            }
         s = 0;
         for( i = 0; i <= 9; i += 2 ) s += pi.charCodeAt(i) - '0'.charCodeAt(0);
         for( i = 1; i <= 9; i += 2 )
            {
            c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
            if( c > 9 )  c = c - 9;
            s += c;
            }
         if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) ) return "La partita IVA non è valida:\n" +
                                                                                "il codice di controllo non corrisponde.\n";
         return '';
         }
function UTL_ControllaCF(cf)
         {
         var validi, i, s, set1, set2, setpari, setdisp;
         if( cf == '' )  return '';
         cf = cf.toUpperCase();
         if( cf.length != 16 ) return "La lunghezza del codice fiscale non è\n"
                                     +"corretta: il codice fiscale dovrebbe essere lungo\n"
                                     +"esattamente 16 caratteri.\n";
         validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
         for( i = 0; i < 16; i++ )
            {
            if( validi.indexOf( cf.charAt(i) ) == -1 )
                return "Il codice fiscale contiene un carattere non valido `" +
                       cf.charAt(i) +
                       "'.\nI caratteri validi sono le lettere e le cifre.\n";
            }
         set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
         set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
         setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
         setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
         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) ) return "Il codice fiscale non è corretto:\n"+
                                                                  "il codice di controllo non corrisponde.\n";
         return "";
         }

function UTL_ControllaEMail(indirizzo)
         {
         if (window.RegExp)
            {
            var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
            var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
            var regnv = new RegExp(nonvalido);
            var regv = new RegExp(valido);
            if (!regnv.test(indirizzo) && regv.test(indirizzo)) return true;
            return false;
	           }
         else
            {
            if (indirizzo.indexOf("@") >= 0) return true;
            return false;
  	         }
         }
