function cargaLista ()
{
	// funcion iteradora, primero busco todos los objetos con la clase ("not")
	$$(".not").each( function(num, index)
	{
		num.onclick=function ()
		{
			atributoID=this.getAttribute("id")
			cadenaID=atributoID.substring(2)
			cargaDetalleNoticia (cadenaID)
		}
		num.onmouseover=function ()
		{
			this.setStyle({color:'#000'});
			this.setStyle({cursor:"pointer"});
		}
		num.onmouseout=function ()
		{
			this.setStyle({color:'#91001d'});
		}

	})
}

// funcion para posicionar la capa del detalle de la noticia
// parametros: id de la noticia
function cargaDetalleNoticia (id)
{
		if ($('biscaityk'))
		{
			$('biscaityk').style.visibility = 'hidden';
		}
		
		// en caso de ya estar abierta una capa noticia la elimino
		if ($('noticiaDHTML'))
		{
			Element.remove ('noticiaDHTML')
		}

		// creo las capas para contener la noticia
		var objBody = document.getElementsByTagName("body").item(0);

		var capaNoticia=document.createElement("div");
		capaNoticia.setAttribute("id","noticiaDHTML");
		objBody.appendChild(capaNoticia);

		Element.hide('noticiaDHTML')

		var capaCarga=document.createElement("div");
		capaCarga.setAttribute("id","capaCargaAJAX");
		capaNoticia.appendChild(capaCarga);

		// url a la que pediremos el detalle de la noticia
		//destino="detalleNoticia.htm?"+id
		destino="/4DACTION/NW_DetalleNoticia/"+id+"/"+Math.round(Math.random()*12357984)
		new Ajax.Updater
		(
		'capaCargaAJAX',
		destino,
		{
			method:'get',
			onSuccess:function()
			{
				// funcion responsable de colocar correctamente la capa de la noticia
				posicionaCapaNoticia ();
			}
			,	aynchronous:true
			, evalScripts:true
			}
		);

}
function posicionaCapaNoticia ()
{
	//alert(document.body.scrollHeight);
	//alert(document.documentElement.scrollTop);
	// obtengo las dimensiones reales de la capa detalle de la noticia
	var dimensiones=$('noticiaDHTML').getDimensions();
	anchoObjeto=dimensiones.width;
	
	// dimensiones de la ventana
	var arrayPageSize = getPageSize();

	// calculo de los margenes de la pagina
	margenLateral=new Number ((arrayPageSize[0]-anchoObjeto)/2)

	$('noticiaDHTML').style.left=margenLateral+"px"
	//$('noticiaDHTML').style.top=20+"px"
	//$('noticiaDHTML').style.top=(screen.height-200)/2+"px"
	$('noticiaDHTML').style.top=(document.documentElement.scrollTop+50)+"px"
	
	
	

	Element.show('noticiaDHTML')
}
function borraCapaNoticia ()
{
	Element.remove ('noticiaDHTML');
	if ($('biscaityk'))
		{
			$('biscaityk').style.visibility = 'visible';
		}
}
// se utiliza para abrir la ventana del buscador
function abreBuscador()
{

		var objBody = document.getElementsByTagName("body").item(0);

		var CapaSombra=document.createElement("div");
		CapaSombra.setAttribute("id","sombreado");
		objBody.appendChild(CapaSombra)

		var capaBuscador=document.createElement("div");
		capaBuscador.setAttribute("id","buscador");
		objBody.appendChild(capaBuscador);

		var capaContenidoBuscador=document.createElement("div");
		capaContenidoBuscador.setAttribute("id","contBuscador");
		capaBuscador.appendChild(capaContenidoBuscador);

		// oculto el buscador para evitar el molesto de efecto que e genera al posicionarlo en el centro de la pantalla
		Element.hide('buscador')

		var dimensiones=$('buscador').getDimensions();

		anchoObjeto=dimensiones.width;
		altoObjeto=dimensiones.height;

		var arrayPageSize = getPageSize();
		var arrayPageScroll = getPageScroll();
		margenLateral=new Number ((arrayPageSize[0]-anchoObjeto)/2)
		margenAlto=new Number ((arrayPageSize[1]-altoObjeto)/2)

		Element.setHeight('sombreado',arrayPageSize[1])
		Element.setWidth('sombreado',arrayPageSize[0])

		$('buscador').style.left=margenLateral+"px"
		$('buscador').style.top=margenAlto+20+"px";

		// cargo la pagina del buscador en el div contBuscador
		cargaPagina('/TextoABuscar.shtml','contBuscador')

		//una vez cargado el buscador, lo hago visible
		Element.show('buscador')




}
// funcion para posicionar la capa del detalle de la noticia
// parametros: id de la noticia
function cargaDetalleVPO (id)
{
		if ($('biscaityk'))
		{
			$('biscaityk').style.visibility = 'hidden';
		}
		// en caso de ya estar abierta una capa noticia la elimino
		if ($('noticiaDHTML'))
		{
			Element.remove ('noticiaDHTML')
		}

		// creo las capas para contener la noticia
		var objBody = document.getElementsByTagName("body").item(0);

		var capaNoticia=document.createElement("div");
		capaNoticia.setAttribute("id","noticiaDHTML");
		objBody.appendChild(capaNoticia);

		Element.hide('noticiaDHTML')

		var capaCarga=document.createElement("div");
		capaCarga.setAttribute("id","capaCargaAJAX");
		capaNoticia.appendChild(capaCarga);

		posicionaCapaNoticia ();
		$('capaCargaAJAX').innerHTML=$(id).innerHTML;
		new Insertion.Before( 'capaCargaAJAX', "<p style='text-align:right;'><a href='#' onclick='cierraCapa()'>"+literalCerrarventanas+"</a></p>" );
		new Insertion.After( 'capaCargaAJAX', "<p  style='text-align:right;'><a href='#' onclick='cierraCapa()'>"+literalCerrarventanas+"</a></p>" );

		$('header').scrollTo();


}
function cierraCapa ()
{
		if ($('noticiaDHTML'))
		{
			Element.remove ('noticiaDHTML')
		}
		
		if ($('biscaityk'))
		{
			$('biscaityk').style.visibility = 'visible';
		}

}
// funcion basica de carga mediante AJAX recibe dos parametros:
// pagina: fichero (html.shtml...) a cargar. ejemplo pagina ->detalle.shtml?id="20";
// donde: div o elemento identificado donde cargo en contenido recibido de la llamada a pagina
function cargaPagina (pagina,donde)
{
	new Ajax.Updater
	(
		donde,
		pagina,
		{
			method:'get',
			onSuccess:function()
			{

			}
			,	aynchronous:true
			, evalScripts:true
		}

	);
}
// funcion que elimina los nodos creados al ejecutar la funcion abreBuscador();
function cierraBuscador ()
{
	Element.remove('sombreado')
	Element.remove('buscador')
}
/****************************************************** funciones para obtener dimensiones de la ventana **********************************************************/
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}


function cargaListaSalas ()
{
	// funcion iteradora, primero busco todos los objetos con la clase ("salasnot")
	$$(".salasnot").each( function(num, index)
	{
		num.onclick=function ()
		{
			atributoID=this.getAttribute("id")
			cadenaID=atributoID.substring(2)
			cargaDetalleSalas (cadenaID)
		}
		num.onmouseover=function ()
		{
			this.setStyle({color:'#000'});
			this.setStyle({cursor:"pointer"});
		}
		num.onmouseout=function ()
		{
			this.setStyle({color:'#91001d'});
		}

	})
}

// funcion para posicionar la capa del detalle de las salas
// parametros: id
function cargaDetalleSalas (id)
{
		if ($('biscaityk'))
		{
			$('biscaityk').style.visibility = 'hidden';
		}
		// en caso de ya estar abierta una capa noticia la elimino
		if ($('noticiaDHTML'))
		{
			Element.remove ('noticiaDHTML')
		}

		document.getElementById('localreserva').style.visibility='hidden';
		document.getElementById('actividadreserva').style.visibility='hidden';

		// creo las capas para contener la noticia
		var objBody = document.getElementsByTagName("body").item(0);

		var capaNoticia=document.createElement("div");
		capaNoticia.setAttribute("id","noticiaDHTML");
		objBody.appendChild(capaNoticia);

		Element.hide('noticiaDHTML')

		var capaCarga=document.createElement("div");
		capaCarga.setAttribute("id","capaCargaAJAX");
		capaNoticia.appendChild(capaCarga);

		// url a la que pediremos el detalle de la noticia
		//destino="detalleNoticia.htm?"+id
		destino="/4DACTION/WebHorariosSalas/EnviarPagina/"+Math.round(Math.random()*12357984)
		new Ajax.Updater
		(
		'capaCargaAJAX',
		destino,
		{
			method:'get',
			onSuccess:function()
			{
				// funcion responsable de colocar correctamente la capa de la noticia
				posicionaCapaNoticia ();
			}
			,	aynchronous:true
			, evalScripts:true
			}
		);

}


function cargaListaPerfil ()
{
	// funcion iteradora, primero busco todos los objetos con la clase ("not")
	$$(".not").each( function(num, index)
	{
		num.onclick=function ()
		{
			atributoID=this.getAttribute("id")
			cadenaID=atributoID.substring(2)
			cargaDetallePerfil (cadenaID)
		}
		num.onmouseover=function ()
		{
			this.setStyle({color:'#000'});
			this.setStyle({cursor:"pointer"});
		}
		num.onmouseout=function ()
		{
			this.setStyle({color:'#91001d'});
		}

	})
}
function cargaDetallePerfil (id)
{
		if ($('biscaityk'))
		{
			$('biscaityk').style.visibility = 'hidden';
		}
		// en caso de ya estar abierta una capa noticia la elimino
		if ($('noticiaDHTML'))
		{
			Element.remove ('noticiaDHTML')
		}

		// creo las capas para contener la noticia
		var objBody = document.getElementsByTagName("body").item(0);

		var capaNoticia=document.createElement("div");
		capaNoticia.setAttribute("id","noticiaDHTML");
		objBody.appendChild(capaNoticia);

		Element.hide('noticiaDHTML')

		var capaCarga=document.createElement("div");
		capaCarga.setAttribute("id","capaCargaAJAX");
		capaNoticia.appendChild(capaCarga);

		// url a la que pediremos el detalle de la licitación-Adjudicación
		//destino="detalleNoticia.htm?"+id
		destino="/4DACTION/NW_DetallePerfil/"+id+"/"+Math.round(Math.random()*12357984)
		new Ajax.Updater
		(
		'capaCargaAJAX',
		destino,
		{
			method:'get',
			onSuccess:function()
			{
				// funcion responsable de colocar correctamente la capa de la noticia
				posicionaCapaNoticia ();
			}
			,	aynchronous:true
			, evalScripts:true
			}
		);

}
