

   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;
	}
	

	function postSubmit(data, type,capa) {
		
		if(type == 'load') {
        	var iframe = dojo.byId("dojoIoIframe");
            /**document.getElementById('visorImagenesId').innerHTML = iframe.contentWindow.document.activeElement.innerHTML;**/
            document.getElementById(capa).innerHTML = iframe.contentWindow.document.activeElement.innerHTML;
     	} 
    }
    
	

    function scrollear_bucavanzado()
    {
	 jQuery(function( $ ) // Cuando pinchamos en el botón buscar del buscador avanzado de puntos o de rutas, desplazamos la página para que se vean los resultados en resoluciones pequeñas 
	  {
       $('#btnMandaConsulta').click(function()
	    {
          $.scrollTo( 1000, 800, { queue:true } ) 
        })
      }) ;
    }

    function scrollear_aposicion()
    {
  	jQuery(function( $ ) // Cuando pinchamos en el botón buscar del buscador avanzado de puntos o de rutas, desplazamos la página para que se vean los resultados en resoluciones pequeñas 
   {

          $.scrollTo( 800, 800, { queue:true } ) 

      }) ;
    }
    
	function ctrlSelect(evento){		
		evento= (evento) ? evento : ((window.event) ? event :null );
		if (evento) { // si existe
			var elem = (evento.target) ? evento.target : ((evento.srcElement) ? evento.srcElement : null);
			if (elem) {
				if (elem.value == 'Todas') {
					document.getElementById('subtipos').disabled = true;
				}
				else {
					document.getElementById('subtipos').disabled = false;
				}
			}
		}
	}  // fin funcion ctrlSelect
	
	function selSelectValue(control, valor){	
	    for(var i = 0; i < control.options.length; i++){
	        if(control.options[i].value == valor){
	            control.selectedIndex = control.options[i].index;
	        }
	    }
	}

	
	
	function cargaComboSimple(elemento,idCombo,idPadre,cadenaInicial, value){	
		var objCombo = document.getElementById(idCombo);
		var url="jsp/portal/utilidades/elementos.jsp?elemento="+elemento+"&id="+idPadre;		
		borraCombo(idCombo,cadenaInicial);		
		$j.getJSON(url,function(data){			
			var jsonObject = data;
			var i=1;
			if (cadenaInicial.length==0){
				i=0;
			}			
			
			for(var element in jsonObject.elementos){
				objCombo.options[i]= new Option(jsonObject.elementos[element].value,jsonObject.elementos[element].key);
				i++;			
			}
			objCombo.disabled= false;
			if(value != null && value != ''){
				selSelectValue(objCombo, value);
			}		
	    }	    
	   );	
	   
	}


	

	 function timedMsg(rutaImagen,nombreImagen,contador){

		var rutaImagenPC = nombreImagen.substring (nombreImagen.lastIndexOf("\\")+1,nombreImagen.length);	
		 setTimeout("insertar_imagen('" + rutaImagen + "','" + rutaImagenPC + "'," + contador + ")",5000);

	  }
	function insertar_imagen(rutaImagen,rutaImagenPC,contador){
			
		var rutaCompleta = rutaImagen + rutaImagenPC;
	
		if (document.getElementById('reloj').style.display=="none"){
			contador=110;
		}
		
	
		var tmp=new Image;
		tmp.src=rutaCompleta ;	
		
		var elemento='';
		elemento = elemento + '<div id="divImagenShadowbox">';
		elemento = elemento + '<a rel=shadowbox class=classShadowbox href="'+ rutaCompleta +'">';
		elemento = elemento + '<img alt=Elemento_multimedia src="'+ rutaCompleta + '"/>';
		elemento = elemento + '</a>';
		elemento = elemento + '</div>';
	    tinyMCE.activeEditor.setContent(tinyMCE.activeEditor.getContent()+ elemento);

	    oculta_capa('reloj');
		procesa_m_o ();
		
    
	}
		
	function insertar_referenciaImg(imagen,contenido){
		var elemento='';
		elemento = elemento + '<div id="divImagenShadowbox">'
		elemento = elemento + '<a rel=shadowbox class=classShadowbox href="'+ contenido +'">'
		elemento = elemento + '<img alt=Elemento_multimedia src="'+ imagen + '"/>';
		elemento = elemento + '</a>'
		elemento = elemento + '</div>'		
	    tinyMCE.activeEditor.setContent(tinyMCE.activeEditor.getContent()+ elemento);
		//procesa_m_o ();
	}
	
	function cargaCombo(elemento,idCombo,idPadre,cadenaInicial, value){		
		var objCombo = document.getElementById(idCombo);
		var objComboCon = document.getElementById('con'+idCombo);
		
		var url="jsp/portal/utilidades/elementos.jsp?elemento="+elemento+"&id="+idPadre;
		var keyControl;		
		borraCombo(idCombo,cadenaInicial);
		if (objComboCon != null){
			borraCombo('con'+idCombo,'-1');
		}
		
		$j.getJSON(url,function(data){			
			var jsonObject = data;
			var i=1;
			if (cadenaInicial.length==0){
				i=0;
			}			
			
			for(var element in jsonObject.elementos){
				
				keyControl=jsonObject.elementos[element].key.split("-"); 
				objCombo.options[i]= new Option(jsonObject.elementos[element].value,keyControl[0]);
				if (objComboCon != null){
					objComboCon.options[i]= new Option(keyControl[0], keyControl[1]);
				}				
				i++;			
			}
			objCombo.disabled= false;
			if (objComboCon != null){
				objComboCon.disabled= false;
			}			
			if(value != null && value != ''){
				selSelectValue(objCombo, value);
			}		
	    }	    
	   );	
	}

function borraCombo(idCombo,cadenaInicial){
		var objCombo = document.getElementById(idCombo);
		objCombo.disabled= true;
		var i;
		for(i=objCombo.options.length-1;i>=0;i--)
		{	objCombo.remove(i);	}		
		if (cadenaInicial.length > 0){
			objCombo.options[0]= new Option(cadenaInicial,-1);
		}
	}

function marcaCombo(idCombo, value){
		var objCombo = document.getElementById(idCombo);
		if(value != null && value != ''){				
			//selSelectValue(objCombo, value);
			objCombo.selectedIndex = value;
		}
	}
	
	function selectCombosValue(provincia, comarca, municipio){
		var comboP;
		var comboCP;

		comboP = document.getElementById("provincia");

		comboCP = document.getElementById("conprovincia");
		//selecciono provincia en combo oculto con valor de parametro
		comboCP.selectedIndex = devuelveIndiceCombo(comboCP,provincia);
		//selecciono provincia en combo visible
		comboP.selectedIndex = devuelveIndiceCombo(comboP,comboCP.options[comboCP.selectedIndex].text);
		comboP.onchange();
		setTimeout('seleccionaComarca('+comarca+','+municipio+');',1000);
	}		
	
	function seleccionaComarca(comarca,municipio){
		var comboC;
		var comboCC;
		comboC = document.getElementById("comarcas");
		comboCC = document.getElementById("concomarcas");
		if (comboC.length < 2 || comboCC.length < 2){
			setTimeout('seleccionaComarca('+comarca+','+municipio+');',1000);
		}
		//selecciono comarca en combo oculto con valor de parametro
		comboCC.selectedIndex = devuelveIndiceCombo(comboCC,comarca);
		//selecciono comarca en combo visible
		comboC.selectedIndex = devuelveIndiceCombo(comboC,comboCC.options[comboCC.selectedIndex].text);
		comboC.onchange();
		setTimeout('seleccionaMunicipio('+municipio+');',1000);
		//selecciono municipio en combo visible
	}
	
    function selectCombosValueVolver(provincia, comarca, municipio){
		var comboP;
		var comboCP;

		comboP = document.getElementById("provincia");

		comboCP = document.getElementById("conprovincia");
		//selecciono provincia en combo oculto con valor de parametro
		comboCP.selectedIndex = devuelveIndiceCombo(comboCP,comboCP.options[provincia-1].value);
		//selecciono provincia en combo visible
		comboP.selectedIndex = devuelveIndiceCombo(comboP,comboCP.options[comboCP.selectedIndex].text);
		comboP.onchange();
		setTimeout('seleccionaComarcaVolver('+comarca+','+municipio+');',1000);
	}
	function seleccionaComarcaVolver(comarca,municipio){
		var comboC;
		var comboCC;
		comboC = document.getElementById("comarcas");
		comboCC = document.getElementById("concomarcas");
		if (comboC.length < 2 || comboCC.length < 2){
			setTimeout('seleccionaComarca('+comarca+','+municipio+');',1000);
		}
		//selecciono comarca en combo oculto con valor de parametro
		comboCC.selectedIndex = devuelveIndiceComboText(comboCC,comarca);
		//selecciono comarca en combo visible
		comboC.selectedIndex = devuelveIndiceCombo(comboC,comboCC.options[comboCC.selectedIndex].text);
		comboC.onchange();
		setTimeout('seleccionaMunicipio('+municipio+');',1000);
		//selecciono municipio en combo visible
	}
	function seleccionaMunicipio(municipio){
		var comboM;
		comboM = document.getElementById("municipios");
		if (comboM.length < 2){
			setTimeout('seleccionaMunicipio('+municipio+');',1000);
		}
		comboM.selectedIndex = devuelveIndiceCombo(comboM,municipio);
	}

		function devuelveIndiceCombo(combo,valor){
			var op = combo.options;
			var l = combo.length;
			var i = 0;
			for (i=0;i<l;i++){
				if (op[i].value == valor){					
					break;
				}
			}
			return i;
		}

		function devuelveIndiceComboText(combo,valor){
			var op = combo.options;
			var l = combo.length;
			var i = 0;
			for (i=0;i<l;i++){
				if (op[i].text == valor){					
					break;
				}
			}
			return i;
		}  

		function pasarGis (tipo, id){
			//alert('En la llamada a pasarGis el tipo es: '+tipo+' y el id: '+id);
			
			var miId="-1";
			var conControl; 
			var control;
			var op;
			var valor;
				
			Control= document.getElementById(tipo);
			conControl= document.getElementById('con'+tipo);
			op=conControl.options;
			// busca el valor en el combo
			
			var b = 1;
			for(a=0;a<b;a++){
				b= a+2;
				if (op[a+1] == undefined){
					b=a;
				}
				if (op[a].text == id){
					miId=op[a].value;	
				}
			}
			//alert('La salida para GIS el tipo es: '+tipo+' y el id: '+ miId);
			return miId;
		}

		//Funcion para cargar el modulo del tiempo
		function cargaElTiempo(codigo){
			  DivTutiempo=document.getElementById('TT_' + codigo);
			  if (DivTutiempo)
			  {
			  var vinOk = 'no';
			  if (!DivTutiempo.links){DivTutiempo.links = DivTutiempo.getElementsByTagName('a');}
			  for (var t=0; t<DivTutiempo.links.length; t++){var comlinksTT = DivTutiempo.links[t]; if (comlinksTT.href.search('http://www.tutiempo.net/') != -1){if(comlinksTT.getAttribute('rel') == 'nofollow'){} else {vinOk='si'; break;} } }
			  }
			  if(DivTutiempo && vinOk == 'si')
			  {
			  while(DivTutiempo.firstChild){DivTutiempo.removeChild(DivTutiempo.firstChild)};
			  DivTutiempo.style.cssText='border:1px solid #ffffff;width:160px; height:54px; margin-left:18px; margin-top:-2px; overflow-x:hidden; overflow-y:hidden; color:#77b244; background: #ffffff; overflow:hidden; width:160px;';
			  marco=document.createElement('iframe');
			  marco.id='iFrame_'+codigo;
			  marco.src='http://www.tutiempo.net/TTapi/_' + codigo;
			  marco.frameBorder=0;
			  marco.scrolling='no';
			  marco.width=160;
			  marco.height='100%';
			  DivTutiempo.appendChild(marco);
			  }
			  else {alert("Error en la carga del API del tiempo\nEl código introducido no es correcto\nPara mas información: www.tutiempo.net");}
			 
			 }
		
		
		function limpiaInputText (id){
			document.getElementById(id).value="";
		}
		// notificacion, crear_cuaderno. Cuando se pulsa un boton añadir se llama a esta funcion
		function procesa_m_o (){
			muestra_capa('notificacion');
			setTimeout (function(){ oculta_capa('notificacion'); oculta_capa('anadir_info');muestra_capa('wysiwig');},5000);
			return false;
		}
		function oculta_capa (idCapa){
			document.getElementById(idCapa).style.display="none";
			return false;
		}
		
		function muestra_capa (idCapa){
			document.getElementById(idCapa).style.display="block";
			return false;
		}	
		function cambiar_tipo_seleccion(tipo){
			var etiqueta;
			
			if (tipo == 'computadora'){ 
				document.getElementById('documento').disabled= false;
				document.getElementById('upload_value').disabled= false;
				document.getElementById('boton_anadir').disabled= false;
				document.getElementById('provincias').disabled= true;
				document.getElementById('comarcas').disabled= true;
				//document.getElementById('municipios').disabled= true;
				document.getElementById('tipo').disabled= true;
				document.getElementById('medio').disabled= true;
				document.getElementById('filtro').disabled= true;
				document.getElementById('boton_buscar').disabled= true;		
				etiqueta=  document.getElementById('labelcomputadora');
				etiqueta.className= 'activo';
				etiqueta=  document.getElementById('labelportal');
				etiqueta.className= ' ';
										
			}
			else if (tipo == 'portal'){
				
				document.getElementById('documento').disabled= true;
				document.getElementById('upload_value').disabled= true;
				document.getElementById('boton_anadir').disabled= true;
				document.getElementById('provincias').disabled= false;
				document.getElementById('comarcas').disabled= false;
				//document.getElementById('municipios').disabled= false;
				document.getElementById('tipo').disabled= false;
				document.getElementById('medio').disabled= false;
				document.getElementById('filtro').disabled= false;
				document.getElementById('boton_buscar').disabled= false;
				etiqueta= document.getElementById('labelportal');
				etiqueta.className= 'activo';
				etiqueta= document.getElementById('labelcomputadora');
				etiqueta.className= ' ';
				
			}
		}
		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 iniciarEditor (){
			var opciones = {
					// General options
					mode : "textareas",
					theme : "advanced",
					language : "es",
					plugins : "safari,spellchecker,pagebreak," +
							"style,layer,table,save,advhr,advimage,advlink," +
							"emotions,iespell,inlinepopups,insertdatetime," +
							"preview,media,searchreplace,print,contextmenu,paste," +
							"directionality,fullscreen,noneditable,visualchars," +
							"nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
				  	width : "676",
				    height: "420",

					// Theme options
					//theme_advanced_buttons1 : "bold,italic,underline,|,forecolor,|,fontselect,fontsizeselect,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,|,preview,fullscreen",
					theme_advanced_buttons1 : "bold,italic,underline,|,forecolor,|,fontselect,fontsizeselect,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,preview,fullscreen",
					theme_advanced_buttons2 : "",
					theme_advanced_buttons3 : "",
				    theme_advanced_buttons4 : "",
					
					theme_advanced_toolbar_location : "top",
					theme_advanced_toolbar_align : "left",
					//theme_advanced_statusbar_location : "bottom",
					//theme_advanced_resizing : true,

					// Example content CSS (should be your site CSS)
					content_css : "js/tinymce/examples/css/example.css",

					// Drop lists for link/image/media/template dialogs
					template_external_list_url : "js/tinymce/examples/lists/template_list.js",
					external_link_list_url : "js/tinymce/examples/lists/link_list.js",
					external_image_list_url : "js/tinymce/examples/lists/image_list.js",
					media_external_list_url : "js/tinymce/examples/lists/media_list.js",

					// Replace values for the template plugin
					template_replace_values : {
						username : "Some User",
						staffid : "991234"
					}
				};
			tinyMCE.init(opciones);
		}
	
		tinyMCE.init({
			// General options
			mode : "textareas",
			theme : "advanced",
			language : "es",
			plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
		  	width : "676",
		    height: "420",

			// Theme options
			//theme_advanced_buttons1 : "bold,italic,underline,|,forecolor,|,fontselect,fontsizeselect,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,link,unlink,|,preview,fullscreen",
			theme_advanced_buttons1 : "bold,italic,underline,|,forecolor,|,fontselect,fontsizeselect,|,bullist,numlist,|,outdent,indent,|,undo,redo,|,preview,fullscreen",
			theme_advanced_buttons2 : "",
			theme_advanced_buttons3 : "",
		    theme_advanced_buttons4 : "",
			
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			content_css : "js/tinymce/examples/css/example.css",

			template_external_list_url : "js/tinymce/examples/lists/template_list.js",
			external_link_list_url : "js/tinymce/examples/lists/link_list.js",
			external_image_list_url : "js/tinymce/examples/lists/image_list.js",
			media_external_list_url : "js/tinymce/examples/lists/media_list.js",

			template_replace_values : {
				username : "Some User",
				staffid : "991234"
			}
		});
		function redimen() {
			$j('#resizable:not(.processed)').TextAreaResizer();
		}
		
		// para el formulario de edicion de perfil
		function cambiarInputBlog(objCheck){
			if (objCheck.checked== true){
				document.getElementById('blog').disabled= false;
			}
			else{
				document.getElementById('blog').disabled= true;
			}
		}
		

