//<script language="JavaScript1.2">
//<!-- classe Menu, per la creazione e l'utilizzo di menu a scomparsa

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 * file: menu.js
 * classe: Menu
 * sintassi del costruttore: var variabile = new Menu('variabile')
 * metodi utilizzabili:
 *  immagine(larghezza,altezza,coloresfondo,coloresfondoattivo,coloretesto,
 *    immagine0,immagine1)
 *  posizione(posizx,posizy)
 *  menu_orizz(descrizione,link,larghezza,coloresfondo,coloresfondoattivo,
 *    coloretesto)
 *    per creare voci del menu orizzontale
 *  menu_vert(descrizione,link)
 *    per creare voci del menu verticale
 *  visualizza()
 *    per visualizzare il menu nella pagina
 *    N.B.: richiama disegna(), che si occupa della creazione del menu
 *  disegna()
 *    per creare il menu nella pagina da visualizzare (restituisce una stringa)
 *    N.B.: non č indispensabile utilizzare questa funzione, perché viene
 *          chiamata automaticamente da visualizza()
 *  visualizzavariabili()
 *    per visualizzare le variabili dell'oggetto della classe Menu
 * 
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

//document.write('<script language="JavaScript1.2" src="./test.js" type="text/javascript"></script>');

document.write('<style type="text/css">'+
  '.bar { font-family: verdana, Arial, Helvetica, sans-serif; font-size: 12px;'+
         'color: #FFFFFF; vertical-align: middle; font-weight: bold}'+
  '.stbar { font-family: verdana, Arial, Helvetica, sans-serif; font-size: 10px;'+
         'color: #FFFFFF; vertical-align: middle; font-weight: normal}'+
  'a.bar { text-decoration: none}'+
  'a.stbar { text-decoration: none}'+
  'a.stbar:hover { text-decoration: none; background-color:}'+
  '</style>');

//<script language="JavaScript1.2">
//<!-- classe Menu, per la creazione e l'utilizzo di menu a scomparsa

// Variabili globali per i test

var Err=0; // Controllo degli errori: 0=NO - altri=SI
var MesgSt=0; // Visualizzazione dei messaggi: 0=NO - altri=SI
var Prove=0; // Visualizzazione dei test: 0=NO - altri=SI
var visVar=0; // Visualizzazione variabili


// funzione costruttore:
function Menu (nome) { // nome = nome della variabile che contiene il Menu
  Messaggio('INIZIO costruttore Menu('+nome+')');
  if (typeof(nome)=='undefined'){
    Errore('nella contruzione dell&acute;oggetto Menu:'+
	  '</br>Sintassi:'+
	  "</br>var variabile = new Menu('variabile')");
    return;
  }
  this.disegnato=0;
  this.nome=nome;
  this.img0=0;
  this.img1=0;
  this.imglargh=0;
  this.imgalt=0;
  this.posizx=0;
  this.posizy=0;
  this.menualt=18;
  this.statomenu=0; // stato: 0 = inattivo (invisibile); 1 = attivo (visibile)
  this.voci= new Array;
  this.largh= new Array;
  this.col = new Array;
  this.colatt = new Array;
  this.coltxt = new Array;
  this.sotto = new Array; // Array contenente i sottomenu
  this.sotto[0]=0; // posizione nei menu - il primo menų č il n° 1
                   // nella posizione sotto[menu][0] č memorizzata la lunghezza del sottomenu
  this.linksotto = new Array; // Array contenente i link dei sottomenu
  Messaggio('FINE costruttore Menu('+nome+')');
}

Menu.prototype.menu_orizz = function (titolo, collegamento, larghezza,
coloresfondo, coloresfondoattivo, coloretesto) {
  Messaggio('INIZIO metodo '+this.nome+'.menu_orizz('+titolo+')');
  var i=++this.sotto[0];
  this.voci[i]=titolo;
  this.largh[i]=larghezza;
  this.col[i]=coloresfondo;
  this.colatt[i]=coloresfondoattivo;
  this.coltxt[i] = coloretesto;
  this.sotto[i]= new Array;
  this.sotto[i][0] = 0; // posizione nei sottomenu - il primo sottomenų č il n° 1
  this.linksotto[i]= new Array;
  this.linksotto[i][0]=collegamento;
  Messaggio('FINE metodo '+this.nome+'.menu_orizz('+titolo+')');
}

Menu.prototype.menu_vert = function (titolo, collegamento) {
  Messaggio('INIZIO metodo '+this.nome+'.menu_vert('+titolo+')');
  if (this.sotto[0]==0){
    Errore('costruzione di sottomenu senza menu principali:</br>'+titolo);
    return;
  }
  var i=this.sotto[0];
  this.sotto[i][0]++;
  var j=this.sotto[i][0];
  this.sotto[i][j]=titolo;
  this.linksotto[i][j]=collegamento;
  Messaggio('FINE metodo '+this.nome+'.menu_vert('+titolo+')');
}

Menu.prototype.visualizza = function () {
  Messaggio('INIZIO metodo '+this.nome+'.visualizza()');
  var stringa=this.disegna();
  document.write(stringa);
  //window.alert(stringa);
  Messaggio('FINE metodo '+this.nome+'.visualizza()');
}

Menu.prototype.disegna = function () {
  Messaggio('INIZIO metodo '+this.nome+'.disegna()');
  var stringa, stringa1, stringa2;
  var i, j;
  var elemento;
  var posizionex=this.posizx;
  var posizioney=this.posizy;
  var lungmenu=this.sotto[0];
  var lungsotto=0;
  elemento='Div-'+this.nome;
  stringa='<div id="'+elemento+'" style="position:absolute; width:'+
    this.imglargh+'px; height:'+this.imgalt+'px; background-color:'+this.col[0]+
	'; left='+posizionex+'px; top='+posizioney+'px; visibility: visible">'+
    '<img id="Img-'+this.nome+'" src="'+this.img0+'" '+
    'height="'+this.imgalt+'" width="'+this.imglargh+'" '+
	'onClick="'+this.nome+'.vis_nasc()"></div>';
  posizionex+=this.imglargh;
  for (i=1; i<=lungmenu; i++) {
    lungsotto=this.sotto[i][0];
    stringa+=this.stilemenu(i)+
	  '<div id="Div-'+this.nome+'-'+i+'" style="position:absolute; width:'+
	  this.largh[i]+'px; height:'+this.menualt+'px; background-color:'+this.col[i]+
	  '; left='+posizionex+'px; top='+posizioney+'px; visibility: hidden"'+
	  'onmouseover="'+this.nome+'.aprimenu('+i+');"'+
	  'onmouseout="'+this.nome+'.chiudimenu('+i+');"'+
	  'onClick="'+this.nome+'.vai('+i+',0);">'+
	  '<table width="'+this.largh[i]+'" border="0" cellspacing="0" '+
	  'cellpadding="0" height="'+this.menualt+'"><tr align="center" valign="middle">'+
	  '<td style="cursor: pointer">'+
	  '<a href="'+this.linksotto[i][0]+'" class="bar-'+
	  this.nome+'-'+i+'" style="color:'+this.coltxt[i]+
	  '" onFocus="this.blur();">'+
	  this.voci[i]+'</a></td></tr></table></div>';
	for (j=1; j<=lungsotto; j++){
	  posizioney+=this.menualt;
	  stringa+=this.stilemenu(i,j)+
	    '<div id="Div-'+this.nome+'-'+i+'-'+j+'" style="position:absolute; width:'+
	    this.largh[i]+'px; height:'+this.menualt+'px; background-color:'+this.col[0]+
		'; left='+posizionex+'px; top='+posizioney+'px; visibility: hidden" '+
		'onmouseover="'+this.nome+'.aprimenu('+i+');"'+
		'onmouseout="'+this.nome+'.chiudimenu('+i+');"'+
		'onClick="'+this.nome+'.vai('+i+','+j+');">'+
		'<table width="'+this.largh[i]+'" border="0" cellspacing="0" '+
		'cellpadding="0" height="'+this.menualt+'"><tr align="center" valign="middle">'+
		'<td style="cursor: pointer">'+
		'<a href="'+this.linksotto[i][j]+'" class="stbar-'+
		this.nome+'-'+i+'-'+j+'" style="color:'+this.coltxt[0]+
		'" onFocus="this.blur();">'+
		this.sotto[i][j]+'</a></td></tr></table></div>';
	}
	posizionex+=this.largh[i];
	posizioney=this.posizy;
  }
  Messaggio('FINE metodo '+this.nome+'.disegna()');
  return(stringa);
}

Menu.prototype.aprimenu = function (i) {
  var j;
  var elemento;
  for (j=1; j<=this.sotto[i][0]; j++) {
    elemento='Div-'+this.nome+'-'+i+'-'+j;
    document.getElementById(elemento).style.visibility='visible';
  }
}

Menu.prototype.chiudimenu = function (i) {
  var j;
  var elemento;
  var funzione;
  for (j=this.sotto[i][0]; j>0;j--) {
    elemento='Div-'+this.nome+'-'+i+'-'+j;
    document.getElementById(elemento).style.visibility='hidden';
  }
}

Menu.prototype.vai = function (i,j) {
  window.name='tutto';
  window.open(this.linksotto[i][j],'tutto');
  //window.alert('vai '+i+','+j);
}

Menu.prototype.scopri = function () {
  if (this.statomenu==0) this.vis_nasc();
}

Menu.prototype.vis_nasc = function () {
  //if (Caricamento==0) return (0);
  var i,j, elemento, posizionex, posizioney;
  var ImmagineMenu=this.nome;
  var stringa='',k;
  if (this.disegnato==0) {
    posizionex=this.posizx;
    posizioney=this.posizy;
	elemento='Div-'+this.nome;
	document.getElementById(elemento).style.left=posizionex;
	document.getElementById(elemento).style.top=posizioney;
    posizionex+=this.imglargh;
	for (i=1;i<=this.sotto[0];i++) {
      posizioney=this.posizy;
      elemento='Div-'+this.nome+'-'+i;
	  document.getElementById(elemento).style.left=posizionex;
	  document.getElementById(elemento).style.top=posizioney;
	  for (j=1;j<=this.sotto[i][0];j++) {
		posizioney+=this.menualt;
		elemento='Div-'+this.nome+'-'+i+'-'+j;
		document.getElementById(elemento).style.left=posizionex;
		document.getElementById(elemento).style.top=posizioney;
	  }
	  posizionex+=this.largh[i];
	}
  }
  if (this.statomenu==0) {
	this.statomenu=1;
	document.images['Img-'+ImmagineMenu].src=this.img1;
	for (i=1;i<=this.sotto[0];i++) {
      elemento='Div-'+this.nome+'-'+i;
	  document.getElementById(elemento).style.visibility='visible';
	}
  } else if (this.statomenu==1) {
	this.statomenu=0;
	document.images['Img-'+ImmagineMenu].src=this.img0;
	for (i=1;i<=this.sotto[0];i++) {
      elemento='Div-'+this.nome+'-'+i;
	  document.getElementById(elemento).style.visibility='hidden';
	  stringa+=(document.getElementById(elemento));
	  for (j=1;j<=this.sotto[i][0];j++) {
		elemento='Div-'+this.nome+'-'+i+'-'+j;
		document.getElementById(elemento).style.visibility='hidden';
		//for (k in document.getElementById(elemento).style) stringa+=variabili(elemento+': '+k,(document.getElementById(elemento).style[k]));
	  }
	}
  }
  //document.write(stringa);
  //window.alert(stringa);
  //window.alert(elemento);
}


Menu.prototype.immagine = function (larghezza, altezza, coloresfondo,
coloresfondoattivo, coloretesto, immagine0, immagine1) {
  Messaggio('INIZIO metodo '+this.nome+'.immagine()');
  this.imglargh=larghezza;
  this.imgalt=altezza;
  this.col[0]=coloresfondo;
  this.colatt[0]=coloresfondoattivo;
  this.coltxt[0]=coloretesto;
  this.img0=immagine0;
  this.img1=immagine1;
  Test(".img0="+this.img0);
  Messaggio('FINE metodo '+this.nome+'.immagine()');
}

Menu.prototype.posizione = function (x, y) {
  Messaggio('INIZIO metodo '+this.nome+'.posizione('+x+','+y+')');
  this.posizx=x;
  this.posizy=y;
  Messaggio('FINE metodo '+this.nome+'.posizione('+x+','+y+')');
}

Menu.prototype.stilemenu = function (i, j) {
  var elemento=this.nome+'-'+i;
  var stringa='<style type="text/css">';
  if (j!=undefined) {
    elemento+='-'+j;
    stringa+=".stbar-"+elemento+" { font-family: verdana, Arial, Helvetica, sans-serif; font-size: 10px;"+
      "color:"+this.col[0]+"; vertical-align: middle; font-weight: normal}"+
    "a.stbar-"+elemento+" { text-decoration: none}"+
    "a.stbar-"+elemento+":hover { text-decoration: none; background-color:"+this.colatt[0]+"}";
	Test(elemento);
  } else {
    stringa+=".bar-"+elemento+" { font-family: verdana, Arial, Helvetica, sans-serif; font-size: 12px;"+
      "color:"+this.col[i]+"; vertical-align: middle; font-weight: bold}"+
    "a.bar-"+elemento+" { text-decoration: none}"+
    "a.bar-"+elemento+":hover { text-decoration: none; background-color:"+this.colatt[i]+"}";
  }  
  stringa+="</style>";
  return (stringa);
}

Menu.prototype.visualizzavariabili = function () {
  if (visVar==0) return;
  var i;
  var stringa='<h'+'2>INIZIO visualizzazione variabili: '+this.nome+'</h'+'2>';
  stringa+= variabili(".nome",this.nome);
  stringa+=variabili(".img0",this.img0);
  stringa+=variabili(".img1",this.img1);
  stringa+=variabili(".imglargh",this.imglargh);
  stringa+=variabili(".imgalt",this.imgalt);
  stringa+=variabili(".posizx",this.posizx);
  stringa+=variabili(".posizy",this.posizy);
  stringa+=variabili(".menualt",this.menualt);
  stringa+=variabili(".statomenu",this.statomenu);
  stringa+=variabili(".voci",this.voci);
  for (i in this.voci) {
    stringa+=variabili('.voci.'+i,this.voci[i]);
  }
  stringa+=variabili(".largh",this.largh);
  for (i in this.largh) {
    stringa+=variabili('.largh.'+i,this.largh[i]);
  }
  stringa+=variabili(".col",this.col);
  for (i in this.col) {
    stringa+=variabili('.col.'+i,this.col[i]);
  }
  stringa+=variabili(".coltxt",this.coltxt);
  for (i in this.coltxt) {
    stringa+=variabili('.coltxt.'+i,this.coltxt[i]);
  }
  stringa+=variabili(".sotto",this.sotto);
  for (i in this.sotto) {
    stringa+=variabili('.sotto.'+i,this.sotto[i]);
  }
  stringa+=variabili(".linksotto",this.linksotto);
  for (i in this.linksotto) {
    stringa+=variabili('.linksotto.'+i,this.linksotto[i]);
  }
  stringa+=variabili(this.nome,this);
  stringa+='<h'+'r>';
  for (i in this) {
    //stringa+=variabili(this.nome+'.'+i,this[i]);
  }
  stringa+='<h'+'r>';
  stringa+='<h'+'2>FINE visualizzazione variabili: '+this.nome+'</h'+'2>';
  document.write (stringa);
}

// TEST

function Test(i){
  if (Prove==0) return;
  if (i==undefined){
    i="";
  }
  document.write("<h4>TEST: "+i+"</h3>");
}

function Errore(i){
  if (Err==0) return;
  if (i==undefined){
    i="";
  }
  document.write("<h3>ERRORE: "+i+"</h3>");
}

function Messaggio(i){
  if (MesgSt==0) return;
  if (i==undefined){
    i="";
  }
  document.write("MESSAGGIO: "+i+"</br>");
}

function variabili (variabile, parametro) {
  if (visVar==0) return('');
  var stringa='<b>'+variabile+' = </b>'+parametro+'</br>';
  return stringa;
}

// browser() restituisce IE in caso di Internet Explorer
function browser () {
  var versione;
  if (navigator.appName=='Microsoft Internet Explorer') {
    versione='IE';}
  if (navigator.appName=='Netscape') {
    versione='Net';}
  if (navigator.appName=='Opera') {
    versione='Ope';}
  return versione;
}

// altre funzioni utili

function DataDocumento () {
  if (browser()=='IE') {
    var mese=document.lastModified.substr( 0, 2);
	if (mese=='01') mese='gennaio';
	if (mese=='02') mese='febbraio';
	if (mese=='03') mese='marzo';
	if (mese=='04') mese='aprile';
	if (mese=='05') mese='maggio';
	if (mese=='06') mese='giugno';
	if (mese=='07') mese='luglio';
	if (mese=='08') mese='agosto';
	if (mese=='09') mese='settembre';
	if (mese=='10') mese='ottobre';
	if (mese=='11') mese='novembre';
	if (mese=='12') mese='dicembre';

    var Stringa=''+
	document.lastModified.substr( 3, 2)  +' '+
	mese  +' '+
	document.lastModified.substr( 6, 4)  +' '+
	document.lastModified.substr( 11);
  } else {
    var Stringa=document.lastModified;
  }
  return Stringa;
}

function intestaPagina (testo) {
  var Stringa='<table border="0" cellpadding="2" cellspacing="2">'+
    '<tbody><th height="27"></th><tr><td width="50"></td>'+
    '<td><h1>'+testo+'</h1></td></tr></tbody></table>';
  return Stringa;
}

function finePaginaVersione () {
  var versione = navigator.appName + " " + navigator.appVersion;
  var Stringa='<hr></hr><p>In caso di problemi nella visualizzazione di alcune '+
  'pagine, puoi scrivermi di cosa si tratta e con quale browser si verifica.</p>'+
  'Il browser che stai	usando &egrave;: ' + versione+
  '<hr></hr><table border="0" width="100%"><tbody><tr>';
  Stringa+='<td width="33%">'+
    '<img src="http://cgi-serv.digiland.it/Count.cgi?df=ita01"></td>';
  Stringa+='<td width="33%">';
  Stringa+='e-mail: <a href="mailto:ita01.libero@gmail.com">';
  Stringa+='ita01.libero@gmail.com</a></td>';
  Stringa+='<td width="33%"></td>';
  //Stringa+='<td width="33%">Ultima modifica: '+ DataDocumento() + '</td>';
  Stringa+='</tr></tbody></table>';
  Stringa+='</body>';
  return Stringa;
}

function finePagina () {
  var Stringa='<hr></hr><table border="0" width="100%"><tbody><tr>';
  Stringa+='<td width="33%">'+
    '<img src="http://cgi-serv.digiland.it/Count.cgi?df=ita01"></td>';
  Stringa+='<td width="33%">';
  Stringa+='e-mail: <a href="mailto:ita01.libero@gmail.com">';
  Stringa+='ita01.libero@gmail.com</a></td>';
  Stringa+='<td width="33%"></td>';
  //Stringa+='<td width="33%">Ultima modifica: '+ DataDocumento() + '</td>';
  Stringa+='</tr></tbody></table>';
  Stringa+='</body>';
  return Stringa;
}


/* parentesi graffe
{}
{
}
*/

//-->
//</script>

