function trim(str){
	if(!str || typeof str != 'string'){
		return "";
	}
	return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}
function validate(){
	var email = trim(window.document.mform.email.value);
	var movil = trim(window.document.mform.movil.value);
	var pass = trim(window.document.mform.pass.value);
	var pass2 = trim(window.document.mform.pass2.value);
	if (trim(window.document.mform.nombre.value) == ''){
	    alert('Por favor, introduzca su nombre');
		window.document.mform.nombre.focus();
		return false;
	}
	else if (trim(window.document.mform.NIF.value) == ''){
	    alert('Por favor, introduzca su NIF');
		window.document.mform.NIF.focus();
		return false;
	}
	else if (trim(window.document.mform.direccion.value) == ''){
	    alert('Por favor, introduzca su dirección');
		window.document.mform.direccion.focus();
		return false;
	}
	else if (trim(window.document.mform.localidad.value) == ''){
	    alert('Por favor, introduzca su localidad');
		window.document.mform.localidad.focus();
		return false;
	}
	else if (trim(window.document.mform.cp.value) == ''){
	    alert('Por favor, introduzca su código postal');
		window.document.mform.cp.focus();
		return false;
	}
	else if(movil == ''){
		alert('Por favor, introduzca su nº de móvil');
		window.document.mform.movil.focus();
		return false;
	}
	else if(email == ''){
		alert('Por favor, introduzca su email');
		window.document.mform.email.focus();
		return false;
	}
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))){
		alert("Dirección de email no válida");
		window.document.mform.email.focus();
		return false;
	}
	else if (trim(window.document.mform.pass.value) == ''){
	    alert('Por favor, escriba su password');
		window.document.mform.pass.focus();
		return false;
	}
	else if (trim(window.document.mform.pass2.value) == ''){
	    alert('Por favor, confirme su password');
		window.document.mform.pass2.focus();
		return false;
	}
	else if (pass != pass2){
	    alert('Password no coincide');
		window.document.mform.pass2.focus();
		return false;
	}
	else{
	    window.document.mform.nombre.value = trim(window.document.mform.nombre.value);
		window.document.mform.email.value = email;
		window.document.mform.movil.value = movil;
		window.document.mform.pass.value = trim(window.document.mform.pass.value);
		window.document.mform.pass2.value = trim(window.document.mform.pass2.value);
		return true;

	}
}
