
function Activate(menu){
  var nodo=document.getElementById(menu);
  nodo.style.visibility = 'visible';
  nodo.style.display = 'inline';
}
function deActivate(menu){
  var nodo=document.getElementById(menu);
  if (nodo != null){
    nodo.style.display = 'none';
    nodo.style.visibility = 'hidden';
    }

}



function visMenu(menu, riferim, dx, dy){
  var nodo=document.getElementById(menu);
  var rif=document.getElementById(riferim);
  Posiziona(nodo, rif, dx, dy);
  Activate(menu);
}

function visMenu(menu, riferim){
  var nodo=document.getElementById(menu);
  var rif=document.getElementById(riferim);
  Posiziona(nodo, rif, 0, 0);
  Activate(menu);
}
function Posiziona(frame, oggRif, deltaX, deltaY) {
  var dB=document.body;
  var eL=0;
  var eT=0;
  for(var p=oggRif; p && p.tagName!='BODY'; p=p.offsetParent){
    eL+=p.offsetLeft;
    eT+=p.offsetTop;
    if (p.tagName =='DIV')
       eT -=p.scrollTop;
 }
 var eH=oggRif.offsetHeight;
 var dH=frame.style.pixelHeight;
 var sT=dB.scrollTop;
  if(eT-dH >=sT &&  eT+eH+dH > dB.clientHeight+sT)
    eT-=dH;
   else eT+=eH;
 frame.style.left=eL + deltaX ;
 frame.style.top=eT + deltaY -1;
//alert(frame.id);
//msgFine(frame.nodeName);
 }

function getY(oggRif) {
     var lista =document.getElementsByTagName("body");
     var oBody = lista.item(0);

   // return oBody.offsetHeight

  var eT=0;
  for(var p=oggRif; p && p.tagName!='BODY'; p=p.offsetParent){
    eT+=p.offsetTop;
   }

   return eT;

 }

 function setResize(oggetto){
     //var lista =window.parent.document; //.getElementsByTagName("body");
     //var oBody = lista.item(0);
     var oBody = window.parent.document;
     var nodo=document.getElementById('xFine');
     var y = getY(nodo);
     oBody.resize(oggetto, y);
     return;
 }

function setValue(nome, valore){
    var nodo = document.getElementById(nome);
    nodo.value        = valore;

  }
function getValue(nome){
    var nodo = document.getElementById(nome);
    if ( nodo != null )
      return nodo.value;
    return "";
  }

function setValueOut(nome, valore) {
    var nodo = document.getElementById(nome);
    if (nodo.firstChild == null ) {
      text = document.createTextNode(valore);
      nodo.appendChild(text);
    } else
       nodo.firstChild.data = valore;
  }

function setErrore(valore){
    var nodo = document.getElementById("errore");
    nodo.innerHTML = valore;

  }

// chiamato in onBeforeUnload per emettere  loading quando si cambia pagina



// ===========================================
//  funzioni per gestire una TreeView
// ===========================================

// cambia lo stato di un nodo

 function cambiaStato( id, path) {
     var nodo=document.getElementById(id);
     var img=document.getElementById("im" + id);
     if ( nodo.style.display =='inline'){
           nodo.style.display ='none';
           elimina(id);
           path = path + "_p.gif";
           img.src=path;
           }
         else{
           nodo.style.display ='inline';
           aggiungi(id, path);
           path = path + "_m.gif";
           img.src=path;
           }
     resize();
     return false;


   }
// setta gli href del menu popup a seconda del nodo selezionato

 var m_parDef =   "";

function setHref(menu, par){
    var omenu=document.getElementById('m' +menu);
    if (omenu == null){ // non esiste la tabella contenente le voci
         omenu=document.getElementById(menu);
        }
    if (omenu == null){ // non esiste la tabella contenente le voci

       return;
        }
    var lst= document.getElementsByTagName('A');
     var par1="";
      if ( par!= null && par.length > 0){
          par1 +=  "&" + par;
       }
       var a;
     for(i=0;i < lst.length;i++){
       a = lst.item(i);
       var at = a.getAttributeNode('mem');

       if (at != null){
           if (at.nodeValue.indexOf("javascript:") < 0)
               a.href= m_hrefBase +'/' + at.nodeValue  + m_parDef + par1;
           else {
               a.href=  at.nodeValue ;
               a.target="" ;
               }

           }

     }
}


// Visualizza un menu popup

function visMenuP( Id, tipo, par){

  m_IdUFu = Id;
  var menu= 'm'+tipo;
   setHref(menu, par);
  var dif=5;
  var obj=document.getElementById(menu);
  if (obj != null){
     obj.style.display ='inline';
     obj.style.visibility = 'visible';
     visMenu(menu,  Id, 0, -2 ) ;
     resize(obj);
  }
  return false;
}
function visMenuP1( Id, tipo, par,x,y){

  m_IdUFu = Id;
  var menu= 'm'+tipo;
  setHref(menu, par);
  var dif=5;
  var mx=x;
  var my=y;
  if (mx == null)
      mx= 15;
  if (my == null)
      my= -10;
  var obj=document.getElementById(menu);
  if (obj != null){
     obj.style.display ='inline';
     obj.style.visibility = 'visible';
     visMenu(menu,  Id, mx, my ) ;
  }
  return false;
}


function setCursor(obj, menu){
  var nodo=document.getElementById(menu);
 if (nodo == null){
    obj.style.cursor = 'default';
    }

}

function getAltPag() {
     var lista = document.getElementsByTagName("body");
     var obj = lista.item(0);
     return obj.offsetHeight;

}
function msgFine(testo) {
     var obj = document.getElementById("xFine");
     /* obj.style.position ="absolute";
      obj.style.top="00";
      obj.style.left="500";  */
      obj.height ="30";
      obj.innerText  = obj.innerText +testo;

}

// *********************************************************************************************************
// Funzioni per gestire:
//                      il resize delle form e dei relativi contenitori.
//                      la visualizzazione delle iframe
//
//

// Aggiorna l'altezza della pagina a seconda del contenuto
// var m_altezza = <xsl:value-of select="$altpag"/>;
 var m_altPrec =0;

 function resize(obj){
   var y = 0;

    if (obj != null) {
       y = getY(obj) + obj.offsetHeight;
   }
   var maxY = document.body.scrollHeight;
     if ( y > maxY){
        maxY= y;
      }

    var frame=getIFrame();
    var oBody =padre();
    if (oBody != null ) {
       oBody.resizeFrame( maxY +30, frame);
      }

}
 function autoResize(h){
     var nodo=document.getElementById('xFine');
    var oBody= document.body;
   // var maxY = getY(nodo) ;
    var    maxY = document.body.scrollHeight;
     if ( h > maxY){
        maxY= h;
      }
   var oBody =padre();
   var frame=getIFrame();

    if (oBody != null ) {
       oBody.resizeFrame( maxY +30, frame);

      }
}
function resizeMioConten( ){
  resizeConten("", null, getIFrame());
}
function resizeConten( nome, maxY, objFrame){
    var nodo=document.getElementById('xFine');

    var oBody= document.body;
    if (maxY == null){
    //  maxY = getY(nodo); Antonio 17/1/05
        maxY = document.body.scrollHeight;
      }

    var oBody =padre();
    if (oBody != null ) {
       if (oBody.resizeIframe == undefined){
           //oBody.resizeIframe = resizeIframe;
           }
        oBody.resizeIframe(nome, maxY +5, objFrame);

      }
}

 function resizeIframe(nome, h, objFrame){
    var nodo;
    if (objFrame != null)
      nodo = objFrame;
    else
      nodo=document.getElementById(nome);

    if (nodo != null     ) {
       nodo.height= h ;
       autoResize(h +30);
     }


}

function resizeFrame( maxY, pframe) {

  var frame = pframe;

   if (pframe == null)
       frame=getIFrame();

   if (pframe == null){
      pframe = frameElement;
     }
  if (frame ==null)
     return;
  var at = frame.getAttributeNode('altezza');
  var altezza = 0;
  if (at != null)
      altezza = at.nodeValue;
  var nmax = maxY;
   if (nmax < altezza)
       nmax = altezza;
 var altPrec = new Number(frame.height);

  if (nmax > altezza || altPrec > altezza ) {
   frame.height= nmax ;

   var h1 = document.body.scrollHeight;
   if (frame.id  != 'Principale' &&   frame.id  != 'ColSinistra'  &&   frame.id  != 'ColDestra'){
       var obj = padre();

       if (obj != null ){
        //frame=getIFrame();
        // obj.resizeFrame( h1 +10, );
        // obj.resize();
         }
      }
     }
 }

function ricarica() {
     var nodo=document.getElementById("documento" );
     nodo.style.visibility='hidden';
     var nodo=document.getElementById("loading" );
     nodo.style.visibility='visible';
  }


function padre() {
   return window.parent.document;

}
function doc() {
   return document;

}
function nascondi(id){
    var obj=document.getElementById(id);
    if (obj.style.visibility !='hidden')
        obj.style.visibility='hidden';

}
function visibile(id){
    var obj=document.getElementById(id);
            alert(obj.style.visibility);

    if (obj.style.visibility !='hidden')
        return true;
    return false;
}

function mostra(id){
   var obj=document.getElementById(id);
   obj.style.visibility='visible';

}
function getIFrame(){
 var oFrame = window.frameElement;

 return oFrame;
}

function visMiaIFrame(titolo){
    var obj = padre();
   obj.visFrame(titolo,  getIFrame());
    resizeMioConten();
}
function visFrame(titolo,  objFrame) {
  var id = objFrame.id;
   var  nodo=document.getElementById("div"+id);  // contenitore della iframe
  nodo.style.visibility='visible';
  if (titolo != null)
      setValueOut('Tit' + id , titolo);
 return true;
}
function setFunzHLst(obj){
  // associa le funzioni di una HLst  per gestire la collaborazione con form interne
    obj.visFrame=visFrame;
    obj.resizeFrame = resizeFrame;
    obj.resize = resize;
    obj.resizeIframe = resizeIframe;
    obj.rinfresca = rinfresca;

}
function posizForm(obj){
 var y = getY(obj);

 var lst= document.getElementsByTagName('IFRAME');
 var a;
 for(i=0;i < lst.length;i++){
    a = lst.item(i);
    var div= document.getElementById('div' +a.id);
    var h = a.height - 60;
    if (div != null){
      if ( y < h)
        div.style.top=0;
    else
        div.style.top=y-h;
       }
      }

}

// ***************************************************************************************************
//  funzioni per gestire il rinfresco di nodi
//  di una treewiev
// ***************************************************************************************************
 var m_nodi = new Array();

 function elimina(id){
   for (var i =0; i < m_nodi.length; i++){
      if (m_nodi[i] == id){
         m_nodi[i] ="";
          return ;
      }

   }
 }
 function aggiungi(id, path){
    for (var i =0; i < m_nodi.length; i++){
      if (m_nodi[i] == id){
      return ;
      }
   }
    m_nodi[i] = id;
 }

 function visualizzaNodi(){
   for (var i =0; i < m_nodi.length; i++){
      var nodo=document.getElementById(m_nodi[i]);
      if (nodo != null)
         cambiaStato(m_nodi[i], m_imgNodo) ;
      }

 }

 var m_href = null;

 function rinfresca(nodo) {
    if ( m_href == null )
         return;

    var path = m_hrefBase + '/servlet/' + m_href ;
    var nodi="";
    for (var i =0; i < m_nodi.length; i++){

        if (m_nodi[i].length > 0){
                nodi = nodi + '&nodo.' + i + '=' + m_nodi[i];
            }
       }
       i++;
       if (nodo != null){
           nodi = nodi + '&nodo.' + i + '=' + nodo.value;
         }
        document.location.href= path + nodi;

 }
  function aggiornaContenitore() {
      var oBody =padre();
      oBody.rinfresca();
   }

function larghezza(id){
  var obj=document.getElementById(id);
  var lst= obj.childNodes ;
  var larg= 0;
  var td;
     for(i=0;i < lst.length;i++){
       td = lst.item(i);
        if (td.nodeName == 'TD')
           larg += new Number(td.width);
       }

  return larg;

}

  function isdefined(variabile) {
    if(typeof(variabile) !="undefined")
    return true;
  else
    return false;
  }

/* ======================================================================================
------- ritorna un intero per poterlo usare nelle operazioni
*/
function getIntero(idNodo){
    var nodo = document.getElementById(idNodo);
    var valore = nodo.value;

       // tolgo punti
       var re = /\./g;             //regular expression pattern.
       valore = valore.replace(re, "");

       var i = valore.indexOf(',');

     var sint="";
     var sdec="00";
     if (i >= 0) {  // ci sono decimali
         sint = valore.substr(0,i); // parte intera dell'importo
         sdec = valore.substr(i+1 , 2); // parte decimale
         if(sdec.length < 2)
          sdec+='0';
       }
       else{
        sint = valore;
       }
   for(i=0;i < sint.length && sint.charAt(i) =='0';i++){ // indice del primo carattere != 0
         }

    if (i > 0)
      sint = sint.substr(i);

     var intero = parseInt(sint + sdec);
     return intero;
    }

/* ======================================================================================
------- ritorna una stringa formato euro da un intero
*/
function getEuro(intero){

    simp = intero.toString(); // trasformo importo in stringa

    sint = simp.substr(0,simp.length - 2); // parte intera dell'importo
    if (sint == '' )
      sint = '0';

    var sdec = simp.substr(simp.length - 2, 2); // parte decimale
    return sint + "," + sdec;

 }

/* ======================================================================================
                     Funzioni per gestione ore
  ====================================================================================== */
//===========================================
//Formatta un'ora nel corretto formato hh:mm,
//mettendo gli zeri ove necessario.
//il parametro ora è una stringa nella forma hh:mm
//ritorna la stringa formattata.
//-------------------------------------------
 function formattaOra(ora) {
   var ore = getOra(ora);
   var minuti = getMinuti(ora);
   var s_ora = "" + ore;
   if (ore < 10)
      s_ora = "0" + ore;
   var s_minuti = "" + minuti;
   if (minuti < 10)
      s_minuti = "0" + minuti;
   return s_ora + ':' + s_minuti;
 }

//===========================================
//converte un ora in minuti
//il parametro ora è una stringa nella forma hh:mm
//ritorna i minuti dell'ora oppure 0 se errori
//Ad esempio convOraInMinuti('09:37') ritorna 577
//-------------------------------------------
function convOraInMinuti(ora) {
   if (ora.length == 0)
      return 0;
   var ore = getOra(ora);
   var minuti = getMinuti(ora);
   //alert(ora.substring(0,2) + '=' + ore + ',  ' + ora.substring(3) + '=' + minuti);
   //alert('convOraInMinuti ' + ora + '-->' + ore + ',' + minuti + ' = ' + (ore*60 + minuti));
   return ore*60 + minuti;
}

//===========================================
//converte i minuti in ora nel format hh:mm (sempre lungo 5 car.)
//il parametro minuti è un int che rappresenta i minuti.
//ritorna i minuti convertiti in ora (stringa)
//-------------------------------------------
function convMinutiInOra(minuti) {
   if (minuti <=0)
     return "";
   var n_minuti = minuti % 60;
   var n_ore = (minuti - n_minuti) / 60;
   //alert('conversione minuti ' + minuti + '-->ore=' + n_ore + ',  minuti=' + n_minuti);
   var s_ore = "" + n_ore;
   if (s_ore.length==1)
      s_ore = "0" + s_ore;
   var s_minuti = "" + n_minuti;
   if (s_minuti.length==1)
      s_minuti = "0" + s_minuti;
   return s_ore + ":" + s_minuti;
}


//===========================================
//Controlla se un ora è sintatticamente corretta.
//Controlla che le ore siano fra 0 e 23 e i minuti fra 0 e 59.
//Parametri:
//   ora      stringa nella forma hh:mm
//   message  se true, emette messaggio di errore con alert
//Ritorna true se tutto ok, false altrimenti
//-------------------------------------------
function checkOra(ora, message) {
   var ore = getOra(ora);
   if (ore <0 || ore > 23) {
      if (message)
        alert("L'ora sembra errata: " + ore);
	  return false;
   }
   var minuti = getMinuti(ora);
   if (minuti <0 || minuti > 59) {
      if (message)
        alert("I minuti sembrano errati: " + minuti);
	  return false;
   }
   return true;
}

//===========================================
//Ritorna la parte ora, in formato numerico, di un ora passata nella forma hh:mm
//Se non c'è il ':' assume che i minuti siano '00'.
//Parametri:
//   ora      stringa nella forma hh:mm
//
//Ad esempio getOra('12:41') ritorna l'int 12.
//           getOra('3') ritorna l'int 3.  
//-------------------------------------------
function getOra(ora) {
  var i = ora.indexOf(':');
  var ore = ora;
  if (i >= 0)
    ore = ore.substring(0, i);

  //nota: il prefisso '0' in javascript indica numero ottale
  //per cui devo levare gli zeri non significativi in testa
  if (ora.charAt(0)=='0')
     return parseInt(ore.substring(1));
  else
     return parseInt(ore);
}

//===========================================
//Ritorna l'ora, in formato stringa (hh:mm) dalla variabile
//di tipo data passata.
//Se la variabile è null o non è una data, ritorna stringa vuota.
//Parametri:
//   data      variabile di tipo data
//
//-------------------------------------------
function getHHMMFromDate(data) {
   if (!(variabile instanceof Date))
     return "";

   var hm = "";
   if (data.getHours() < 10)
     hm = '0';
   hm = hm + data.getHours() + ':';
   if (data.getMinutes() < 10)
     hm = hm + '0';
   hm = hm + data.getMinutes();
   return hm;
}


//===========================================
//Ritorna i minuti, in formato numerico, di un ora
//passata nella forma hh:mm
//Se non c'è il ':' assume che i minuti siano '00'.
//Ad esempio getMinuti('12:41') ritorna l'int 41.
//-------------------------------------------
function getMinuti(ora) {
  var i = ora.indexOf(':');
  if (i<0)
    return 0;  
  var minuti = ora.substring(i+1);

  //nota: il prefisso '0' in javascript indica numero ottale
  //per cui devo levare gli zeri non significativi in testa
  if (minuti.charAt(0)=='0')
     return parseInt(minuti.substring(1));
  else
     return parseInt(minuti);
}


/* ======================================================================================
------- Metodi per l'oggetto String, restituiscono la stringa cui sono applicati
------- senza spazi iniziali e/o finali:
-------
------- str_a = stringa.Trim();
------- str_a contiene il valore di stringa senza spazi iniziali ne' finali
-------
------- str_a = stringa.LTrim();
------- str_a contiene il valore di stringa senza spazi iniziali
-------
------- str_a = stringa.RTrim();
------- str_a contiene il valore di stringa senza spazi finali
-------
------- le funzioni in minuscolo non sono funzioni dell'oggetto string, ma generiche, che si possono
------- chiamare cosi:  trim(stringa), ltrim(stringa), rtrim(stringa)
-------
------- N.B.
------- [\s] nelle RegExp contiene sia gli spazi che i ritorni a capo, avanzamento riga
------- tabulatore, tabulatore verticale. Tutti questi caratteri, se presenti, verranno
------- eliminati.
------- --- */
function trim(str) {
return str.replace(/\s+$|^\s+/g,"");
}
function ltrim(str) {
return str.replace(/^\s+/,"");
}

function rtrim(str) {
return str.replace(/\s+$/,"");
}

function Trim() {
return this.replace(/\s+$|^\s+/g,"");
}

function LTrim() {
return this.replace(/^\s+/,"");
}

function RTrim() {
return this.replace(/\s+$/,"");
}

String.prototype.Trim=Trim;
String.prototype.RTrim=RTrim;
String.prototype.LTrim=LTrim;

function getPar(nome){
  return  "&" + nome+ "=" + getValue(nome);

}

//<!--
// Ultimate client-side JavaScript client sniff. Version 3.03
// (C) Netscape Communications 1999-2001.  Permission granted to reuse and distribute.
// Revised 17 May 99 to add is_nav5up and is_ie5up (see below).
// Revised 20 Dec 00 to add is_gecko and change is_nav5up to is_nav6up
//                      also added support for IE5.5 Opera4&5 HotJava3 AOLTV
// Revised 22 Feb 01 to correct Javascript Detection for IE 5.x, Opera 4,
//                      correct Opera 5 detection
//                      add support for winME and win2k
//                      synch with browser-type-oo.js
// Revised 26 Mar 01 to correct Opera detection
// Revised 02 Oct 01 to add IE6 detection

// Everything you always wanted to know about your JavaScript client
// but were afraid to ask. Creates "is_" variables indicating:
// (1) browser vendor:
//     is_nav, is_ie, is_opera, is_hotjava, is_webtv, is_TVNavigator, is_AOLTV
// (2) browser version number:
//     is_major (integer indicating major version number: 2, 3, 4 ...)
//     is_minor (float   indicating full  version number: 2.02, 3.01, 4.04 ...)
// (3) browser vendor AND major version number
//     is_nav2, is_nav3, is_nav4, is_nav4up, is_nav6, is_nav6up, is_gecko, is_ie3,
//     is_ie4, is_ie4up, is_ie5, is_ie5up, is_ie5_5, is_ie5_5up, is_ie6, is_ie6up, is_hotjava3, is_hotjava3up,
//     is_opera2, is_opera3, is_opera4, is_opera5, is_opera5up
// (4) JavaScript version number:
//     is_js (float indicating full JavaScript version number: 1, 1.1, 1.2 ...)
// (5) OS platform and version:
//     is_win, is_win16, is_win32, is_win31, is_win95, is_winnt, is_win98, is_winme, is_win2k
//     is_os2
//     is_mac, is_mac68k, is_macppc
//     is_unix
//     is_sun, is_sun4, is_sun5, is_suni86
//     is_irix, is_irix5, is_irix6
//     is_hpux, is_hpux9, is_hpux10
//     is_aix, is_aix1, is_aix2, is_aix3, is_aix4
//     is_linux, is_sco, is_unixware, is_mpras, is_reliant
//     is_dec, is_sinix, is_freebsd, is_bsd
//     is_vms
//
// See http://www.it97.de/JavaScript/JS_tutorial/bstat/navobj.html and
// http://www.it97.de/JavaScript/JS_tutorial/bstat/Browseraol.html
// for detailed lists of userAgent strings.
//
// Note: you don't want your Nav4 or IE4 code to "turn off" or
// stop working when new versions of browsers are released, so
// in conditional code forks, use is_ie5up ("IE 5.0 or greater")
// is_opera5up ("Opera 5.0 or greater") instead of is_ie5 or is_opera5
// to check version in code which you want to work on future
// versions.

    // convert all characters to lowercase to simplify testing
    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
    // If you want to allow spoofing, take out the tests for opera and webtv.
    var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
    var is_nav2 = (is_nav && (is_major == 2));
    var is_nav3 = (is_nav && (is_major == 3));
    var is_nav4 = (is_nav && (is_major == 4));
    var is_nav4up = (is_nav && (is_major >= 4));
    var is_navonly      = (is_nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    var is_nav6 = (is_nav && (is_major == 5));
    var is_nav6up = (is_nav && (is_major >= 5));
    var is_gecko = (agt.indexOf('gecko') != -1);


    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

    // KNOWN BUG: On AOL4, returns false if IE3 is embedded browser
    // or if this is the first browser window opened.  Thus the
    // variables is_aol, is_aol3, and is_aol4 aren't 100% reliable.
    var is_aol   = (agt.indexOf("aol") != -1);
    var is_aol3  = (is_aol && is_ie3);
    var is_aol4  = (is_aol && is_ie4);
    var is_aol5  = (agt.indexOf("aol 5") != -1);
    var is_aol6  = (agt.indexOf("aol 6") != -1);

    var is_opera = (agt.indexOf("opera") != -1);
    var is_opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    var is_opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    var is_opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    var is_opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    var is_opera5up = (is_opera && !is_opera2 && !is_opera3 && !is_opera4);

    var is_webtv = (agt.indexOf("webtv") != -1);

    var is_TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1));
    var is_AOLTV = is_TVNavigator;

    var is_hotjava = (agt.indexOf("hotjava") != -1);
    var is_hotjava3 = (is_hotjava && (is_major == 3));
    var is_hotjava3up = (is_hotjava && (is_major >= 3));

    // *** JAVASCRIPT VERSION CHECK ***
    var is_js;
    if (is_nav2 || is_ie3) is_js = 1.0;
    else if (is_nav3) is_js = 1.1;
    else if (is_opera5up) is_js = 1.3;
    else if (is_opera) is_js = 1.1;
    else if ((is_nav4 && (is_minor <= 4.05)) || is_ie4) is_js = 1.2;
    else if ((is_nav4 && (is_minor > 4.05)) || is_ie5) is_js = 1.3;
    else if (is_hotjava3up) is_js = 1.4;
    else if (is_nav6 || is_gecko) is_js = 1.5;
    // NOTE: In the future, update this code when newer versions of JS
    // are released. For now, we try to provide some upward compatibility
    // so that future versions of Nav and IE will show they are at
    // *least* JS 1.x capable. Always check for JS version compatibility
    // with > or >=.
    else if (is_nav6up) is_js = 1.5;
    // NOTE: ie5up on mac is 1.4
    else if (is_ie5up) is_js = 1.3

    // HACK: no idea for other browsers; always check for JS version with > or >=
    else is_js = 0.0;

    // *** PLATFORM ***
    var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

    // is this a 16 bit compiled version?
    var is_win16 = ((agt.indexOf("win16")!=-1) ||
               (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) ||
               (agt.indexOf("windows 16-bit")!=-1) );

    var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
                    (agt.indexOf("windows 16-bit")!=-1));

    var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
    var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));

    // NOTE: Reliable detection of Win98 may not be possible. It appears that:
    //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
    //       - On Mercury client, the 32-bit version will return "Win98", but
    //         the 16-bit version running on Win98 will still return "Win95".
    var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
    var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
    var is_win32 = (is_win95 || is_winnt || is_win98 ||
                    ((is_major >= 4) && (navigator.platform == "Win32")) ||
                    (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

    var is_os2   = ((agt.indexOf("os/2")!=-1) ||
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||
                    (agt.indexOf("ibm-webexplorer")!=-1));

    var is_mac    = (agt.indexOf("mac")!=-1);
    // hack ie5 js version for mac
    if (is_mac && is_ie5up) is_js = 1.4;
    var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) ||
                               (agt.indexOf("68000")!=-1)));
    var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) ||
                                (agt.indexOf("powerpc")!=-1)));

    var is_sun   = (agt.indexOf("sunos")!=-1);
    var is_sun4  = (agt.indexOf("sunos 4")!=-1);
    var is_sun5  = (agt.indexOf("sunos 5")!=-1);
    var is_suni86= (is_sun && (agt.indexOf("i86")!=-1));
    var is_irix  = (agt.indexOf("irix") !=-1);    // SGI
    var is_irix5 = (agt.indexOf("irix 5") !=-1);
    var is_irix6 = ((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1));
    var is_hpux  = (agt.indexOf("hp-ux")!=-1);
    var is_hpux9 = (is_hpux && (agt.indexOf("09.")!=-1));
    var is_hpux10= (is_hpux && (agt.indexOf("10.")!=-1));
    var is_aix   = (agt.indexOf("aix") !=-1);      // IBM
    var is_aix1  = (agt.indexOf("aix 1") !=-1);
    var is_aix2  = (agt.indexOf("aix 2") !=-1);
    var is_aix3  = (agt.indexOf("aix 3") !=-1);
    var is_aix4  = (agt.indexOf("aix 4") !=-1);
    var is_linux = (agt.indexOf("inux")!=-1);
    var is_sco   = (agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1);
    var is_unixware = (agt.indexOf("unix_system_v")!=-1);
    var is_mpras    = (agt.indexOf("ncr")!=-1);
    var is_reliant  = (agt.indexOf("reliantunix")!=-1);
    var is_dec   = ((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) ||
           (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) ||
           (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1));
    var is_sinix = (agt.indexOf("sinix")!=-1);
    var is_freebsd = (agt.indexOf("freebsd")!=-1);
    var is_bsd = (agt.indexOf("bsd")!=-1);
    var is_unix  = ((agt.indexOf("x11")!=-1) || is_sun || is_irix || is_hpux ||
                 is_sco ||is_unixware || is_mpras || is_reliant ||
                 is_dec || is_sinix || is_aix || is_linux || is_bsd || is_freebsd);

    var is_vms   = ((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1));







 // Funzioni per la gestione dei bottoni per la formattazione

 function addTabella(nome) {
   var rows = prompt('Inserisci il numero di righe',0);
   var cols = prompt('Inserisci il numero di colonne',0);
   if ( rows == 0 || cols == 0)
      return;
   var s = "<table class='testo' >\n";
   for ( i = 1; i <= rows; i++ ) {
      s += "  <tr>\n";
      for ( j = 1; j <= cols; j++ ) {
        s += "    <td width='80'>Riga"+i+" colonna"+j+"</td>";
      }
      s += "  </tr>\n";
   }
   s += "</table>";
   insertAtCursor(nome,s);
 }



 function insImg(nome, src) {
   if ( src == "" )
      return;
   var s = "<img src='"+src+"' />";
   insertAtCursor(nome,s);
 }

function insertAtCursor(nome, myValue) {
    var nodo = document.getElementById(nome);
        //IE support
        if (document.selection) {
                nodo.focus();
                sel = document.selection.createRange();
                sel.text = myValue;
        }
        //MOZILLA/NETSCAPE support
        else if (nodo.selectionStart || nodo.selectionStart == '0') {
                var startPos = nodo.selectionStart;
                var endPos = nodo.selectionEnd;
                nodo.value = nodo.value.substring(0, startPos)+ myValue+ nodo.value.substring(endPos, nodo.value.length);
        } else {
                nodo.value += myValue;
        }
}

 function getSelection(nome) {
    var nodo = document.getElementById(nome);
        //IE support
        if (document.selection) {
                nodo.focus();
                sel = document.selection.createRange();
                return sel.text;
        }
        //MOZILLA/NETSCAPE support
        else if (nodo.selectionStart || nodo.selectionStart == '0') {
                var startPos = nodo.selectionStart;
                var endPos = nodo.selectionEnd;
                return nodo.value.substring(startPos,endPos);
        } else {
                return nodo.value;
        }
 }

 function bold(nome) {
   var s = getSelection(nome);
   if ( s == "")
      s = "Testo da scrivere in bold";

   insertAtCursor(nome,s.bold());
 }

 function italic(nome) {
   var s = getSelection(nome);
   if ( s == "")
      s = "Testo da scrivere in italico";

   insertAtCursor(nome,s.italics());
 }

 function colore(nome, col) {
   var s = getSelection(nome);
   if ( s == "")
      s = "Testo da scrivere in colorato";

   insertAtCursor(nome,s.fontcolor(col));
 }

 function insHREF(nome, src, desc) {
   src = prompt('Inserisci l\'indirizzo della pagina da referenziare (per l\'email, mailto:paride@pppppp.sm)','http://www.tuosito.com/pagina.html');
   var d = getSelection(nome);
   if ( desc != "")
      d = desc;
   if ( src == "" )
      src = "http://www.tuosito.com/pagina.html";
   insertAtCursor(nome,d.link(src));
 }

