function buscar(texto,caracter) // BUSCA UN CARACTER Y DEVUELVE SU POSICIÓN
{
	for(i=0;i<texto.length;i++)
	{
		if(texto.charAt(i)==caracter) return i;
	}
	return false
}

function nombre_archivo(ruta) //PERMITE SACAR EL NOMBRE DE UN ARCHIVO DE UNA URL
{
	var nombre = ruta.split("").reverse().join("");
	posicion=buscar(nombre,"/");
	nombre = nombre.substring(0,posicion);
	nombre = nombre.split("").reverse().join("");
	return nombre;
}
function menu_animacion_dentro(imagen)
{
	if(imagen=='img_inscripcion')
	{
		document.getElementById(imagen).src='./_img/inscripcion_1.jpg';
		document.getElementById('etiqueta_inscripcion').style.background='#dd862f';
	}
	if(imagen=='img_ite')
	{
		document.getElementById('img_ite').src='./_img/ite_1.jpg';
		document.getElementById('etiqueta_ite').style.background='#dd862f';
	}
	if(imagen=='img_recursos')
	{
		document.getElementById('img_recursos').src='./_img/recursos_1.jpg';
		document.getElementById('etiqueta_recursos').style.background='#dd862f';
	}
	if(imagen=='img_media')
	{
		document.getElementById('img_media').src='./_img/media_1.jpg';
		document.getElementById('etiqueta_media').style.background='#dd862f';
	}
	if(imagen=='img_anteriores')
	{
		document.getElementById('img_anteriores').src='./_img/edanteriores_1.jpg';
		document.getElementById('etiqueta_anteriores').style.background='#dd862f';
	}
	if(imagen=='img_participantes')
	{
		document.getElementById('img_participantes').src='./_img/participantes_1.jpg';
		document.getElementById('etiqueta_participantes').style.background='#dd862f';
	}
}
function menu_animacion_fuera(imagen)
{
	if(imagen=='img_inscripcion')
	{
		document.getElementById(imagen).src='./_img/inscripcion_2.jpg';
		document.getElementById('etiqueta_inscripcion').style.background='#000';
	}
	if(imagen=='img_ite')
	{
		document.getElementById('img_ite').src='./_img/ite_2.jpg';
		document.getElementById('etiqueta_ite').style.background='#000';
	}
	if(imagen=='img_recursos')
	{
		document.getElementById('img_recursos').src='./_img/recursos_2.jpg';
		document.getElementById('etiqueta_recursos').style.background='#000';
	}
	if(imagen=='img_media')
	{
		document.getElementById('img_media').src='./_img/media_2.jpg';
		document.getElementById('etiqueta_media').style.background='#000';
	}
	if(imagen=='img_anteriores')
	{
		document.getElementById('img_anteriores').src='./_img/edanteriores_2.jpg';
		document.getElementById('etiqueta_anteriores').style.background='#000';
	}
	if(imagen=='img_participantes')
	{
		document.getElementById('img_participantes').src='./_img/participantes_2.jpg';
		document.getElementById('etiqueta_participantes').style.background='#000';
	}
}
function mostrar_ocultar_submenu(id_capa,ncapas)
{
	if (ncapas>=1)
	{
		document.getElementById('submenu_1').style.display = "none";
		document.getElementById('enlace_1').style.textDecoration  = "none";
	}
	if (ncapas>=2)
	{
		document.getElementById('submenu_2').style.display = "none";
		document.getElementById('enlace_2').style.textDecoration  = "none";
	}
	if (ncapas>=3)
	{
		document.getElementById('submenu_3').style.display = "none";
		document.getElementById('enlace_3').style.textDecoration  = "none";
	}
	if
	(ncapas>=4)
	{
		document.getElementById('submenu_4').style.display = "none";
		document.getElementById('enlace_4').style.textDecoration  = "none";
	}
	if (ncapas>=5)
	{
		document.getElementById('submenu_5').style.display = "none";
		document.getElementById('enlace_5').style.textDecoration  = "none";
	}
	document.getElementById('submenu_'+id_capa).style.display = "block";
	document.getElementById('enlace_'+id_capa).style.textDecoration  = "underline";
	/*
	<a href="javascript: mostrar_ocultar_submenu('id_capa','2')">Mostrar/Ocultar capa.</a>
	*/
}
function ir_a(ruta)
{
	window.location.href = ruta;
}
function ir_a_nueva(ruta)
{
	window.location.href = ruta;
}
function pasarMayusculas(cadena) {
	var result="";
	var str = cadena.split('');
	for(i=0; i<=str.length-1; i++) {
		str[i] = str[i].toUpperCase();
		result+=str[i];
	}
	return result;
}

function validarDNI (dni)
{
	if(dni.substr(0,1)=='X') {
		dni=dni.substr(1,dni.length);
	}
	numero = dni.substr(0,dni.length-1);
	let = dni.substr(dni.length-1,1);
	numero = numero % 23;
	letra='TRWAGMYFPDXBNJZSQVHLCKET';
	letra=letra.substring(numero,numero+1);
	if (letra!=let)
	{
		return 0;
	}
	else
	{
		return 1;
	}
}
function validar_votacion()
{
	document.getElementById('dni').value=pasarMayusculas(document.getElementById('dni').value);
	var a = document.getElementById('a').checked;
	var b = document.getElementById('b').checked;
	var c = document.getElementById('c').checked;
	var d = document.getElementById('d').checked;
	var e = document.getElementById('e').checked;
	var f = document.getElementById('f').checked;
	if(validarDNI (document.getElementById('dni').value)==0)
	{
		alert('El formato de el NIF/NIE es incorrecto.\nAsegurese de introducir un NIF del tipo 01234567A, o un NIE del tipo X01234567A');
		return 0;
	}
	if(!a && !b && !c && !d && !e && !f)
	{
		alert('Debes marcar tu votación.');
		return 0;
	}
	return 1;
}

