
var oMenu;
var aSelect = [];
var nElement;
var sezioneAperta;
/*Browsercheck object*/
function cm_bwcheck(){
	this.agent=navigator.userAgent.toLowerCase()
	this.op=(this.agent.indexOf("opera ")>-1 || this.agent.indexOf("opera/")>-1) && window.opera
	this.ie=((this.agent.indexOf("msie")>-1) && (!this.op))
	this.nt=(this.agent.indexOf("netscape")>-1)
  	this.mz=((this.agent.indexOf("mozilla/")>-1) && (!this.ie) && (!this.nt) && (!this.op))
	return this
}
var bw=new cm_bwcheck()
function initmenu(){
	oMenu = new menu('menu');
	oCont = document.getElementById("mainmenu");
	if (document.getElementById('contenuto')) aSelect = document.getElementById('contenuto').getElementsByTagName('select')
	
	var oTable = document.createElement('table');
		oTable.id = 'menuTbl';
		oTable.width = '100%';
		oTable.cellPadding = 0;
		oTable.cellSpacing = 0;
		oTable.border = 0;
	var oTBody = document.createElement('tbody');
	var oTr = document.createElement('tr');
	
	var aLi = document.getElementById('menu').getElementsByTagName('li');
	var aLiPrimoLivello = [];
	for (var i=0; i<aLi.length; i++)
		if ((aLi[i].className == 'primoLivello') || (aLi[i].className == 'primoLivelloactive')) aLiPrimoLivello.push(aLi[i]);
	
	for (var i=0; i<aLiPrimoLivello.length; i++){
		var oTd = document.createElement('td');
		
		
		/*primo tasto non attivo*/
		if (i==0 &&  aLiPrimoLivello[i].className != 'primoLivelloactive'){
			var oStart = document.createElement('td');
			oStart.width = 12; oStart.innerHTML = '&nbsp;';
			oStart.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/inizio_a.gif')";
			oTd.start = oStart;
		}
		/*primo tasto attivo*/
		if (i==0 &&  aLiPrimoLivello[i].className == 'primoLivelloactive'){
			var oStart = document.createElement('td');
			oStart.width = 12; oStart.innerHTML = '&nbsp;';
			oStart.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/inizio_b.gif')";
			oTd.start = oStart;
		}
		/*tasto non attivo preceduto da un tasto non attivo*/
		if (i!=0 && aLiPrimoLivello[i].className != 'primoLivelloactive' &&  i > 0 && aLiPrimoLivello[i-1].className != 'primoLivelloactive' ){
			var oCurva = document.createElement('td');
			oCurva.width = 27;
			oCurva.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_aa.gif')";
			oCurva.innerHTML = '&nbsp;';
			oTd.curva = oCurva;
		}
		/*tasto non attivo preceduto da un tasto attivo*/
		if (i!=0 && aLiPrimoLivello[i].className != 'primoLivelloactive' &&  i > 0 && aLiPrimoLivello[i-1].className == 'primoLivelloactive' ){
			var oCurva = document.createElement('td');
			oCurva.width = 27;
			oCurva.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_ba.gif')";
			oCurva.innerHTML = '&nbsp;';
			oTd.curva = oCurva;
		}	
		/*tasto attivo*/
		if (i!=0 && aLiPrimoLivello[i].className == 'primoLivelloactive'){
			var oCurva = document.createElement('td');
			oCurva.width = 27;
			oCurva.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_ab.gif')";
			oCurva.innerHTML = '&nbsp;';
			oTd.curva = oCurva;
		}	
		/*ultimo tasto non attivo */
		if (i==aLiPrimoLivello.length-1 &&  aLiPrimoLivello[i].className != 'primoLivelloactive'){
			var oEnd = document.createElement('td');
			oEnd.width = 14; oEnd.innerHTML = '&nbsp;';
			oEnd.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/fine_a.gif')";	
			oTd.end = oEnd;		
		}
		/*ultimo tasto attivo */
		if (i==aLiPrimoLivello.length-1 &&  aLiPrimoLivello[i].className == 'primoLivelloactive'){
			var oEnd = document.createElement('td');
			oEnd.width = 14; oEnd.innerHTML = '&nbsp;';
			oEnd.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/fine_b.gif')";	
			oTd.end = oEnd;		
		}

		oTd.align = 'center';
		oTd.valign = 'middle';
		oTd.className = aLiPrimoLivello[i].className;
		oTd.innerHTML = aLiPrimoLivello[i].innerHTML;

		oTd.id = aLiPrimoLivello[i].id;
		
		if (i==0) oTr.appendChild(oStart);
		if (i!=0) oTr.appendChild(oCurva); 
		oTr.appendChild(oTd);
		oMenu.add(oTd);
		if (i==aLiPrimoLivello.length-1) oTr.appendChild(oEnd);
	}
	
	oCont.appendChild(oTable);
	oTable.appendChild(oTBody);
	oTBody.appendChild(oTr);
	
	oCont.removeChild(document.getElementById('menu'));
	oMenu.init();
}

/*******************************************************************************************************/


// global flag
var isIE = false;
 
// global request and XML document objects
var req;
 
 
function menu(id){
 this.elem = document.getElementById(id);
 this.items = [];
 
 this.add = function(elem){
 	this.items.push(elem);
 }
 var menuNumero
 this.init = function(){
 	nElement = this.items.length
	for (var i=0; i<nElement; i++){
	  this.items[i].isLoaded = false;
	  this.items[i].onmouseover = function(){
		// GESTIONE DELL?OVER SU IE
		if (this.isLoaded && document.all) this.getElementsByTagName('ul')[0].style.display='block';
			//CONTROLLO SE QUALCHE SEZIONE APERTA E' ANCORA ATTIVA
			chiudiLivello()
			if (sezioneAperta != this.previousSibling.nextSibling.id){
				menuColor(sezioneAperta);
				this.getElementsByTagName('ul')[0].style.display='block'
				if (this.getElementsByTagName('ul')[0])
					if (bw.ie)
						this.getElementsByTagName('ul')[0].style.top = (this.previousSibling.nextSibling.offsetHeight - 1)+'px';
					else
						this.getElementsByTagName('ul')[0].style.top = (this.previousSibling.nextSibling.offsetHeight + document.getElementById('intestazione').offsetHeight - 1)+'px';
				if (this.curva && !this.start && this.previousSibling.previousSibling.className != 'primoLivelloactive') this.curva.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_ab.gif')";
				if (this.curva && !this.start && this.previousSibling.previousSibling.className == 'primoLivelloactive') this.curva.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_bb.gif')";			
				
				if (this.start) this.start.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/inizio_b.gif')";
				if (this.end) this.end.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/fine_b.gif')";
				this.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/sfondo_b.gif')";
				
				if (this.nextSibling && !this.end && this.nextSibling.nextSibling.className != 'primoLivelloactive')
					this.nextSibling.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_ba.gif')";
				if (this.nextSibling && !this.end && this.nextSibling.nextSibling.className == 'primoLivelloactive')
						this.nextSibling.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_bb.gif')";
				this.previousSibling.nextSibling.id
			}		
			sezioneAperta = this.previousSibling.nextSibling.id;
			if (aSelect){
				for (var i = 0; i<aSelect.length; i++){
					if (this.nextSibling.nextSibling) if ((this.nextSibling.nextSibling.offsetHeight - this.nextSibling.nextSibling.nextSibling.offsetHeight) + 80 > aSelect[i].offsetTop) aSelect[i].style.visibility='hidden';
				}
			}
	  }
	  // GESTIONE DELL?OVER SU IE
	  if (document.all){
		  this.items[i].onmouseleave = function(){
		  	if (this.getElementsByTagName('ul')[0]){
				this.getElementsByTagName('ul')[0].style.display='none';
				if (this.getElementsByTagName('ul')[0].style.display == 'none' && sezioneAttiva != this.previousSibling.nextSibling.id){
					 if (this.curva && !this.start && this.previousSibling.previousSibling.className != 'primoLivelloactive') this.curva.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_aa.gif')";
					 if (this.curva && !this.start && this.previousSibling.previousSibling.className == 'primoLivelloactive') this.curva.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_ba.gif')";			
						
					 if (this.start) this.start.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/inizio_a.gif')";
					 if (this.end) this.end.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/fine_a.gif')";
					 this.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/sfondo_a.gif')";
						
					 if (this.nextSibling && !this.end && this.nextSibling.nextSibling.className != 'primoLivelloactive')
					 this.nextSibling.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_aa.gif')";
					 if (this.nextSibling && !this.end && this.nextSibling.nextSibling.className == 'primoLivelloactive')
					 this.nextSibling.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_ab.gif')";
				}
				sezioneAperta = '';
			}	
		  };
	  }
	  this.items[i].onmouseout = function(){
		  //CONTROLLO SE QUALCHE SEZIONE APERTA E' ANCORA ATTIVA
		  chiudiLivello()
		  if (aSelect){
				for (var i = 0; i<aSelect.length; i++){
					if (this.nextSibling.nextSibling) if ((this.nextSibling.nextSibling.offsetHeight - this.nextSibling.nextSibling.nextSibling.offsetHeight) + 80 > aSelect[i].offsetTop) aSelect[i].style.visibility='visible';
				}
		  }
		  if (bw.op || (!document.all && this.getElementsByTagName('ul')[0])){
				 //this.getElementsByTagName('ul')[0].style.display='none'
				 if (sezioneAttiva != this.previousSibling.nextSibling.id){
					 if (this.curva && !this.start && this.previousSibling.previousSibling.className != 'primoLivelloactive') this.curva.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_aa.gif')";
					 if (this.curva && !this.start && this.previousSibling.previousSibling.className == 'primoLivelloactive') this.curva.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_ba.gif')";			
						
					 if (this.start) this.start.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/inizio_a.gif')";
					 if (this.end) this.end.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/fine_a.gif')";
					 this.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/sfondo_a.gif')";
						
					 if (this.nextSibling && !this.end && this.nextSibling.nextSibling.className != 'primoLivelloactive')
					 this.nextSibling.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_aa.gif')";
					 if (this.nextSibling && !this.end && this.nextSibling.nextSibling.className == 'primoLivelloactive')
					 this.nextSibling.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_ab.gif')";
				 }
				 sezioneAperta = '';
			}
	  };
	  this.items[i].buildMenuStrip = buildMenuStrip;
	 }
 }
}

function chiudiLivello(){
	if (oMenu){
	    for (var i=0; i<oMenu.items.length; i++){
	  		//if (oMenu.items[i].isLoaded)
			if (oMenu.items[i].id != sezioneAperta)
				if (oMenu.items[i].getElementsByTagName('ul')[0].style.display == 'block')
					oMenu.items[i].getElementsByTagName('ul')[0].style.display = 'none';
	    }
	}
}

function menuColor(sezioneAperta){
	for (var i=0; i<oMenu.items.length; i++){
		if (sezioneAttiva != oMenu.items[i].id && sezioneAperta == oMenu.items[i].id){
			if (oMenu.items[i].curva && !oMenu.items[i].start && oMenu.items[i].previousSibling.previousSibling.className != 'primoLivelloactive') oMenu.items[i].curva.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_aa.gif')";
	  	  	if (oMenu.items[i].curva && !oMenu.items[i].start && oMenu.items[i].previousSibling.previousSibling.className == 'primoLivelloactive') oMenu.items[i].curva.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_ba.gif')";			
		  	if (oMenu.items[i].start) oMenu.items[i].start.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/inizio_a.gif')";
		  	if (oMenu.items[i].end) oMenu.items[i].end.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/fine_a.gif')";
		  	oMenu.items[i].style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/sfondo_a.gif')";
			
		  	if (oMenu.items[i].nextSibling && !oMenu.items[i].end && oMenu.items[i].nextSibling.nextSibling.className != 'primoLivelloactive')
			oMenu.items[i].nextSibling.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_aa.gif')";
		  	if (oMenu.items[i].nextSibling && !oMenu.items[i].end && oMenu.items[i].nextSibling.nextSibling.className == 'primoLivelloactive')
			oMenu.items[i].nextSibling.style.backgroundImage = "url('" + sBasePath + "img/homepage/tastiera/curvaTASTI_ab.gif')";
		}
    }
}

function buildMenuStrip(items){
	var ul = document.createElement('ul');
	if (document.all) ul.style.display='block';
	this.isLoaded = true;
	if (bw.ie)
		ul.style.top = (this.previousSibling.nextSibling.offsetHeight - 1)+'px';
	else
		ul.style.top = (this.previousSibling.nextSibling.offsetHeight + document.getElementById('intestazione').offsetHeight - 1)+'px';
}

function  cambiaRicerca(){
	if (document.getElementById('tipoRicerca1').checked){
		document.getElementById('ParoleContenuteDocumento').value = document.getElementById('parola').value;
		document.getElementById('ricercaWeb').style.display = 'block';
		document.getElementById('ricercaIndiceAZ').style.display = 'none';
	}else{
		document.getElementById('parola').value = document.getElementById('ParoleContenuteDocumento').value;
		document.getElementById('ricercaWeb').style.display = 'none';
		document.getElementById('ricercaIndiceAZ').style.display = 'block';
	}
}



function apriOrdineDelGiorno(giorno, meseanno){
	document.forms["formOrdineGiorno"].hGiornoSel.value = giorno;
	document.forms["formOrdineGiorno"].hMeseSel.value = meseanno;
	document.forms["formOrdineGiorno"].submit();
}


