// JavaScript Document

/**
* show/unshow div IMPORTANT: set style="display:none" in the html if u want hidden div at beginning
**/
function toggleDiv(obj,show) {
		var el = document.getElementById(obj);
		var statoDiv;
		el.style.display =(show==undefined)? ((el.style.display  != 'none' ) ? 'none' : '' ): ((!show) ? 'none' : '' )
}

/**
* check if the text past as param is empty (in several ways!)
**/
function isEmpty(str){ 
	if (str==null || str==undefined)
		return true;
	//rimuovi i tag, rimuovi gli spazi, cosa rimane?
	str=trim(str.replace(/<\/?[^>]+>/gi, '').replace(/(&nbsp;)|(&ensp;)|(&emsp;)/g, ' '));
	return (str =="");
}
/**
* remove useless space at the beginning & the end of a string
**/
function trim (str)
{
return str.replace(/^\s*/g, '').replace(/\s*$/g, '');
}

/**
* managing cookies
**/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/**
* Set up Event Listener
**/
function addEvent(elm, evType, fn, useCapture) { 
	if (elm.addEventListener) { elm.addEventListener(evType, fn, useCapture); return true; } 
	else if (elm.attachEvent) { var r = elm.attachEvent('on' + evType, fn); return r; }
	else { elm['on' + evType] = fn; }
}

/*menu orizzontale*/
var cssmenuids=["navBar"] //Enter id(s) of CSS Horizontal UL menus, separated by commas
var csssubmenuoffset=-2; //Offset of submenus from main menu. Default is 0 pixels.

function createcssmenu2(){
for (var i=0; i<cssmenuids.length; i++){
  var ultags=document.getElementById(cssmenuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
			ultags[t].style.top=ultags[t].parentNode.offsetHeight+csssubmenuoffset+"px"
    	var spanref=document.createElement("span")
			spanref.className="arrowdiv"
			ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
    	ultags[t].parentNode.onmouseover=function(){
					this.style.zIndex=100
    	this.getElementsByTagName("ul")[0].style.visibility="visible"
					this.getElementsByTagName("ul")[0].style.zIndex=0
    	}
    	ultags[t].parentNode.onmouseout=function(){
					this.style.zIndex=0
					this.getElementsByTagName("ul")[0].style.visibility="hidden"
					this.getElementsByTagName("ul")[0].style.zIndex=100
    	}
    }
  }
}

/**
 * Open popup
 */
 var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height) {
  if(popUpWin){ if(!popUpWin.closed) popUpWin.close();}
  	popUpWin=window.open(URLStr,'popupRSSguide','scrollbars=no,width='+width+',height='+height+',left='+left+', top='+top+'');
	if (window.focus) {popUpWin.focus()}
}

/**
* Apre una popup con la galleria fotografica  con il nome passato
*/
function openGallery(galleria , initialPage){
	if (typeof(initialPage)!="undefined" && initialPage != null)
		initialPage='#'+initialPage;
	else
		initialPage='';
	this.location.href='../turismo/gallerie/index.php?g='+galleria+initialPage;
/*
	var page=(initialPage != null) ? "&p="+initialPage : "";
	popUpWindow('/turismo/galleries/galleryLoad.htm?g='+galleria+initialPage,100,50,900,550);
*/
}

/* aggiunge l'evento necessario per creare il menù orizzontale*/
if (window.addEventListener)
window.addEventListener("load", createcssmenu2, false)
else if (window.attachEvent)
window.attachEvent("onload", createcssmenu2)
