function longitud(input, nombre, minima, maxima) {
	if (input.value.length<minima) {
		if (minima > 1) {
			alert("Debes introducir un valor correcto en el campo " + nombre + ",\nque debe tener un mínimo de " + minima + " caracteres.");
		} else {
			alert("El campo " + nombre + " no puede estar vacío.");
		}
		input.focus();
		return(false);
	}
	if (input.value.length>maxima) {
		diferencia=input.value.length-maxima;
		alert("Debes introducir un valor correcto en el campo " + nombre + ".\nDebe tener un máximo de " + maxima + " caracteres.\nSobran " + diferencia + ".");
		input.focus();
		return(false);
	}
	return(true);
}
var pagrev = "includes/vmrd-login.php";
var pagrevnew = "includes/vmrd-newuser.php";
function escero(input, nombre) {
	if (input.value=='0') {
		alert("Debes seleccionar un valor correcto en el campo " + nombre + ".");
		input.focus();
		return(false);
	}
	return(true);
}

function trim(input){
	var string=input.value;
	expresion=/^\s*(\w*)/gi;
	string = string.replace(expresion,"$1");
	expresion=/(\w*)\s*$/gi;
	string = string.replace(expresion,"$1");
	input.value=string;
}

function netejar(input) {
	trim(input);
	string = input.value;
	caractersDolents=/[<>]/g;
	string = string.replace(/\"/g,"\'\'");
	string = string.replace(caractersDolents,"");
	input.value = string;
}

function validar() {
		netejar(formLogin.usuario);
		netejar(formLogin.clave);
		if ( (longitud(formLogin.usuario,"Usuario",5,15)==false)
			|| (longitud(formLogin.clave,"Contraseña",5,15)==false)
			) {
				return(false);
		}
		formLogin.submit();
}
