function blinking(elmId,firstColour,lastColour,delay,begin){
	var blinker=document.getElementById(elmId);
	if(blinker){

		if(begin){
			blinker.style.color=firstColour;
			begin=false;
		}
		else{
			blinker.style.color=lastColour;
			begin=true;
		}
		setTimeout('blinking(\''+elmId+'\',\''+firstColour+'\',\''+lastColour+'\','+delay+','+begin+')',delay);
	}
}
// 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){
var img1 ;
var img2 ;
var img3 ;
var img4 ;
img1 ='/img/dovesiamo/cartina1.gif';
img2 ='/img/dovesiamo/cartina2.gif';
img3 ='/img/dovesiamo/cartina3.gif';
img4 ='/img/dovesiamo/cartina4.gif';
mylocation ='/img/dovesiamo/cartina';
extension ='.gif';
zoomlocation = '/img/dovesiamo/zoom';
extension ='.gif';
n = parseInt(document.cartina.src.charAt(document.cartina.src.length - 5));
newN = n
if ((action == 'piu') && (n < 4)){
	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 idComune=frm.elements[prefisso+'IDComune'].value;
	var idNazione=frm.elements[prefisso+'IDNazione'].value;
	
	var pu=e3_popUp('/all/puComuneCerca.asp?idComune='+encodeURIComponent(idComune) + '&idNazione='+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;
}

//Apre popup per selezione Comune
/*
function cercaComune(prefisso) { //v4.0
  var form=window.document.forms[0];
	var idComune=form.elements[prefisso+'Comune'].value;
	var idNazione=form.elements[prefisso+'Nazione'].value;
	var pu=e3_popUp('/all/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;
}
*/

//Apre popup per selezione degli immobili in un complesso
function cercaImmobile(idnazione) { //v4.0
//	var pu=e3_popUp('puImmobileCerca.asp','geo','scrollbars=yes,resizable=yes,width=750,height=500,status=no,location=no,toolbar=no');
//	return false;
	return e3_dettaglio('puImmobileCerca.asp?fNazione='+encodeURIComponent(idnazione), 'complesso_immobile', '750', '500')
}

// 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
}

//Converte una stringa in formato gg/mm/aaaa in una data (ritorna null se data non valida)
function e3_parseDate(str) {
	// Checks for the following valid date formats:
	// DD/MM/YY   DD/MM/YYYY   DD-MM-YY   DD-MM-YYYY
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year
	
	var matchArray = str.match(datePat); // is the format ok?
	if (matchArray == null) {
	  return null;
	}
	day = matchArray[1];
	month = matchArray[3]; // parse date into variables
	year = matchArray[4];
	if (month < 1 || month > 12) { // check month range
	  //alert("Month must be between 1 and 12.");
	  return null;
	}
	if (day < 1 || day > 31) {
		//alert("Day must be between 1 and 31.");
		return null;
	}
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		//alert("Month "+month+" doesn't have 31 days!")
		return null;
	}
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			//alert("February " + year + " doesn't have " + day + " days!");
			return null;
			}
	}

  return new Date(Date.UTC(year,month-1,day));  
}

function sendForm(frm, operazione){
//	frm.action = document.location.href;
  setOperation(frm, operazione);
	frm.submit();

  return false;
}


function setOperation(frm, operazione)
{
	frm.elements['operazione'].value = operazione;

  return true;
}