function apri_popup(str, larghezza, altezza, scrollbar) 
{
searchWin = window.open(str,"","scrollbars="+scrollbar+",resizable=yes,status=no,location=no,toolbar=no,width="+larghezza+",height="+altezza+",left="+((screen.width-larghezza)/2)+",top="+((screen.height-altezza)/2)+"");
}


/*====================================
   PCR functions JavaScript
   [eustema s.p.a.] - 2004/07
====================================*/

/*
onload = function() {
	globalSet();
	mapHover.init();
}
*/


/*  versione IE
-------------------*/

function IEdetect() {
	isIE = 0;
	if (navigator.appVersion.indexOf("MSIE")!=-1) {
		IEver = navigator.appVersion.split("MSIE");
		isIE = parseFloat(IEver[1]);
	}
	return isIE;
}



/*  settaggi layout / fix 
------------------------------*/

function globalSet() {
	// [Alessio Cartocci - 2006]

	var imag, i;
	isMac = navigator.userAgent.toLowerCase().indexOf("mac");
	isLinux = navigator.userAgent.toLowerCase().indexOf("linux");
	isKde = navigator.appVersion.indexOf("Konqueror");
	isSafari = navigator.appVersion.indexOf("Safari");

	// switch sfondo
	if (document.getElementById("wpsportletdx").className.indexOf("big")!=-1) {
		document.getElementById("layout").className = "big";
	}

	// IE fix
	if (IEdetect()>0) {
	
		// IE Mac
		if (isMac!=-1) {
			el = document.getElementById("wpsportletsx").getElementsByTagName("div");
			for (i=0; i<=el.length-1; i++) {
				if (el[i].className=="containersx user") {
					hx = el[i].getElementsByTagName("h3");
					hxTmp = hx[0].innerHTML;
					hx[0].innerHTML = "<span class=\"ieppc\">" + hxTmp + "</span>";
				}
			}
			if (navigator.userAgent.indexOf("5.0")!=-1) {
				document.getElementById("layout").style.position = "relative";
				document.getElementById("macro").style.top = "-64px";
			}
		}
		// fine IE Mac

		if (IEdetect()<7) {
			// emulazione tag <abbr> per IE5+/win: basato sullo script di Jason Davis [http://www.jasonkarldavis.com/scripts/abbrhack]
			if (isMac==-1) {
				document.documentElement.setAttribute("xmlns:acc","http://www.w3.org/1999/xhtml");
				abbrTag = document.body.getElementsByTagName("abbr");
				for (i=0; i<=abbrTag.length-1; i++) {
					abbrTag[i].parentElement.innerHTML = abbrTag[i].parentElement.innerHTML.replace(/<abbr/gi, "<acc:abbr class=\"abbr\"").replace(/<\/abbr/gi, "</acc:abbr");
				}
			}
		}

		// wass
		try {
			wassName = String(window.location).split("wps")[0].split("/")[3];
			styles = document.getElementsByTagName("head")[0].getElementsByTagName("link");
			for (j=0;j<styles.length;j++) {
				href = styles[j].href;
				if (href.indexOf("ie")!=-1 && wassName.indexOf("was")!=-1) {
					href = "/" + wassName + href;
				}
			}
		}
		catch (e) {
			// do nothing
		}
	}

	// ridimensionamento input ricerca - Mac
	if (isMac!=-1 && IEdetect()==0) {
		document.getElementById("cerca").style.width = "53%";
	}

	// correzioni "veniali" - Linux
	if (isLinux!=-1) {
		document.getElementById("macro").style.paddingRight = "35px";
		document.getElementById("formricerca").getElementsByTagName("div")[0].style.width = "19.5em";
	}

	if (IEdetect()>0 || isKde!=-1 || isSafari!=-1) {

		// ridimensionamento immagini content
		imag = document.getElementById("wpsportletdx").getElementsByTagName("img");
		for (i=0; i<=imag.length-1; i++) {
			imagParent = imag[i].parentElement;

			// max-width img blocco foto + testo
			max = 558;
			if (imag[i].className!="all" && imagParent.className=="isfototesto") {
				if (imag[i].className!="home") {
					if (document.getElementById("wpsportletdx").className=="big") max = 251; 
					else max = 190;
				}
			}
			if (imagParent.className!="isbranddisezione") {
				if (imag[i].style.pixelWidth>max || imag[i].width>max) {
					imag[i].width = max + "px";
					imag[i].style.width = max + "px";
				}
			}
		}
		
		// min-width pathbar + workaround
		divsDx = document.getElementById("wpsportletdx").getElementsByTagName("div");
		for (k=0; k<=divsDx.length-1; k++) {
			if (divsDx[k].className=="isbranddisezione") return;
		}
		if (document.getElementById("pathbar") && document.getElementById("pathbar").offsetWidth<140) {
			document.getElementById("pathbar").style.width = "140px";
		}
	}

}



/*  mappe immagine
-----------------------------*/

/*------------------------------
	Alessio Cartocci 2006-07
    v. 1.5 [hover + tooltip]
------------------------------*/

var mapHover = {
	init : function() {
		img_map = document.getElementsByTagName("img");
		this.altArr = new Array();
		for (k=0; k<=img_map.length-1; k++) {
			this.imgMap = img_map[k];
			if (this.imgMap.parentNode.className=="contmap") {
				this.imgMap.parentNode.style.background = "url(" + img_map[k].src + ") no-repeat";
				this.imgMap.parentNode.style.width = img_map[k].width + "px";
				this.isMap = this.imgMap;
				areaMap = this.imgMap.parentNode.getElementsByTagName("area");
				for (i=0; i<=areaMap.length-1; i++) {
					areaMap[i].value = i + 1;
					if (areaMap[i].href) {
						imgMapSrc = areaMap[i].relatedSrc = this.imgMap.src;
						srcLen = imgMapSrc.length;
						areaMap[i].srcLen = imgMapSrc.substring(0,srcLen-4);
						areaMap[i].relatedImg = this.imgMap;
						areaMap[i].onmouseover = function() {
							this.relatedImg.src = this.srcLen + "-" + this.value + ".gif";
							mapHover.showTip(this.value,0);
						};
						areaMap[i].onfocus = function() {
							this.relatedImg.src = this.srcLen + "-" + this.value + ".gif";
							mapHover.showTip(this.value,1);
						};
						areaMap[i].onmouseout = areaMap[i].onblur = function() {
							this.relatedImg.src = this.relatedSrc;
							mapHover.showTip(0);
						};
						areaMap[i].onmousemove = function(e) {mapHover.moveTip(e);};
					}
					if (areaMap[i].alt) this.altArr[i] = areaMap[i].alt;
				}
				this.showTip(0);
			}
		}
	},
	showTip : function(i,s) {
		mapLi = this.isMap.parentNode.getElementsByTagName("li");
		for (a=0; a<=mapLi.length-1; a++) {
			if (mapLi[a].className=="tooltip") {
				mapLi[a].style.visibility = "hidden";
				mapLi[a].style.position = "absolute";
				mapLi[a].style.left = "-1000em";
				if (i>0) {
					try {
						hx = mapLi[a].getElementsByTagName("h4")[0].firstChild.nodeValue;
						if (this.altArr[i-1]==hx) {
							this.isLi = mapLi[a];
							mapLi[a].style.visibility = "visible";
							mapLi[a].style.width = "12em";
							//added for PCR
							mapLiUl = mapLi[a].getElementsByTagName("ul");
							for (b=0; b<=mapLiUl.length-1; b++) {
								mapLiLi = mapLiUl[b].getElementsByTagName("li");
								for (c=0; c<=mapLiLi.length-1; c++) {
									mapLiLi[c].style.display = "inline";
									mapLiLiCont = mapLiLi[c].firstChild.nodeValue;
									sepVal = (navigator.userAgent.toLowerCase().indexOf("khtml")==-1) ? ", " : ", &nbsp;";
									if (IEdetect()>0) mapLiLiCont = mapLiLiCont.substring(0, mapLiLiCont.length-1);
									if (mapLiLiCont.indexOf(",")==-1 && c<mapLiLi.length-1) mapLiLi[c].innerHTML = mapLiLiCont + sepVal;
									if (mapLiLiCont.indexOf(".")==-1 && c==mapLiLi.length-1) mapLiLi[c].innerHTML = mapLiLiCont + ".";
								}
							}
							//end PCR
							if (s>0) mapLi[a].style.left = "auto";
						}
					}
					catch(err) {
						//do nothing
					}
				}
			}
		}
	},
	moveTip : function(e) {
		moz = document.getElementById && !document.all;
		try {
			tipX = moz ? e.clientX + 18 : event.clientX + 18;
			tipY = moz ? e.clientY - this.isLi.style.height : event.clientY - this.isLi.style.height;
			this.isLi.style.left = tipX + "px";
			this.isLi.style.top = tipY + "px";
		}
		catch(err) {
			//do nothing
		}
	}
}



/*  tasto stampa
--------------------*/

function btnPrint() {
	document.write('<div class="funzioni"><p><input type="button" class="frmbtn" onclick="javascript:window.print();" value="Stampa" name="btnprint" title="Stampa questo contenuto" /></p></div>');
}



/*  newsletter
------------------*/

function newsletterSelect(id) {
	if (document.getElementById("n"+id+"check").checked==true) {
		document.getElementById("n"+id+"a").style.display="block";
		document.getElementById("n"+id+"b").style.display="block";
	}
	else {
		document.getElementById("n"+id+"a").style.display="none";
		document.getElementById("n"+id+"b").style.display="none";
	}
}

function aggiornaEmail() {
	if (document.forms["emailform"].newemail.value == null || document.forms["emailform"].newemail.value == "") {
		alert ("Inserire un'indirizzo e-mail");
		return false;
	}
	else {
		appoMail = new RegExp("^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$");
		if (appoMail.test(document.forms["emailform"].newemail.value)== false) {
			alert("Formato dell'indirizzo e-mail non corretto");
			document.forms["emailform"].newemail.value="";
			document.forms["emailform"].newemail.focus();
			return false; 
		} 
		else return true;
	}
}



/*  santi del giorno - invio mail (temporanea)
-------------------------------------------------*/

function SaintSend(str_date) {
	var objForm = document.getElementById("frmSaint");
	var objEl;
	var strMail = "mailto:?subject=dal sito del Comune di Roma: Tanti auguri!&body=Oggi, " + str_date + " e' ";
	for (i=0; i<objForm.elements.length; i++) {
		objEl = objForm.elements[i];
		if (objEl.type=="radio") {
			if (objEl.checked) {
				strMail+=objEl.value+".  Tanti auguri!";
				location.href = strMail;
			}
		}
	}
}



/*  cerco e offro (temporaneo)
---------------------------------*/

function trim(arg) {
      var trimvalue = "";
      arglen = arg.length;
      if (arglen<1) return trimvalue;
      i = 0;
      pos = -1;
      while (i<arglen) {
          if (arg.charCodeAt(i)!=32 && !isNaN(arg.charCodeAt(i))) {
              pos = i;
              break;
          }
          i++;
      }
      var lastpos = -1;
      i = arglen;
      while (i>=0) {
          if (arg.charCodeAt(i)!=32 && !isNaN(arg.charCodeAt(i))) {
              lastpos = i;
              break;
          }
          i--;
      }
      trimvalue = arg.substring(pos,lastpos + 1);
      return trimvalue;
}

function imgfile(sw) {
	if (sw==1) document.getElementById("image").style.display = "block";
	else document.getElementById("image").style.display = "none";
}

function invia() {
	var subm = true;
	var message = "";
	var emailFilter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	var fileimmagine = trim(document.getElementById("imagefile").value);
	if (trim(document.getElementById("title").value)=="") {
		message = message + "Inserire un titolo\n";
		subm = false;	
	}
	if (trim(document.getElementById("content").value)=="") {
		message = message + "Inserire una descrizione\n";
		subm = false;	
	}
	if (trim(document.getElementById("email").value)=="") {
		message = message + "Inserire un indirizzo e-mail\n";
		subm = false;	
	}
	else if (!emailFilter.test(trim(document.getElementById("email").value))) {
		message = message + "Il formato dell'indirizzo e-mail non è corretto\n";
		subm = false;
	}
	if (isNaN(trim(document.getElementById("phone").value))) {
		message = message + "Il formato del numero telefonico non è corretto\n";
		subm = false;	
	}
	if (isNaN(trim(document.getElementById("price").value))) {
		message = message + "Il formato del prezzo non è corretto";
		subm = false;	
	}
	if (fileimmagine!="") {
		if (document.getElementById("imagefile").value!=fileimmagine) {
			message = message + "Il nome del file non può iniziare o terminare con uno spazio vuoto\n";
			subm = false;		
		}
		if (!(fileimmagine.lastIndexOf('.gif')==fileimmagine.length-4 || fileimmagine.lastIndexOf('.jpg')==fileimmagine.length-4 || fileimmagine.lastIndexOf('.png')==fileimmagine.length-4)) {
			message = message + "Formato del file immagine non valido\n";
			subm = false;	
		}
	}
	if (subm) return true;
	else {
		alert(message);
		return false;
	}
}



/*  cookies login utente
----------------------------*/

// IBM Tivoli Access Manager Integration
// for WebSphere Portal Server

// Set this variable to a semi-colon list of the names of cookies you do not want to delete
var exception_list = "";

function delete_cookie(name,path) {
    // Set expiration date to last year
	var expiration_date = new Date();
	expiration_date.setYear(expiration_date.getYear()-1);
	expiration_date = expiration_date.toGMTString();

	// Expire the cookie
	var cookie_string = name + "=; expires=" + expiration_date;
	if (path!=null) cookie_string += "; path=" + path;
	document . cookie = cookie_string;
}

function name_in_list(n,lst) {
	var arr = lst.split("; ");
	for (var j=0; j<arr.length; j++) {
	    if (arr[j]==n) return true;
	}
	return false;
}

function delete_all_cookies(path,exceptions) {
    // Get cookie list and split into an array of cookie entries
	var cookie_string = "" + document.cookie;
	var cookie_array = cookie_string.split("; ");

	// Delete each cookie ...
	// EXCEPT those whose naems appear in the semicolon delimited list passed in as the second parameter to this function
	for (var i=0; i<cookie_array.length; ++i) {
	    var single_cookie = cookie_array[i].split("=");
	    var name = single_cookie[0];
	    if (name_in_list(name,exceptions)==false) delete_cookie(name,path);
	}
}