function openPopup(title, url, method, params) {
	var titleStr="<h2>"+title+"</h2>";
	$('popup').show();
	$('darkOverlay').show();
	var t=$$('.flashObj');
	for(var i=0; i<t.length; i++) {
		t[i].hide();	
	}
	var t=$('popupContents');
	var ajax = new Ajax.Request(url,
	{
	method: method, 
	parameters: params,
	onFailure: function() {t.update(titleStr+"Operazione fallita.")}, 
	onLoaded: function() {t.update(titleStr+"<img src='img/indicator1.gif' witdh='10' height='10' alt='' /> Richiesta inviata.")}, 
	onInteractive: function() {t.update(titleStr+"Ricezione dati in corso.")},
	onSuccess: function(data) {
			t.update(titleStr+data.responseText);
		}
	}
	);
}
function closePopup() {
	$('popup').hide();
	$('darkOverlay').hide();
	var t=$$('.flashObj');
	for(var i=0; i<t.length; i++) {
		t[i].show();	
	}
}

function openPopupRegister() {
	openPopup();	
}

function preferiti(title, lnk){
	var testo="<img alt='aggiungi ai preferiti' src='backend/modules/Locali/icons/cuore.gif' width='16' height='16' /> Aggiungi ai Preferiti";
	var data="";
	if(window.sidebar && window.sidebar.addPanel) {
		if(navigator.userAgent.lastIndexOf("Netscape")!=-1) {
			data="<a href='#' onclick=\"window.sidebar.addPanel( '"+title+"', '"+lnk+"', '' ); return false;\" title='Aggiungi ai Preferiti'>"+testo+"<\/a>";
		} else {
			data="<a href='#' onclick=\"window.sidebar.addPanel( '"+title+"', '"+lnk+"', '' ); return false;\" title='Aggiungi ai Preferiti'>"+testo+"<\/a>";
		}
	} else if( window.opera && window.print ) {
		data="<a title='"+title+"' rel='sidebar' href='"+lnk+"' title='Aggiungi ai Preferiti'>"+testo+"<\/a>";
	} else if( window.external && ( navigator.platform == "Win32" || ( window.ScriptEngine && ScriptEngine().indexOf("InScript") + 1 ) ) ) {
		data="<a href='#' onclick=\"window.external.AddFavorite( location.href.replace( \/#.*\/, '' ), document.title ); return false;\" title='Aggiungi ai Preferiti'>"+testo+"<\/a>";
	}
	document.getElementById("preferiti").innerHTML=data;
}

function showEvents(timespan) {
switch(timespan) {
	case "day":
	titleStr="oggi";
	break;
	case "week":
	titleStr="questa settimana";
	break;
	case "month":
	titleStr="questo mese";
	break;
}
var t=$('eventiBox');
var tt=$('eventiBoxTitle');
var url = 'aj_events.php';
var ajax = new Ajax.Request(url,
{
method: 'post', 
parameters: {timespan:timespan, detailPage:"eventoScheda.php"},
onFailure: function() {t.update("Operazione fallita.")}, 
onLoaded: function() {t.update("<img src='img/indicator1.gif' witdh='10' height='10' alt='' /> Richiesta inviata.")}, 
onInteractive: function() {t.update("Ricezione dati in corso.")},
onSuccess: function(data) {
		t.update(data.responseText);
		tt.update("Cosa fare&hellip; "+titleStr);
	}
}
);
}

function writeMsg(autore, msg, autore_id) {
autore=autore.split("<").join("&lt;").split(">").join("&gt;");
msg=msg.split("<").join("&lt;").split(">").join("&gt;");
//document.form_sb.autore.value="";
document.form_sb.msg.value="";
var t=$('sb_response');
var url = 'sb_edit.php';
var ajax = new Ajax.Request(url,
{
method: 'post', 
parameters: {autore:autore, msg:msg, autore_id:autore_id},
onFailure: function() {t.update("Operazione fallita.")}, 
onLoaded: function() {t.update("<img src='img/indicator1.gif' witdh='10' height='10' alt='' /> Richiesta inviata.")}, 
onInteractive: function() {t.update("Ricezione dati in corso.")},
onSuccess: function(data) {
		t.update(data.responseText);
		updateShoutbox();
	}
}
);
}

function updateShoutbox() {
var t=$('sb_container');
var url = 'sb_update.php';
var ajax = new Ajax.Request(url,
{
onFailure: function() {}, 
onLoaded: function() {}, 
onInteractive: function() {},
onSuccess: function(data) {
		t.update(data.responseText);
	}
}
);		
}

// fogli di stile

function setActiveStyleSheet(title) {
  var i, a, main;
  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel") &&
        a.getAttribute("rel").indexOf("style") != -1 &&
        a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  var title = getActiveStyleSheet();
  if(title!="print") {
  	createCookie("style", title, 365);
  }
}

function getActiveStyleSheet() {
  var i, a;
  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel") &&
        a.getAttribute("rel").indexOf("style") != -1 &&
        a.getAttribute("title") &&
        !a.disabled
        ) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for (i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if (a.getAttribute("rel") &&
        a.getAttribute("rel").indexOf("style") != -1 &&
        a.getAttribute("rel").indexOf("alt") == -1 &&
        a.getAttribute("title")
        ) return a.getAttribute("title");
  }
  return null;
}

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 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 restore() {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}
restore();









