// JavaScript Document

//----------------------------------------------------------------------------------------------------//
//----------------------------------- FUNCIONES MENU DE PESTAÑAS -------------------------------------//
//----------------------------------------------------------------------------------------------------//

function resultados() {
	var resultados = document.getElementById('resultados');
	var arbitraje = document.getElementById('arbitraje');
	var federacion = document.getElementById('federacion');
	var car = document.getElementById('car');
	var fotografias = document.getElementById('fotografias');
	var hapkido = document.getElementById('hapkido');
	if (resultados.style.position != 'absolute'){
		resultados.style.position = 'absolute';
		resultados.style.top = '0';
		arbitraje.style.position = '';
		federacion.style.position = '';
		car.style.position = '';
		fotografias.style.position = '';
		hapkido.style.position = '';
	} 	
}

function arbitraje() {
	var resultados = document.getElementById('resultados');
	var arbitraje = document.getElementById('arbitraje');
	var federacion = document.getElementById('federacion');
	var car = document.getElementById('car');
	var fotografias = document.getElementById('fotografias');
	var hapkido = document.getElementById('hapkido');
	if (arbitraje.style.position != 'absolute'){
		arbitraje.style.position = 'absolute';
		arbitraje.style.top = '0';
		resultados.style.position = '';
		federacion.style.position = '';
		car.style.position = '';
		fotografias.style.position = '';
		hapkido.style.position = '';
	} 	
}

function federacion() {
	var resultados = document.getElementById('resultados');
	var arbitraje = document.getElementById('arbitraje');
	var federacion = document.getElementById('federacion');
	var car = document.getElementById('car');
	var fotografias = document.getElementById('fotografias');
	var hapkido = document.getElementById('hapkido');
	if (federacion.style.position != 'absolute'){
		federacion.style.position = 'absolute';
		federacion.style.top = '0';
		resultados.style.position = '';
		arbitraje.style.position = '';
		car.style.position = '';
		fotografias.style.position = '';
		hapkido.style.position = '';
	} 	
}

function car() {
	var resultados = document.getElementById('resultados');
	var arbitraje = document.getElementById('arbitraje');
	var federacion = document.getElementById('federacion');
	var car = document.getElementById('car');
	var fotografias = document.getElementById('fotografias');
	var hapkido = document.getElementById('hapkido');
	if (car.style.position != 'absolute'){
		car.style.position = 'absolute';
		car.style.top = '0';
		arbitraje.style.position = '';
		federacion.style.position = '';
		resultados.style.position = '';
		fotografias.style.position = '';
		hapkido.style.position = '';
	} 	
}

function fotografias() {
	var resultados = document.getElementById('resultados');
	var arbitraje = document.getElementById('arbitraje');
	var federacion = document.getElementById('federacion');
	var car = document.getElementById('car');
	var fotografias = document.getElementById('fotografias');
	var hapkido = document.getElementById('hapkido');
	if (fotografias.style.position != 'absolute'){
		fotografias.style.position = 'absolute';
		fotografias.style.top = '0';
		arbitraje.style.position = '';
		federacion.style.position = '';
		resultados.style.position = '';
		car.style.position = '';
		hapkido.style.position = '';
	} 	
}

function galeria() {
	var resultados = document.getElementById('resultados');
	var arbitraje = document.getElementById('arbitraje');
	var federacion = document.getElementById('federacion');
	var car = document.getElementById('car');
	var fotografias = document.getElementById('fotografias');
	var galeria = document.getElementById('galeria');
	if (galeria.style.position != 'absolute'){
		galeria.style.position = 'absolute';
		galeria.style.top = '0';
		arbitraje.style.position = '';
		federacion.style.position = '';
		resultados.style.position = '';
		car.style.position = '';
		fotografias.style.position = '';
	} 	
}

//----------------------------------------------------------------------------------------------------//
//--------------------------------------- AJAX CARGAR PAGINA -----------------------------------------//
//----------------------------------------------------------------------------------------------------//

// Esta funcion carga las paginas
function llamara(url, id_contenedor)
{
	if (id_contenedor=='resultado')
	{
		palabra=document.buscador.palabra.value;
		url=url+"?palabra="+palabra;
	}
	if (id_contenedor=='mostrarfecha')
	{
		dni=document.mvencimiento.dni.value;
		apellidos=document.mvencimiento.apellidos.value;
		url=url+"?dni="+dni+"&apellidos="+apellidos;
	}
	Descarga(url, id_contenedor);
}

function Descarga(url,id_contenedor)
{
	var pagina_requerida = false
	if (window.XMLHttpRequest) 
	{// Si es Mozilla, Safari etc
		pagina_requerida = new XMLHttpRequest()
	} 
	else if (window.ActiveXObject)
	{ // pero si es IE
		try 
		{
			pagina_requerida = new ActiveXObject("Msxml2.XMLHTTP")
		} 
		catch (e)
		{ // en caso que sea una versin antigua
			try
			{
				pagina_requerida = new ActiveXObject("Microsoft.XMLHTTP")
			}
			catch (e){}
		}
	}
	else
		return false
	pagina_requerida.onreadystatechange=function(){ // funci n de respuesta
		cargarpagina(pagina_requerida, id_contenedor)
	}
	
	pagina_requerida.open('GET', url, true) // asignamos los mtodos open y send
	pagina_requerida.send(null)
}


// todo es correcto y ha llegado el momento de poner la informacion requerida
// en su sitio en la pagina xhtml
function cargarpagina(pagina_requerida, id_contenedor)
{
	if (pagina_requerida.readyState == 1)
		if  (id_contenedor == 'resultado')  
			document.getElementById('resultado').innerHTML='<img src="http://fet.nnatali.com/images/loader.gif" alt="cargando" class="loader" />'
		if  (id_contenedor == 'mostrarfecha')  
			document.getElementById('mostrarfecha').innerHTML='<img src="http://fet.nnatali.com/images/loader.gif" alt="cargando" class="loader" />'
		if  (id_contenedor == 'imagen')  
			document.getElementById('imagen').innerHTML='<img src="http://fet.nnatali.com/images/loader.gif" alt="cargando" class="loader" />'
		if  (id_contenedor == 'calendario')  
			document.getElementById('calendario').innerHTML='<img src="http://fet.nnatali.com/images/loader.gif" alt="cargando" class="loader" />'
		if  (id_contenedor == 'mevento')  
			document.getElementById('mevento').innerHTML='<img src="http://fet.nnatali.com/images/loader.gif" alt="cargando" class="loader" />'
		if  (id_contenedor == 'cizquierda')  
			document.getElementById('cizquierda').innerHTML='<img src="http://fet.nnatali.com/images/loader.gif" alt="cargando" class="loader" />'
	
	if (pagina_requerida.readyState == 4 && (pagina_requerida.status==200 || window.location.href.indexOf("http")==-1))
		document.getElementById(id_contenedor).innerHTML=pagina_requerida.responseText
}

//----------------------------------------------------------------------------------------------------//
//----------------------------------- FUNCIONES IMAGENES NOTICIAS ------------------------------------//
//----------------------------------------------------------------------------------------------------//

function imagen1() {
	var imagen1 = document.getElementById('imagen1');
	var imagen2 = document.getElementById('imagen2');
	var imagen3 = document.getElementById('imagen3');
	var imagen4 = document.getElementById('imagen4');

	imagen1.style.display = 'block';
	imagen2.style.display = 'none';
	imagen3.style.display = 'none';
	imagen4.style.display = 'none';
}

function imagen2() {
	var imagen1 = document.getElementById('imagen1');
	var imagen2 = document.getElementById('imagen2');
	var imagen3 = document.getElementById('imagen3');
	var imagen4 = document.getElementById('imagen4');

	imagen1.style.display = 'none';
	imagen2.style.display = 'block';
	imagen3.style.display = 'none';
	imagen4.style.display = 'none';
}

function imagen3() {
	var imagen1 = document.getElementById('imagen1');
	var imagen2 = document.getElementById('imagen2');
	var imagen3 = document.getElementById('imagen3');
	var imagen4 = document.getElementById('imagen4');

	imagen1.style.display = 'none';
	imagen2.style.display = 'none';
	imagen3.style.display = 'block';
	imagen4.style.display = 'none';
}

function imagen4() {
	var imagen1 = document.getElementById('imagen1');
	var imagen2 = document.getElementById('imagen2');
	var imagen3 = document.getElementById('imagen3');
	var imagen4 = document.getElementById('imagen4');

	imagen1.style.display = 'none';
	imagen2.style.display = 'none';
	imagen3.style.display = 'none';
	imagen4.style.display = 'block';
}

function aterritoriales() {
	var aterritoriales = document.getElementById('aterritoriales');
	if (aterritoriales.style.display == 'none') {
		aterritoriales.style.display = 'block';
	} else {
		aterritoriales.style.display = 'none';	
	}
}
