function ApriFinestra(_finestra)
{
  window.open('',_finestra,'toolbar=no,scrollbars=yes,menubar=yes,width=640,height=480,top=50,left=50'); 
}

function ApriFinestraBorse(_finestra)
{
  window.open('',_finestra,'toolbar=no,scrollbars=yes,menubar=yes,width=640,height=400,top=50,left=50'); 
}


function ApriFinestraPopUpFoto()
{
  window.open('','popupfoto','toolbar=no,scrollbars=no,menubar=no,width=586,height=502,top=30,left=30'); 
}

function ApriFinestraPopUpFotoV()
{
  window.open('','popupfoto','toolbar=no,scrollbars=no,menubar=no,width=486,height=622,top=10,left=10'); 
}


/*function Avviso(_finestra)
{
  window.open(_finestra,'Avviso','toolbar=no,scrollbars=no,menubar=no,width=500,height=150,top=70,left=70'); 
}*/


function preferiti(){
  var url = window.document.location;
  var title = window.document.title;
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
    window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}


function getGiorno(data2) 
{
	var t = new Date(data2);
	var day="";
	if (t.getDay()==1) {day="Lunedì"; }
	if (t.getDay()==2) {day="Martedì"; }
	if (t.getDay()==3) {day="Mercoledì"; }
	if (t.getDay()==4) {day="Giovedì"; }
	if (t.getDay()==5) {day="Venerdì"; }
	if (t.getDay()==6) {day="Sabato"; }
	if (t.getDay()==0) {day="Domenica"; }
	return day;
}

function Cookie(document, name, days){
	// impsta il document
	this.$document = document;
	// imposta il nome del cookie
	this.$name = name;
	// imposta la scadenza
	if(!days)days = 7;
	this.$expiration = new Date(new Date().getTime() + days * 86400000);
	//imposta il numero di valori
	this.nId = 0;
}

function _SaveCookie(){
	// ciclo interno alle proprieta' dei cookie per impostare correttamente la punteggiatura
	// ed evitare conflitti coi caratteri riservati come ; e =, sostituiti da & e :
	var cookieval = "";
	for(var prop in this){
		if((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function') || (this[prop] == null))continue;
		if(cookieval != "")cookieval += '&';
		cookieval += prop + ':' + escape(this[prop]);
	}
	// imposta il valore
	var cookie = this.$name + '=' + cookieval;
	if(this.$expiration)cookie += '; expires=' + this.$expiration.toGMTString();
	// imposta il cookie
	this.$document.cookie = cookie;
}

function _LoadCookie(){
	// carica tutti i cookie
	var allCookies = this.$document.cookie;
	if(allCookies == "")return false;
	// prende il cookie giusto
	var start = allCookies.indexOf(this.$name + '=');
	if(start == -1)return false;
	start += this.$name.length + 1;

	// suddivide i valori
	var end = allCookies.indexOf(';', start);
	if(end == -1)end = allCookies.length;
	var cookieval = allCookies.substring(start, end);
	
	var a = cookieval.split('&');
	for(var i = 0; i < a.length; i++){
		a[i] = a[i].split(':');
	}
	for(var i = 0; i < a.length; i++){
		this[a[i][0]] = unescape(a[i][1]);
	}

	return true;
}

function _DeleteCookie(){
	var cookie;
	cookie = this.$name + '=';
	this.nId = 0;
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

	this.$document.cookie = cookie;
	this.salva();
}


function _InsertCookie(valore){
	this.nId++;
	this['id' + this.nId] = valore;
	this.salva();
	alert("Iniziativa inserita nella pagina 'crea il tuo programma'");
}

function _InsertCookie_lang1(valore) {
        this.inserisci(valore);
}

function _InsertCookie_lang2(valore){
	this.nId++;
	this['id' + this.nId] = valore;
	this.salva();
	alert("Event in [my planner]");
}

function _RemoveCookie(_id){
	var ID = 0;
	for(var z = 0; z <= this.nId; z++) {
		if (this['id' + z] == _id) {
			ID = z;
			for(var i = ID; i < this.nId; i++){
				this['id' + i] = this['id' + (i + 1)];
			}
			this['id' + this.nId] = null;
			this.nId--;
			this.salva();
		} 
	}
}

function dammicookie()
{
	var stringasql = "";
	for (var i=1; i <= miofestival.nId;i++)
	{
		stringasql += "" + miofestival['id' + i];
		if (i != miofestival.nId) {
			stringasql += "|";
		}
	}
//	alert(stringasql);
	document.test.stringa.value += "" + stringasql + "";
	document.test.submit();
}

function dammicookie2(_id)
{

	var stringasql = "";
	for (var i=1; i <= miofestival.nId;i++)
	{
		stringasql += "" + miofestival['id' + i];
		if (i != miofestival.nId) {
			stringasql += "|";
		}
	}
	//	eval('document.test' + _id + '.elements[1].value += "' + stringasql + '";');
	
	eval('document.test' + _id + '.stringa.value += "' + stringasql + '";');
	eval("document.test" + _id + ".submit();");
    
}

function dammicookie3()
{

	var stringasql = "";
	for (var i=1; i <= miofestival.nId;i++)
	{
		stringasql += "" + miofestival['id' + i];
		if (i != miofestival.nId) {
			stringasql += "|";
		}
	}
	//alert(stringasql);
	
	
	eval('parent.menu.document.testmenu.stringa.value += "' + stringasql + '";');
	eval("parent.menu.document.testmenu.submit();");
    
}


function dammicookie4()
{
	var stringasql = "";
	for (var i=1; i <= miofestival.nId; i++)
	{
		stringasql += "" + miofestival['id' + i];
		if (i != miofestival.nId) {
			stringasql += "|";
		}
	}
	//alert(stringasql);
	
        location.href="Viewer?cmd=miofestival&level=0&levelname=crea il tuo programma&levellink=Viewer?cmd=miofestival&stringa=" + stringasql ;
    
}


new Cookie();
Cookie.prototype.salva = _SaveCookie;
Cookie.prototype.carica = _LoadCookie;
Cookie.prototype.svuota = _DeleteCookie;
Cookie.prototype.inserisci = _InsertCookie;
Cookie.prototype.inserisci_lang1 = _InsertCookie_lang1;
Cookie.prototype.inserisci_lang2 = _InsertCookie_lang2;
Cookie.prototype.rimuovi = _RemoveCookie;
// Fine definizione della classe Cookie

var miofestival = new Cookie(document, "miofestival");
miofestival.carica();


function verificaPrivacy() {

    if (document.main.privacy[1].checked) {
      alert("ATTENZIONE. E' necessario dare il consenso all'informativa sulla privacy.")
      }
    else {
     document.main.submit();
   }
  }
