function validator(theForm) {

	mensaje = "";

	if (theForm.dni.value == "") mensaje += "\nEl D.N.I. está vacio.\nPonga el número de su dni (sin letra ni guión)";
	else {
		if (!solonum(theForm.dni) || (theForm.dni.value.length < 6 )) mensaje += "\nEl D.N.I. es incorrecto.";
		mensaje += vallong(theForm.dni, 8, "D.N.I.");
	}

	if (mensaje != "") {
		alert(mensaje);
		return false;
	}

	// theForm.submit;
	return true;
}

function vallong(campo, max, nombrecampo) {
	if (campo.value != "") {
		str = campo.value;
		if (str.length > max) return("\nEl nº máximo de caracteres permitidos en el campo '" + nombrecampo + "' es " + max + ". Y ahora mismo tiene puesto " + str.length + " caracteres.");
		else return ("");
	} else {
		return ("");
	}
}

function solonum(supuesto) {
	var str = supuesto.value;
// Devuelve false si los caracters no están entre a-z, A-Z, o espacio.
	for (var i = 0; i < str.length; i++) {
		var ch = str.substring(i, i + 1);
		if (ch < "0" || ch > "9") {
			return false;
		}
	}
	return true;
}
