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 'il mio 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();
   }
  }

function Carica_SocialNetwork() {
    var lang = $('#hidden_socialnetwork_lang').val();
    var urlencoded = $('#hidden_socialnetwork_urlencoded').val();
    $('#div_socialnetwork').html(
            "<div style='width: 110px;height: 20px; float: left;border-right: 1px solid red;padding-right: 5px;margin-right: 10px;'>"
//            + "<div id='fb-root'></div><script src='http://connect.facebook.net/en_US/all.js#appId=269923616354852&amp;xfbml=1'></script><fb:like href='' send='false' layout='button_count' width='80' show_faces='false' font=''></fb:like>"
//            + "<iframe src='http://www.facebook.com/plugins/like.php?app_id=269923616354852&amp;href&amp;send=false&amp;layout=button_count&amp;width=450&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:450px; height:21px;' allowTransparency='true'></iframe>"
            + "<iframe src='facebook.php?url=" + urlencoded + "&lang=" + lang + "' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:110px; height:21px;' allowTransparency='true'></iframe>"
//	+ "<fb:like href='' send='false' layout='button_count' width='110' show_faces='false' font=''></fb:like>"
            + "</div>"
            + "<div style='width: 75px;height: 20px; float: left;border-right: 1px solid red;padding-right: 10px;margin-right: 10px;'>"
            + (lang=='ita'
                ?"<a href='http://www.facebook.com/share.php?u=" + urlencoded + "' target='_blank' style='' title='Condividi su facebook'><span style='display: block; float: left; padding-top: 2px;color: black; font-size: 11px;'>Condividi</span><img style='margin-top: 2px;float: right;' src='images/ico_facebook.gif' alt='facebook'/></a>"
                :"<a href='http://www.facebook.com/share.php?u=" + urlencoded + "' target='_blank' style='' title='Share on facebook'><span style='display: block; float: left; padding-top: 2px;color: black; font-size: 11px;'>Share</span><img style='padding-top: 2px;float: right;' src='images/ico_facebook.gif' alt='facebook'/></a>"
                )
            + "</div>"
            + "<div style='float: left'><a href='http://twitter.com/share' class='twitter-share-button' data-count='horizontal'>Tweet</a><script type='text/javascript' src='http://platform.twitter.com/widgets.js'></script></div><div style='clear'></div>"
);
}

