

function validarRegistro() {
	
	if((validarCampos())&&(validarE_Mail())&&(validarTelefono())&&(validarNIF())&&(validarCP())) {		
		return true;
	}
	else {
		return false;
	}
}

function validarE_Mail2(id) {
	
	valor = document.getElementById(id).value;
	if(!(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(valor))) {
		alert("Introduzca una dirección de correo válida");
		document.getElementById(id).focus();
		return false;
		
	}
	return true;
}

function validarE_Mail() {
	
	valor = document.getElementById("email_registro").value;
	if(!(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(valor))) {  
		alert("Introduzca una dirección de correo válida");
		document.getElementById("email_registro").focus();
		alert(document.getElementById("email_registro").value);
		return false;
	}
	return true;
}

function validarTelefono() {

	var valor = document.getElementById("telefono").value;
	if(!(/^\d{9}$/.test(valor)) ) {
		alert("Introduzca un teléfono válido");
		document.getElementById("telefono").focus();
		return false;
	}
	return true;
}

function validarNIF () {
	
	var valor = document.getElementById("dni").value;
	var letras = ['T', 'R', 'W', 'A', 'G', 'M', 'Y', 'F', 'P', 'D', 'X', 'B', 'N', 'J', 'Z', 'S', 'Q', 'V', 'H', 'L', 'C', 'K', 'E', 'T']; 

if(valor!='')
{
	if(!(/^\d{8}[A-Z]$/.test(valor))) 
	{
		alert("Introduzca un DNI válido");
		document.getElementById("dni").focus();
		return false;
	} 
	if(valor.charAt(8) != letras[(valor.substring(0, 8))%23]) 
	{
		alert("Introduzca un DNI válido");
		document.getElementById("dni").focus();
		return false;
	}
}
else
{
	return true;
}
	return true;
}

function validarCP() {
	
	var valor = document.getElementById("codigopostal").value;
	if(isNaN(valor)) {
		alert("Introduzca un código postal válido");
		document.getElementById("codigopostal").focus();
		return false;
	}
	return true;
}

function validarCampos() {
	
	var valor = document.getElementById("nombre").value;
	if(valor == null || valor.length == 0 || /^\s+$/.test(valor)) {
		alert("Introduzca un nombre válido");
		document.getElementById("nombre").focus();
		return false;
	}
	valor = document.getElementById("apellido1").value;
	if(valor == null || valor.length == 0 || /^\s+$/.test(valor)) {
		alert("Introduzca un apellido válido");
		document.getElementById("apellido1").focus();
		return false;
	}
	valor = document.getElementById("apellido2").value;
	if(valor == null || valor.length == 0 || /^\s+$/.test(valor)) {
		alert("Introduzca un apellido válido");
		document.getElementById("apellido2").focus();
		return false;
	}
	valor = document.getElementById("direccion").value;
	if(valor == null || valor.length == 0 || /^\s+$/.test(valor)) {
		alert("Introduzca una dirección válida");
		document.getElementById("direccion").focus();
		return false;
	}
	valor = document.getElementById("localidad").value;
	if(valor == null || valor.length == 0 || /^\s+$/.test(valor)) {
		alert("Introduzca una localidad válida");
		document.getElementById("localidad").focus();
		return false;
	}
	valor = document.getElementById("provincia").value;
	if(valor == null || valor.length == 0 || /^\s+$/.test(valor)) {
		alert("Introduzca una provincia válida");
		document.getElementById("provincia").focus();
		return false;
	}

	valor = document.getElementById("user").value;
	if(valor == null || valor.length == 0 || /^\s+$/.test(valor)) {
		alert("Introduzca un usuario válido");
		document.getElementById("user").focus();
		return false;
	}
	valor = document.getElementById("contrasenia").value;
	if(valor == null || valor.length == 0 || /^\s+$/.test(valor)) {
		alert("Introduzca una conraseña válida");
		document.getElementById("contrasenia").focus();
		return false;
	}
	return true;
}

