var geocoder1=null;
var geocoder2=null;
var map1=null;
var map2=null;

// JavaScript Document
window.onload = function()
{
	var menu=document.getElementById('menu');
	
	var opciones=menu.getElementsByTagName('a');
	for (i=0;i<opciones.length; i++)
	{
		if (opciones[i].parentNode.parentNode.id=='menu')
		{
			opciones[i].onclick=function()
			{
				if (this.id!='') {var id=this.id.split('opcion').join('');}
				var hijos=menu.getElementsByTagName('ul');
				if ((this.id!='') &&  (document.getElementById('submenu'+id)))
				{
					if ((document.getElementById('submenu'+id).style.display=='none') || (document.getElementById('submenu'+id).style.display==''))
					{
						document.getElementById('submenu'+id).style.display='block';
						this.className='senalada';
					}
					else
					{
						document.getElementById('submenu'+id).style.display='none';
						this.className='';
					}
				}
			}
		}
		else if (opciones[i].parentNode.parentNode.parentNode.parentNode.id=='menu')
		{
			opciones[i].onclick=function()
			{
				if (this.id!='') {var id=this.id.split('opcion').join('');}
				
				var submenu=this.parentNode.parentNode;
				var submenus=submenu.getElementsByTagName('li');
				if (typeof(nivel1)!='undefined') ;
				else {var cadena='';}
				
				for (j=0; j<submenus.length; j++)
				{
					var aux=submenus[j].getElementsByTagName('ul');
					
					for (k=0;k<aux.length;k++)
					{
						if (cadena!=aux[k].id) {aux[k].style.display='none';}
						if (document.getElementById('sub'+id)) {document.getElementById('sub'+id).style.display='block';}
					}
				}
			}
		}
	}
	if ((typeof(nivel1)!='undefined') && (nivel1!=0))
	{
		document.getElementById('opcion'+nivel1).className+=' activa';
		if (nivel1!=7)
			document.getElementById('submenu'+nivel1).style.display+='block';
	}
	if (typeof(nivel2)!='undefined')
	{
		if (document.getElementById('opcion'+nivel1+'_'+nivel2))
		{
			document.getElementById('opcion'+nivel1+'_'+nivel2).className+=' activa';
			var hijos=document.getElementById('opcion'+nivel1+'_'+nivel2).parentNode.getElementsByTagName('ul');
			if (hijos.length==0) {document.getElementById('opcion'+nivel1+'_'+nivel2).className+=' sin_hijos';}
			if (document.getElementById('sub'+nivel1+'_'+nivel2)) {document.getElementById('sub'+nivel1+'_'+nivel2).style.display+='block';}
		}
	}
	if (typeof(nivel3)!='undefined')
	{
		document.getElementById('opcion'+nivel1+'_'+nivel2+'_'+nivel3).className+=' activa';
		document.getElementById('sub'+nivel1+'_'+nivel2).style.display='block';
	}
	
	var lis_segundo_nivel=menu.getElementsByTagName('li');
	for (j=0;j<lis_segundo_nivel.length;j++)
	{
		if (lis_segundo_nivel[j].parentNode.id!='menu')
		{
			var hijos=lis_segundo_nivel[j].getElementsByTagName('ul');
			if ((hijos.length>0) & (lis_segundo_nivel[j].className=="activa")) {lis_segundo_nivel[j].firstChild.className+=' hijos';}
		}
	}
	
	var mapas=getElementsByClass("google_map");
	if (mapas.length>0) {pintamapas(mapas);}
	
	if (document.getElementById('descripcion_servicio'))
	{
		var listado=document.getElementById('descripcion_servicio');
		var items=getElementsByClass("plegable",listado)
		
		for (i=0;i<items.length;i++)
		{
			var sublistas=items[i].getElementsByTagName('ul');
			for (j=0;j<sublistas.length;j++) {sublistas[j].style.display='none';}
			
			var enlace=document.createElement('a');
			enlace.setAttribute("href","javascript:void(0)");
			var imagen=document.createElement('img');
			imagen.setAttribute("src","/images/flea/desplegar.gif");
			imagen.setAttribute("alt","Desplegar");
			enlace.appendChild(imagen)
			
			var texto=items[i].childNodes[0];
			items[i].insertBefore(enlace,texto);
			items[i].insertBefore(document.createTextNode(" "),texto);
			enlace.onclick=function()
			{
				var text=this.firstChild.getAttribute("alt");
				if (text=='Desplegar')
				{
					var listas=this.parentNode.getElementsByTagName('ul');
					for (j=0;j<listas.length;j++) {listas[j].style.display='block';}
					this.firstChild.setAttribute("src","/images/flea/plegar.gif");
					this.firstChild.setAttribute("alt","Plegar");
				}
				else
				{
					var listas=this.parentNode.getElementsByTagName('ul');
					
					for (j=0;j<listas.length;j++) {listas[j].style.display='none';}
					this.firstChild.setAttribute("src","/images/flea/desplegar.gif");
					this.firstChild.setAttribute("alt","Desplegar");
				}
			}
		}
	}
}

/* Add this code to your existing scripts */

/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
Created by: Dustin Diaz :: http://www.dustindiaz.com/ */

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;
}
