
//Si el navegador del cliente es Mozilla la variable siguiente valdrá true
var moz = document.getElementById && !document.all;

function bajaBoton(boton) {
	
	var elemento = $(boton);
	
	if(elemento.className != 'selMenu') {
		
		elemento.style.height = "36px";
		elemento.style.paddingTop = "32px";
	}

}

function subeBoton(boton) {
	
	var elemento = $(boton);
	
	if(elemento.className != 'selMenu') {
		elemento.style.paddingTop = 0;
		elemento.style.height = "71px";
	}
	
}

function getAbsoluteElementPosition(element) {
	
	if (typeof element == "string")
		element = document.getElementById(element)
	
	if (!element) return { top:0,left:0 };
	
	var y = 0;
	var x = 0;
	
	while (element.offsetParent) {
		x += element.offsetLeft;
		y += element.offsetTop;
		element = element.offsetParent;
	}
	
	return {top:y,left:x};
}

function muestraMenuFundacion(menu, referencia) {
	
	var pos = getAbsoluteElementPosition($(referencia));
	
	// leemos el alto dependiendo del menu
	var alto = dameAltoMenuFundacion(menu);
		
	$(menu).style.top = pos.top - alto;
	$(menu).style.left = pos.left;
	
	$(menu).style.display = "block";
	
}

function dameAltoMenuFundacion(menu) {
	
	switch(menu) {
		
		case 'contacta':
			return 123;
			break;		
			
		case 'centros':
			return 216;
			break;		
			
		case 'organizacion':
			return 92;
			break;		
			
	}
}

function muestraMenuAsociacion(menu, referencia) {
	
	var pos = getAbsoluteElementPosition($(referencia));
	
	// leemos el alto dependiendo del menu
	var alto = dameAltoMenuAsociacion(menu);
		
	$(menu).style.top = pos.top - alto;
	$(menu).style.left = pos.left;
	
	$(menu).style.display = "block";
	
}

function dameAltoMenuAsociacion(menu) {
	
	// alto de celda: 31
	
	switch(menu) {
		
		case 'contacta':
			return 155;
			break;		
			
		case 'difusion':
			return 62;
			break;		
			
		case 'servicios':
			return 93;
			break;		
			
		case 'organizacion':
			return 62;
			break;		
			
	}
}


function muestraMenuServicios(menu, referencia) {
	
	var pos = getAbsoluteElementPosition($(referencia));
	
	// leemos el alto dependiendo del menu
	var alto = dameAltoMenuServicios(menu);
		
	$(menu).style.top = pos.top - alto;
	$(menu).style.left = pos.left;
	
	$(menu).style.display = "block";
	
}

function dameAltoMenuServicios(menu) {
	
	// alto de celda: 31
	
	switch(menu) {
		
		case 'contacta':
			return 93;
			break;		

		
		case 'responsabilidad':
			return 62;
			break;		
			
		case 'servicios':
			return 186;
			break;		
			
		case 'organizacion':
			return 31;
			break;		
			
	}
}

function muestraMenuAcceso(menu, referencia) {
	
	var pos = getAbsoluteElementPosition($(referencia));
	
	// leemos el alto dependiendo del menu
	var alto = dameAltoMenuAcceso(menu);
		
	$(menu).style.top = pos.top - alto;
	$(menu).style.left = pos.left;
	
	$(menu).style.display = "block";
	
}

function dameAltoMenuAcceso(menu) {
	
	// alto de celda: 31
	
	switch(menu) {
		
		case 'juegos':
			return 93;
			break;		

		
		case 'musica':
			return 62;
			break;		
			
		case 'deportes':
			return 93;
			break;		
			
		case 'actualidad':
			return 31;
			break;		
			
	}
}


Event.observe(document, 'mousedown', ocultarSubmenus, false);

function ocultarSubmenus(e) {
	
	// comprobamos que no haya pulsado en un calendario (para no ocultarlo)
		
	//Obtenemos el elemento sobre el que se ha presionado el botón del ratón
	var fobj = moz ? e.target : event.srcElement;
	
	while (fobj.tagName.toLowerCase() != "html" && fobj.className != "menuSecundario") {
		fobj = moz ? fobj.parentNode : fobj.parentElement;
	}
	
	if (fobj.className == "menuSecundario") {
		return false;
	}
	
	var total = $$('.menuSecundario').length;
	
	for(x=0; x<total; x++) {
		$$('.menuSecundario')[x].hide();
	}
		
		
}

function comprobarDatosInformacion() {
	
	// comprobamos que ha completado todos los datos
	if($('nombre').value =="" || $('nombre').value == null) {
		alert("Debe indicar su nombre.");
		$('nombre').focus();
		return false;
	}
	
	if($('apellidos').value =="" || $('apellidos').value == null) {
		alert("Debe indicar sus apellidos.");
		$('apellidos').focus();
		return false;
	}
	
	if($('socio').value =="" || $('socio').value == null) {
		alert("Debe indicar su nº de socio.");
		$('socio').focus();
		return false;
	}
	
	if($('telefono').value =="" || $('telefono').value == null) {
		alert("Debe indicar su nº de teléfono.");
		$('telefono').focus();
		return false;
	}
	
	if($('localidad').value =="" || $('localidad').value == null) {
		alert("Debe indicar su localidad.");
		$('localidad').focus();
		return false;
	}
	
	if($('pregunta').value =="" || $('pregunta').value == null) {
		alert("Debe indicar su pregunta.");
		$('pregunta').focus();
		return false;
	}
	
	if($('email').value =="" || $('email').value == null) {
		alert("Debe indicar su email.");
		$('email').focus();
		return false;
	}
	
	formContacta.submit();
	return true;
	
}

function comprobarDatosInformacionServicios() {
	
	// comprobamos que ha completado todos los datos
	if($('nombre').value =="" || $('nombre').value == null) {
		alert("Debe indicar su nombre.");
		$('nombre').focus();
		return false;
	}
	
	if($('apellidos').value =="" || $('apellidos').value == null) {
		alert("Debe indicar sus apellidos.");
		$('apellidos').focus();
		return false;
	}
	
	if($('telefono').value =="" || $('telefono').value == null) {
		alert("Debe indicar su nº de teléfono.");
		$('telefono').focus();
		return false;
	}
	
	if($('localidad').value =="" || $('localidad').value == null) {
		alert("Debe indicar su localidad.");
		$('localidad').focus();
		return false;
	}
	
	if($('pregunta').value =="" || $('pregunta').value == null) {
		alert("Debe indicar su pregunta.");
		$('pregunta').focus();
		return false;
	}
	
	if($('email').value =="" || $('email').value == null) {
		alert("Debe indicar su email.");
		$('email').focus();
		return false;
	}
	
	formContacta.submit();
	return true;
	
}

function comprobarDatosPresupuestoServicios() {
	
	// comprobamos que ha completado todos los datos
	if($('nombre').value =="" || $('nombre').value == null) {
		alert("Debe indicar su nombre.");
		$('nombre').focus();
		return false;
	}
	
	if($('apellidos').value =="" || $('apellidos').value == null) {
		alert("Debe indicar sus apellidos.");
		$('apellidos').focus();
		return false;
	}
	
	if($('telefono').value =="" || $('telefono').value == null) {
		alert("Debe indicar su nº de teléfono.");
		$('telefono').focus();
		return false;
	}
	
	if($('localidad').value =="" || $('localidad').value == null) {
		alert("Debe indicar su localidad.");
		$('localidad').focus();
		return false;
	}
	
	if($('pregunta').value =="" || $('pregunta').value == null) {
		alert("Debe dar una descripción del trabajo.");
		$('pregunta').focus();
		return false;
	}
	
	if($('email').value =="" || $('email').value == null) {
		alert("Debe indicar su email.");
		$('email').focus();
		return false;
	}
	
	formContacta.submit();
	return true;
	
}


function comprobarDatosColabora() {
	
	// comprobamos que ha completado todos los datos
	if($('nombre').value =="" || $('nombre').value == null) {
		alert("Debe indicar su nombre.");
		$('nombre').focus();
		return false;
	}
	
	if($('apellidos').value =="" || $('apellidos').value == null) {
		alert("Debe indicar sus apellidos.");
		$('apellidos').focus();
		return false;
	}
	
	if($('telefono').value =="" || $('telefono').value == null) {
		alert("Debe indicar su nº de teléfono.");
		$('telefono').focus();
		return false;
	}
	
	if($('localidad').value =="" || $('localidad').value == null) {
		alert("Debe indicar su localidad.");
		$('localidad').focus();
		return false;
	}
	
	if($('email').value =="" || $('email').value == null) {
		alert("Debe indicar su email.");
		$('email').focus();
		return false;
	}
	
	
	if($('forma').value =="" || $('forma').value == null) {
		alert("Debe indicar como desea colaborar.");
		$('forma').focus();
		return false;
	}
	
	
	// el importe
	var importe = $('importe').value;
	if(importe =="0" || importe == null) {
		alert("Debe indicar el importe que desea donar.");
		$('importe').focus();
		return false;
	} else {
		
		// comprobamos que sea numerico
		importe = parseFloat(importe);
		
		if (isNaN(importe)) { 
			alert("El importe  " + $('importe').value + " no es válido.\nPor favor, introduce un valor correcto.");
			$('importe').focus();
			return false;
		}
		
	}
	
	if($('modoHidden').value =="0" || $('forma').value == null) {
		alert("Debe indicar el modo de donativo.");
		return false;
	}
	
	
	formContacta.submit();
	return true;
	
}

function comprobarDatosColaboraAsociacion() {
	
	// comprobamos que ha completado todos los datos
	if($('nombre').value =="" || $('nombre').value == null) {
		alert("Debe indicar su nombre.");
		$('nombre').focus();
		return false;
	}
	
	if($('apellidos').value =="" || $('apellidos').value == null) {
		alert("Debe indicar sus apellidos.");
		$('apellidos').focus();
		return false;
	}
	
	if($('telefono').value =="" || $('telefono').value == null) {
		alert("Debe indicar su nº de teléfono.");
		$('telefono').focus();
		return false;
	}
	
	if($('localidad').value =="" || $('localidad').value == null) {
		alert("Debe indicar su localidad.");
		$('localidad').focus();
		return false;
	}
	
	if($('fechaNacimiento').value =="" || $('fechaNacimiento').value == null) {
		alert("Debe indicar la fecha de nacimiento.");
		$('fechaNacimiento').focus();
		return false;
	}
	
	if($('forma').value =="" || $('forma').value == null) {
		alert("Debe indicar como desea colaborar.");
		$('forma').focus();
		return false;
	}
	
	if($('email').value =="" || $('email').value == null) {
		alert("Debe indicar su email.");
		$('email').focus();
		return false;
	}
	
	if($('modoHidden').value =="0" || $('forma').value == null) {
		alert("Debe indicar el modo de donativo.");
		return false;
	}
	
	
	formContacta.submit();
	return true;
	
}


function comprobarDatosSocioAsociacion() {
	
	// comprobamos que ha completado todos los datos
	if($('nombre').value =="" || $('nombre').value == null) {
		alert("Debe indicar su nombre.");
		$('nombre').focus();
		return false;
	}
	
	if($('apellidos').value =="" || $('apellidos').value == null) {
		alert("Debe indicar sus apellidos.");
		$('apellidos').focus();
		return false;
	}
	
	if($('fechaNacimiento').value =="" || $('fechaNacimiento').value == null) {
		alert("Debe indicar su fecha de nacimiento.");
		$('fechaNacimiento').focus();
		return false;
	}
	
	if($('telefono').value =="" || $('telefono').value == null) {
		alert("Debe indicar su nº de teléfono.");
		$('telefono').focus();
		return false;
	}
	
	if($('localidad').value =="" || $('localidad').value == null) {
		alert("Debe indicar su localidad.");
		$('localidad').focus();
		return false;
	}
	
	if($('email').value =="" || $('email').value == null) {
		alert("Debe indicar su email.");
		$('email').focus();
		return false;
	}
	
	
	if($('forma').value =="" || $('forma').value == null) {
		alert("Debe indicar como desea colaborar.");
		$('forma').focus();
		return false;
	}
	
	
	// el importe
	var importe = $('importe').value;
	if(importe =="0" || importe == null) {
		alert("Debe indicar el importe que desea donar.");
		$('importe').focus();
		return false;
	} else {
		
		// comprobamos que sea numerico
		importe = parseFloat(importe);
		
		if (isNaN(importe)) { 
			alert("El importe  " + $('importe').value + " no es válido.\nPor favor, introduce un valor correcto.");
			$('importe').focus();
			return false;
		}
		
	}
	
	if($('modoHidden').value =="0" || $('forma').value == null) {
		alert("Debe indicar el modo de donativo.");
		return false;
	}
	
	
	formContacta.submit();
	return true;
	
}


function cambiarModoDonativo(modo) {
	
	// cambiamos el modo
	
	$('modoHidden').value = modo;
	
	$('cuadro1').style.backgroundColor = "white";
	$('cuadro3').style.backgroundColor = "white";
	
	
	$('cuadro' + modo).style.backgroundColor = "#731D34";
	
	
}

function comprobarDatosVoluntario() {
	
	// comprobamos que ha completado todos los datos
	if($('nombre').value =="" || $('nombre').value == null) {
		alert("Debe indicar su nombre.");
		$('nombre').focus();
		return false;
	}
	
	if($('apellidos').value =="" || $('apellidos').value == null) {
		alert("Debe indicar sus apellidos.");
		$('apellidos').focus();
		return false;
	}
	
	if($('fechaNacimiento').value =="" || $('fechaNacimiento').value == null) {
		alert("Debe indicar su fecha de Nacimiento.");
		$('fechaNacimiento').focus();
		return false;
	}
	
	if($('telefono').value =="" || $('telefono').value == null) {
		alert("Debe indicar su nº de teléfono.");
		$('telefono').focus();
		return false;
	}
	
	if($('localidad').value =="" || $('localidad').value == null) {
		alert("Debe indicar su localidad.");
		$('localidad').focus();
		return false;
	}
	
	if($('formacion').value =="" || $('formacion').value == null) {
		alert("Debe indicar su formación.");
		$('formacion').focus();
		return false;
	}
	
	if($('fechaEstudios').value =="" || $('fechaEstudios').value == null) {
		alert("Debe indicar su fecha de finalización de estudios.");
		$('fechaEstudios').focus();
		return false;
	}
	
	if($('email').value =="" || $('email').value == null) {
		alert("Debe indicar su email.");
		$('email').focus();
		return false;
	}
	
	formContacta.submit();
	return true;
	
}


function comprobarDatosVoluntarioAsociacion() {
	
	// comprobamos que ha completado todos los datos
	if($('nombre').value =="" || $('nombre').value == null) {
		alert("Debe indicar su nombre.");
		$('nombre').focus();
		return false;
	}
	
	if($('apellidos').value =="" || $('apellidos').value == null) {
		alert("Debe indicar sus apellidos.");
		$('apellidos').focus();
		return false;
	}
	
	if($('fechaNacimiento').value =="" || $('fechaNacimiento').value == null) {
		alert("Debe indicar su fecha de Nacimiento.");
		$('fechaNacimiento').focus();
		return false;
	}
	
	if($('telefono').value =="" || $('telefono').value == null) {
		alert("Debe indicar su nº de teléfono.");
		$('telefono').focus();
		return false;
	}
	
	if($('localidad').value =="" || $('localidad').value == null) {
		alert("Debe indicar su localidad.");
		$('localidad').focus();
		return false;
	}
	
	if($('formacion').value =="" || $('formacion').value == null) {
		alert("Debe indicar su formación.");
		$('formacion').focus();
		return false;
	}

	if($('email').value =="" || $('email').value == null) {
		alert("Debe indicar su email.");
		$('email').focus();
		return false;
	}
	
	formContacta.submit();
	return true;
	
}

function comprobarDatosTrabaja() {
	
	// comprobamos que ha completado todos los datos
	if($('nombre').value =="" || $('nombre').value == null) {
		alert("Debe indicar su nombre.");
		$('nombre').focus();
		return false;
	}
	
	if($('apellidos').value =="" || $('apellidos').value == null) {
		alert("Debe indicar sus apellidos.");
		$('apellidos').focus();
		return false;
	}
	
	if($('fechaNacimiento').value =="" || $('fechaNacimiento').value == null) {
		alert("Debe indicar su fecha de Nacimiento.");
		$('fechaNacimiento').focus();
		return false;
	}
	
	if($('telefono').value =="" || $('telefono').value == null) {
		alert("Debe indicar su nº de teléfono.");
		$('telefono').focus();
		return false;
	}
	
	if($('localidad').value =="" || $('localidad').value == null) {
		alert("Debe indicar su localidad.");
		$('localidad').focus();
		return false;
	}
	
	if($('formacion').value =="" || $('formacion').value == null) {
		alert("Debe indicar su formación.");
		$('formacion').focus();
		return false;
	}
	
	if($('fechaEstudios').value =="" || $('fechaEstudios').value == null) {
		alert("Debe indicar su fecha de finalización de estudios.");
		$('fechaEstudios').focus();
		return false;
	}
	
	if($('email').value =="" || $('email').value == null) {
		alert("Debe indicar su email.");
		$('email').focus();
		return false;
	}
	
	formContacta.submit();
	return true;
	
}


function mostrarProteccionDatos() {
	
	if($('textoProteccionDatos').style.display!="block") {
		
		var pos = getAbsoluteElementPosition($('proteccionDatos'));
		
		if(moz) {
			
			$('textoProteccionDatos').style.top = pos.top - 514;
			$('textoProteccionDatos').style.left = pos.left - 292;
			
		} else {
				
			$('textoProteccionDatos').style.top = pos.top - 550;
			$('textoProteccionDatos').style.left = pos.left - 230;
		}
		
		$('textoProteccionDatos').style.display="block";
	}
	
}

function ocultarProteccionDatos() {

	if($('textoProteccionDatos').style.display!="none") {
		$('textoProteccionDatos').style.display="none";
	}	

}

contImagen=0;
contFile=0;

function mostrarAddFile() {
		
	cont = document.getElementById('UploadFile');
	var eleNew=document.createElement('span');
	eleNew.innerHTML += "<a href='javascript: addFile(10);' >Añadir un archivo adjunto</a>";
	cont.appendChild(eleNew);
	
}

function addFile(total)
{
	sw=0;
	sw2=0;
	
	x=document.getElementsByTagName("input");
	y=document.getElementsByTagName("img");
	
	for(i=0;i<x.length;i++)
	{
		if(x[i].type=="file")
		{
			sw++;	
		}
	}
	
	for(i=0;i<y.length;i++)
	{
		if(y[i].id=="archivoSubida[]")
		{
			sw2++;	
		}
	}
	
	
	if(sw<(total-sw2))
	{
		cont = document.getElementById('UploadFile2');
		var eleNew=document.createElement('span');
	   	eleNew.setAttribute('id','contFile'+contFile);
	   	eleNew.setAttribute('style','display: block;');
		eleNew.innerHTML += "<input type='file' name='archivoSubida[]' /><a href='javascript: removeFile(\"contFile"+contFile+"\");' >Eliminar</a><br />";
		cont.appendChild(eleNew);
		contFile++;
	}
}

function removeFile(nodo)
{
        cont = document.getElementById('UploadFile2');
        cont.removeChild(document.getElementById(nodo));
}

function mostrarAddImagen() {
		
	cont = document.getElementById('ImageFile');
	var eleNew=document.createElement('span');
	eleNew.innerHTML += "<a href='javascript: addImagen(10);' >Añadir una imagen</a><BR>";
	cont.appendChild(eleNew);
	
}

function addImagen(total)
{
	sw=0;
	sw2=0;
	
	x=document.getElementsByTagName("input");
	y=document.getElementsByTagName("img");
	
	for(i=0;i<x.length;i++)
	{
		if(x[i].type=="file")
		{
			sw++;	
		}
	}
	
	for(i=0;i<y.length;i++)
	{
		if(y[i].id=="imagenSubida[]")
		{
			sw2++;	
		}
	}
	
	
	if(sw<(total-sw2))
	{
		cont = document.getElementById('ImageFile2');
		var eleNew=document.createElement('span');
	   	eleNew.setAttribute('id','contImg'+contImagen);
	   	eleNew.setAttribute('style','display: block;');
		eleNew.innerHTML += "<span class='labelForm'>Imagen:</span><input type='file' name='imagenSubida[]' /><br />";
		eleNew.innerHTML += "<span class='labelForm'>Pie de foto:</span><input type='text' name='pieFoto[]' style='width: 100%;' /><br />";
		eleNew.innerHTML += "<a href='javascript: removeImagen(\"contImg"+contImagen+"\");' >Eliminar</a><div class='margen1'></div>";
		
		cont.appendChild(eleNew);
		contImagen++;
	}
}

function removeImagen(nodo)
{
        cont = document.getElementById('ImageFile2');
        cont.removeChild(document.getElementById(nodo));
}

function addFavoritos() {
	
	if (document.all) {
		external.AddFavorite("http://www.fgarciagil.org", "Fundación García Gil") 
	} else {
		alert("Para agregar fgarciagil.org a favoritos, pulsa las teclas CONTROL + D en el teclado."); 
	}
}

