function ToolTipStc(bMostra, oEle, sInfo, sTitolo, lCorrSx, lwidth)
{

  twnd = document.all? document.all.StcTlTpP : document.getElementById("StcTlTpP");
  twnd.style.visibility = (bMostra && sInfo.length > 0) ? "visible" : "hidden";
  twnd.style.width = lwidth;
  tdnd = document.all? document.all.StcTdTpP : document.getElementById("StcTdTpP");
  tdndTtl = document.all? document.all.StcTdTpPTtl : document.getElementById("StcTdTpPTtl");
  tdnd.innerHTML = sInfo
  tdndTtl.innerHTML = sTitolo
    sb = getScrollXY(false);
    var sbR = sb * 1

  if ((bMostra && sInfo.length > 0)){
     twnd.style.top = oEle.clientY+sbR+1;// dht-120;//oEle.clientY-80;
     twnd.style.left=oEle.clientX+1+lCorrSx;
  }else{
     twnd.style.top = 1;// dht-120;//oEle.clientY-80;
     twnd.style.left = 1;
  }

 }

function ToolTipPers(bMostra, oEle, sInfo)
{

  twnd = document.all? document.all.TlTpP : document.getElementById("TlTpP");
  twnd.style.visibility = (bMostra && sInfo.length > 0) ? "visible" : "hidden";
  tdnd = document.all? document.all.TdTpP : document.getElementById("TdTpP");
  tdnd.innerHTML = sInfo
    sb = getScrollXY(false);
    var sbR = sb * 1

  if ((bMostra && sInfo.length > 0)){
     twnd.style.top = oEle.clientY+sbR+1;// dht-120;//oEle.clientY-80;
     twnd.style.left = oEle.clientX+1;
  }else{
     twnd.style.top = 1;// dht-120;//oEle.clientY-80;
     twnd.style.left = 1;
  }

 }

function PosizioneCursore(bMostra, oEle)
{


twnd= document.all? document.all.imgip : document.getElementById("imgip");
twnd.style.visibility= bMostra ? "visible" : "hidden";
    sb = getScrollXY(false);
    var sbR = sb * 1

dht= document.all?  (self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight))+sbR : document.height;
twnd.style.top = dht-120;//oEle.clientY-80;
twnd.style.left=oEle.clientX+4;

 }

function getScrollXY(bW) {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
    if(bW){   // 
      return (  scrOfX );    //
    } else {    //
       return (  scrOfY );  //
   }  //      scrOfX + '|' +
 // return (  scrOfY );
}

function Hidediv(nobj, Mostra)
  {
     var espressione = document.all? document.all.nobj : document.getElementById(nobj);
      if(espressione == undefined){
     espressione = !document.all? document.all.nobj : document.getElementById(nobj);
    }
      if(!Mostra)
        {
          espressione.style.visibility = "hidden";
        }
        else
        {
          espressione.style.visibility = "visible";
        }
  }



function ridimfinestra(imgal,w,h)
   {
     var myWidth = document.images[imgal].width;
      if (myWidth > w)
      {
          w = myWidth;
          }

       window.resizeTo(w + 30, h + 40);
       self.focus();
   }

function ridimWindow()
   {
     var myWidth = document.images["img"].width;
     var myHeight = document.images["img"].height;
     var scrwidth = screen.availwidth;
     var scrheight = screen.availheight;
      if (myHeight > scrheight)
      {
          myHeight = scrheight;
          }
      if (myWidth > scrwidth)
      {
          myWidth = scrwidth;
          }

       window.resizeTo(myWidth + 60, myHeight + 100);
       self.focus();
   }

function resizeWindow(imgal,w,h)
  {
    var nwi = document.images[imgal].width;
    var nhe = document.images[imgal].height;
    var nra;
    var h1 = h;
    var w1 = w;
    if (nwi > 0 && nhe > 0)
      {
        var mywidth = screen.availwidth * 0.90;
        var myheight = screen.availheight * 0.90;
        if (mywidth < w1 || w1==0)  w1=mywidth;
        if (myheight < h1 || h1==0) h1=myheight;
             if (nwi > w1 && !w1==0)
                {
             nra = nhe / nwi;
                  nhe = w1 * nra;
                  nwi = w1;
                }
            if (nhe > h1 && !h1==0)
               {
            nra = nwi / nhe;
                nwi = h1 * nra;
                nhe = h1;
               }
       document.images[imgal].width = nwi;
       document.images[imgal].height = nhe;
       }
    }



function validaEmail(eMail)
    {
      var espressione;
      //espressione = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
      espressione = /^\w+([\.\-]?\w+)+@\w+([\.\-]?\w+)+(\.\w{2,})+$/;
      return espressione.test(eMail);
    }

function validapass(pass)
   {
      var espressione;
      espressione = /^([a-zA-Z0-9]{5,})+$/ig;
//      espressione = /^((([a-z]|[A-Z])|[0-9])){5,}/ig;         ([a-zA-Z0-9]{5,})+
//      espressione = /^([a-z]|[A-Z]|[0-9]?\w{5,})/;
       var Risultato = espressione.test('');
//       window.alert (Risultato);
       Risultato = espressione.test(pass);
//       window.alert (Risultato + ' ' + pass);
      return Risultato;
    }

function validauser(user)
   {
      var espressione;
      espressione = /^([a-zA-Z0-9_]{4,})+$/ig;
//      espressione = /^((([a-z]|[A-Z]|[0-9]|[_]))){4,}/ig;       ([a-z]|[A-Z]|[0-9]|[_]{4,})+
      return espressione.test(user);
    }

function validatrova(tForm, tbox)
   {
    var myform = document.forms[tForm];
     var espressione;
     var valore;
     var valore1;
     var valore2;
     valore = myform.elements[tbox].value;
      valore = valore.replace(/^\s+|\s+$/g, '') ;
      valore = valore.replace(/[ ]{1,}/g,"+");
      espressione = /([a-z]|[A-Z]|[0-9]|[+]|[%]|[à]|[è]|[ì]|[ò]|[ù])+/ig;
      valore2 = valore.match(espressione);
          if(valore2)
    {

     valore = valore2.toString("");
     }
     myform.elements[tbox].value = valore;
     if(valore.length > 2){
     document.forms[tForm].submit();
     }else{
        window.alert('Il Formato del testo da cercare e\' errato o vuoto\n             (Consentiti solo caratteri alfanumerici (a-z, 0-9), le vocali accentate (à, è, ì, ò, ù) e gli spazi per separare le parole.)\n             minimo 3 caratteri\n');
     }
    }

function visua()
   {
   var ora = new Date();
   var oo = ora.getHours();
   var mn = ora.getMinutes();
   var sec = ora.getSeconds();
   var oo2  = ((oo < 10) ? '0' : '');
   var mn2  = ((mn < 10) ? ':0' : ':');
   var sec2  = ((sec < 10) ? ':0' : ':');
   var hh = oo2 + oo + mn2 + mn + sec2 + sec;
   if(document.all)
      document.all.primo.innerHTML = ',&nbsp;' + hh;
   else
      if(document.getElementById)
         document.getElementById('primo').innerHTML  = ',&nbsp;' + hh;
   window.setTimeout('visua()',1000);
   }



function ConfermaInvio(tForm, cara)
   {
   var myform = document.forms[tForm];
   var requira = myform.required.value;
   var require = requira.split(',');
   var lung = require.length;
   var errore1 = '\n';
   var errore = '';
   var nomeerrore = '';
   var valpass = '';
   var valtest = '';
   var ok = true;
   var caratx = 0;

   if (requira.length>0){
    for (var x=0;x<lung;x++)
       {
        valtest = '§' + require[x];

              if (myform.elements[require[x]].type=='radio'|myform.elements[require[x]].type=='checkbox')
                 {
                   caratx = 1;
                   myform.elements[require[x]].style.border='none';
                    }else{
                    caratx = cara;
                   myform.elements[require[x]].style.border='2px inset #D3D3D3';
                 }
                     if (myform.elements[require[x]].type == 'select-one')
                    {
                     caratx = 1;
                     myform.elements[require[x]].style.background='White';
                     myform.elements[require[x]].style.color='black';
                    }
        if (valtest.indexOf("email") > 0)
        {
                    if (!validaEmail(myform.elements[require[x]].value))
                    {
                     ok = false;
                     myform.elements[require[x]].style.border='2px inset #FF0000';
                     if (myform.elements[require[x]].type == 'select-one')
                    {
                     myform.elements[require[x]].style.background='#FF0000';
                     myform.elements[require[x]].style.color='White';
                    }
                     nomeerrore = myform.elements[require[x]].name;
                     nomeerrore = nomeerrore.replace(/["_"]{1}/g," ");
                     errore = errore + 'Il Formato del [' + nomeerrore + '] e\' errato o vuoto\n';
                    }
        }else if (myform.elements[require[x]].type=='password')  ///  valtest.indexOf("password") > 0
        {
                    valpass = validapass(myform.elements[require[x]].value); // myform.elements[require[x]].value;
                    if (!valpass)
                    {
                     ok = false;
                     myform.elements[require[x]].style.border='2px inset #FF0000';
                     if (myform.elements[require[x]].type == 'select-one')
                    {
                     myform.elements[require[x]].style.background='#FF0000';
                     myform.elements[require[x]].style.color='White';
                    }
                     nomeerrore = myform.elements[require[x]].name;
                     nomeerrore = nomeerrore.replace(/["_"]{1}/g," ");
                     errore = errore + 'Il Formato del [' + nomeerrore + ' -' + valpass +'] e\' errato o vuoto\n             (Consentiti solo caratteri alfanumerici (a-z, 0-9).)\n             minimo 6 caratteri\n';
                    }
        }else if (valtest.indexOf("nome_utente") > 0) // || valtest.indexOf("categoria") > 0
        {
                    valpass = myform.elements[require[x]].value;
                    if (!validauser(valpass))
                    {
                     ok = false;
                     myform.elements[require[x]].style.border='2px inset #FF0000';
                     if (myform.elements[require[x]].type == 'select-one')
                    {
                     myform.elements[require[x]].style.background='red';
                     myform.elements[require[x]].style.color='White';
                    }
                     nomeerrore = myform.elements[require[x]].name;
                     nomeerrore = nomeerrore.replace(/["_"]{1}/g," ");
                     errore = errore + 'Il Formato del [' + nomeerrore + '] e\' errato o vuoto\n             (Consentiti solo caratteri alfanumerici (a-z, 0-9) e il trattino basso.)\n';
                    }
        }else{
                     if (myform.elements[require[x]].value.length < caratx)
                    {
                     nomeerrore = myform.elements[require[x]].name;
                     nomeerrore = nomeerrore.replace(/["_"]{1}/g," ");
                     if (caratx > 1)
                     {
                       errore = errore + 'Il campo [' + nomeerrore + '] contiene meno di ' + caratx + ' caratteri (' + myform.elements[require[x]].value.length + ')\n';
                     }
                     else
                     {
                       errore = errore + 'Il Formato del campo [' + nomeerrore + '] non puo\' essere vuoto\n';
                     }
                     ok = false;
                     myform.elements[require[x]].style.border='2px inset #FF0000';
                     if (myform.elements[require[x]].type == 'select-one')
                    {
                     myform.elements[require[x]].style.background='red';
                     myform.elements[require[x]].style.color='White';
                    }
                    }
         }

      }
   }
    if (!ok)
   {
   errore = '      Impossibile continuare:\n' + errore + '\n       Riprova.'
   window.alert(errore)//errore
          }else{
   var ok = window.confirm('Confermi?'); // confermi
    if (ok)
       {
       document.forms[tForm].submit();
       }
   }
   }

function resetform(tForm)
    {
   var myform = document.forms[tForm];
   var lung = myform.length;
    var tipo = '';
    var ok = window.confirm('Resettare i campi?');
    if (ok)
       {
    for (var x=0;x<lung;x++)
       {
         tipooggetto = myform.elements[[x]].type
    if (tipooggetto=='radio'|tipooggetto=='checkbox')
       {
         myform.elements[[x]].style.border='none';
          }else{
         myform.elements[[x]].style.border='2px inset #D3D3D3';
       }
       if (myform.elements[[x]].type == 'select-one')
      {
       myform.elements[[x]].style.background='White';
       myform.elements[[x]].style.color='Black';
      }
     }
        document.forms[tForm].reset();
       }
    }


function apriPicture(nurl, sMyPicture)
   {
     var scrollwin = '';
        mywin = window.open(nurl + '?img=' + sMyPicture, 'Picture', 'width=600,height=100' + scrollwin + ',scrollbars=yes,z-lock=yes,status=no,menubar=no,resizable=yes');
   }

function apriRegistra(nurl)
   {
        mywin = window.open(nurl, 'Picture', 'width=550,height=550,scrollbars=yes,location=0,menubar=no,resizable=yes,status=no,menubar=no,toolbar=no,location=no');
   }

function Stampa()
    {
      alert("Attenzione!!!\n\nLa pagina verra' stampata in senso verticale.\nPer stamparla in senso orizzontale modificare\nl'opzione presente nelle proprietà della propria\nstampante.");//();
      self.print();
    }
 
   function Mfavo()
    {
        var squi = self.document.location;
        var snme = self.document.title;
        window.external.AddFavorite(squi,snme);
    }
// calendario
 function innerCalendarCode(laData, txBox) {
   function montharr(m0, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11) {
     this[0] = m0;
     this[1] = m1;
     this[2] = m2;
     this[3] = m3;
     this[4] = m4;
     this[5] = m5;
     this[6] = m6;
     this[7] = m7;
     this[8] = m8;
     this[9] = m9;
     this[10] = m10;
     this[11] = m11;
   }
   function calendar(CampoTesto) {
     var monthNames = "gennaio   febbraio  marzo     aprile    maggio    giugno    luglio    agosto    settembre ottobre   novembre  dicembre  ";
     var Adesso = new Date();
     var today = new Date(laData);
     var thisDay;
     var monthDays = new montharr(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
     var ayear = Adesso.getYear();
     if (ayear <= 200 && ayear > 70) {
        ayear += 1900;
     }
     if (ayear <= 200 ) {
        ayear += 2000;
     }

     var year = today.getYear();
     if (year <= 200 && year > 70) {
        year += 1900;
     }
     if (year <= 200 ) {
        year += 2000;
     }
     thisDay = today.getDate();
     var ilMse = 0;

     if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {
        monthDays[1] = 29;
     }
     ilMse = today.getMonth();
     //nDays = monthDays[today.getMonth()];
     nDays = monthDays[ilMse];
     var preMese = (today.getMonth() - 1);
     var preAnno = (year);
     if (preMese < 0){
        preMese = 11;
        preAnno = preAnno - 1;
     }
     var segMese= (today.getMonth() + 1);
     var sucAnno = (year);
     if (segMese> 11){
        segMese = 0;
        sucAnno = preAnno + 1;
     }
     firstDay = today;
     firstDay.setDate(1);
     testMe = firstDay.getDate();
     if (testMe == 2) {
        firstDay.setDate(0);
     }
     startDay = firstDay.getDay()-1;
     var clln = ("<CENTER>");
     clln = clln + ("<TABLE class=\"sinisra\" border=\"0\" style=\"font-size:8pt;\" cellspacing=\"0\" align=\"center\" cellpadding=\"1\" width=\"100%\">");
     clln = clln + ("<TR class=\"rigatitolo\">");
     clln = clln + ("<TH style=\"text-transform: capitalize;\" align=\"left\" valign=\"middle\">");
        if(CampoTesto.length > 0){clln = clln + '<a class="btn" title="' + (monthNames.substring(preMese  * 10, (preMese + 1) * 10)) + preAnno  + '" href="javascript:innerCalendarCode(\'' + (preMese + 1)  + '/' + (thisDay)  + '/' + preAnno   + '\',\'' + CampoTesto + '\')" target="_self" hreflang="it">&lt;</a>';}
     clln = clln + ("</TH>");
     clln = clln + ("<TH colspan=\"5\" style=\"text-transform: capitalize;\">");
     clln = clln + (monthNames.substring(ilMse  * 10, (ilMse + 1) * 10));
     clln = clln + (" ");
     clln = clln + (year);
     clln = clln + ("</TH>");
     clln = clln + ("<TH style=\"text-transform: capitalize;\" align=\"right\" valign=\"middle\">");
        if(CampoTesto.length > 0){clln = clln + '<a class="btn" title="' + (monthNames.substring(segMese  * 10, (segMese + 1) * 10)) + sucAnno  + '" href="javascript:innerCalendarCode(\'' + (segMese + 1) + '/' + (thisDay)  + '/' + sucAnno    + '\',\'' + CampoTesto + '\')" target="_self" hreflang="it">&gt;</a>';}
     clln = clln + ("</TH>");
     clln = clln + ("</TR>");
     clln = clln + ("<TR class=\"riga1\" ><TH>Lu</TH><TH>Ma</TH><TH>Me</TH><TH>Gi</TH><TH>Ve</TH><TH>Sa</TH><TH>Do</TH>");
     clln = clln + ("</TR>");
     clln = clln + ("<TR >");
     column = 0;
     for (i = 0; i < startDay; i++) {
         clln = clln + ("<TD align=\"right\"></TD>");
         column++;
     }
     for (i = 1; i <= nDays; i++) {
         clln = clln + ("<TD align=\"center\" style=\"background-color: ");      //thisDay
         if ((i == Adesso.getDate()) && (ilMse == Adesso.getMonth()) && (year == ayear)) {
            clln = clln + ("yellow; COLOR: #FF0000; font-weight: bold; border: 1px solid #008486;\"  class=\"rigatitolo\" title=\"Oggi\"");
         }else{
            clln = clln + ("white; border: 1px solid #c6ffbb;\"");
         }
         clln = clln + (' >');
            if(CampoTesto.length > 0){clln = clln + ('<a class="btn" style="text-decoration: none;" title="Imposta al ');
         clln = clln + ('' + ('00' + i).substr(('00' + i).length - 2) + '/' + ('00'+(today.getMonth() + 1)).substr(('00'+(today.getMonth() + 1)).length-2)  + '/' + year + '');
         clln = clln + ('" href="#" onclick="javascript:' + CampoTesto + '.value=\'');
         clln = clln + ('' + ('00' + i).substr(('00' + i).length - 2) + '/' + ('00'+(today.getMonth() + 1)).substr(('00'+(today.getMonth() + 1)).length-2)  + '/' + year + '');
         clln = clln + ('\';" target="_self" hreflang="it">');}
         clln = clln + ("" + ('00' + i).substr(('00' + i).length - 2) + "");
            if(CampoTesto.length > 0){clln = clln +("<a>");}
         clln = clln + ("</TD>");
         column++;
         if (column == 7) {
            clln = clln + ("</TR><TR>");
            column = 0;
         }
     }
     clln = clln + ("</TR>");
     clln = clln + ("</TABLE>");
   if(CampoTesto.length == 0){
     document.writeln(clln);
   } else {
     if(document.all){
        document.all.LivMese.innerHTML = clln;
     }else {
        if(document.getElementById)
           document.getElementById('LivMese').innerHTML  = clln;
      }
    }
   }
   calendar(txBox);
}
   // <condizione> ? <istruzione1> : <istruzione2>
