// FUNZIONE FADE IMMAGINE ROLLOVER

function high(which2){
theobject=which2
highlighting=setInterval("highlightit(theobject)",50)
}
function low(which2){
clearInterval(highlighting)
if (which2.style.MozOpacity)
which2.style.MozOpacity=0.3
else if (which2.filters)
which2.filters.alpha.opacity=30
}
function highlightit(cur2){
if (cur2.style.MozOpacity<1)
cur2.style.MozOpacity=parseFloat(cur2.style.MozOpacity)+0.1
else if (cur2.filters&&cur2.filters.alpha.opacity<100)
cur2.filters.alpha.opacity+=10
else if (window.highlighting)
clearInterval(highlighting)
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

// FUNZIONI DI DREAMWEAVER

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function zoom(action,citta){
var img1 ;
var img2 ;
var img3 ;
img1 ='/img/uffici/'+citta+'/cartina1.gif'; 
img2 ='/img/uffici/'+citta+'/cartina2.gif'; 
img3 ='/img/uffici/'+citta+'/cartina3.gif'; 
mylocation ='/img/uffici/'+citta+'/cartina';
extension ='.gif';
zoomlocation = '/img/uffici/zoom';
extension ='.gif';
n = parseInt(document.cartina.src.charAt(document.cartina.src.length - 5));
newN = n
if ((action == 'piu') && (n < 3)){
	newN = n + 1;
	
}
if ((action == 'meno') && (n > 1)){
	newN = n - 1;
}
document.cartina.src = mylocation + newN + extension;
document.zoomlevel.src = zoomlocation + newN + extension;
}

// Apertura pop-up generica
// N.B. ritorna null se l'aperura viene bloccata dal browser
function e3_popUp(url, name, param) {
	var popUp;

  popUp=window.open(url, name, param);
//Se l'apertura del pop up viene bloccata esce
  if (popUp==null) return null;
	popUp.focus();
	return popUp;
}

// Apertuta pop-up dettaglio 
function e3_dettaglio(url, name, w, h)
{
	e3_popUp(url, name, 'scrollbars=yes,resizable=yes,width='+w+',height='+h+',status=no,location=no,toolbar=no');
	return false;
}

//Apre popup per selezione Comune
function cercaComune(frm, prefisso) { //v4.0
  /*
	var form=window.document.forms[0];
	var idComune=form.elements[prefisso+'Comune'].value;
	var idNazione=form.elements[prefisso+'Nazione'].value;
	*/
	var idComune=frm.elements[prefisso+'Comune'].value;
	var idNazione=frm.elements[prefisso+'Nazione'].value;
	var pu=e3_popUp('/puComuneCerca.asp?fComune='+encodeURIComponent(idComune) + '&fNazione='+encodeURIComponent(idNazione)+'&Prefisso='+encodeURIComponent(prefisso),'geo','scrollbars=yes,resizable=yes,width=750,height=500,status=no,location=no,toolbar=no');
	pu.prefisso=prefisso;
	return false;
}

// Preload immagini per rollover
function e3_preloadImg() {
 var i;
 var j;
 var oImg;
 var overImg;
 var oSrc;

 if (!document.MM_p) document.MM_p=new Array();
 j=document.MM_p.length; 

 for (i=0;i<document.images.length;++i) {
  oImg=document.images[i];
  overImg=oImg.getAttribute('srcOver');
  if (overImg!=null) {
		if (overImg.indexOf("#")!=0) { 	//Preload image
			document.MM_p[j]=new Image; 
			document.MM_p[j++].src=overImg;
		}
  }
 }
}

/* SELEZIONE VOCE MENU INIZIO */
// Inizializzazione barra dei menu
function e3_initMenuBar(menuName) {
 var oImg;
 var overImg;
 var oSrc;
 var i;

 var oMenu;
 var menuItems;
 var aTags;
 var liTag;
 var aTag;
 var candidate;
 var candidateWeight;
 var weight;

 if (typeof(menuName)!='string')
   return;

//Cerca il menu (se non esiste esce)
 oMenu=document.getElementById(menuName);
 if (typeof(oMenu)!='object')
   return;
//Cerca le voci del menu (se non esistono esce)
 menuItems=oMenu.getElementsByTagName('li');
 if (typeof(menuItems)!='object')
   return;
 //Cerca tra le voci di menu la condidata per la selezione
 candidateWeight=0;
 for (i=0;i<menuItems.length;i++) {
	 liTag=menuItems[i];
	 aTags=liTag.getElementsByTagName('a');
	 //Cerca il link associato alla voce di menu (se non esiste ignora la voce)
	 if (typeof(aTags)!='object') continue;
	 aTag=aTags[0];
	 //Controlla la corrispondenza
	 weight=matchUrl(aTag.href);
	 //Se maggiore abbiamo trovato una candidata potenziale
	 if (weight>candidateWeight) {
		 candidateWeight=weight;
		 candidate=liTag;
	 }
 } 
//Se non e' stata trovata una candidata esce
 if (!candidate) return;
//Se non esiste l'attributo "classOver" esce
 if (!candidate.getAttribute('classOver')) return;
//Evidenzia la voce
 candidate.oClassName=liTag.getAttribute('classOver');
 candidate.className=liTag.getAttribute('classOver');
}

//Ritorna il numero di caratteri corrispondenti
function matchUrl(url) {
	var i;
	var deep;
	var currUrl=window.location.href;
	var urlDeep=getDeep(url);
	//Se la profondita' dell'URL e' 0 esce (no corrispondenza)
	if (urlDeep==0) return 0;

  var currUrlDeep=getDeep(currUrl);
	if (currUrlDeep<urlDeep) return 0;
			
	//var len=url.length;
	//if (currUrl.length<len) len=currUrl.length;
	var len=Math.min(url.length, currUrl.length);
	
	for (i=7;i<(len-1);++i) {
		if (url.substring(i,i+1)!=currUrl.substring(i,i+1)) break;
		if (url.substring(i,i+1)=="/") ++deep;
	}
	
	return (deep==0 ? 0 : i);
}

//Ritorna la profondita' del percorso
function getDeep(url) {
	var i;
	var deep=0;
	
	for (i=7;i<url.length;++i) {
		if (url.substring(i,i+1)=="?") break;
		if (url.substring(i,i+1)=="/") ++deep;
	}
	
  return deep;
}
/* SELEZIONE VOCE MENU FINE*/

//Menu Over
function e3_menuSwap(obj)
{
  if (typeof(obj)!='object') 
	  return;
		
  if(!obj.oClassName) //Salva la classe originale
    obj.oClassName=obj.className;	
	
	obj.className=obj.getAttribute('classOver');  //Swap
}

//Menu Out
function e3_menuRestore(obj)
{
  if (typeof(obj)!='object') 
	  return;

  if(!obj.oClassName) 
	  return;
		
	obj.className=obj.oClassName;
}

//Roll over immagini
function e3_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; 

	for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) 
		x.src=x.oSrc;
}


function e3_swapImage(evt) {
  var src;
  var overImg;	//Over image
  
  if (typeof(event)!='undefined') 
   src=event.srcElement;			//Internet Explorer
  else
   src=evt.target;					//Mozilla	
  overImg=src.getAttribute('srcOver');
  if (overImg==null) return;			// Se non esiste l'immagine over esce
  
  document.MM_sr=new Array; 
  document.MM_sr[0]=src; 
  if(!src.oSrc) 
  	src.oSrc=src.src; 				//Salva immagine
  src.src=overImg;					//Swap
}

function sendForm(frm, operazione){
//	frm.action = document.location.href;
	frm.elements['operazione'].value = operazione;
	frm.submit();

  return false;
}

function frmRicercaValidate(frm) {
	if (frm.elements['fRegione'].value=='') {
		window.alert("Selezionare la nazione e la provincia");
	  return false
	}
	  
	return true;
}

// FUNZIONE ALERT JAVA
function MM_popupMsg(msg) { //v1.0
  alert(msg);
}
