if (typeof(scripts) == 'undefined') scripts = new Object();

function getPathToStaticFiles() {
	// Soy comun.js y voy a averiguar mi propia ruta, ya sea absoluta o relativa
	var js = /js\/comun\.js(\?.*)?$/;
	var head_scripts = document.getElementsByTagName('script');
	for (var i=0; i < head_scripts.length; i++){
		var script_src = head_scripts[i].src;
		if (script_src.match(js)){
			return script_src.replace(js, '');
		}
	}
}

var pathToStaticFiles = getPathToStaticFiles();

function importa_js(fichero_js) {
	if (scripts[fichero_js] != null) return;
  
	try{
		// En Safari 2.0 no funciona con DOM
		document.write('<script type="text/javascript" src="'+fichero_js+'"><\/script>');
	} catch(e) {
		var dom_script = document.createElement('script');
		dom_script.type = 'text/javascript';
		dom_script.src = fichero_js;
		document.getElementsByTagName('head')[0].appendChild(dom_script);
	}	
  
  scripts[fichero_js] = fichero_js;
}

importa_js(pathToStaticFiles + 'js/prototype.js');
importa_js(pathToStaticFiles + 'js/scriptaculous.js');
importa_js(pathToStaticFiles + 'js/sugerencias.js');
importa_js(pathToStaticFiles + 'js/autocompleterLocal.js');


var Css={
	reset:function(){
		var styOp="<style type='text/css'>";
		styCss="#efectosCont .transp{opacity:0.5;filter:alpha(opacity=50)}";
		var styCl="</style>";
		var styJs='<link rel="stylesheet" type="text/css" href="' + pathToStaticFiles + 'css/estilos-js.css"/>';
		document.write(styOp+styCss+styCl+styJs);
	} 
}; 

Css.reset(); 

var Document = {
	addEvent:function(obj, type, fn ){
		var fnx = fn;
		if(type=='dom:loaded'){
			if (obj.addEventListener)
				type = 'DOMContentLoaded';
			else {
				type = 'readystatechange';
				fnx = function(){
					if(/interactive|complete/.test(obj.readyState)) fn();
				};
			}
		}
		if (obj.addEventListener)
			obj.addEventListener( type, fnx, false );
		else if (obj.attachEvent){
			obj["e"+type+fn] = fnx;
			obj[type+fn] = function() {
				obj["e"+type+fn]( window.event ); 
			};
			obj.attachEvent("on"+type, obj[type+fn]);
		}
	},

	removeEvent:function(obj, type, fn ){
		if(type=='dom:loaded'){
			if (obj.addEventListener)
				type = 'DOMContentLoaded';
			else
				type = 'readystatechange';
		}
		if (obj.removeEventListener)
			obj.removeEventListener( type, fn, false );
		else if (obj.detachEvent){
			obj.detachEvent( "on"+type, obj[type+fn] );
			obj[type+fn] = null;
			obj["e"+type+fn] = null;
		}
	}
};

function readyState(fn){
	if(document.readyState == "interactive" || document.readyState == "complete"){
		fn();
	}
}

//onDomReady
window.onDomReady = DomReady;

function DomReady(fn){
	if(document.addEventListener){
		document.addEventListener("DOMContentLoaded", fn, false);
	}
	else{
		document.onreadystatechange = function(){readyState(fn)}
	}
}
function ocultaTb(){
	if(document.getElementsByTagName("table")){
		var oTable = document.getElementsByTagName("table");
		for(i=0;i<oTable.length;i++) {
			document.getElementById("opciones_der").style.display = "none";
			document.getElementById("ctr").style.width = "100%";
		}
	}
}
//Posicion de los iconos de CALENDARIO
var position = {
	getRealLeft : function(objeto) {
		var xPos = 0; do { xPos += objeto.offsetLeft || 0; objeto = objeto.offsetParent; } while (objeto != null);
		return xPos;
	},
	getRealTop : function(objeto){
		var yPos = 0; do { yPos += objeto.offsetTop || 0; objeto = objeto.offsetParent; } while (objeto != null);
		return yPos;
	},
	getRealPos : function(objeto){
		var xPos = 0; var yPos = 0;
		do { xPos += objeto.offsetLeft || 0; yPos += objeto.offsetTop || 0; objeto = objeto.offsetParent; } while (objeto != null);
		return [xPos, yPos];
	}
}
function scrollToElement(element) {
	var pos = position.getRealPos(element);
	window.scrollTo(pos[0], pos[1]);
}

var writeCalendar = {
	reitera : 42,
	isBisiesto : function(qYear){
		if (((( qYear % 4 == 0 ) && ( qYear % 100 != 0 )) || ( qYear % 400 == 0 )))	//es bisiesto
			return true;
		return false;
	},
	viewdate:function(qDay,qMonth,qYear,obj){
		if (qDay < 10) {qDay ="0"+qDay;}	//Para enviar el dato del formulario el formato es yyyy-mm-dd
		aux_month = parseInt((qMonth+1));
		if (aux_month < 10) { aux_month = "0"+aux_month;}
		aux_date = qDay+"/"+aux_month+"/"+qYear;
		switch (obj){
			case 1:	obj_aux = dom.$("fechadesde")
				//objDay = dom.$("diadesde"); objMonth = dom.$("mesdesde"); objYear = dom.$("anyodesde");
				break;
			case 2:	obj_aux = dom.$("fechahasta")
				//objDay = dom.$("diahasta"); objMonth = dom.$("meshasta"); objYear = dom.$("anyohasta");
				break;
		}
		//objDay.value = qDay; objMonth.value = aux_month; objYear.value = qYear;
		obj_aux.value = aux_date;
		dom.$("calendar").style.display = "none";
	},
	moveToMonth : function(estado,qDay,qMonth,qYear,qObj){
		//desplazarse entre meses
		switch(estado) {
			case 1: aux_qMonth = qMonth-1;
				break;
			default:aux_qMonth = qMonth+1;
				break;
		}
		if (aux_qMonth >= 12){ qYear++;aux_qMonth=0;}		//Quiere decir que es anio nuevo
		if (aux_qMonth < 0){ qYear--; aux_qMonth = 11;}		//quiere decir que es anio viejo
		tHeader = writeCalendar.header(qDay,aHeaderCalendar[aux_qMonth][0],aux_qMonth,qYear,qObj);
		tBody = writeCalendar.body(qDay,aHeaderCalendar[aux_qMonth][1],aux_qMonth,qYear,qObj);
		aHeaderCalendar[1][1] = (writeCalendar.isBisiesto(qYear))?29:28;
		dom.$("calendar").innerHTML = tHeader+tBody;
	},
	close : function(){
		dom.$("calendar").style.display = "none";
	},
	header : function(qDay,txtMonth,qMonth,qYear,qObj) {
		tHeader = '<table class="lCalendar" cellpadding="0" cellspacing="0"><caption>Calendario</caption><colgroup><col width="24px" /><col width="24px" /><col width="24px" /><col width="24px" /><col width="24px" /><col width="24px" /><col width="24px" /><colgroup><thead>';
		tHeader +='<tr><th class="desplaza"><a href="#" onclick="writeCalendar.moveToMonth(1,'+qDay+','+qMonth+','+qYear+','+qObj+');return false;">&lt;&lt;</a></th>';
			tHeader +='<th colspan="4" class="year">'+txtMonth+'</td>';
			tHeader +='<th class="desplaza"><a href="#" onclick="writeCalendar.moveToMonth(0,'+qDay+','+qMonth+','+qYear+','+qObj+');return false;">&gt;&gt;</a></th>';
			tHeader +='<th class="desplaza"><a href="#" onclick="writeCalendar.close();return false;">x</a></th>';
		tHeader +='</tr>';
		tHeader +='<tr><th>L</th>';
			tHeader +='<th>M</th><th>X</th><th>J</th><th>V</th><th>S</th><th>D</th></tr>';
		tHeader +='</thead><tfoot><tr><td colspan="7">Cierre de la tabla</td></tr></tfoot>';
		return tHeader;
	},
	body : function(qDay,qNumDays,qMonth,qYear,qObj){
		aux_dateInit = new Date(qYear,qMonth,1);
		dateInit = (aux_dateInit.getDay());
		contDays=1;
		tBody = '<tbody><tr>';
		for (var ii=1;ii<=writeCalendar.reitera;ii++){
			openTD = '<td class="days">';
			//if (((ii+1) % 7) == 0) { openTD = '<td class="days festivo">';}
			//if (ii % 7==0) { openTD = '<td class="days festivo last">';}
			if ((ii>=dateInit) && (contDays<=qNumDays)){
				if (contDays == qDay){ openTD = '<td class="today">';}
				bodyTD = contDays;
				if (qYear <= year){
					if (qMonth <= month){
						bodyTD = '<a href="#" onclick="writeCalendar.viewdate('+contDays+','+qMonth+','+qYear+','+qObj+');return false;">'+contDays+'</a>';
						if (qMonth == month) { if (contDays > qDay){ bodyTD = contDays;}}
					}
				}
				contDays++;
			}
			else { bodyTD='&nbsp;';}
			tBody += openTD+bodyTD+'</td>';
			if (ii % 7 == 0){ tBody +='</tr><tr>';}
		}
		tBody +='</tbody></table>';
		return tBody;
	},
	init : function(qObj,posLeft,posTop){
		var dateToday = new Date();
		today = dateToday.getDate();		//Que dia es hoy
		month = dateToday.getMonth();		//Que mes es el actual //el rango es desde 0(enero) hasta 11(diciembre)
		aux_year = dateToday.getYear();		//Anio actual. Tener en cuenta que en Mozilla
		year = (aux_year < 2000)?aux_year+1900:aux_year;
		tHeader = writeCalendar.header(today,aHeaderCalendar[month][0],month,year,qObj);
		tBody = writeCalendar.body(today,aHeaderCalendar[month][1],month,year,qObj);
		aHeaderCalendar[1][1] = (writeCalendar.isBisiesto(year))?29:28;
		dom.$("calendar").innerHTML = tHeader+tBody;
		dom.$("calendar").style.left = posLeft+"px";
		dom.$("calendar").style.top = posTop+25+"px";
		dom.$("calendar").style.display = "block";
	}
}

/* Aadiremos trim al prototype de String */
String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g,''); };
String.prototype.trimHTML = function(){ return this.replace(/^(?:&nbsp;|\s)+|(?:&nbsp;|\s)+$/g,''); };
Array.prototype.contains = function (element) { 
	for (var i = 0; i < this.length; i++)
		if (this[i] == element) return true;
	return false; 
};

dom={
	$:function(id){
		return document.getElementById(id);
	}
};
function getElementsByClass(searchClass,node,tag) {
        var classElements = new Array();
        if ( node == null ) 
			node = document;
        if ( tag == null ) 
			tag = '*';
        var els = node.getElementsByTagName(tag);
        var elsLen = els.length;
        var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
        for (i = 0, j = 0; i < elsLen; i++) {
			if ( pattern.test(els[i].className) ) {
					classElements[j] = els[i];
					j++;
			}
        }
        return classElements;
}
Document.addEvent(document, "dom:loaded", function() {
	if(document.getElementById("lenguasCoof")){
		var lg = document.getElementById("lenguasCooful");
		lg.style.display ="none";	
	}	
	if(document.getElementsByTagName("body") && document.getElementById("lenguasCoof")){
		var lgUl = document.getElementById("lenguasCoof").getElementsByTagName("a");
		for(j=0;j<lgUl.length;j++){
			lgUl[0].onclick  = function(){
				var lgA = document.getElementById("lenguasCooful");
				if(lgA.style.display=="none"){
					lgA.style.display ="block";
					return false;
				} else {lgA.style.display ="none";return false;}
			}
		}
	}
	if(screen.deviceXDPI == 120){
		document.getElementsByTagName("body")[0].style.fontSize = "50%";
	}
	if(document.getElementById("fbuscarheader")){
		document.getElementById("fbuscarheader").onsubmit=function(){
			valorcampo=document.getElementById("cajaBusqueda").value;
			if(valorcampo.toUpperCase()=='PALABRA CLAVE' || valorcampo.trim()==''){
				alert('Escriba un texto para la b\u00FAsqueda, por favor.');
				return false;
			}
		}
	}
	if(document.getElementById("fbuscadorder")){
		var fechaRegEx = new RegExp('^\\d{1,2}/\\d{1,2}/(?:\\d{2}|\\d{4})$');
		var existValTexto;
		var existValAutor;
		var existValTipo;
		var existCampo;
		var existCampo2;
		document.getElementById("fbuscadorder").onsubmit=function(){
			
			valortexto=document.getElementById("texto")?document.getElementById("texto").value:null;
			valorautor=document.getElementById("autor")?document.getElementById("autor").value:null;
			valortipo=document.getElementById("tipocombo")?document.getElementById("tipocombo").value:null;
			valorcampo=document.getElementById("fde")?document.getElementById("fde").value:null;
			valorcampo2=document.getElementById("fa")?document.getElementById("fa").value:null;


			if(valortexto=='Text' || valortexto=='Keyword' || valortexto=='Texto' || valortexto=='Testua'   || valortexto.trim()==''){
				existValTexto = 0;
			}else {
				existValTexto = 1;
			}     

			if(valorautor=='Author' || valorautor=='Autor' || valorautor=='Egilea'  || valorautor == null || valorautor.trim()==''){
				existValAutor = 0;
			}else{
				existValAutor = 1;
			}

			if(valortipo=='' || valortipo == null){
				existValTipo = 0;
			}else{
				existValTipo = 1;
			}

			if(valorcampo=='dd/mm/aaaa' || valorcampo=='dd/mm/yyyy' || valorcampo.trim() == ''){
				existCampo = 0;
				valorcampo='';
			}else{
				existCampo = 1;
			}      

			if(valorcampo2=='dd/mm/aaaa' || valorcampo2=='dd/mm/yyyy' || valorcampo2.trim()  == ''){
				existCampo2 = 0;
				valorcampo2 = '';
			}else{
				existCampo2 = 1;
			}

			if(existValTexto==0 && existValAutor==0 && existCampo==0 && existCampo2==0){
				if(existValTipo == 0){
					alert('Introduzca al menos uno de los campos de b\u00FAsqueda.');
					return false;
				}else{
					document.getElementById("texto").value='';
					if(valorautor != null){
						document.getElementById("autor").value='';
					}          
					document.getElementById("fde").value='';
					document.getElementById("fa").value='';
					return true;
				}
			}else if(existCampo==1 || existCampo2==1){
				if(valorcampo != null && fechaRegEx.test(valorcampo.trim()) == false ){ //1 mal
					if(valorcampo == ''){ //si en vacio o dd/mm/aaaa o dd/mm/yyyy
						if(valorcampo2!='' && fechaRegEx.test(valorcampo2.trim())!= false){   //2 bien
							document.getElementById("fde").value='';
							if(valorautor=='Author' || valorautor=='Autor' || valorautor=='Egilea' ){
								document.getElementById("autor").value='';
							}
							if(valortexto=='Text' || valortexto=='Keyword' || valortexto=='Texto' || valortexto=='Testua'  ){
								document.getElementById("texto").value='';
							}
							return true;
						}else{
							alert('La Fecha para la b\u00FAsqueda no es valida.');
							return false;
						}
					}else{
						alert('La Fecha "de" para la b\u00FAsqueda no es valida.');
						return false;
					}
				}else if(valorcampo2 != null && fechaRegEx.test(valorcampo2.trim()) == false){ //2 mal
					if(valorcampo2 == ''){ //si en vacio o dd/mm/aaaa o dd/mm/yyyy 
						if(valorcampo!='' && fechaRegEx.test(valorcampo.trim())!==false){            //1 bien
							document.getElementById("fa").value='';
							if(valorautor=='Author' || valorautor=='Autor' || valorautor=='Egilea' ){
								document.getElementById("autor").value='';
							}
							if(valortexto=='Text' || valortexto=='Keyword' || valortexto=='Texto' || valortexto=='Testua'  ){
								document.getElementById("texto").value='';
							}
							return true;
						}else{
							alert('La Fecha para la b\u00FAsqueda no es valida.');
							return false;
						}
					}else{
						alert('La Fecha "a" para la b\u00FAsqueda no es valida.');
						return false;
					}
				}else{
					if(valorautor=='Author' || valorautor=='Autor' || valorautor=='Egilea' ){
						document.getElementById("autor").value='';
					}
					return true;
				}
			}else{
				if(valorautor=='Author' || valorautor=='Autor' || valorautor=='Egilea' ){
					document.getElementById("autor").value='';
				}
				document.getElementById("fde").value='';
				document.getElementById("fa").value='';
				return true;
			}
				
		}
	}
	if(document.getElementById("f_bus_glosario")){
		document.getElementById("f_bus_glosario").onsubmit=function(){
			buscag=document.getElementById("buscag").value;
			if(buscag=='trmino' || buscag.trim()==''){
				alert('Escriba un t\u00e9rmino para la b\u00FAsqueda, por favor.');
				return false;
			}
		}
	}
	if(document.getElementById("fbusavanz")){
		document.getElementById("fbusavanz").onsubmit=function(){
			txtlibre=document.getElementById("txtlibre").value;
			if(txtlibre.toUpperCase()=='TEXTO' || txtlibre.trim()==''){
				alert('Escriba un texto para la b\u00FAsqueda, por favor.');
				return false;
			}
		}
	}
	if(document.getElementById("form_bus_avanz")){
		document.getElementById("form_bus_avanz").onsubmit=function(){
			valortexto=document.getElementById("txtlibre").value;
			if(valortexto.toUpperCase()=='TEXTO A BUSCAR' || valortexto.toUpperCase()=='TEXT' || valortexto.trim()==''){
				alert('Escriba un texto para la b\u00FAsqueda, por favor.');
				return false;
			}
		}
	}
	if(document.getElementById("oficina_virtual")){
		var cjov=document.getElementById("oficina_virtual");
		cjov.style.background='none';
		var imgOv=document.createElement('img');
		imgOv.setAttribute('src','img/icono_ofVirtual.gif');
		phijo=cjov.childNodes[0];
		cjov.insertBefore(imgOv,phijo);
	}
	
	if(document.getElementById("txtlibre")){
		txtlibre=document.getElementById("txtlibre");
		txtlibre.onfocus=function(){
			if(txtlibre.value.toUpperCase()=='TEXTO A BUSCAR' || txtlibre.value.toUpperCase()=='TEXT') {
				txtlibre.value='';
				txtlibre.style.color='#666';
			}
		}
	}
	if(document.getElementById("cajaBusqueda")){
		cjbsq=document.getElementById("cajaBusqueda");
		cjbsq.onfocus=function(){
			if(cjbsq.value.toUpperCase()=='PALABRA CLAVE' || cjbsq.value.toUpperCase()=='GAKO-HITZA' || cjbsq.value.toUpperCase()=='PARAULA CLAU' || cjbsq.value.toUpperCase()=='KEY WORD') {
				cjbsq.value='';
				cjbsq.style.color='#666';
			}
		}
	}
	if(document.getElementById("buscag")){
		fterm=document.getElementById("buscag");
		fterm.onfocus=function(){
			if(this.value.toLowerCase()=='t\u00E9rmino') {
				this.value='';
				this.style.color='#666';
			}
		}
	}
	if(document.getElementById("texto")){
		ftxt=document.getElementById("texto");
		ftxt.onfocus=function(){
			if(ftxt.value.toUpperCase()=='TEXTO' || ftxt.value.toUpperCase()=='TESTUA' || ftxt.value.toUpperCase()=='TEXT' || ftxt.value.toUpperCase()=='KEYWORD') {
				ftxt.value='';
				ftxt.style.color='#666';
			}
		}
	}
	if(document.getElementById("autor")){
		fautor=document.getElementById("autor");
		fautor.onfocus=function(){
			if(fautor.value.toUpperCase()=='AUTOR' || fautor.value.toUpperCase()=='EGILEA' || fautor.value.toUpperCase()=='AUTOR') {
				fautor.value='';
				fautor.style.color='#666';
			}
		}
	}
	if(document.getElementById("fde")){
		fde=document.getElementById("fde");
		fde.onfocus=function(){
			if(fde.value.toUpperCase()=='DD/MM/AAAA' || fde.value.toUpperCase()=='DD/MM/YYYY') {
				fde.value='';
				fde.style.color='#666';
			}
		}
	}
	if(document.getElementById("fa")){
		fa=document.getElementById("fa");
		fa.onfocus=function(){
			if(fa.value.toUpperCase()=='DD/MM/AAAA' || fa.value.toUpperCase()=='DD/MM/YYYY') {
				fa.value='';
				fa.style.color='#666';
			}
		}
	}
	if(document.getElementById("fechadesde")){
		fde=document.getElementById("fechadesde");
		fde.onfocus=function(){
			if(fde.value.toUpperCase()=='DD/MM/AAAA' || fde.value.toUpperCase()=='DD/MM/YYYY') {
				fde.value='';
				fde.style.color='#666';
			}
		}
	}
	if(document.getElementById("fechahasta")){
		fa=document.getElementById("fechahasta");
		fa.onfocus=function(){
			if(fa.value.toUpperCase()=='DD/MM/AAAA' || fa.value.toUpperCase()=='DD/MM/YYYY') {
				fa.value='';
				fa.style.color='#666';
			}
		}
	}
	if(document.getElementById("volverPag")){
		if(document.getElementById("volverPag").href.replace(document.location,'')=='#'){
			document.getElementById("volverPag").href='javascript:history.back()';
		}
		document.getElementById("volverPag").style.visibility='visible';
	}
	if(document.getElementById("aviso")){
		document.getElementById("aviso").onclick=function(){
			nvnt=window.open(this.href,'nvnt','width=725,height=720');
			return false;
		}
	}
	if(document.getElementById("op_visita")){
		abreLink = document.getElementById("op_visita");
		abreLink.onclick=function(){
			nvnt=window.open(abreLink.href,'nvnt','height=536,width=780');
			return false;
		}
	}
	if(document.getElementById("fotosucur")){
		var anchoTotal = document.getElementById("fichatotal");
		anchoTotal.style.marginLeft="25em";
	}
	if (dom.$("calendar1")){
		icoCalendar = getElementsByClass("icocalendario");
		for(var i=0;i<icoCalendar.length;i++){ icoCalendar[i].style.visibility="visible";}
		dom.$("calendar1").onclick = function(){
			posLeft = position.getRealLeft(dom.$("calendar1"));
			posTop = position.getRealTop(dom.$("calendar1"));
			writeCalendar.init(1,posLeft,posTop);
			return false;
		}
	}
	if (dom.$("calendar2")){
		dom.$("calendar2").onclick = function(){
			posLeft = position.getRealLeft(dom.$("calendar2"));
			posTop = position.getRealTop(dom.$("calendar2"));
			writeCalendar.init(2,posLeft,posTop);
			return false;
		}
	}
	//Validacion formulario de Contacto	
	if(document.getElementById("form_contacto")){
		document.getElementById("btnEnviof").onclick=function(){
			var formContact = valida.captura(document.getElementById("form_contacto"))
				if(formContact){
				document.getElementById("form_contacto").submit()
			}else{
				return false;
			}
		}
	}
	//Validacion formulario de consulta
	if(document.getElementById("form_consulta")){
		document.getElementById("btnEnviof").onclick=function(){
			var formContact = valida.captura(document.getElementById("form_consulta"))
				if(formContact){
				document.getElementById("form_consulta").submit()
			}else{
				return false;
			}
		}
	}
	//Validacion busqueda avanzada
	/*if(document.getElementById("form_bus_avanz")){
		document.getElementById("btnEnviof").onclick=function(){
			var formContact = valida.captura(document.getElementById("form_bus_avanz"));
			if(formContact) { document.getElementById("form_bus_avanz").submit();}
			return false;
		}
		document.getElementById("btnEnvioc").onclick=function(){
			var formContact = valida.captura(document.getElementById("form_bus_avanz"));
			if(formContact) { document.getElementById("form_bus_avanz").submit();}
			return false;
		}
	}*/
	/*Validacion fechas en formulario derecha*/
	if(document.getElementById("desde_dia") && document.getElementById("desde_mes") && document.getElementById("desde_anyo") && document.getElementById("hasta_dia") && document.getElementById("hasta_mes") && document.getElementById("hasta_anyo")){
		document.getElementById("f_buscar_derecha").onclick=function(){
			var wfechaValida='Por favor, seleccione una fecha de inicio menor que la fecha de fin.';
			var dd=document.getElementById("desde_dia");
			var dm=document.getElementById("desde_mes");
			var da=document.getElementById("desde_anyo");
			var hd=document.getElementById("hasta_dia");
			var hm=document.getElementById("hasta_mes");
			var ha=document.getElementById("hasta_anyo");
			if(!dd.selectedIndex || !dm.selectedIndex || !da.selectedIndex || !hd.selectedIndex || !hm.selectedIndex || !ha.selectedIndex){
				// Si no seleccionamos alguno no filtramos las fechas
				dd.selectedIndex=dm.selectedIndex=da.selectedIndex=hd.selectedIndex=hm.selectedIndex=ha.selectedIndex=0;
			}
			else{
				if(da.value>ha.value){
					alert(wfechaValida);
					return false;
				}
				else if(da.value==ha.value && dm.value>hm.value){
					alert(wfechaValida);
					return false;
				}
				else if(da.value==ha.value && dm.value==hm.value && dd.value>hd.value){
					alert(wfechaValida);
					return false;
				}
			}
		}
	}
	if(document.getElementById("comboAreas")){
		document.getElementById("comboAreas").style.display = "block";
	}
	if( document.getElementById( "volverPag" ) ){
	   var regresar = document.getElementById("volverPag" );
	   regresar.onclick = function () {history.back(); return false};
	}
	if(document.getElementById("comboAnyos")){
		document.getElementById("comboAnyos").style.display = "block";
	}
  	if( document.getElementById( "ir_norm" ) ){
		var ir_a = document.getElementById("ir_norm");
		ir_a.onclick = function () {MM_jumpMenuGo('year','window.open()',1); return false};
  	}
	if(document.getElementById("ctr") && document.getElementById("opciones_der") && document.getElementById("pie")){
		var alturaEm=(document.getElementById("ctr").offsetHeight/(document.getElementById("pie").offsetHeight/3))+"em";
		if(document.getElementById("opciones_der").offsetHeight < document.getElementById("ctr").offsetHeight)
			document.getElementById("opciones_der").style.height=alturaEm;
	}
  	if( document.getElementById( "ir_circ" ) ){
	       var ir_a = document.getElementById("ir_circ");
	       ir_a.onclick = function () {MM_jumpMenuGo('circ','parent',1); return false};
  	}
  	if( document.getElementById( "ir_ciran" ) ){
		 var ir_a = document.getElementById("ir_ciran");
		 ir_a.onclick = function () {MM_jumpMenuGo('analitico','window.open()',1); return false};
	}
	if( document.getElementById( "ir_auto" ) ){
		var ir_a = document.getElementById("ir_auto");
		ir_a.onclick = function () {MM_jumpMenuGo('autonomico','parent',1); return false};
  	}
  	if( document.getElementById( "ir_concel" ) ){
		var ir_a = document.getElementById("ir_concel");
		ir_a.onclick = function () {MM_jumpMenuGo('concelsel','parent',1); return false};
  	}
  	if( document.getElementById( "ir_areas" ) ){
		var ir_a = document.getElementById("ir_areas");
		ir_a.onclick = function () {MM_jumpMenuGo('areas','parent',1); return false};
  	}
  	if( document.getElementById( "ir_eff" ) ){
		var ir_a = document.getElementById("ir_eff");
		ir_a.onclick = function () {MM_jumpMenuGo('sel_eff','parent',1); return false};
  	}
  	if( document.getElementById( "ir_otc" ) ){
		var ir_a = document.getElementById("ir_otc");
		ir_a.onclick = function () {MM_jumpMenuGo('sel_otc','parent',1); return false};
  	}
  	if( document.getElementById( "ir_gal" ) ){
		var ir_a = document.getElementById("ir_gal");
		ir_a.onclick = function () {MM_jumpMenuGo('anyo','parent',1); return false};
  	}
	if( document.getElementById( "ir_cebs" ) ){
		var ir_a = document.getElementById("ir_cebs");
		ir_a.onclick = function () {MM_jumpMenuGo('anyo','parent',1); return false};
  	}
  	if( document.getElementById( "ir_monedas" ) ){
		var ir_a = document.getElementById("ir_monedas");
		ir_a.onclick = function () {MM_jumpMenuGo('paises','parent',1); return false};
  	}
	if (dom.$("ctr")){
		nodisp = getElementsByClass("nodisp");
		for(var i=0;i<nodisp.length;i++){ nodisp[i].style.display="none";}
	}
	if (dom.$("ctr")){
		impr = getElementsByClass("tituloCentro",document , "h2");
		for(var i=0;i<impr.length;i++){ 
			try {
				impr[i].firstChild.onclick= function(){window.print()}
			}catch(err){
				
			}
		}
	}
	
	if (dom.$("print")){
		impr = document.getElementById("print");
		impr.onclick= function(){window.print()}
	}
	
	if (dom.$("print1")){
		impr = document.getElementById("print1");
		impr.onclick= function(){window.print()}
	}

	//Sustitución overflow-x y overflow-y//
	var news = getElementsByClass('newshome', dom.$('ctr'), 'ul');
	for(var i=0;i<news.length;i++){ 
		news[i].style.overflowY='auto';
		news[i].style.overflowX='hidden';
	}
		
	var tables = getElementsByClass('tblgenerica', dom.$('ctr'), 'div');
	for(var i=0;i<tables.length;i++){ 
		tables[i].style.overflowY='auto';
		tables[i].style.overflowX='hidden';
	}
	
	
  	if(document.getElementById("tb1") ){			
		try {
			for(var i=1;i<50;i++){
				var nTb = document.getElementById("tb" + i);
				nTb.style.display= "none";
				resize();
			}
		} catch(err) {
			var mTb = document.getElementById("menu_tb").getElementsByTagName("li");
			for(j=0;j<mTb.length;j++) {
				mTb[j].setAttribute("id", j +1);
				mTb[j].onclick = function(){
					try {
						for(var i=1;i<50;i++){
							var nTb = document.getElementById("tb" + i);
							nTb.style.display= "none";
						}
					} catch(err) {
					
					}
					var tTb = document.getElementById("tb" + this.id);
					if (tTb.style.display == "none" ){
						tTb.style.display = "block";
						resize();
					} else {
						tTb.style.display = "none";
					}
				}
			}
		}
	}
	if(document.getElementById("circana")){
		var spn = document.getElementById("circana").getElementsByTagName("span");
		for (i=0;i<spn.length;i++) {
			if(navigator.appName.indexOf("Explorer")!=-1){
				spn[i].parentNode.getElementsByTagName('ul')[0].setAttribute("className", "hidden");
			}
			else {
				spn[i].parentNode.getElementsByTagName('ul')[0].setAttribute("class", "hidden");
			}
		}	
	}
	if(document.getElementById("circana")){
		var lnkmp=function(){			
			listamapa=document.getElementById("circana").getElementsByTagName('span');
			document.getElementById('pie').style.height = '726px';
			var i=0;
			for(i=0;i<listamapa.length;i++){
				listamapa[i].style.display = "inline";
				var txtSpan = listamapa[i].innerHTML;
				listamapa[i].innerHTML = "";	
				var nLink = document.createElement('a');
				nLink.href= "#";
				nLink.innerHTML = txtSpan;
				listamapa[i].appendChild(nLink)
				listamapa[i].onclick=function(){
					ulamostrar=this.parentNode.getElementsByTagName('ul')[0];
					if(this.className=='nodo'){
						ulamostrar.className= "visible";
						this.className='nodom';
						resize();	
					}
					else{
						ulamostrar.className= "hidden";
						this.className='nodo';
						resize();
					}
					return false;
					}
			}
		}
		lnkmp();
	}
	if(document.getElementById("circana")){resize();}
	if(document.getElementById("ir")){
		var ir_a = document.getElementById("ir_eff" );
		ir_a.onclick = function () {MM_jumpMenuGo('anyo','parent',1); return false};
	}

	/* Listas - Chapa */
	var ulOculto = getElementsByClass('dv_oculto', dom.$('ctr'), 'ul');
	var divOculto = getElementsByClass('dv_oculto', dom.$('ctr'), 'div');
	var oculto = ulOculto.concat(divOculto);
	
	var icoMas = pathToStaticFiles + 'img/Icomas.gif'; var icoMenos = pathToStaticFiles + 'img/icoMenos.gif';
	var altMas = 'Mostrar lista'; var altMenos = 'Ocultar informaci\u00f3n';
	var tags = ['A', 'STRONG', 'ACRONYM', 'ABBR', 'EMPH'];
	for(var i=0;i<oculto.length;i++){
		var anchor = document.createElement('a');
		var s = oculto[i].parentNode.childNodes;
		var siblings = new Array(s.length);
		for (var g = 0; g < s.length; g++) siblings[g] = s[g];

		var toRemove = new Array();

		for (var j = 0; j < siblings.length && siblings[j].className != 'dv_oculto'; j++) {
			var child = siblings[j];
			if (child.data && !/^\s*$/.test(child.data) || child.nodeName && tags.contains(child.nodeName)) {
				if (child.nodeName == 'A') {
					anchor.innerHTML += child.innerHTML;
				}
				else if (child.nodeName == 'STRONG') {
					anchor.appendChild(child);
					continue;
				}
				else if (child.nodeName == 'ABBR' || child.nodeName == 'ACRONYM') {
					anchor.appendChild(child);
					continue;
				} 
				else if (child.data && !/^\s*$/.test(child.data)) {
					anchor.innerHTML += child.data;
				} else {
					anchor.innerHTML += ' ';
				}
			}
			toRemove.push(child);
		}

		anchor.innerHTML = anchor.innerHTML.trimHTML() + '&nbsp;';
		anchor.id = 'chapa_' + i;
		anchor.href = '#' + anchor.id;

		var img = document.createElement('img');
		img.src = icoMas;
		anchor.title = img.alt = img.title = altMas;
		anchor.appendChild(img);
		
		anchor.className = 'dv_oculto';
		anchor.onclick = function()
			{
				if (this.parentNode.className == 'dv_oculto') {
					this.parentNode.className = 'dv_visible';
					this.lastChild.src = icoMenos;
					this.title = this.lastChild.alt = this.lastChild.title = altMenos;
					//scrollToElement(this);
				} 
				else {
					this.parentNode.className = 'dv_oculto';
					this.lastChild.src = icoMas;
					this.title = this.lastChild.alt = this.lastChild.title = altMas;
				}
				resize();
				return false;
			}
		
		oculto[i].parentNode.insertBefore(anchor, oculto[i].parentNode.firstChild);
		oculto[i].parentNode.className = 'dv_oculto';
		for (var k = 0; k < toRemove.length; k++)
			oculto[i].parentNode.removeChild(toRemove[k]);
	}
	if (oculto.length > 0)
		resize();
});
Document.addEvent(window, "load", function() {
	if (getElementsByClass("logo")){
		logoBdE = getElementsByClass("logo");
		logoBdE[0].style.cursor = 'pointer';
		logoBdE[0].onclick = function() {
			MM_goToURL('parent','http://www.bde.es/webbde/es/')
		}; 
	}												   
});
function resize(){
	var ctr = dom.$('ctr'); var opciones_der = dom.$('opciones_der'); var pie = dom.$('pie');
	if(ctr && opciones_der && pie){
		opciones_der.style.height = null;
		if (opciones_der.offsetHeight < ctr.offsetHeight)
			opciones_der.style.height = (Math.max(opciones_der.offsetHeight,ctr.offsetHeight)/(30/3))+'em';
	}
}
function MM_jumpMenuGo(selName,targ,restore){ //v3.0
	var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}

function MM_findObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
	}
	if(!(x=d[n])&&d.all) 
		x=d.all[n]; 
	for (i=0;!x&&i<d.forms.length;i++) 
		x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
		x=MM_findObj(n,d.layers[i].document);
	if(!x && d.getElementById) 
		x=d.getElementById(n); 
	return x;
}
 
function MM_jumpMenu(targ,selObj,restore){ //v3.0
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}
function MM_goToURL() { //v3.0
	var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
	for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function imprimir(){
	if(navigator.appName.indexOf("Explorer")!=-1){
		document.getElementById('opciones_der').style.height = 'auto';
	}
}
window.onbeforeprint = imprimir;

if (typeof(bde_fnsDomLoaded) != 'undefined') {
	for (var i = 0; i < bde_fnsDomLoaded.length; i++) {
		Document.addEvent(document, 'dom:loaded', bde_fnsDomLoaded[i]);
	}
}
