﻿function showloadingpanel(visible) {
   if (visible) {
      var newDiv2 = document.createElement("DIV");
      newDiv2.id = "showloadingpanel";
      newDiv2.style.position = "absolute";
      newDiv2.style.left = "0px";
      newDiv2.style.top = "0px";
      newDiv2.style.height = "100%";
      newDiv2.style.width = "100%";
      newDiv2.style.Zindex = "100";
      newDiv2.style.lineHeight = "0px";
      newDiv2.style.backgroundColor = "#000000";
      newDiv2.style.opacity = "0.50";
      //newDiv2.style.filter = "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
      newDiv2.style.filter = "alpha(style=0,opacity=50)";
      newDiv2.style.MozOpacity = "0.50";
      newDiv2.style.border = "0.50";
      if (window.event) {
         document.body.insertBefore(newDiv2);
      } else {
         document.body.appendChild(newDiv2);
      }
   } else {
      var objdiv = document.getElementById("showloadingpanel").parentNode;
      if (navigator.appVersion.indexOf("MSIE")>=0) {
         document.getElementById("showloadingpanel").removeNode(true);
      } else {
         for (i = 0; i < objdiv.childNodes.length; i++) {
            if (objdiv.childNodes[i].id == "showloadingpanel") {
               objdiv.removeChild(objdiv.childNodes[i]);
            }
         }
      }
   }
}
// color picker
function rendiinvisibile(idid) {
   if (document.getElementById('colorpicker')) {
      document.getElementById('colorpicker').style.visibility = "hidden";
      if (document.getElementById("colorpicker")) {
         var objdiv = document.getElementById("colorpicker").parentNode;
         if (navigator.appVersion.indexOf("MSIE") >= 0) {
            document.getElementById("colorpicker").offsetParent.removeNode(true);
         } else {
            objdiv.removeChild(objdiv.childNodes[0]);
         }
      }
   }
   if (idid) {
      source = document.getElementById(idid);
      source.value = source.value.toUpperCase();
      if (source.value) {
         var espressione = /^#[A-F0-9]{6}$/;
         if (!espressione.test(source.value)) {
            alert("colore non valido");
            source.value = ""
            source.style.backgroundColor = "#FFFFFF";
         } else {
            source.style.backgroundColor = source.value;
         }
      }   
   }   
}
function settacolore(e, idid) {
   var ns6 = document.getElementById && !document.all
   var ie = document.all
   var artabus = ''
   source = ie ? event.srcElement : e.target
   if (source.tagName == "TABLE") return
   while (source.tagName != "TD" && source.tagName != "HTML") source = ns6 ? source.parentNode : source.parentElement
   if (idid) {
      document.getElementById(idid).style.backgroundColor = artabus = source.bgColor.toUpperCase();
      document.getElementById(idid).value = artabus;
   }
}
function CreaColorPicker(idid) {
   var total = 1657;
   var X = Y = j = RG = B = 0;
   var aR = new Array(total);
   var aG = new Array(total);
   var aB = new Array(total);
   var parserHtml = "";
   var espressione = /^#[A-F0-9]{6}$/;
   if (!espressione.test(idid.value)) {
      if (!idid.value) {
         
      } else {
         alert("colore non valido");
         idid.value = ""
         idid.style.backgroundColor = "#FFFFFF";
      }
   } else {
      idid.style.backgroundColor = idid.value;
   }
   idid.onblur = function() { rendiinvisibile(idid.id); };
   /*if (idid.onblur) {
      
   } else if (idid.attachEvent) {
      idid.attachEvent('onblur', function() { rendiinvisibile(idid.id) });
   } */
   idid.maxLength = 7;
   if (document.getElementById("colorpicker")) {
      var objdiv = document.getElementById("colorpicker").parentNode;
      if (navigator.appVersion.indexOf("MSIE") >= 0) {
         objdiv.removeNode(true);
      }else{
         objdiv.removeChild(objdiv.childNodes[0]);
      }   
   }
   for (var i = 0; i < 256; i++) {
      aR[i + 510] = aR[i + 765] = aG[i + 1020] = aG[i + 5 * 255] = aB[i] = aB[i + 255] = 0;
      aR[510 - i] = aR[i + 1020] = aG[i] = aG[1020 - i] = aB[i + 510] = aB[1530 - i] = i;
      aR[i] = aR[1530 - i] = aG[i + 255] = aG[i + 510] = aB[i + 765] = aB[i + 1020] = 255;
      if (i < 255) { aR[i / 2 + 1530] = 127; aG[i / 2 + 1530] = 127; aB[i / 2 + 1530] = 127; }
   }
   var hexbase = new Array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
   var i = 0; var jl = new Array();
   for (x = 0; x < 16; x++) for (y = 0; y < 16; y++) jl[i++] = hexbase[x] + hexbase[y];
   parserHtml = parserHtml + '<' + 'table id="colorpicker" border="0" cellspacing="0" cellpadding="0" onMouseover="settacolore(event, ' + chr(39) + idid.id + chr(39) + ')" onClick="rendiinvisibile(' + chr(39) + idid.id + chr(39) + ')">';
   var H = W = 63;
   for (Y = 0; Y <= H; Y++) {
      s = '<' + 'tr height=2>'; j = Math.round(Y * (510 / (H + 1)) - 255)
      for (X = 0; X <= W; X++) {
         i = Math.round(X * (total / W))
         R = aR[i] - j; if (R < 0) R = 0;if (R > 255 || isNaN(R)) R = 255;
         G = aG[i] - j; if (G < 0) G = 0;if (G > 255 || isNaN(G)) G = 255;
         B = aB[i] - j; if (B < 0) B = 0;if (B > 255 || isNaN(B)) B = 255;
         s = s + '<' + 'td width=2 bgcolor=#' + jl[R] + jl[G] + jl[B] + '><' + '/td>';
      }
      parserHtml = parserHtml + s + '<' + '/tr>';
   }
   parserHtml = parserHtml + '<' + '/table>';
   var newDiv = document.createElement("DIV");
   newDiv.innerHTML = parserHtml;
   newDiv.style.position = "absolute";
   var oLeft = 0;
   var oTop = 0;
   var pi = idid;
   while (pi) {
      oLeft = oLeft + pi.offsetLeft;
      oTop = oTop + pi.offsetTop;
      pi = pi.offsetParent;
   }
   newDiv.style.left = oLeft+"px";
   newDiv.style.top = oTop + idid.offsetHeight + "px";
   if (window.event) {
      document.body.insertBefore(newDiv);
   } else {
      document.body.appendChild(newDiv);
   }
}

// end color picker

var defaulbackcolor = "#FFFFFF";
var defaulcolor = "#000000";
var defaulfocusbackcolor = "#FFFFCC";
var defaulfocuscolor = "#000000";
function unfocuscomune(obj, type, bkcolor, fontcolor) {
    if (bkcolor) {
        obj.style.backgroundColor = bkcolor;
    } else {
        obj.style.backgroundColor = defaulbackcolor;
    }
    if (fontcolor) {
        obj.style.Color = fontcolor;
    } else {
        obj.style.Color = defaulcolor;
    }
    obj.value = obj.value.toUpperCase();
    if (document.getElementById("rectrighe")) {
       for (var i = 10; i > 0; i--) {
          if (i == 1) {
              setTimeout("destroydiv('" + document.getElementById("rectrighe").id + "')", 50 * (10 - i));
          } else {
              setTimeout("setOpacity('" + i + "','" + document.getElementById("rectrighe").id + "')", 50 * (10 - i));
          }
       }
      // document.getElementById("rectrighe").style.display = "none";
    }
}
function focuscomune(obj, bkcolor, fontcolor) {
   if (bkcolor) {
      obj.style.backgroundColor = bkcolor;
   } else {
      obj.style.backgroundColor = defaulfocusbackcolor;
   }
   if (fontcolor) {
      obj.style.Color = fontcolor;
   } else {
      obj.style.Color = defaulfocuscolor;
   }
   obj.onkeypress = keycomune;
}
function focustext(obj, type, bkcolor, fontcolor) {
   if (type == "data") {
      obj.onkeypress = keydata;
   } else if (type == "num") {
      obj.onkeypress = keynum;
   } else if (type == "ora") {
      obj.onkeypress = keyora;
   } else if (type == "val") {
      obj.onkeypress = keyval;
   } else if (type == "clr") {
      CreaColorPicker(obj);
   }
   if (type != 'clr') {
      if (bkcolor) {
         obj.style.backgroundColor = bkcolor;
      } else {
         obj.style.backgroundColor = defaulfocusbackcolor;
      }
      if (fontcolor) {
         obj.style.Color = fontcolor;
      } else {
         obj.style.Color = defaulfocuscolor;
      }
   }   
}
function unfocustext(obj, type, bkcolor, fontcolor) {
   if (type != 'clr') {
      if (bkcolor) {
         obj.style.backgroundColor = bkcolor;
      } else {
         obj.style.backgroundColor = defaulbackcolor;
      }
      if (fontcolor) {
         obj.style.Color = fontcolor;
      } else {
         obj.style.Color = defaulcolor;
      }
      obj.value = obj.value.toUpperCase();
   }   
   if (type == "data") {
       if (obj.value) {
           if (validadata(obj) == false) {
               alert("Data non valida. La data deve essere scritta nel formato gg/mm/aaaa.");
               obj.value = "";
               obj.focus();
               obj.select();
           }
       }
   } else if (type == "num") {
       if (obj.value) {
           if (validanum(obj) == false) {
               alert("numero non valido.");
               obj.value = "";
               obj.focus();
               obj.select();
           }
       }
   } else if (type == "ora") {
       if (obj.value) {
           if (validaora(obj) == false) {
               alert("ora non valida.");
               obj.value = "";
               obj.focus();
               obj.select();
           }
       }
   } else if (type == "val") {
       if (obj.value) {
           if (validaval(obj) == false) {
               alert("importo non valido.");
               obj.value = "";
               obj.focus();
               obj.select();
           }
       }
   }   
}
function keycomune(evt) {
   var obj;
   if (window.event) {
      obj = window.event.srcElement;
   } else {
      obj = evt.srcelement ? evt.srcelement : evt.target;
   }
   leftdiv = 0
   var li = obj;
   while (li) {
      leftdiv = leftdiv + li.offsetLeft;
      li = li.offsetParent;
   }
   topdiv = 0
   var lo = obj;
   while (lo) {
      topdiv = topdiv + lo.offsetTop;
      lo = lo.offsetParent;
   }
   topdiv = topdiv + obj.offsetHeight + 1;
   var newdiv;
   if (!document.getElementById("rectrighe")) {
      var strobjlist = "<div id='riga1' class='selrighe' onmouseover=" + String.fromCharCode(34) + "this.style.backgroundColor='#454442'; this.style.color='#A6B6DA'" + String.fromCharCode(34) + " onmouseout=" + String.fromCharCode(34) + "this.style.backgroundColor='#FFFFFF'; this.style.color='#000000'" + String.fromCharCode(34) + ">a</div>";
      strobjlist = strobjlist + "<div id='riga2' class='selrighe' onmouseover=" + String.fromCharCode(34) + "this.style.backgroundColor='#454442'; this.style.color='#A6B6DA'" + String.fromCharCode(34) + " onmouseout=" + String.fromCharCode(34) + "this.style.backgroundColor='#FFFFFF'; this.style.color='#000000'" + String.fromCharCode(34) + ">b</div>";
      strobjlist = strobjlist + "<div id='riga3' class='selrighe' onmouseover=" + String.fromCharCode(34) + "this.style.backgroundColor='#454442'; this.style.color='#A6B6DA'" + String.fromCharCode(34) + " onmouseout=" + String.fromCharCode(34) + "this.style.backgroundColor='#FFFFFF'; this.style.color='#000000'" + String.fromCharCode(34) + ">c</div>";
      strobjlist = strobjlist + "<div id='riga4' class='selrighe' onmouseover=" + String.fromCharCode(34) + "this.style.backgroundColor='#454442'; this.style.color='#A6B6DA'" + String.fromCharCode(34) + " onmouseout=" + String.fromCharCode(34) + "this.style.backgroundColor='#FFFFFF'; this.style.color='#000000'" + String.fromCharCode(34) + ">d</div>";
      strobjlist = strobjlist + "<div id='riga5' class='selrighe' onmouseover=" + String.fromCharCode(34) + "this.style.backgroundColor='#454442'; this.style.color='#A6B6DA'" + String.fromCharCode(34) + " onmouseout=" + String.fromCharCode(34) + "this.style.backgroundColor='#FFFFFF'; this.style.color='#000000'" + String.fromCharCode(34) + ">e</div>";
      strobjlist = strobjlist + "<div id='riga6' class='selrighe' onmouseover=" + String.fromCharCode(34) + "this.style.backgroundColor='#454442'; this.style.color='#A6B6DA'" + String.fromCharCode(34) + " onmouseout=" + String.fromCharCode(34) + "this.style.backgroundColor='#FFFFFF'; this.style.color='#000000'" + String.fromCharCode(34) + ">f</div>";
      strobjlist = strobjlist + "<div id='riga7' class='selrighe' onmouseover=" + String.fromCharCode(34) + "this.style.backgroundColor='#454442'; this.style.color='#A6B6DA'" + String.fromCharCode(34) + " onmouseout=" + String.fromCharCode(34) + "this.style.backgroundColor='#FFFFFF'; this.style.color='#000000'" + String.fromCharCode(34) + ">g</div>";
      strobjlist = strobjlist + "<div id='riga8' class='selrighe' onmouseover=" + String.fromCharCode(34) + "this.style.backgroundColor='#454442'; this.style.color='#A6B6DA'" + String.fromCharCode(34) + " onmouseout=" + String.fromCharCode(34) + "this.style.backgroundColor='#FFFFFF'; this.style.color='#000000'" + String.fromCharCode(34) + ">h</div>";
      strobjlist = strobjlist + "<div id='riga9' class='selrighe' onmouseover=" + String.fromCharCode(34) + "this.style.backgroundColor='#454442'; this.style.color='#A6B6DA'" + String.fromCharCode(34) + " onmouseout=" + String.fromCharCode(34) + "this.style.backgroundColor='#FFFFFF'; this.style.color='#000000'" + String.fromCharCode(34) + ">i</div>";
      strobjlist = strobjlist + "<div id='riga10' class='selrighe' onmouseover=" + String.fromCharCode(34) + "this.style.backgroundColor='#454442'; this.style.color='#A6B6DA'" + String.fromCharCode(34) + " onmouseout=" + String.fromCharCode(34) + "this.style.backgroundColor='#FFFFFF'; this.style.color='#000000'" + String.fromCharCode(34) + ">l</div>";
      var newdiv = document.createElement('div');
      var divIdName = "rectrighe";
      newdiv.setAttribute('id', divIdName);
      newdiv.style.display = "none";
      newdiv.style.width = "200px";
      newdiv.innerHTML = strobjlist;
      document.body.appendChild(newdiv);
   } else {
      newdiv = document.getElementById("rectrighe");
   }
   if (newdiv.style.display != "block"){
      newdiv.style.position = "absolute";
      newdiv.style.left = leftdiv + "px";
      newdiv.style.top = topdiv + "px";
      newdiv.style.border = "solid 1px #E1E1E1";
      setOpacity("1", newdiv.id);
      newdiv.style.display = "block";
      for (var i = 0; i < 11; i++) {
         setTimeout("setOpacity('" + i + "','" + newdiv.id + "')", 50*i);
      }    
   }   
}
function keydata(evt) {
   var key = "";
   var obj;
   if (window.event) {
      key = window.event.keyCode;
      obj = window.event.srcElement;
   } else {
      key = (window.Event) ? evt.which : evt.keyCode;
      obj = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   }
   var ValidChars = "0123456789/" + String.fromCharCode(8) + String.fromCharCode(0);
   if (ValidChars.indexOf(String.fromCharCode(key)) == -1) {
      return false;
   }
}
function keyora(evt) {
   var key = "";
   if (window.event) {
      key = window.event.keyCode;
   } else {
      key = (window.Event) ? evt.which : evt.keyCode;
   }
   var ValidChars = "0123456789:" + String.fromCharCode(8) + String.fromCharCode(0);
   if (ValidChars.indexOf(String.fromCharCode(key)) == -1) {
       return false;
   }
}
function keynum(evt) {
   var key = "";
   var obj;
   if (window.event) {
      key = window.event.keyCode;
      obj = window.event.srcElement;
   } else {
      key = (window.Event) ? evt.which : evt.keyCode;
      obj = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   }
   var ValidChars = "0123456789" + String.fromCharCode(8) + String.fromCharCode(0);
   if (ValidChars.indexOf(String.fromCharCode(key)) == -1) {
      return false;
   }
}
function keyval(evt) {
   var key = "";
   if (window.event) {
      key = window.event.keyCode;
   } else {
      key = (window.Event) ? evt.which : evt.keyCode;
   }
   var ValidChars = "0123456789,." + String.fromCharCode(8) + String.fromCharCode(0);
   if (ValidChars.indexOf(String.fromCharCode(key)) == -1) {
      return false;
   }
}
function validadata(obj) {
   var stringa = obj.value
   var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
   if (!espressione.test(stringa)) {
      return false;
   } else {
      anno = parseInt(stringa.substr(6), 10);
      if (anno < 1800) { return false; } 
      mese = parseInt(stringa.substr(3, 2), 10);
      giorno = parseInt(stringa.substr(0, 2), 10);
      var data = new Date(anno, mese - 1, giorno);
      if (data.getFullYear() == anno && data.getMonth() + 1 == mese && data.getDate() == giorno) {
         return true;
      } else {
         return false;
      }
   }
}
function validaora(obj) {
    var stringa = obj.value
    var espressione = /^[0-9]{2}\:[0-9]{2}$/;
    if (!espressione.test(stringa)) {
        return false;
    } else {
        var ora = parseInt(stringa.substr(0, 2), 10);
        var minuti = parseInt(stringa.substr(3, 2), 10);
        if (ora > 23 || ora < 0) {
           return false;
        }
        if (minuti > 59 || minuti < 0) {
           return false;
        }
        return true;
    }
}
function validanum(obj) {
   return isnumeric(obj.value);
}
function validaval(obj) {
   if(isnumeric(obj.value)) {
      var num = 0.00;
      num = obj.value.replace(",", ".");
      obj.value = parseFloat(num).toFixed(2).replace(".", ",");
      return true;
   } else {
      return false;
   }   
}
function setOpacity(value, obj) {
    if (document.getElementById(obj)) {
        document.getElementById(obj).style.opacity = value / 10;
        document.getElementById(obj).style.filter = 'alpha(opacity=' + value * 10 + ')';
    }
}
function destroydiv(obj) {
    if (document.getElementById(obj)) {
        document.getElementById(obj).style.display = "none";
    }
}
function colormenu(obj, firstcolor, endcolor, fontcolor, typegradient) {
   setGradient(obj, firstcolor, endcolor, typegradient); //'#5571F2', 0);
   obj.style.color = fontcolor;
}
function trim(stringa){ 
   while (stringa.substring(0,1) == ' '){
      stringa = stringa.substring(1, stringa.length);
   }
   while (stringa.substring(stringa.length-1, stringa.length) == ' '){
      stringa = stringa.substring(0,stringa.length-1);
   }
   return stringa;
}
function mid(String, Start, Length)
{
    if (String == null)
        return (false);
    
    if (Start > String.length)
        return '';
    
    if (Length == null || Length.length == 0)
        return (false);
 
    return String.substr((Start - 1), Length);
}
function val(String){
   if(!isNaN(String)){
      return parseFloat(String);
   } else {
      return 0;
   }   
}
function instr(String1, String2){
    var a = 0;
    if (String1 == null || String2 == null)
        return (false);
    String1 = String1.toLowerCase();
    String2 = String2.toLowerCase();
    a = String1.indexOf(String2);
    if (a == -1)
        return 0;
    else
        return a + 1;
}
function right(string, len) {
   return string.substr(string.length - len);
}
function isdate(date) {
   var stringa = date;
   var espressione = /^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
   if (!espressione.test(stringa)) {
      return false;
   } else {
      anno = parseInt(stringa.substr(6), 10);
      if (anno < 1800) { return false; }
      mese = parseInt(stringa.substr(3, 2), 10);
      giorno = parseInt(stringa.substr(0, 2), 10);
      var data = new Date(anno, mese - 1, giorno);
      if (data.getFullYear() == anno && data.getMonth() + 1 == mese && data.getDate() == giorno) {
         return true;
      } else {
         return false;
      }
   }
}
function istime(time) {
   var stringa = time
   var espressione = /^[0-9]{2}\:[0-9]{2}$/;
   if (!espressione.test(stringa)) {
      return false;
   } else {
      var ora = parseInt(stringa.substr(0, 2), 10);
      var minuti = parseInt(stringa.substr(3, 2), 10);
      if (ora > 23 || ora < 0) {
         return false;
      }
      if (minuti > 59 || minuti < 0) {
         return false;
      }
      return true;
   }
}
function isnumeric(number) {
   number = String(number).replace(",", ".");
   if (number.lenght == 0) { return false; }
   return !isNaN(number);
}
function chr(AscNumber) {
   return String.fromCharCode(AscNumber);
}
function asc(chart) {
   return chart.charCodeAt(0);
}
function fiscale(cognome, nome, datanascita, sesso, codcomuneistat) {
var cogn = "";
var cons = "";
var Pari1 = "";
var Pari11 = "";
var dispari = "";
var cfp = "";
var riempie = "";
var s = 0;
var p = 0;
var voca = "";
var mese = "";
var lu1 = "";
var nu1 = "";
var ss = "";
var lu2 = "";
var nu2 = "";
var i = 0;
var co = "";
var n = 0;
var hu11 = "";
var nu11 = "";
var nom = "";
var cont = 0;
var coris = "";
var giorno = "";
var gi = "";
var g = "";
var anno = "";
var Ms = "";
var CF = "";
var a = 0;
var b = 0;
var ric = 0;
var c = 0;
var d = 0;
var e = 0;
var finale = "";

   cons = "BCDFGHLMNPQRSTVWKXYJZ";
   voca = "AEIOU";
   mese = "ABCDEHLMPRST";
   Pari1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   Pari11 = "0123456789";
   dispari = "0100050709131517192102041820110306081214161022252423";
   riempie = "XXX";
   nome = trim(nome).toUpperCase();
   cognome = trim(cognome).toUpperCase();
   sesso = trim(sesso).toUpperCase();
   lu1 = nome;
   nu1 = lu1.length;
   lu2 = cognome
   nu2 = lu2.length;
   cogn = " ";
   for(i=1; i<nu1; i++){
      co = mid(lu1, i, 1);
      for(n=1; n<cons.length; n++){
         if(co == mid(cons, n, 1)) { cogn = cogn + co; }
      }
   }
   hu11 = trim(cogn);
   nu11 = hu11.length;
   cogn = " ";
   if(nu11 < 3){
      for(i=1; i<nu1; i++){
         co = mid(lu1, i, 1)
         for(n=1; n<voca.length; n++){
            if(co == mid(voca, n, 1)){ cogn = cogn + co; }
         }
      }
   }
   cogn = trim(cogn);
   lu1 = hu11 + cogn;
   lu1 = mid(lu1, 0, 3);
   lu1 = trim(lu1);
   nu11 = lu1.length;
   if(nu11 < 3){ lu1 = lu1 + mid(riempie, 1, (3 - nu11)); }
   nom = " ";
   cont = 0;
   for(i=1; i<nu2; i++){
      co = mid(lu2, i, 1);
      for(n=1; n<cons.length;n++){
         if(co == mid(cons, n, 1)){ cont = cont + 1; }
      }
   }
   coris = " ";
   if(cont > 3){
      nom = " ";
      cont = 0;
      for(i=1; i<nu2; i++){
         co = mid(lu2, i, 1);
         for(n=1; n<cons.length;n++){
            if(co == mid(cons, n, 1)){
               cont = cont + 1;
               if(cont == 2){
                  coris = co;
               }else{
                  nom = trim(nom + co);
               }
            }
         }
      }
   } else {
      nom = " ";
      cont = 0;
      for(i=1; i<nu2; i++){
         co = mid(lu2, i, 1);
         for(n=1; n<cons.length;n++){
            if(co==mid(cons, n, 1)){ nom = trim(nom + co); }
         }
      }
   }
   hu11 = trim(hu11);
   hu11 = mid(nom, 1, 3);
   nu11 = hu11.length;
   if(nu11 < 3){
      if(coris==""){ hu11 = hu11 + trim(coris); }
   }
   nu11 = trim(hu11).length;
   if(nu11<3){
      nom = " ";
      for(i=1; i<nu2; i++){
         co = mid(lu2, i, 1);
         for(n=1; n<cons.length;n++){
            if(co==mid(voca, n, 1)){ nom = trim(nom + co); }
         }
      }
   }
   lu2 = trim(mid(hu11 + nom, 1, 3));
   if(lu2.length < 3){ lu2 = lu2 + mid(riempie, 1, (3 - lu2.length)); }
   giorno = mid(datanascita, 0, 2);
   ss = mid(datanascita, 4, 2);
   gi = trim(giorno);
   if(trim(sesso).toLowerCase()=="f"){
      g = val(datanascita) + 40
      gi = trim((string)(g));
   }
   anno = right(datanascita, 2);
   Ms = mid(mese, ss, 1);
   CF = lu1 + lu2 + anno + mid(mese, ss, 1) + gi + codcomuneistat;
   a = 0;
   for(i=2; i<=14; i=i+2){
     cfp = mid(CF, i, 1);
     if(instr(Pari1, cfp)>0){
        a = a + instr(Pari1, cfp) - 1;
     }else{
        a = a + instr(Pari11, cfp) - 1;
     }
   }
   b = 0;
   ric = 0;
   for(i=1; i<=15; i=i+2){
      cfp = mid(CF, i, 1);
      if (instr(Pari1, cfp) > 0) {
         ric = instr(Pari1, cfp) * 2 - 1;
         b = b + val(mid(dispari, ric, 2));
      } else {
         ric = instr(Pari11, cfp) * 2 - 1;
         b = b + val(mid(dispari, ric, 2));
      }
   }
   c = a + b;
   d = parseInt(c / 26);
   e = c - (d * 26);
   finale = mid(Pari1, e + 1, 1);
   CF = CF + finale;
   return CF;
}








// SET GRADIENT FROM GRADIENT LIBRARY;







var setGradient = (function() {

   //private variables;
   var p_dCanvas = document.createElement('canvas');
   var p_useCanvas = !!(typeof (p_dCanvas.getContext) == 'function');
   var p_dCtx = p_useCanvas ? p_dCanvas.getContext('2d') : null;
   var p_isIE = /*@cc_on!@*/false;


   //test if toDataURL() is supported by Canvas since Safari may not support it

   try { p_dCtx.canvas.toDataURL() } catch (err) {
      p_useCanvas = false;
   };

   if (p_useCanvas) {

      return function(dEl, sColor1, sColor2, bRepeatY) {

         if (typeof (dEl) == 'string') dEl = document.getElementById(dEl);
         if (!dEl) return false;
         var nW = dEl.offsetWidth;
         var nH = dEl.offsetHeight;
         p_dCanvas.width = nW;
         p_dCanvas.height = nH;


         var dGradient;
         var sRepeat;
         // Create gradients
         if (bRepeatY) {
            dGradient = p_dCtx.createLinearGradient(0, 0, nW, 0);
            sRepeat = 'repeat-y';
         } else {
            dGradient = p_dCtx.createLinearGradient(0, 0, 0, nH);
            sRepeat = 'repeat-x';
         }

         dGradient.addColorStop(0, sColor1);
         dGradient.addColorStop(1, sColor2);

         p_dCtx.fillStyle = dGradient;
         p_dCtx.fillRect(0, 0, nW, nH);
         var sDataUrl = p_dCtx.canvas.toDataURL('image/png');

         with (dEl.style) {
            backgroundRepeat = sRepeat;
            backgroundImage = 'url(' + sDataUrl + ')';
            backgroundColor = sColor2;
         };
      }
   } else if (p_isIE) {

      p_dCanvas = p_useCanvas = p_dCtx = null;
      return function(dEl, sColor1, sColor2, bRepeatY) {
         if (typeof (dEl) == 'string') dEl = document.getElementById(dEl);
         if (!dEl) return false;
         dEl.style.zoom = 1;
         var sF = dEl.currentStyle.filter;
         dEl.style.filter = ' ' + ['progid:DXImageTransform.Microsoft.gradient(	GradientType=', +(!!bRepeatY), ',enabled=true,startColorstr=', sColor1, ', endColorstr=', sColor2, ')'].join('');

      };

   } else {

      p_dCanvas = p_useCanvas = p_dCtx = null;
      return function(dEl, sColor1, sColor2) {

         if (typeof (dEl) == 'string') dEl = document.getElementById(dEl);
         if (!dEl) return false;
         with (dEl.style) {
            backgroundColor = sColor2;
         };
      }
   }
})();
