function BasesLegalsObrir()
{
	window.open(rootEstatic + "elteumobilBases.htm", "_blank", "width=630,height=670,toolbar=0,directories=0,location=0,status=0,resizable=1");
}

function CercadorEnviar(obj)
{
	var cercadorForm = document.getElementById("Cercador");
	if (!cercadorForm)
		return;

	switch (obj.value)
	{
		case "scroon":
			cercadorForm.action = '/p25anys/search.jsp';
			break;
		default:
			cercadorForm.action = '/searcher/Search';
			break;
	}
	
	//alert(cercadorForm.action);
}

function ClaseCanviar(obj, clase, pareNivell)
{
	if (!pareNivell)
		pareNivell = 0;
		
	for(var i = 0; i < pareNivell; i++)
		obj = obj.parentNode;

	obj.className = clase;
}

function CookieGet(name)
{
	var cnt;
	var items;
	var pairs;

	items = document.cookie.split("; ");
	for(cnt = 0; cnt < items.length; cnt++)
		{
		pairs = items[cnt].split("=");
		if (name == pairs[0]) 
			return(unescape(pairs[1]));
		}

	return("");
}

function CookieSet(name, value, expires)
{
	var cookie;

	cookie = name + "=" + escape(value) + ";";

	if (expires)
		cookie += " expires=" + expires.toUTCString() + ";";

	document.cookie = cookie;
}

function FonsCambiar(index)
{
	var obj = document.getElementById("TriaFons");
	var elements = obj.getElementsByTagName("div");
	for(var i = 0; i < elements.length; i++)
	{
		if (elements[i].className != "ColorOn")
			continue;
		elements[i].className = "ColorOff";
	}

	obj = document.getElementById("Color" + index);			
	obj.className = "ColorOn";
	
	obj = document.getElementById("Capcalera");			
	obj.style.backgroundImage = "url(" + rootEstatic + "img/Capcalera" + index + ".jpg)";
	obj.style.visibility = "visible";
	
	obj = document.getElementById("Peu");			
	obj.style.backgroundImage = "url(" + rootEstatic + "img/Peu" + index + ".jpg)";
	obj.style.visibility = "visible";
	
	var colors =  new Array("071b34", "01322e", "0e1c03", "221f10", "2f1204", "3a0134", "160925", "000000");
	
	obj = document.getElementById("CapcaleraArea");
	obj.style.backgroundColor = "#" + colors[index];
	
	obj = document.getElementById("PeuArea");
	obj.style.backgroundColor = "#" + colors[index];

	var colors =  new Array("a5b5cf", "66c1b6", "86a86e", "c1bcab", "c8906b", "c9a3c3", "9d7ccb", "9a9a9a");
		
	obj = document.getElementById("CercadorParaules");
	if (obj)
		obj.style.backgroundColor = "#" + colors[index];
	
	for(var i = 1; i <= 7; i++)
	{
		obj = document.getElementById("Menu" + i + "Inici");
		
		if (obj.className == "MenuIniciSeleccionat")
			continue;
		
		obj.style.backgroundImage = "url(" + rootEstatic + "img/Menu" + index + "Inici.gif)";
		
		obj = document.getElementById("Menu" + i + "Fi");
		obj.style.backgroundImage = "url(" + rootEstatic + "img/Menu" + index + "Fi.gif)";
		
		obj = document.getElementById("Menu" + i);
		obj.style.backgroundImage = "url(" + rootEstatic + "img/Menu" + index + "Fons.gif)";
	}

	obj = document.getElementById("ImatgeGran");
	if (obj)
		obj.src = "" + rootEstatic + "img/Tv3ImatgeAlternativa" + index + "Gran.jpg";
	
	for(var i = 0; i < document.images.length; i++)
	{
		if (document.images[i].className != "LlistatImatge")
			continue;
		if (document.images[i].src.indexOf("Tv3ImatgeAlternativa") == -1)
			continue;
		document.images[i].src = "" + rootEstatic + "img/Tv3ImatgeAlternativa" + index + "Petita.jpg";
	}
	
	obj = document.getElementById("CapcaleraBanner");
	if (obj)
	{
		obj.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="728" height="90" id="Banner" align="middle">' +
						'	<param name="allowScriptAccess" value="sameDomain" />' +
						'	<param name="allowFullScreen" value="false" />' +
						'	<param name="movie" value="' + rootEstatic + 'media/Banner' + index + '.swf" />' +
						'	<param name="quality" value="high" />' +
						'	<param name="bgcolor" value="#ffffff" />' +
						'	<embed src="' + rootEstatic + 'media/Banner' + index + '.swf" quality="high" bgcolor="#ffffff" width="728" height="90" name="Banner" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />' +
						'</object>';
	}
	
	CookieSet("Color", index, new Date(2050, 11, 31));
}

function HnlEmbed(code)
{
    document.write(code);
}

function ImatgeAlternativaMostrar(gran)
{
	var index = CookieGet("Color");

	if (gran)
		document.write('<img id="ImatgeGran" src="' + rootEstatic + 'img/Tv3ImatgeAlternativa' + index + 'Gran.jpg" alt="" />');
	else
		document.write('<img class="LlistatImatge" src="' + rootEstatic + 'img/Tv3ImatgeAlternativa' + index + 'Petita.jpg" alt="" />');
}

function ItemImatgesEstatCanviar(obj, estatInicial, estatFinal, pareNivell)
{
	if (!pareNivell)
		pareNivell = 0;
		
	for(var i = 0; i < pareNivell; i++)
		obj = obj.parentNode;
		
	var imatges = obj.getElementsByTagName("img");
	for(var i = 0; i < imatges.length; i++)
	{
		if (imatges[i].src.indexOf(estatInicial) == -1)
			continue;
		imatges[i].src = imatges[i].src.replace(estatInicial, estatFinal);
	}
}

function ItemOut(obj, type)
{
	switch (type)
	{
		case "Cercador":
			ClaseCanviar(obj, 'CercadorResultat', 2);
		break;
		case "Home":
			ClaseCanviar(obj, 'HomeDestacat', 2);
			ItemImatgesEstatCanviar(obj, "[On]", "[Off]", 2);
			break;
		
		case "Llistat":
			ClaseCanviar(obj, 'LlistatTextCaixa', 1);
			ClaseCanviar(obj, 'LlistatItem', 2);
			break;
			
		case "Pod":
			ClaseCanviar(obj, 'HomePodCast', 1);
			break;
			
		case "Portada":
			ClaseCanviar(obj, 'PortadaDestacat', 2);
			ItemImatgesEstatCanviar(obj, "[On]", "[Off]", 2);
			break;
			
		case "Imatge":
			if (unescape(obj.src).indexOf("[No]") != -1)
				return false;
			if (unescape(obj.src).indexOf("[On]") != -1)
				obj.src = unescape(obj.src).replace("[On]", "[Off]");
			break;
	}
}

function ItemOver(obj, type)
{
	switch (type)
	{
		case "Cercador":
			ClaseCanviar(obj, 'CercadorResultatOn', 2);
		break;
		case "Home":
			ClaseCanviar(obj, 'HomeDestacatOn', 2);
			ItemImatgesEstatCanviar(obj, "[Off]", "[On]", 2);
			break;
			
		case "Llistat":
			ClaseCanviar(obj, 'LlistatTextCaixaOn', 1);
			ClaseCanviar(obj, 'LlistatItemOn', 2);
			break;
			
		case "Pod":
			ClaseCanviar(obj, 'HomePodCastOn', 1);
			break;
			
		case "Portada":
			ClaseCanviar(obj, 'PortadaDestacatOn', 2);
			ItemImatgesEstatCanviar(obj, "[Off]", "[On]", 2);
			break;
			
		case "Imatge":
			if (unescape(obj.src).indexOf("[No]") != -1)
				return false;
			
			if (unescape(obj.src).indexOf("[Off]") != -1)
				obj.src = unescape(obj.src).replace("[Off]", "[On]");
			break;
	}
}

function MenuOut(obj)
{
	obj.style.textDecoration = "none";
	obj.style.fontWeight = "normal";
}

function MenuOver(obj)
{
	obj.style.fontWeight = "bold";
}

function MenuSeleccionar(pagina)
{
	window.location = pagina;
}

function PaginaInicialitzar()
{
	var index = CookieGet("Color");
	if (index == "")
		index = 0;
	FonsCambiar(index);
}


