function pulsaTecla(e){
	var teclas="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_";
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	return (teclas.indexOf(keychar)>=0)
}
function ftrim(str){
	var long = str.length;
	while(str.substring(0,1)==" "){
		str = str.substring(1,long);
	}

	long = str.length;
	while(str.substring(long-1,long)==" "){
		str = str.substring(0,long-1);
		long = str.length;
	}

	return str;
}
function compLogin(){
	apagar(document.theForm.login);
	apagar(document.theForm.pass);
	apagar(document.theForm.repPass);

	var login = String(document.theForm.login.value);
	var pass = String(document.theForm.pass.value);
	
	if(!testLogin(login)){
		iluminar(document.theForm.login);
		return false;
	}

	if(!testPassword(pass)){
		iluminar(document.theForm.pass);
		iluminar(document.theForm.repPass);
		return false;
	}

	document.theForm.submit();
}

function compDatos(){
	var form = document.theForm;
	
	apagar(form.usuNombre);
	apagar(form.usuApellidos);
	apagar(form.usuEmail);
	
	if(form.usuNombre.value==""){
		alert("Debes de rellenar el campo Nombre.");
		iluminar(form.usuNombre);
		return false;
	}

	if(form.usuApellidos.value==""){
		alert("Debes de rellenar el campo Apellidos.");
		iluminar(form.usuApellidos);
		return false;
	}
	
	if(!isValidEmail(form.usuEmail.value)){
		alert("Debes de introducir un email válido.");
		iluminar(form.usuEmail);
		return false;
	}

	if(!form.aceptacion.checked){
		alert("Debes aceptar las condiciones de uso de la web.");
		iluminar(form.aceptacion);
		return false;
	}
	
	document.theForm.submit();
}

function iluminar(object){
	object.style.background="#FFDD00";
}
function apagar(object){
	object.style.background="#FFFFFF";
}

function isValidEmail(str) {
  return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}	

function testLogin(login){
	if(login==""){
		alert("Debes de rellenar el campo Login.");
		return false;
	}
	return true;
}
function testPassword(password){
	var repPassword = String(document.theForm.repPass.value);
	if (password==""){
		alert("Debes de rellenar el campo Password.");
		return false;
	}
	if (repPassword==""){
		alert("Debes de rellenar el campo de repetición de Password.");
		return false;
	}
	if (password!=repPassword){
		alert("Los campos de Password no coinciden.");
		return false;
	}
	return true;
}

