if (document.images) {
  var activado = new Array();
  var desactivado = new Array();
  for (i=1; i<=20; i++) {
    desactivado["menu_"+i] = new Image();
    desactivado["menu_"+i].src = "imagenes/menu/menu_"+i+"_off.png";
    activado["menu_"+i] = new Image();
    activado["menu_"+i].src = "imagenes/menu/menu_"+i+"_on.png";
  }
}

function load() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl()); 
		map.addControl(new GMapTypeControl());       
		map.setCenter(new GLatLng(43.542496,-5.666597), 16);
		var point = new GPoint(-5.666597, 43.542496);
		var marker = new GMarker(point);
		GEvent.addListener(marker, "click", function() {
    			marker.openInfoWindowHtml("<img src='imagenes/gei-servicios-de-asesoria-fiscal-laboral-y-contable-logo-contacto.jpg'>");});
		map.addOverlay(marker);
		//gijon
		map.setMapType(G_SATELLITE_TYPE);
	}
}

function act(nombreImagen) {
  if (document.images) {
    document[nombreImagen].src=activado[nombreImagen].src;
  }
}

function desact(nombreImagen) {
  if (document.images) {
    document[nombreImagen].src=desactivado[nombreImagen].src;
  }
}

function mostrar_elemento(id,clase){
	$("#listado li a").removeClass('marcado');
	$("#enlace_"+id).addClass('marcado');
	$("."+clase).hide();
	$("#elemento_"+id).fadeIn(400);
}

function validar_formulario(f,direccion){
	var filters = {
		obligatorio: function(el) {return ($(el).val() != '' && $(el).val() != -1);},
		email: function(el) {return /^[A-Za-z_\.][A-Za-z0-9_\.]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/.test($(el).val());},
		telefono: function(el){return /^[0-9]*$/.test($(el).val());}
	};

	$.extend({
		stop: function(e){
		   if (e.preventDefault) e.preventDefault();
		   if (e.stopPropagation) e.stopPropagation();
		}
	});
	
	if (typeof filters == 'undefined') return;
    
	$('#'+f).find("input, textarea, select").each(function(x,el){
        if ($(el).attr("className") != 'undefined') {
        	$.each(new String($(el).attr("className")).split(" "), function(x, klass){
        		if ($.isFunction(filters[klass]))
        			if (!filters[klass](el)){
        				$(el).addClass("error");
        			} else $(el).removeClass("error");
        	});
        }
    });
	
	if ($('#'+f).find(".error").size() > 0) {
		//$.stop(e || window.event);
		alert('Los campos marcados con (*) son obligatorios.');
		return false;
	} else {
		$('#'+f).attr('action',direccion);
		$('#'+f).submit();
	}
}

function isEmailAddress(theElement, nombre_del_elemento ) {
	var s = theElement.value;
	var  filter=/^[A-Za-z][A-Za-z0-9_\.-]*@[A-Za-z0-9_]+.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) {
		return true;
	}
	if (filter.test(s)) {
		return true;
	} else alert("Ingrese una dirección de correo válida");
	theElement.focus();
	return false;
}

function mail(texto){
	var mailres = true;            
	var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
	var arroba = texto.indexOf("@",0);
	var punto = texto.lastIndexOf(".");
	if ((texto.lastIndexOf("@")) != arroba){
		arroba = -1;
	}
	var contador=0;
	while (contador<texto.length){
		if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
			mailres = false;
		} else contador++;
	}
	if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1)){
		mailres = true;
	} else mailres = false;
	return mailres;
}

function validar() {
	n=document.getElementById('nombre').value;
	a=document.getElementById('apellidos').value;
	e=document.getElementById('edad').value;
	nif=document.getElementById('nif').value;
	c=document.getElementById('ciudad').value;
	t=document.getElementById('telefono').value;
	em=document.getElementById('email').value;
	num=document.getElementById('numero').value;
	if ((n=='')||(a=='')||(e=='')||(nif=='')||(c=='')||(t=='')||(em=='')||(n=='')){
		alert("Todos los campos marcados son obligatorios.");
	} else {
		if (!mail(em)){
			alert("El email debe tener un formato válido.");
		} else {
			if ((num>0)&&(num<=20)){
				document.getElementById('formulario').action = '#';
				document.getElementById('formulario').submit();
			} else alert("El número de personas debe estar entre 0 y 20.");
		}
	}
}
