/*Borra los campos del formulario de alta de socio*/
function borrarFormularioAltaSocio()
{
	document.getElementById('nombre').value = "";
	document.getElementById('apellidos').value = "";
	document.getElementById('dni').value = "";
	document.getElementById('fecnac').value = "";
	document.getElementById('direccion').value = "";
	document.getElementById('cp').value = "";
	document.getElementById('ciudad').value = "";
	document.getElementById('provincia').value = "";
	document.getElementById('telefono').value = "";
	document.getElementById('movil').value = "";
	document.getElementById('correo').value = "";
	
}


/*Borra los campos del formulario de alta de socio*/
function validarFormularioAltaSocio()
{
	if (document.getElementById('nombre').value == "")
	{
		alert('El campo nombre es obligatorio');
		document.getElementById('nombre').focus();
		return 0;
	}
	if (document.getElementById('apellidos').value == "")
	{
		alert('El campo apellidos es obligatorio');
		document.getElementById('apellidos').focus();
		return 0;		
	}
	if (document.getElementById('dni').value == "")
	{
		alert('El campo dni es obligatorio');
		document.getElementById('dni').focus();
		return 0;
	}
	if (document.getElementById('fecnac').value == "")
	{
		alert('El campo fecha de nacimiento es obligatorio');
		document.getElementById('fecnac').focus();
		return 0;		
	}
	else 
	{
		fecval = esFechaValida(document.getElementById('fecnac').value);
		if (fecval == 1)
		{
			alert('El formato de la fecha no es correcto. Debe ser dd/mm/aaaa');
			document.getElementById('fecnac').focus();
			return 0;	
		}
		if (fecval == 2)
		{
			alert('La fecha no es válida');
			document.getElementById('fecnac').focus();
			return 0;	
		}
	}
	if (document.getElementById('direccion').value == "")
	{
		alert('El campo dirección es obligatorio');
		document.getElementById('direccion').focus();
		return 0;		
	}
	if (document.getElementById('cp').value == "")
	{
		alert('El campo codigo postal es obligatorio');
		document.getElementById('cp').focus();
		return 0;		
	}
	if (document.getElementById('ciudad').value == "")
	{
		alert('El campo ciudad es obligatorio');
		document.getElementById('ciudad').focus();
		return 0;		
	}
	if (document.getElementById('provincia').value == "")
	{
		alert('El cmapo provincia es obligatorio');
		document.getElementById('provincia').focus();
		return 0;		
	}
	if ((document.getElementById('telefono').value == "") &&(document.getElementById('movil').value == "") &&(document.getElementById('correo').value == ""))
	{
		alert('Es necesario cubrir un teléfono movil o fijo, o bien un correo electrónico para el contacto');
		return 0;		
	}
	
	//si todo está correcto, enviamos el formulario
	document.f_alta.submit(); 
}




/*FOROS*/


function borrarFormularioNuevoTema()
{
	document.getElementById('titTema').value = "";
	document.getElementById('titPost').value = "";
	document.getElementById('txtPost').value = "";
	
}

function validarFormularioNuevoTema()
{
	if (document.getElementById('titTema').value == "")
	{
		alert('El título para el tema es obligatorio');
		document.getElementById('titTema').focus();
		return 0;
	}
	if (document.getElementById('titPost').value == "")
	{
		alert('Debes introducir título para el primer comentario');
		document.getElementById('titPost').focus();
		return 0;		
	}
	if (document.getElementById('txtPost').value == "")
	{
		alert('Debes introducir texto para el primer comentario');
		document.getElementById('txtPost').focus();
		return 0;
	}
	
	//si todo está correcto, enviamos el formulario
	document.f_tema.submit(); 
}

function borrarFormularioNuevoPost()
{
	document.getElementById('titPost').value = "";
	document.getElementById('txtPost').value = "";
	
}

function validarFormularioNuevoPost()
{
	if (document.getElementById('titPost').value == "")
	{
		alert('Debes introducir título para el primer comentario');
		document.getElementById('titPost').focus();
		return 0;		
	}
	if (document.getElementById('txtPost').value == "")
	{
		alert('Debes introducir texto para el primer comentario');
		document.getElementById('txtPost').focus();
		return 0;
	}
	
	//si todo está correcto, enviamos el formulario
	document.f_post.submit(); 
}



function borrarFormularioNuevoUser()
{
	document.getElementById('login').value = "";
	document.getElementById('password').value = "";
	document.getElementById('correo').value = "";	
}

function validarFormularioNuevoUser()
{
	if (document.getElementById('login').value == "")
	{
		alert('Debes introducir un nombre de usuario');
		document.getElementById('login').focus();
		return 0;		
	}
	if (document.getElementById('password').value == "")
	{
		alert('Debes introducir una contraseña');
		document.getElementById('password').focus();
		return 0;
	}
	if (document.getElementById('correo').value == "")
	{
		alert('Debes introducir un email válido');
		document.getElementById('correo').focus();
		return 0;
	}
	//si todo está correcto, enviamos el formulario
	document.f_user.submit(); 
}

function esFechaValida(fecha)
{
	if (fecha.length != 10) 
		return 1;
	else
	{
		if(fecha.charAt(2) != '/' || fecha.charAt(5) != '/') return 1;
		
		ano = parseInt(fecha.substring(6,10));
		mes = parseInt(fecha.substring(3,5));
		dia = parseInt(fecha.substring(0,2));
		
		if ((mes==1)||(mes==3)||(mes==5)||(mes==7)||(mes==8)||(mes==10)||(mes==12))
			if(dia<1 ||dia>31) return 2;
		else if ((mes==4)||(mes==6)||(mes==9)||(mes==11))
			if(dia<1 ||dia>30) return 2;	
		else if (mes==2)	
			if(dia<1 ||dia>29) return 2;
	}	
	
	return 0;
}

function esMailValido(email)
{
	cadenaMail = email.split('@');
	if (cadenaMail[1]!= null)
	{
		cadenaMail = cadenaMail.split('.');
		if (cadenaMail[1]!= null)
			return 1;
		else
			return 0;
	}
	else
		return 0;
}




function mostrarPagina (numPag)
{
		i=1;
		while(document.getElementById('pag_'+i) != null)
		{
			if (i == parseInt(numPag))
			{
				document.getElementById('pag_'+i).style.display = "";
				document.getElementById('num_'+i).className = "pagina_actual";
			}
			else
			{
				document.getElementById('pag_'+i).style.display = "none";
				document.getElementById('num_'+i).className = "pagina_normal";
			}
			
			i++;
		}
}

function votarEncuesta(idEncuesta)
{
	var i = 1;
	opcionSeleccionada = 0;
	numero_respuestas = 0;
	do
	{
		if ( document.getElementById('op_'+i) != null )
		{
			if (document.getElementById('op_'+i).checked)
				opcionSeleccionada = document.getElementById('op_'+i).value;
			numero_respuestas ++;
		}
		
		i++;
	}while (document.getElementById('op_'+i) != null);
	
	if(opcionSeleccionada != 0)
	{
		document.getElementById('idPregunta').value = idEncuesta;
		document.getElementById('opElegida').value = opcionSeleccionada;

		document.f_encuesta.submit(); 
	}
}