function CampoLimpiarValorInicial(obj, valorInicial)
{
	if (obj.value == valorInicial)
		obj.value = "";
}
function EliminarInput(formName, inputName)
{
	document.getElementById(formName).removeChild(document.getElementById(inputName));
}
function FuentesAjustar()
{
	var buscador = document.getElementById("Buscador");
	var obj2 = document.createElement("a");
	obj2.innerHTML = "Recerca avan&ccedil;ada";
	obj2.className = "BuscadorAvanzado";
	obj2.style.visibility = "hidden";
	buscador.appendChild(obj2);
	var ancho = parseInt(obj2.offsetWidth);
	buscador.removeChild(obj2);
	if (ancho > 104)
	{
		if (navigator.userAgent.indexOf("MSIE") != -1)
			document.body.style.fontSize = "0.48em";
		else
			document.body.style.fontSize = "0.542em";		
	}
}
function FuentesAjustarPreHome()
{	
	try
	{
	document.write("<a id='FuentesAjustar' href='' style='visibility:visible' class='BuscadorAvanzado'>Recerca avan&ccedil;ada</a>")	
	var ancho = parseInt(document.getElementById("FuentesAjustar").offsetWidth);
	var obj = document.getElementById("FuentesAjustar");
	var parent = obj.parentNode;
	parent.removeChild(obj);
	if (ancho > 104)
		{
		if (navigator.userAgent.indexOf("MSIE") != -1)
			document.body.style.fontSize = "0.48em";
		else
			document.body.style.fontSize = "0.542em";		
		}
	}
	catch(err)
	{
		//alert(err);
	}
	
}
function Incrustar(code)
{
    document.write(code);
}
function IncrustarCalendario(obj,tipo,input)
{
	if(tipo == "Calendario" && document.getElementById(obj).style.display == 'none')
		document.getElementById(obj).style.display = 'block';
	var nummes = CalcularNumeroMes();
	var anyo = CalcularAnyo();
	CalcularMesAnterior(obj,tipo,input,nummes + 1,anyo);
}
function IncrustarPlayer(video, ancho, alto, id, div)
{

	document.getElementById(div).innerHTML = "";
	
	Incrustar(	"<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"//fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"" + ancho + "\" height=\"" + alto + "\" id=\"" + id + "\">"+
				"<param name=\"allowScriptAccess\" value=\"sameDomain\" />"+
				"<param name=\"scale\" value=\"noscale\" />"+
				"<param name=\"movie\" value=\"" + video + "\" />"+
				"<param name=\"quality\" value=\"high\" />"+
				"<param name=\"bgcolor\" value=\"#ffffff\" />"+
				" <!--[if !IE]> -->"+
				"<object data=\"" + video + "\" width=\"" + ancho + "\" height=\"" + alto + "\" name=\"" + id + "\" type=\"application/x-shockwave-flash\" />"+
				" <!--<![endif]-->"+
				"</object>");
}

function Mostrar(obj)
{
	document.getElementById(obj).style.display = 'block';
}
/* INICIO IMPRESCINDIBLES: funciones para gestionar el reproductor de imprescindibles de la home */

function Imprescindible(imagen, texto, url, title, popup)
{
	this.imagen = imagen;
	this.texto = texto;
	this.url = url;
	this.title = title;
	this.popup = popup;
}

function ImprescindibleOver(obj)
{
	var type = obj.id.substring(28);

	switch (type)
	{
		case "Play":
			//if (obj.src.indexOf("Off.gif") != -1)
			//	obj.src = "../_images/DestacadoImprescindibleBotonPlayOver.gif";
			if (obj.className.indexOf("On") == -1)
				obj.className = "DestacadoImprescindibleBotonPlayOver";
			break;
		case "Pause":
			//if (obj.src.indexOf("Off.gif") != -1)
			//	obj.src = "../_images/DestacadoImprescindibleBotonPauseOver.gif";
			//alert(obj.className.indexOf("Off"));
			if (obj.className.indexOf("On") == -1)
				obj.className = "DestacadoImprescindibleBotonPauseOver";
			break;
		default:
			if (obj.className == "DestacadoImprescindibleBotonOff")
				obj.className = "DestacadoImprescindibleBotonOver";
			break;
	}
}

function ImprescindibleOut(obj)
{
	var type = obj.id.substring(28);
	
	switch (type)
	{
		case "Play":
			//if (obj.src.indexOf("Over.gif") != -1)
			//	obj.src = "../_images/DestacadoImprescindibleBotonPlayOff.gif";
			if (obj.className.indexOf("On") == -1)
				obj.className = "DestacadoImprescindibleBotonPlayOff";
			break;
		case "Pause":
			//if (obj.src.indexOf("Over.gif") != -1)
			//	obj.src = "../_images/DestacadoImprescindibleBotonPauseOff.gif";
			if (obj.className.indexOf("On") == -1)
				obj.className = "DestacadoImprescindibleBotonPauseOff";
			break;
		default:
			if (obj.className == "DestacadoImprescindibleBotonOver")
				obj.className = "DestacadoImprescindibleBotonOff";
			break;
	}
}

function ImprescindiblePlay(activo)
{
	var playObj = document.getElementById("DestacadoImprescindibleBotonPlay");
	var pauseObj = document.getElementById("DestacadoImprescindibleBotonPause");

	if (activo)
	{
		//if (playObj.src.indexOf("On.gif") != -1)
		//	return;
		//playObj.src = "../_images/DestacadoImprescindibleBotonPlayOn.gif";
		//pauseObj.src = "../_images/DestacadoImprescindibleBotonPauseOff.gif";
		if (playObj.className.indexOf("On") != -1)
			return;
		playObj.className = "DestacadoImprescindibleBotonPlayOn";
		pauseObj.className = "DestacadoImprescindibleBotonPauseOff";
		ImprescindibleIntervalId = setInterval(ImprescindibleSeleccionarSiguiente, 5000);
	}
	else
	{
		//if (pauseObj.src.indexOf("On.gif") != -1)
		//	return;
		if (pauseObj.className.indexOf("On") != -1)
			return;
		//playObj.src = "../_images/DestacadoImprescindibleBotonPlayOff.gif";
		//pauseObj.src = "../_images/DestacadoImprescindibleBotonPauseOn.gif";
		playObj.className = "DestacadoImprescindibleBotonPlayOff";
		pauseObj.className = "DestacadoImprescindibleBotonPauseOn";
		
		if (ImprescindibleIntervalId != null)
		{
			clearInterval(ImprescindibleIntervalId);
			ImprescindibleIntervalId = null;
		}
	}
}

function ImprescindibleReproductorCrear()
{
	var script =	"<div id=\"DestacadoImprescindibleBotones\">";
	
	var pos = 610;
	var botonesScript = "";
	for(var i = 0; i < Imprescindibles.length; i++)
	{
		pos -= 12;
		botonesScript = "	<div id=\"DestacadoImprescindibleBoton" + i + "\" class=\"DestacadoImprescindibleBotonOff\" onclick=\"ImprescindibleSeleccionar(this)\" onmouseover=\"ImprescindibleOver(this)\" onmouseout=\"ImprescindibleOut(this)\" tabindex=\"0\">" + (i + 1) + "</div>" + botonesScript;
	}
	
	/*
	script +=		"	<img id=\"DestacadoImprescindibleBotonPlay\" src=\"../_images/DestacadoImprescindibleBotonPlayOn.gif\" onclick=\"ImprescindiblePlay(true)\" onmouseover=\"ImprescindibleOver(this)\" onmouseout=\"ImprescindibleOut(this)\" alt=\"Reprodu&iuml;r\" tabindex=\"0\" />" +
					"	<img id=\"DestacadoImprescindibleBotonPause\" src=\"../_images/DestacadoImprescindibleBotonPauseOff.gif\" onclick=\"ImprescindiblePlay(false)\" onmouseover=\"ImprescindibleOver(this)\" onmouseout=\"ImprescindibleOut(this)\" alt=\"Pausa\" tabindex=\"0\" />";
	*/		
	script +=		"	<div id=\"DestacadoImprescindibleBotonPlay\" class=\"DestacadoImprescindibleBotonPlayOn\" onclick=\"ImprescindiblePlay(true)\" onmouseover=\"ImprescindibleOver(this)\" onmouseout=\"ImprescindibleOut(this)\" title=\"Reprodu&iuml;r\" tabindex=\"0\"></div>" +
					"	<div id=\"DestacadoImprescindibleBotonPause\" class=\"DestacadoImprescindibleBotonPauseOff\" onclick=\"ImprescindiblePlay(false)\" onmouseover=\"ImprescindibleOver(this)\" onmouseout=\"ImprescindibleOut(this)\" title=\"Pausa\" tabindex=\"0\" /></div>";
	
	script += botonesScript;
	
				
	for(i = Imprescindibles.length - 1; i >= 0; i--){
		script += "<a href=\"" + Imprescindibles[i].url + "\"";
		
		if("true" == Imprescindibles[i].popup){			
			if(Imprescindibles[i].title != null && Imprescindibles[i].title != ""){
				script += " title=\""+ Imprescindibles[i].title +"\"";
			}					
			script += " onclick='window.open(this.href);return false;'";		
		}
		 
		script += "><img id=\"DestacadoImprescindibleItem" + i + "\" class=\"DestacadoImprescindibleItem\" src=\"" + Imprescindibles[i].imagen + "\" alt=\"" + Imprescindibles[i].texto + "\" /></a>";
	}
	script +=		"</div>";
	
	document.getElementById("DestacadoImprescindibleContenedor").innerHTML = "";		
	document.write(script);
	
	ImprescindibleSeleccionarSiguiente();
	ImprescindibleIntervalId = setInterval(ImprescindibleSeleccionarSiguiente, 5000);
}

function ImprescindibleSeleccionar(item)
{
	if (ImprescindibleIntervalId != null)
	{
		clearInterval(ImprescindibleIntervalId);
		ImprescindibleIntervalId = setInterval(ImprescindibleSeleccionarSiguiente, 5000);
	}
	
	if (ImprescindibleSeleccionado != null)
	{
		var obj = document.getElementById("DestacadoImprescindibleBoton" + ImprescindibleSeleccionado);
		obj.className = "DestacadoImprescindibleBotonOff";
		ImprescindibleMostrarDestacado(ImprescindibleSeleccionado, false);
	}
	
	item.className = "DestacadoImprescindibleBotonOn";
	ImprescindibleSeleccionado = parseInt(item.id.substring(28));
	ImprescindibleMostrarDestacado(ImprescindibleSeleccionado, true);
}

function ImprescindibleSeleccionarSiguiente()
{
	if (Imprescindibles.length < 2)
		return;
		
	if (ImprescindibleSeleccionado == null)
		ImprescindibleSeleccionado = -1;
	else
	{
		var obj = document.getElementById("DestacadoImprescindibleBoton" + ImprescindibleSeleccionado);
		obj.className = "DestacadoImprescindibleBotonOff";
		ImprescindibleMostrarDestacado(ImprescindibleSeleccionado, false);
	}
		
	ImprescindibleSeleccionado++;
	if (ImprescindibleSeleccionado >= Imprescindibles.length)
		ImprescindibleSeleccionado = 0;
	
	obj = document.getElementById("DestacadoImprescindibleBoton" + ImprescindibleSeleccionado);
	obj.className = "DestacadoImprescindibleBotonOn";
	ImprescindibleMostrarDestacado(ImprescindibleSeleccionado, true);
}

function ImprescindibleMostrarDestacado(itemIndice, visible)
{
	var obj = document.getElementById("DestacadoImprescindibleItem" + itemIndice);
	if (!obj)
		return;
	if (visible)
		obj.style.display = "inline";
	else
		obj.style.display = "none";
}

var ImprescindibleIntervalId = null;
var ImprescindibleSeleccionado = null;

/* FIN IMPRESCINDIBLES: funciones para gestionar el reproductor de imprescindibles de la home */