// funcion que carga una ruta dada en central.
	function IrRuta(irRutaId) {	
		document.getElementById('irRutaId').value=irRutaId;
		document.getElementById('IrARuta').click();
	}

	function llamarVisorFlash(totalelementos,prof,video){
		/*
		 * añadido un contador de elementos porque si no, peta
		 */
		// Obtenemos el objeto Flash		
		for(i=0;i<totalelementos;i++){
			if (i == video){
				document.getElementById('cont_video'+i).className='activado';
			}
			else{
				document.getElementById('cont_video'+i).className='normal';
			}
		
		}
		objFlash = document.visor_videoflash || document.getElementById( 'visor_videoflash' );
		// Enviamos el texto a la función a través del 'alias'
		objFlash.recibirHtml( prof );
	}

	function VideoActual(numVideo) //Función que le devuelve al jsp el vídeo que se ha cargado
	{	document.getElementById('ordenVideo').value=numVideo;
		document.getElementById('marcaVideoActual').click();
	
	}

	function IrAPuntoHtml(idPunto, idRuta) //Cargamos la pantalla de info correspondiente a la ficha del punto o ruta del vídeo actual
	{	
		if(idPunto == -1){
			document.getElementById('rutaIdVideo').value=idRuta;
			document.getElementById('cargaObtenerDetalleRutas').click();
		}
		else
		{	document.getElementById('ptoInteresId').value=idPunto;
			document.getElementById('cargaPuntoInteresVideo').click();				
		}
	}

	function cargaLightBox() 
	{
		$j('#contiene_listado a.lightbox').lightBox();
	}
	
	function cargaLightBoxComponente(componente) 
	{
		$j(componente).lightBox();
	}
	
	function mensajeErrorRegistro(){
		
		if(document.getElementById('hdnErrorAutentifica')!=null)
		{	if(document.getElementById('hdnErrorAutentifica').value.length > 0)
			{	// Cuando existen errores			
				document.getElementById('usuario').value =document.getElementById('hdnErrorAutentifica').value;
				document.getElementById('usuario').style.color = '#FF0000'; 
				alert(document.getElementById('hdnErrorAutentifica').value);
			}
			else
			{	// Cuando no existen errores		
				document.getElementById('usuario').style.color = '#aaa';
			}
			
		}
		
	}

	function numPuntos (){
		var punto;
		var i= 0;
		var numres= 0;
		punto= document.getElementById("lista_rutas_li" + i);
		while (punto != null){
			if (punto.style.display != "none"){
				numres++;
			}			
			i++;
			punto= document.getElementById("lista_rutas_li" + i);
		}
		return numres;
	}

	function ultimoIndice (){
		var punto;
		var i= 0;
		punto= document.getElementById("lista_rutas_li" + i);
		while (punto != null){			
			i++;
			punto= document.getElementById("lista_rutas_li" + i);
		}
		return i-1;
	}

	function creaPuntoUsuarioDesdeListado(paramNombrePunto, paramIdPunto){
		function construirPunto (idPunto, nombre, codigo){
			var puntoLista= document.createElement('li');
			var enlace = document.createElement('a');
			var cadOnClick;
			var span= document.createElement('span');

			puntoLista.id= "lista_rutas_li" + idPunto;
			puntoLista.className= "llegada punto_ruta_base";
			enlace.id= "lista_rutas_a" + idPunto;		
			enlace.className= "llegada";
			enlace.onclick= function(){
						activaPunto(this.parentNode, this); 
						seleccionaPuntoMapa('puntos',codigo );
						document.getElementById('ptoInteresIdHdn').value= - codigo; 
						document.getElementById('botonHdn').click(); };
			enlace.appendChild(document.createTextNode(nombre));
			span.style.display="none";
			span.id= "codPunto" + idPunto;
			span.appendChild(document.createTextNode(codigo));
			
			puntoLista.appendChild(enlace);
			puntoLista.appendChild(span);
			
			return puntoLista;
		}

		function anadirALista (punto){
			var lista= document.getElementById('lista_rutas_ul_crear_punto');
			lista.appendChild(punto);
			if (numPuntos() == 1){
				
			}		
		}
		
		function pintaPunto(nombrePunto, codigo){
			var ultimoInd= ultimoIndice();
			var ultPunto = document.getElementById("lista_rutas_li" + ultimoInd);
			ultPunto.className= "normal punto_ruta_base";
			var ultEnlace = document.getElementById("lista_rutas_a" + ultimoInd);
			ultEnlace.className= "normal";
			var nombre= nombrePunto; 
			var punto= construirPunto(ultimoInd+1, nombre, codigo);
			if (numPuntos() == 0){
				punto.className="normal punto_ruta_base";
				// enlace = normal
			}
			else if (numPuntos() == 1){
				document.getElementById ("lista_rutas_ul_crear_punto").style.borderLeft= "2px solid #E5ECD9";			
				ultPunto.className= "salida punto_ruta_base";
				ultEnlace.className= "salida";
			}
			anadirALista(punto);
			if (numPuntos() > 7){
				document.getElementById("easyscrollnav").style.display= "block";
			} 
			return false;
		}  // fin pintaPunto
		
		pintaPunto(paramNombrePunto, paramIdPunto);
	} // fin creaPuntoUsuario

	function creaPuntoUsuario(){
		function construirPunto (idPunto, nombre, codigo){
			var puntoLista= document.createElement('li');
			var enlace = document.createElement('a');
			var cadOnClick;
			var span= document.createElement('span');

			puntoLista.id= "lista_rutas_li" + idPunto;
			puntoLista.className= "llegada punto_ruta_base";
			enlace.id= "lista_rutas_a" + idPunto;		
			enlace.className= "llegada";
			enlace.onclick= function(){
						activaPunto(this.parentNode, this); 
						seleccionaPuntoMapa('puntos',codigo );
						document.getElementById('ptoInteresIdHdn').value= - codigo; 
						document.getElementById('botonHdn').click(); };
			enlace.appendChild(document.createTextNode(nombre));
			span.style.display="none";
			span.id= "codPunto" + idPunto;
			span.appendChild(document.createTextNode('-'+codigo));
			
			puntoLista.appendChild(enlace);
			puntoLista.appendChild(span);
			
			return puntoLista;
		}

		function anadirALista (punto){
			var lista= document.getElementById('lista_rutas_ul_crear_punto');
			lista.appendChild(punto);
			if (numPuntos() == 0){
				lista.style.border= "none";
			}		
		}
		
		function pintaPunto(codigo){
			var ultimoInd= ultimoIndice();
			var ultPunto = document.getElementById("lista_rutas_li" + ultimoInd);
			if (numPuntos() > 0){
				ultPunto.className= "normal punto_ruta_base";
				var ultEnlace = document.getElementById("lista_rutas_a" + ultimoInd);
				ultEnlace.className= "normal";
			}
			var nombre= document.getElementById("nombrePunto").value; 
			var punto= construirPunto(ultimoInd+1, nombre, codigo);
			if (numPuntos() == 0){
				punto.className="normal punto_ruta_base";
				// enlace = normal
			}
			else if (numPuntos() == 1){
				document.getElementById ("lista_rutas_ul_crear_punto").style.borderLeft= "2px solid #E5ECD9";			
				ultPunto.className= "salida punto_ruta_base";
				ultEnlace.className= "salida";
			}
			anadirALista(punto);
			if (numPuntos() > 7){
				document.getElementById("easyscrollnav").style.display= "block";
			} 
			return false;
		}  // fin pintaPunto
		
		var hidden= document.getElementById('puntoRecienCreado');
		if (hidden.value != ''){
			pintaPunto(hidden.value);
		}
	} // fin creaPuntoUsuario


	// elimina el punto activo de una ruta dentro de "Crea tu Ruta" 
	function eliminaPuntoRuta (){

		function puntoVisible (indComienzo){
			var punto;
			var indres = -1;
			var i= indComienzo;
			var salir = false;
			punto= document.getElementById("lista_rutas_li" + i);
			while ((punto != null) && (!salir)){
				if (punto.style.display != "none"){
					salir= true;
					indres= i;
				}
				i++;
				punto= document.getElementById("lista_rutas_li" + i);
			}
			return indres;
		}
			
		var ind;
		var salir;
		var punto, puntoSig;
		ind= puntoVisible(0);
		punto = document.getElementById("lista_rutas_li" + ind); 
		// caso solo hay un punto
		if ( numPuntos() == 1){
			punto.style.display= "none";
			
		}
		// caso hay exactamente dos puntos
		else if (numPuntos() == 2){
			if (punto.className == "activo_salida punto_ruta_base") {  // quitamos primer punto
				punto.style.display= "none";
				ind= puntoVisible(0); // se puede poner ind+1 en lugar de 0
				punto = document.getElementById("lista_rutas_li" + ind);
				punto.className= "normal punto_ruta_base"; // el segundo punto queda como el unico.			
				document.getElementById ("lista_rutas_a"+ind).className= "normal";
			}
			else { // quitamos el segundo punto			
				punto.className= "normal punto_ruta_base"; // el primer punto queda como el unico.
				document.getElementById ("lista_rutas_a" + ind).className= "normal";
				ind= puntoVisible (ind+1);
				punto = document.getElementById("lista_rutas_li"+ ind);
				punto.style.display = "none";
			}
			document.getElementById ("lista_rutas_ul_crear_punto").style.border= "none";
		}
		else { // hay al menos tres puntos		
			salir= false;
			indAnt= ind;
			ind= puntoVisible(ind+1);
			puntoSig = document.getElementById("lista_rutas_li" + ind);
			while ( (puntoSig != null) && (!salir) ){
				if ( (punto.style.display != "none") && (punto.className == "activo_salida punto_ruta_base") ){ 
					// es el primero
					punto.style.display= "none";
					puntoSig.className = "salida punto_ruta_base";
					document.getElementById ("lista_rutas_a" + ind).className= "salida";
					salir= true;
				}
				else if ( puntoSig.className == "activo_llegada punto_ruta_base") { 
					// es el ultimo
					puntoSig.style.display= "none";
					punto.className= "llegada punto_ruta_base";
					document.getElementById ("lista_rutas_a" + indAnt).className= "llegada";
					salir= true;
				}
				else if (punto.className == "activo_normal punto_ruta_base"){
					punto.style.display= "none";
					salir= true;								
				}			
				punto= puntoSig;
				indAnt= ind;
				ind = puntoVisible(ind + 1);
				puntoSig= document.getElementById("lista_rutas_li" + ind);
			} // fin while
		}
		if ((document.getElementById ("easyscrollnav") != null) && (numPuntos()<=7 )) {
			document.getElementById ("easyscrollnav").style.display= "none";
			document.getElementById ("lista_rutas_contenido_scroll").style.top= 0;
		}
	} // fin eliminaPuntoRuta


	function eliminaTodosPuntosRuta (){
	/*	document.getElementById ("lista_rutas_ul_crear_punto").style.display= "none"; */
		var punto;
		var i=0;
		punto= document.getElementById("lista_rutas_li" + i);
		while (punto != null){
			punto.style.display = "none";
			i++;
			punto= document.getElementById("lista_rutas_li" + i);
		}
		if (document.getElementById ("easyscrollnav") != null) {
			document.getElementById ("easyscrollnav").style.display= "none";
		}
	}

	function obtenerPuntosRuta (visibles){
		var i;
		var punto;
		var codigo;
		var resultado="";
		i=0;
		punto= document.getElementById("lista_rutas_li" + i);
		while (punto != null){
			if ((punto.style.display == "none") && (!visibles) ){
				codigo= document.getElementById("codPunto" + i).innerHTML;
				if (resultado != ""){
					resultado+= "|";
				}
				resultado+= codigo;
			}
			else if ((punto.style.display != "none") && (visibles) ){
				codigo= document.getElementById("codPunto" + i).innerHTML;
				if (resultado != ""){
					resultado+= "|";
				}
				resultado+= codigo;
			}
			i++;
			punto= document.getElementById("lista_rutas_li" + i);
		}
		return resultado;
	} // fin obtenerPuntosRuta


	function activaPunto(obj, aObj){
		var fila;
		var aFila;
		var straux;	
		var b=2;

		for (i=0;i<b;i++){
			if (document.getElementById('lista_rutas_li'+i) != null){
				fila = document.getElementById('lista_rutas_li'+i);
				aFila = document.getElementById('lista_rutas_a'+i);
				straux=fila.className;
				straux=straux.replace(new RegExp('activo_'),'');
				fila.className = straux;
			
				straux=aFila.className;
				straux=straux.replace(new RegExp('activo_'),'');
				aFila.className =straux;
				b=i+2;
			}else{
				i=b;
			}		 		
		}
		if (obj!=null){
			obj.className = 'activo_'+ obj.className;
		}
		if (aObj!=null){
			aObj.className = 'activo_'+ aObj.className;
		}
	}

	function activaBotonMenu(aId){	
		var primer=1;
		var ultimo=6;
		var aFila;	
		for (i=primer;i<ultimo;i++){		
			aFila = document.getElementById('menuCentral'+i);
			aFila.className = '';
		}
		document.getElementById(aId).className = 'activo';
	}

	function activaTabMultimedia(lId){	
		var primer=1;
		var ultimo=4;
		var lTab;	
		var pTab;
		for (i=primer;i<ultimo;i++){
			lTab= document.getElementById('botonTab'+i);
			lTab.className='TabbedPanelsTab';
			pTab= document.getElementById('tabContenido'+i);
			pTab.className='TabbedPanelsContent';
			pTab.style["display"] = "none";
		}
		document.getElementById('botonTab'+lId).className='TabbedPanelsTab TabbedPanelsTabSelected';
		document.getElementById('tabContenido'+lId).className='TabbedPanelsContent TabbedPanelsContentVisible';
		document.getElementById('tabContenido'+lId).style["display"] = "block";
	}

	function divAyuda(){
			$j('div.demo-show:eq(0)> div').hide();  
				//$j('div.demo-show:eq(0)> div#ayuda_descarga').show(); 
			$j('div.demo-show:eq(0)> div#ayuda_blogs').show(); 
			$j('div.demo-show:eq(0)> h3').click(
				function() {
					$j(this).next().slideToggle('fast')
				});
		}

		function ocultacionDivDescarga() {
			  if ($j("#form_rutabase").is(":hidden")) 
			   {
				$j("#form_rutabase").slideDown("slow");
				document.getElementById("txt_ocultar_rutabase").textContent = "Ocultar"; <!-- para ie -->
				document.getElementById("txt_ocultar_rutabase").innerText = "Ocultar"; <!-- para firefox -->
	    		document.getElementById("ocultar_rutabase").style.backgroundImage = "url('img/ico_subir_rutabase.jpg')";
			   } 
			  else 
			   {
				$j("#form_rutabase").slideUp("slow");
				document.getElementById("txt_ocultar_rutabase").textContent = "Mostrar";
				document.getElementById("txt_ocultar_rutabase").innerText = "Mostrar";
	    		document.getElementById("ocultar_rutabase").style.backgroundImage = "url('img/ico_bajar_rutabase.jpg')";
			  }
			}
			
		function buscarRuta(buscar)
		  {
		   if(buscar == 'true'){
		    	 document.getElementById('opcion_ruta_subir').checked = '';
		    	 document.getElementById('provincia').disabled = '';
		    	 document.getElementById('botonBuscar').disabled = '';
		    	 document.getElementById('documento').disabled = true; 
		    	 document.getElementById('subir_rutabase').disabled = 'disabled'; 
			}else{
		    	document.getElementById('opcion_ruta_buscar').checked = '';
		    	document.getElementById('provincia').disabled = 'disabled';
		    	document.getElementById('comarcas').disabled = 'disabled'; 
		    	document.getElementById('municipios').disabled = 'disabled';
		    	document.getElementById('botonBuscar').disabled = 'disabled'; 
		    	document.getElementById('documento').disabled = false;
		    	document.getElementById('subir_rutabase').disabled = ''; 
			}
		  }
		  
		  	function cambiar_publico_privado(tipo){
			var etiqueta1, etiqueta2;
			
			if (tipo == 'publico'){ 
				etiqueta1= document.getElementById('labelpublico');
				etiqueta1.className="activo";
				etiqueta2= document.getElementById('labelprivado');
				etiqueta2.className="desactivo";		
													
			}
			else if (tipo == 'privado'){
				etiqueta1= document.getElementById('labelpublico');
				etiqueta1.className="desactivo";
				etiqueta2= document.getElementById('labelprivado');
				etiqueta2.className="activo";
				
			}
		}
		
		  
		  function postSubmit(data, type,capa) {
			if(type == 'load') {
	        	var iframe = dojo.byId("dojoIoIframe");
	            document.getElementById(capa).innerHTML = iframe.contentWindow.document.activeElement.innerHTML;
	     	} 
	    }
	    
		function sendIt(form,div){
	   		var bindArgs = {
	    	transport: "IframeTransport",
	       	formNode: document.getElementById(form),
	       	mimetype: "text/html",
	        load: function(type, data, evt){
	        document.getElementById(div).innerHTML =
		    data.firstChild.innerHTML;
	       }
	   };
	   var request = dojo.io.bind(bindArgs);
	}
		
		function inicializaVisorGoogle(x, y)
		{
			initialize(x,y);
		}
		
		function restaurarCombosBusquedaImagenes(provincia,comarcas,municipios)
		{
			activaBotonMenu('menuCentral5');
			selectCombosValueVolver(provincia,comarcas,municipios);
		}

		function restaurarCombosBusquedaParquesNaturales(provincia,parque_natural)
		{
			activaBotonMenu('menuCentral4');
			cargaComboSimple('parques','parque_natural',provincia,'Seleccione un parque natural');
			cargarComboParqueNatural(parque_natural);	
		}

		function cargarComboParqueNatural(valor_parque) {
			if (document.getElementById('parque_natural').disabled == true){
				setTimeout('cargarComboParqueNatural('+valor_parque+');',300);
			}
			else{
				var ind= devuelveIndiceCombo(document.getElementById('parque_natural'),valor_parque);
				document.getElementById('parque_natural').selectedIndex = ind;
			}
			
		}

		function restaurarCombosBusquedaPuntoInteres(provincia,comarcas,municipios,tipologia,subtipologias,acceso,acceso_rodado,emplazamiento,protegidos)
		{
			activaBotonMenu('menuCentral3');
			selectCombosValueVolver(provincia,comarcas,municipios);
			document.getElementById('tipologia').selectedIndex = devuelveIndiceCombo(document.getElementById('tipologia'),tipologia);
			cargaCombo('subtipologias','subtipologias',tipologia,'Todas');
			borraCombo('subtipologias','Todas');
			document.getElementById('acceso').selectedIndex = devuelveIndiceCombo(document.getElementById('acceso'),acceso);
			document.getElementById('acceso_rodado').selectedIndex = devuelveIndiceCombo(document.getElementById('acceso_rodado'),acceso_rodado);
			document.getElementById('emplazamiento').selectedIndex = devuelveIndiceCombo(document.getElementById('emplazamiento'),emplazamiento);
			document.getElementById('espacios').selectedIndex = devuelveIndiceCombo(document.getElementById('espacios'),protegidos);
			cargarComboSubtipologias(subtipologias);	
		}

		function cargarComboSubtipologias(valor_subtipologias) {
			if (document.getElementById('subtipologias').disabled == true){
				setTimeout('cargarComboSubtipologias('+valor_subtipologias+');',300);
			}
			else{
				var ind= devuelveIndiceCombo(document.getElementById('subtipologias'),valor_subtipologias);
				document.getElementById('subtipologias').selectedIndex = ind;
			}
			
		}

		function restaurarCombosBusquedaComarca(provincia,comarcas,municipios){
			activaBotonMenu('menuCentral1');
			selectCombosValueVolver(provincia,comarcas,municipios);
		}

		function restaurarCombosBusquedaAvanzada(provincia,comarcas,municipios,caracteristicas,recorrido,estacion,tipologia,dificultad,longitud,tiempo,discapacitados){
			activaBotonMenu('menuCentral2');
			selectCombosValueVolver(provincia,comarcas,municipios);
			var combo_caract = document.getElementById('caracteristicas');
			var v_caracteristicas;
			var formulario= document.buscador_avanzado;
			if ((caracteristicas != null) && (caracteristicas != "")){
				// marcamos el checkbox
				document.getElementById('TipR1').checked = true;
				combo_caract.disabled= false;
				v_caracteristicas= caracteristicas.split(', ');
				// falta la seleccion
				//var i; 
				//for (i=0; i < v_caracteristicas.lenght; i++){
					//combo_caract.options[v_caracteristicas[i]].click();
				//}
			}
			if ((recorrido != null) && (recorrido != "")){
				document.getElementById('TipR2').checked = true;
				document.getElementById('recorrido').disabled = false;
				document.getElementById('recorrido').selectedIndex = devuelveIndiceCombo(document.getElementById('recorrido'),recorrido);
			}
			//if ((estacion != null) && (estacion != "")){
				// marcamos el checkbox
				//document.getElementById('TipR3').checked = true;
				//document.getElementById('estacion').disabled = false;
				//var v_estaciones= estacion.split(', ');
				// falta la seleccion
			//}
			//if ((tipologia != null) && (tipologia != "")){
				//document.getElementById('TipR4').checked = true;
				//document.getElementById('tipologia').disabled = false;
				//document.getElementById('tipologia').selectedIndex = devuelveIndiceCombo(document.getElementById('tipologia'),tipologia);
			//}
			//if ((dificultad != null) && (dificultad != "")){
				//document.getElementById('TipR5').checked = true;
				//document.getElementById('dificultad').disabled = false;
				//document.getElementById('dificultad').selectedIndex = devuelveIndiceCombo(document.getElementById('dificultad'),dificultad);
			//}
			//if ((longitud != null) && (longitud != "")){
				//document.getElementById('TipR6').checked = true;
				//document.getElementById('longitud').disabled = false;
				//document.getElementById('longitud').selectedIndex = devuelveIndiceCombo(document.getElementById('longitud'),longitud);
			//}
			//if ((longitud != null) && (longitud != "")){
				//document.getElementById('TipR7').checked = true;
				//document.getElementById('tiempo').disabled = false;
				//document.getElementById('tiempo').selectedIndex = devuelveIndiceCombo(document.getElementById('tiempo'),tiempo);
			//}
			//if ((discapacitados != null) && (discapacitados != "")){
			//	document.getElementById('TipR8').checked = true;
				//	document.getElementById('discapacitados').disabled = false;
			//	document.getElementById('discapacitados').selectedIndex = devuelveIndiceCombo(document.getElementById('discapacitados'),discapacitados);
			//}
		}
