function viewLegenda(obj,ID)
{
	if (obj.getAttribute('title')=='Vedi legenda')
	{
		obj.src="img/meno.gif";
		obj.title="Chiudi legenda";
		document.getElementById(ID).className = "viewLegend";
	}else
	{
		obj.src="img/piu.gif";
		obj.title="Vedi legenda";
		document.getElementById(ID).className = "noView";
	}
}

function viewEmotion(idTD,idT)
{
	if(document.getElementById(idT).className == 'viewEmotion')
	{
		document.getElementById(idT).className = 'noView';
		document.getElementById(idTD).innerHTML = 'Visualizza Emotion';
	}else
	{
		document.getElementById(idT).className = 'viewEmotion';
		document.getElementById(idTD).innerHTML = 'Nascondi Emotion';
	}
}

function viewCommenti(obj,ID)
{
	if (obj.getAttribute('title')=='Vedi commenti')
	{
		obj.src="img/meno.gif";
		obj.title="Chiudi commenti";
		document.getElementById(ID).className = "viewLegend";
	}else
	{
		obj.src="img/piu.gif";
		obj.title="Vedi commenti";
		document.getElementById(ID).className = "noView";
	}
}

function cambiaImmagine(obj,video,nome,conta)
{
	if (obj.getAttribute('title')=='piu')
	{
		videoE(video,nome,conta);
		obj.src="img/meno.gif";
		obj.title="meno";
	}else
	{
		deleteE(conta);
		obj.src="img/piu.gif";
		obj.title="piu";
	}
}

function videoE(video,nome,conta)
{
	var newvar = document.getElementById(conta);
	var br = document.createElement('br');
	newvar.appendChild(br);
	if(document.createElement && document.getElementById && document.getElementsByTagName) {
		for (i=0; i<video.length; i++)
		{
			// crea elementi
			var span = document.createElement('span');
			span.setAttribute('name','span'+i);
			var a = document.createElement('a');
			a.setAttribute('href','#');
			video1 = video[i];
			nome1 = nome[i];
			//function(){}
			a.onclick =  Function("seeVideo(video1,nome1)");
			var txt = document.createTextNode(nome[i]);
			var br = document.createElement('br');
			a.appendChild(txt);
			span.appendChild(a);
			newvar.appendChild(span);
			newvar.appendChild(br);
		}
	}
}

function deleteE(conta)
{
	if(document.removeChild && document.getElementById && document.getElementsByTagName)
	{
		for (i=document.getElementById(conta).childNodes.length; i>3; i--)
		{
			// rimuovi 
			var div = document.getElementById(conta).lastChild;
			document.getElementById(conta).removeChild(div);
		}
	}
}

function seeVideo(video,nome,data)
{
	var nomeV =  nome.replace(/_/g," "); 
	document.getElementById('nameVideo').innerHTML = nomeV+"  "+data;
	var player = document.getElementById('video');
	if(document.createElement && document.getElementById && document.getElementsByTagName)
	{
		var OPER=navigator.userAgent.indexOf("Opera");
		if(!document.all || OPER>-1)
		{
			var object = document.createElement('object');
			object.setAttribute('type','application/x-shockwave-flash');
			object.setAttribute('data',video);
			object.setAttribute('width','425');
			object.setAttribute('height','366');
			object.setAttribute('id','eMovie');
			var param1 = document.createElement('param');
			param1.setAttribute('name','movie');
			param1.setAttribute('value',video);
			param1.setAttribute('id','pMovie');
			var param2 = document.createElement('param');
			param2.setAttribute('name','allowScriptAcess');
			param2.setAttribute('value','sameDomain');
			var param3 = document.createElement('param');
			param3.setAttribute('name','quality');
			param3.setAttribute('value','best');
			var param4 = document.createElement('param');
			param4.setAttribute('name','wmode');
			param4.setAttribute('value','transparent');
			var param5 = document.createElement('param');
			param5.setAttribute('name','scale');
			param5.setAttribute('value','showall');
			var param6 = document.createElement('param');
			param6.setAttribute('name','FlashVars');
			param6.setAttribute('value','playerMode=embedded');
		
			object.appendChild(param1);
			object.appendChild(param2);
			object.appendChild(param3);
			object.appendChild(param4);
			object.appendChild(param5);
			object.appendChild(param6);
		}else
		{
			var object = document.createElement('embed');
			object.setAttribute('src',video);
			object.setAttribute('type','application/x-shockwave-flash');
			object.setAttribute('wmode','transparent');
			object.setAttribute('width','425');
			object.setAttribute('height','366');
		}
		player.appendChild(object);
		player.replaceChild(object,player.childNodes[0]);
	}
}

function viewDati(obj,ID,album,click)
{
	if (click != undefined)
	{
		document.getElementById(ID).className = "viewV";
		document.getElementById(album).className = "videoAlbum";
	}else
	{
		if (obj.getAttribute('title')=='piu')
		{
			obj.src="img/meno.gif";
			obj.title="meno";
			if (album != undefined)
			{
				document.getElementById(ID).className = "viewV";
			}else
			{
				document.getElementById(ID).className = "view";
			}
			if(album != '' && album != undefined)
			{
				document.getElementById(album).className = "videoAlbum";
			}
		}else
		{
			obj.src="img/piu.gif";
			obj.title="piu";
			document.getElementById(ID).className = "noView";
			if(album != '' && album != undefined)
			{
				document.getElementById(album).className = "noVideoAlbum";
			}
		}
	}
}
function impostaCookie (nome, valore, scadenza) {
    if (scadenza == "") {
        var oggi = new Date()
        oggi.setMonth(oggi.getMonth() + 3);
        scadenza = oggi.toGMTString() //restituisce la data nel formato necessario
    }
    valore = escape(valore);
    document.cookie=nome + "=" + valore + ";expires=" + scadenza;
}
function valoreCookie (nome) {
   var valore=document.cookie; //ottiene la stringa di cookie
   var inizioCookie=valore.indexOf(" " + nome + "="); //trova il cookie desiderato
 
   if (inizioCookie == -1) { //se non esiste, magari è all'inizio della stringa
      inizioCookie = valore.indexOf(nome + "=");
   }
 
   if (inizioCookie == -1) { //il cookie non esiste proprio
      valore = null;
   }
 
   if (inizioCookie >= 0) {//il cookie esiste
      inizioCookie = valore.indexOf("=", inizioCookie) + 1; //qui inizia la stringa del valore
      var fineCookie = valore.indexOf(";", inizioCookie); //qui finisce
      if (fineCookie == -1)  //se non viene trovato, allora è l'ultimo cookie
         fineCookie = valore.length;
      valore = unescape(valore.substring(inizioCookie, fineCookie)); //elimina i caratteri commutati
   }
 
   return valore;
}
function cookieAttivi () {
    ris = false; //imposta il risultato a falso
    impostaCookie("testCookie", "test"); //crea il cookie fittizio
    if (valoreCookie("testCookie") == "test") { //se esiste
        ris = true; //allora i cookie sono abilitati
    }
    return ris;
}
function changeSquadra(ID)
{
	IDP = document.getElementById('IDA').value;
	document.getElementById(IDP).className = "noView";
	document.getElementById(ID).className = "active";
	document.getElementById('IDA').value = ID;
}