/*
	Funciones Generales de la Web www.tuimagenpersonal.com
	Desarrollado por Francisco Javier Martínez
	francisco_javier_martinez@hotmail.com
*/


// RollOver y RollOut sobre Los Elementos de las Noticias
function rollOverNoticia(queNoticia)
{
	document.getElementById("noticia" + queNoticia).style.backgroundColor = "#DB0AAC";
	document.getElementById("noticia" + queNoticia).getElementsByTagName("a")[0].style.color = "#FFFFFF";
	document.getElementById("noticia" + queNoticia).getElementsByTagName("a")[1].style.color = "#FFFFFF";
}

function quitarRollOverNoticia(queNoticia)
{
	document.getElementById("noticia" + queNoticia).style.backgroundColor = "#EFEFEF";
	document.getElementById("noticia" + queNoticia).getElementsByTagName("a")[0].style.color = "#333333";
	document.getElementById("noticia" + queNoticia).getElementsByTagName("a")[1].style.color = "#000000";
}

// RollOver y RollOut Sobre el Boton Volver
var obejo_global_roll_volver = null;
var colorInicialGlobal = null;
function rolloverVolver(objReferer,colorRoll,colorInicial)
{
	colorInicialGlobal = colorInicial;
	objReferer.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = colorRoll;
	obejo_global_roll_volver = objReferer;
	objReferer = agregar_evento_dinamico(objReferer,"mouseout","quitarRollOverVolver");
}

function quitarRollOverVolver()
{
	obejo_global_roll_volver.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = colorInicialGlobal;
}

// RollOver y RollOut Sobre el Boton Volver
var obejo_global_roll_volver = null;
function rolloverBotonesInterior(objReferer)
{
	objReferer.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "#DB0AAC";
	obejo_global_roll_volver = objReferer;
	objReferer = agregar_evento_dinamico(objReferer,"mouseout","quitarRolloverBotonesInterior");
}

function quitarRolloverBotonesInterior()
{
	obejo_global_roll_volver.parentNode.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = "#6E6E6E";
}


//Rollover para las imagenes de las capas de la home
function rollOverImgDivHome(id)
{
	document.getElementById("tabla" + id).style.backgroundColor = "#DB0AAC";
	document.getElementById("tabla" + id).getElementsByTagName("a")[0].style.color = "#FFFFFF";
	
}
function quitarRollOverImgDivHome(id)
{
	document.getElementById("tabla" + id).style.backgroundColor = "#C6C4C6";
	document.getElementById("tabla" + id).getElementsByTagName("a")[0].style.color = "#424242";
}




/*
	Función que asigna dinamicamente un evento
	Parametro 1: El objeto al que se le asignará el evento
	Parametro 2: Evento que asignamos (Como SOLO IE tiene ON en sus eventos, la cadena no ha de llevar el ON. Si lo tiene, la función se lo quitará).
	Parámetro 3: Función que asignamos al objeto en ese evento
*/
function agregar_evento_dinamico (el_objeto, el_evento, la_funcion)
{
	if(el_evento.substr(0,2).toLowerCase() == "on")
	{
		el_evento = el_evento.substr(2,el_evento.length)
	}
	// Agregamos en tiempo de Ejecución el evento MouseOut del Boton
	if (window.addEventListener) // Si El navegador tiene un EventListener (Firefox y Netscape)
	{
		el_objeto.addEventListener(el_evento,eval(la_funcion),true);
		
	}
	else // Si no es Netscape ni Firefox
	{
		// Si el navegador es IE 5+
		if (window.attachEvent)
		{
			var cadena_evento = "on" + el_evento;
			el_objeto.attachEvent(cadena_evento,eval(la_funcion));
		}
		else // Si no es IE 5+
		{
			if (document.getElementById)
			{
				el_objeto.onmouseout = eval(la_funcion);
			}
		}
	}
	return(el_objeto);
}


// Función para agregar a Favoritos la ventana actual
function agregarFavoritos()
{
	var titulo = document.title;
	var url = document.location.href;
	if(document.all)
	{
		if(document.location.href.indexOf("http://") ==  -1)
		{
			url = "http://" + document.location.href;
		}
		// Para IE
		window.external.AddFavorite(url,titulo);
	}
	else
	{
		if(document.location.href.indexOf("http://") ==  -1)
		{
			url = "http://" + document.location.href;
		}
		// Para Firefox
		window.sidebar.addPanel(titulo, url,"");
	}
	
}


function colocateContent()
{
	if(parseInt(top.contenido.iframePagina.document.getElementsByTagName("table")[0].offsetHeight) <= parseInt(top.contenido.document.getElementById("noticias").offsetHeight))
	{
//		alert("NOTICIAS GRANDES. Alto Contenido = " + (parseInt(top.contenido.document.getElementById("noticias").offsetHeight) + 48))
		top.contenido.document.getElementById("iframePagina").height = (parseInt(top.contenido.document.getElementById("noticias").offsetHeight));
		top.document.getElementById("contenido").height = (parseInt(top.contenido.document.getElementById("noticias").offsetHeight) + 48);
	}
	else
	{
//		alert("NOTICIAS PEQUEÑAS. Alto Contenido = " + parseInt(top.contenido.iframePagina.document.getElementsByTagName("table")[0].offsetHeight))
		top.contenido.document.getElementById("iframePagina").height = (parseInt(top.contenido.iframePagina.document.getElementsByTagName("table")[0].offsetHeight));
		top.document.getElementById("contenido").height = (parseInt(top.contenido.iframePagina.document.getElementsByTagName("table")[0].offsetHeight) + 48);
	}
	top.document.getElementById("contenido").width = 592;
}


// Función que abre un popup para sacar la página de enviar a un amigo
var popup = null;
function enviarAmigo(laPagina)
{
	if(popup != null)
		popup.close();
				
	altoPantalla = parseInt(screen.availHeight);
	anchoPantalla = parseInt(screen.availWidth);
	
	centroAncho = parseInt((anchoPantalla/2))
	centroAlto = parseInt((altoPantalla/2))

	anchoPopup = 392;
	altoPopup = 235;
	formularioEnviarAmigo = "enviarAmigo.php?paginaMandar=" + laPagina;

	laXPopup = centroAncho - parseInt((anchoPopup/2))
	laYPopup = centroAlto - parseInt((altoPopup/2))
				
	/*Cálculo del posicionamiento del Popup*/

	popup = window.open(formularioEnviarAmigo,"popup","'statusbar=no,menubar=no,scrollbars=no,width=" + anchoPopup + ",height=" + altoPopup + ",left = " + laXPopup + ",top = " + laYPopup)
}


function bajaNewsletter()
{
	if(popup != null)
		popup.close();
				
	altoPantalla = parseInt(screen.availHeight);
	anchoPantalla = parseInt(screen.availWidth);
	
	centroAncho = parseInt((anchoPantalla/2))
	centroAlto = parseInt((altoPantalla/2))

	anchoPopup = 392;
	altoPopup = 225;
	formularioBajaNewsletter = "/contenidos/bajaNewsletter.php";

	laXPopup = centroAncho - parseInt((anchoPopup/2))
	laYPopup = centroAlto - parseInt((altoPopup/2))
				
	/*Cálculo del posicionamiento del Popup*/

	popup = window.open(formularioBajaNewsletter,"popup","'statusbar=no,menubar=no,scrollbars=no,width=" + anchoPopup + ",height=" + altoPopup + ",left = " + laXPopup + ",top = " + laYPopup)
}


function cargarPoliticaDesdePopup()
{
	/*
		Como tenemos abierta una página desde un popup, y tiene un FORMULARIO, hacemos que cargue la página por medio de un POST y cargando (target) en el IFRAME correspondiente.
		Despues de hacer en envio por post, cerramos la ventana actual (Popup)
	*/

	var contenidosPolitica = "/politicaPrivacidad.php";
	
	opener.document.location.href = contenidosPolitica;
	
//	document.forms[0].action = contenidosPolitica;
//	document.forms[0].target = "contenido";
//	document.forms[0].submit();
	window.close();
}





function buscar(valueBuscar)
{
	if(valueBuscar.length > 0 && valueBuscar != "")
	{
		document.location.href = "/contenidos/resultadoBusqueda.php?palabra=" + valueBuscar;
		document.getElementById("buscar").value = "";
	}
	else
	{
		alert("Introduzca palabra a buscar");
		document.getElementById("buscar").focus();
	}
}
