function validate_email(email) {
	with (email)
		{
		apos=indexOf("@");
		dotpos=lastIndexOf(".");
		if (apos<1||dotpos-apos<2) {return false;}
		else {return true;}
		}
}


function validar_formulario_acceso (form){
		var myForm=form;

		div = document.getElementById('error_nombre');
		div.style.visibility = 'hidden'; 
		div = document.getElementById('error_email');
		div.style.visibility = 'hidden'; 
		div = document.getElementById('error_password');
		div.style.visibility = 'hidden'; 
		div = document.getElementById('error_password_redundante');
		div.style.visibility = 'hidden'; 


		if (myForm.nombre.value == "")
			{   myForm.nombre.focus(); 
				div = document.getElementById('error_nombre');
				div.style.visibility = 'visible'; 
				return;         //nombre
			}

		else if (myForm.email.value == "")
			{   myForm.email.focus();
				div = document.getElementById('error_email');
				div.style.visibility = 'visible'; 
				return;         //email
			}                                                           

		else if (myForm.email.value != "" && validate_email(myForm.email.value)==false)
			{   
				myForm.email.focus();
				div = document.getElementById('error_email');
				div.style.visibility = 'visible'; 
				return;         //email
			}                                                           

		else if (myForm.password.value == "")
			{   myForm.password.focus();
				div = document.getElementById('error_password');
				div.style.visibility = 'visible'; 
				return;         //password_1
			}                                                           

		else if (myForm.password_redundante.value == "")
			{   myForm.password_redundante.focus(); 
				div = document.getElementById('error_password_redundante');
				div.style.visibility = 'visible'; 
				return;         //password_2
			}                                                           

		else if (myForm.password.value != myForm.password_redundante.value)
			{   myForm.password_redundante.focus(); 
				div = document.getElementById('error_password_redundante');
				div.style.visibility = 'visible'; 
				return;         //password_2
			}                                                           

		else if (myForm.condiciones_legales.checked == false)
			{   myForm.condiciones_legales.focus();
				alert("Debe aceptar las condiciones legales");
				return;     //Condiciones legales           
			}
	
		else
			{   
//				myForm.boton_submit.value="enviar";
				myForm.submit(); 
				return;
			}
	}

function validar_campo_vacio (campo){

		div = document.getElementById("error_" + campo.id);
		
		if (campo.value != "")
			{
				div.style.visibility = 'hidden'; 
				return;
			}
		else
			{
				div.style.visibility = 'visible'; 
				return;
			}
}

function validar_campo_email (campo){

		div = document.getElementById("error_" + campo.id);

		if (campo.value != "" && validate_email(campo.value)==false)
			{   
				div.style.visibility = 'visible'; 
				return;
			}
		else if (campo.value != "" && validate_email(campo.value)==true)
			{
				div.style.visibility = 'hidden'; 
				return;
			}
}

function validar_concordancia_passwords (password1, password2){

		if (password1.value == "")
			{   
				password1.focus(); 
				div = document.getElementById("error_"+password1.id);
				div.style.visibility = 'visible'; 
				return;
			}
		else if (password2.value == "")
			{   
				password2.focus(); 
				div = document.getElementById("error_"+password2.id);
				div.style.visibility = 'visible'; 
				return;
			}
		else if (password1.value != password2.value)
			{   
				div = document.getElementById("error_"+password2.id);
				div.innerHTML="Las contraseņas introducidas no coinciden"
				div.style.visibility = 'visible'; 
				return;
			}
		else if (password1.value == password2.value)
			{   
				div = document.getElementById("error_"+password1.id);
				div.style.visibility = 'hidden'; 
				div = document.getElementById("error_"+password2.id);
				div.style.visibility = 'hidden'; 
				return;
			}
}