var map=null;
var geocoder=null;

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');
					/*for (j=0;j<hijos.length;j++) {
						if (hijos[j].parentNode.parentNode.id=='menu') {
						hijos[j].style.display='none';
						}
					}*/
				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') {
	//			var cadena='submenu'+nivel1+'_'+nivel2;
				}
				else {
					var cadena='';
				}
				//alert(cadena);
				for (j=0; j<submenus.length; j++) {
		
					var aux=submenus[j].getElementsByTagName('ul');
					
						for (k=0;k<aux.length;k++) {
				//			alert(aux[k].id);
						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 (document.getElementById('submenu'+nivel1)) {
		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';
			}
			
		}
	}

if (document.getElementById('google_map')) {
	if (GBrowserIsCompatible()) {

     	map = new GMap2(document.getElementById('google_map'));
	
		
		
		geocoder = new GClientGeocoder();
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
	
	showAddress('Avenida de Manoteras, nº 52 28050 Madrid');
	 }
}

}


function showAddress(address) {

  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        alert(address + " not found");
      } else {
        map.setCenter(point, 15);
       marker = new GMarker(point);
	   map.addOverlay(marker);
      marker.openInfoWindowHtml('<b>Fundación everis</b>');
      }
    }
  );
}


var framesetQuery = "";
if ( window.top.location.search != 0 ) {
framesetQuery = window.top.location.search;
} else {
framesetQuery = "?OpenFrameset";
}

function getParameter ( queryString, parameterName ) {
// Add "=" to the parameter name (i.e. parameterName=value)
var parameterName = parameterName + "=";
if ( queryString.length > 0 ) {
// Find the beginning of the string
begin = queryString.indexOf ( parameterName );
// If the parameter name is not found, skip it, otherwise return the value
if ( begin != -1 ) {
// Add the length (integer) to the beginning
begin += parameterName.length;
// Multiple parameters are separated by the "&" sign
end = queryString.indexOf ( "&" , begin );
if ( end == -1 ) {
end = queryString.length
}
// Return the string
return unescape ( queryString.substring ( begin, end ) );
}
// Return "null" if no parameter has been found
return "null";
}
}

function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=966,height=661');");
}

