
function MM_preloadImages() {
	var d=document; 
	if(d.images){ 
		if(!d.MM_p) 
			d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; 
	for(i=0; i<a.length; i++)
		if (a[i].indexOf("#")!=0){ 
			d.MM_p[j]=new Image; 
			d.MM_p[j++].src=a[i];
		}
	}
}


function desactivarMenuSuperior(id){
	document.getElementById(id).style.visibility = 'hidden';
}

function activarMenuSuperior(id){

	document.getElementById('alcaudete').style.visibility = 'hidden';	
	document.getElementById('ayuntamiento').style.visibility = 'hidden';		
	document.getElementById('turismoydesarrollo').style.visibility = 'hidden';	
	document.getElementById('culturayocio').style.visibility = 'hidden';	
	document.getElementById('servicios').style.visibility = 'hidden';
	
	document.getElementById(id).style.visibility = 'visible';
	
	if(id == 'alcaudete'){
		document.getElementById(id).style.left = '365px';
		document.getElementById(id).style.top = '15px';
		document.getElementById(id).style.height = '150px';
		document.getElementById(id).style.width = '110px';
	}else if(id == 'ayuntamiento'){
		document.getElementById(id).style.left = '530px';
		document.getElementById(id).style.top = '103px';
		document.getElementById(id).style.width = '120px';
	}else if(id == 'turismoydesarrollo'){
		document.getElementById(id).style.left = '540px';
		document.getElementById(id).style.top = '107px';	
		document.getElementById(id).style.height = '130px';
		document.getElementById(id).style.width = '115px';
	}else if(id == 'culturayocio'){
		document.getElementById(id).style.left = '540px';
		document.getElementById(id).style.top = '195px';	
		document.getElementById(id).style.height = '200px';
		document.getElementById(id).style.width = '115px';
	}else if(id == 'servicios'){			
		document.getElementById(id).style.left = '738px';
		document.getElementById(id).style.top = '15px';	
		document.getElementById(id).style.width = '160px';
	}
	
}

function selMenuIzquierdaAlcaudete(){
	document.getElementById('botonAlcaudete').style.backgroundImage = 'url(css/img/botonMenuIzquierdaOn1.gif)';
	
	document.getElementById('botonAyuntamiento').style.backgroundImage = 'url(css/img/botonAyuntamientoOff.gif)';
	document.getElementById('botonServicios').style.backgroundImage = 'url(css/img/botonServiciosOff.gif)';
	document.getElementById('botonTurismoyDesarrollo').style.backgroundImage = 'url(css/img/botonTurismoyDesarrolloOff.gif)';	
	document.getElementById('botonCulturayOcio').style.backgroundImage = 'url(css/img/botonCulturayOcioOff.gif)';
}

function selMenuIzquierdaAyuntamiento(){
	document.getElementById('botonAyuntamiento').style.backgroundImage = 'url(css/img/botonMenuIzquierdaOn1.gif)';
	
	document.getElementById('botonServicios').style.backgroundImage = 'url(css/img/botonServiciosOff.gif)';
	document.getElementById('botonTurismoyDesarrollo').style.backgroundImage = 'url(css/img/botonTurismoyDesarrolloOff.gif)';	
	document.getElementById('botonCulturayOcio').style.backgroundImage = 'url(css/img/botonCulturayOcioOff.gif)';
	document.getElementById('botonAlcaudete').style.backgroundImage = 'url(css/img/botonAlcaudeteOff.gif)';
}

function selMenuIzquierdaServicios(){
	document.getElementById('botonServicios').style.backgroundImage = 'url(css/img/botonServiciosOn.gif)';
	
	document.getElementById('botonAyuntamiento').style.backgroundImage = 'url(css/img/botonAyuntamientoOff.gif)';	
	document.getElementById('botonTurismoyDesarrollo').style.backgroundImage = 'url(css/img/botonTurismoyDesarrolloOff.gif)';	
	document.getElementById('botonCulturayOcio').style.backgroundImage = 'url(css/img/botonCulturayOcioOff.gif)';
	document.getElementById('botonAlcaudete').style.backgroundImage = 'url(css/img/botonAlcaudeteOff.gif)';
}

function selMenuIzquierdaTurismoyDesarrollo(){
	document.getElementById('botonTurismoyDesarrollo').style.backgroundImage = 'url(css/img/botonMenuIzquierdaOn2.gif)';
	
	document.getElementById('botonAyuntamiento').style.backgroundImage = 'url(css/img/botonAyuntamientoOff.gif)';
	document.getElementById('botonServicios').style.backgroundImage = 'url(css/img/botonServiciosOff.gif)';
	document.getElementById('botonCulturayOcio').style.backgroundImage = 'url(css/img/botonCulturayOcioOff.gif)';
	document.getElementById('botonAlcaudete').style.backgroundImage = 'url(css/img/botonAlcaudeteOff.gif)';	
}

function selMenuIzquierdaCulturayOcio(){
	document.getElementById('botonCulturayOcio').style.backgroundImage = 'url(css/img/botonMenuIzquierdaOn2.gif)';
	
	document.getElementById('botonAyuntamiento').style.backgroundImage = 'url(css/img/botonAyuntamientoOff.gif)';
	document.getElementById('botonServicios').style.backgroundImage = 'url(css/img/botonServiciosOff.gif)';
	document.getElementById('botonTurismoyDesarrollo').style.backgroundImage = 'url(css/img/botonTurismoyDesarrolloOff.gif)';	
	document.getElementById('botonAlcaudete').style.backgroundImage = 'url(css/img/botonAlcaudeteOff.gif)';	
}

function selMenuSuperiorAlcaudete(id){
	document.getElementById('botonPresentacion').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonSituacion').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonHistoria').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonGuiaTuristica').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonImagenes').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	
	document.getElementById('botonPresentacion').style.color = '#E7DBB3';
	document.getElementById('botonSituacion').style.color = '#E7DBB3';
	document.getElementById('botonHistoria').style.color = '#E7DBB3';
	document.getElementById('botonGuiaTuristica').style.color = '#E7DBB3';
	document.getElementById('botonImagenes').style.color = '#E7DBB3';
	
	document.getElementById(id).style.backgroundImage = 'url(css/img/botonMenuSuperiorOn.gif)';		
	document.getElementById(id).style.color = '#FFC600';		
}

function selMenuSuperiorAyuntamiento(id){
	document.getElementById('botonDireccionesyTelefonos').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonOrganizacion').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonAlcaldiayConcejalias').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonPlenodelaCorporacion').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonAreas').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonNormativa').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonTablondeAnuncios').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	
	document.getElementById('botonDireccionesyTelefonos').style.color = '#E7DBB3';
	document.getElementById('botonOrganizacion').style.color = '#E7DBB3';
	document.getElementById('botonAlcaldiayConcejalias').style.color = '#E7DBB3';
	document.getElementById('botonPlenodelaCorporacion').style.color = '#E7DBB3';
	document.getElementById('botonAreas').style.color = '#E7DBB3';
	document.getElementById('botonNormativa').style.color = '#E7DBB3';
	document.getElementById('botonTablondeAnuncios').style.color = '#E7DBB3';
	
	document.getElementById(id).style.backgroundImage = 'url(css/img/botonMenuSuperiorOn.gif)';		
	document.getElementById(id).style.color = '#FFC600';	
}

function selMenuSuperiorServicios(id){
	document.getElementById('botoneAdministracion').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonNoticias').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonEmpleo').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonParticipacionCiudadana').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonCursosyJornadas').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonAlertas').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonEnlaces').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	
	document.getElementById('botoneAdministracion').style.color = '#E7DBB3';
	document.getElementById('botonNoticias').style.color = '#E7DBB3';
	document.getElementById('botonEmpleo').style.color = '#E7DBB3';
	document.getElementById('botonParticipacionCiudadana').style.color = '#E7DBB3';
	document.getElementById('botonCursosyJornadas').style.color = '#E7DBB3';
	document.getElementById('botonAlertas').style.color = '#E7DBB3';
	document.getElementById('botonEnlaces').style.color = '#E7DBB3';
	
	document.getElementById(id).style.backgroundImage = 'url(css/img/botonMenuSuperiorOn.gif)';		
	document.getElementById(id).style.color = '#FFC600';			
}

function selMenuSuperiorTurismoyDesarrollo(id){
	document.getElementById('botonEmpresas').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonAgendaTurismo').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonTurismoActivo').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonMedioAmbiente').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	

	document.getElementById('botonEmpresas').style.color = '#E7DBB3';
	document.getElementById('botonAgendaTurismo').style.color = '#E7DBB3';
	document.getElementById('botonTurismoActivo').style.color = '#E7DBB3';
	document.getElementById('botonMedioAmbiente').style.color = '#E7DBB3';
	
	document.getElementById(id).style.backgroundImage = 'url(css/img/botonMenuSuperiorOn.gif)';		
	document.getElementById(id).style.color = '#FFC600';
}

function selMenuSuperiorCulturayOcio(id){
	document.getElementById('botonActividadesCulturales').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonDeporte').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonJuventud').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonlaCasadelaCultura').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonlaBandaMunicipal').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	
	document.getElementById('botonAgenda').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';	

	document.getElementById('botonActividadesCulturales').style.color = '#E7DBB3';
	document.getElementById('botonDeporte').style.color = '#E7DBB3';
	document.getElementById('botonJuventud').style.color = '#E7DBB3';
	document.getElementById('botonlaCasadelaCultura').style.color = '#E7DBB3';
	document.getElementById('botonlaBandaMunicipal').style.color = '#E7DBB3';
	document.getElementById('botonAgenda').style.color = '#E7DBB3';
	
	document.getElementById(id).style.backgroundImage = 'url(css/img/botonMenuSuperiorOn.gif)';		
	document.getElementById(id).style.color = '#FFC600';
}
function selMenuDerechaDatosUsuario(){
	document.getElementById('botonSalirCiudadano').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';
	document.getElementById('botonDatosCiudadano').style.backgroundImage = 'url(css/img/botonMenuSuperiorOn.gif)';
	document.getElementById('botonDatosCiudadano').style.color = '#FFC600';	
}
function selMenuDerechaSalir(){
	document.getElementById('botonDatosCiudadano').style.backgroundImage = 'url(css/img/botonMenuSuperiorOff.gif)';
	document.getElementById('botonSalirCiudadano').style.backgroundImage = 'url(css/img/botonMenuSuperiorOn.gif)';
	document.getElementById('botonSalirCiudadano').style.color = '#FFC600';	
}


function AbrirImagenVentana(ruta_imagen)
{
	img = new Image();
	img.src = ruta_imagen;
	
	alto = img.height;
	ancho = img.width;
	
	if(ancho>=screen.width)
    ancho=screen.width*0.7;

	if(alto>=screen.height)
    alto=screen.height*0.7;
	
	medio_x = screen.width/2;
	medio_y = screen.height/2;
	
	pos_x = medio_x - ancho/2;
	pos_y = medio_y - alto/2;
	
	
	window.open(ruta_imagen, '_blank', 'toolbar=no, location=no, directories=no, status=no, scrollbars=auto, resizable=no, copyhistory=no, width=' + ancho + ', height=' + alto + ', left=0,top=0');
}

//-------------------------------------------------------------------------//
function EnviarDatos(accion, validar,clase)
{   
	var confirmacion = new Boolean(true);
	
	if(accion=='eliminar'){
		confirmacion = confirm('Confirmar eliminacion');	
	}
	if(confirmacion){
		if(validar)
		{
			if(ValidarFormulario(document.getElementById('formulario')))
			{
				document.getElementById('accion').value = accion;
				document.getElementById('clase').value=clase;
				document.formulario.submit();
				return true;
			}
			else
			{	
				alert('Debe completar los campos con *');
				return false;
			}
		}
		else
		{   
			document.getElementById('accion').value = accion;
			document.getElementById('clase').value = clase;
			document.formulario.submit();
			return true;
		}
	}
}

//-----------------------------------------------------------------------------------//

function ValidarFormulario(formulario)
{
    var indiceMenor;
	for (i = 0; i < document.getElementById('formulario').length; i++)
	{
		var elemento = formulario.elements[i];
		var completo, correcto, longitudminima;

		completo = true;
		correcto = true;
		longitudminima = true;

		if (elemento.title != null && elemento.title.charAt(0) == '*'){		
			if ( ((elemento.type == 'file' || elemento.type == 'hidden' || elemento.type == 'text' || elemento.type == 'textarea' || elemento.type == 'password' || elemento.type.toString().indexOf('select') >= 0 )
			&& (Trim(elemento.value).length) <= 0 || (elemento.type.toString().indexOf('select') >= 0 && (elemento.value == 0 || elemento.value == '' || elemento.selectedIndex == -1))))
			{	
				completo = false;
			}
		}

		/*
		Añadimos ademas la comprobación de cada campo del formulario en base al tipo de datos que debe
		contener para asegurarnos que el formato es correcto, además de si la longitud del mismo es la
		mínima exigida.
		Para ellos utilizaremos los siguientes tipos de datos
		int, float, date, email
		*/
		if (completo && elemento.minlength != null && elemento.title.charAt(0) == '*')
		{
			if ( elemento.type.toLowerCase() == 'text'  && Trim(elemento.value).length < Number(elemento.minlength))
				longitudminima = false;
		}
		if (completo && longitudminima && elemento.tipo != null){
          	if ( elemento.type.toLowerCase() == 'text'  && elemento.value.length > 0){
				if (elemento.tipo.toLowerCase() == 'date') correcto = isDate(elemento.value);
			 	if (elemento.tipo.toLowerCase() == 'int') correcto = isInteger(elemento.value);
			 	if (elemento.tipo.toLowerCase() == 'url'){
                      correcto = (elemento.value.toLowerCase().indexOf('http://') >= 0 && elemento.value.toLowerCase().indexOf('.') >= 0 && elemento.value.length > 7);

                    }
			 	if (elemento.tipo.toLowerCase() == 'tlf'){
					if (isInteger(elemento.value) && elemento.value.length>=9 )
						correcto = true;
					else{
						alert('El formato de teléfono del campo "' + elemento.title.substring(elemento.title.charAt(0) == '*' ? 1:0, elemento.title.length) + '" es incorrecto');
						return false;
					}
			 	}
			 	if (elemento.tipo.toLowerCase() == 'float') correcto = isFloat(elemento.value);
			 	if (elemento.tipo.toLowerCase() == 'email') correcto = validarEmail(elemento.value);
    			     if (elemento.tipo.toLowerCase() == 'nif')   correcto = (validarNif(elemento.value)==elemento.value);
			}
		}
		if (!completo)
		{
			//alert('El campo "' + elemento.title.substring(elemento.title.charAt(0) == '*' ? 1:0, elemento.title.length) + '" es obligatorio');
			return false;
		}

		if (! longitudminima)
		{
			alert('El campo "' + elemento.title.substring(elemento.title.charAt(0) == '*' ? 1:0, elemento.title.length) + '" ha de tener una longitud mínima de ' + elemento.minlength + ' caracteres');
			return false;
		}

		if (!correcto)
		{
			alert('El formato del campo "' + elemento.title.substring(elemento.title.charAt(0) == '*' ? 1:0, elemento.title.length) + '" es incorrecto');
			return false;
		}
	}

	return true;
}
//-----------------------------------------------------------------------------------//
function TrimIzquierda(cadena)
{
	var resultado = "";
	var i = len = 0;

	if (cadena+"" == "undefined" || cadena == null)
	return null;

	cadena += "";

	if (cadena.length == 0)
		resultado = "";
	else
	{
		len = cadena.length;

	 while ((i <= len) && (cadena.charAt(i) == " "))
		i++;

		resultado = cadena.substring(i, len);
	}

	return resultado;
}
//-----------------------------------------------------------------------------------//
function TrimDerecha(cadena)
{
	var resultado = "";
	var i = 0;

	if (cadena+"" == "undefined" || cadena == null)
		return null;

	cadena += "";

	if (cadena.length == 0)
		resultado = "";
	else
	{
	i = cadena.length - 1;
	while ((i >= 0) && (cadena.charAt(i) == " "))
			i--;

	 resultado = cadena.substring(0, i + 1);
	}

	return resultado;
}
//-----------------------------------------------------------------------------------//
function Trim(cadena)
{
	cadena = TrimIzquierda(cadena);
	cadena = TrimDerecha(cadena);

	return cadena;
}

//-----------------------------------------------------------------------------------//
