// Documento Java script
// Ivan Velarde - 2009


//------------------------------------------------

// Verifica nombre de 6 a 30 caracteres, uc, lc, and underscore only.
function verifica_nombre (strng) {
var error = "";
if (strng == "") 
	{
	error = "No escribio un nombre.\n";
	}
var illegalChars = /[\(\)\<\>\,\;\:\\\"\[\],0-9]/; // allow letters, numbers, and underscores
if ((strng.length < 6) || (strng.length > 30)) 
	{
	error = "Por favor escriba su nombre y apellido.\n";
	}
else if (illegalChars.test(strng)) 
	{
	error = "El nombre contiene caracteres no validos.\n";
	}
return error;
}


// Verify password - between 6–8 chars, uppercase, lowercase, and numeral
function verifica_password (strng) {
	var error = "";
	if (strng == "") {
		error = "No ha escrito una clave.\n";
		}
	var illegalChars = /[\W_]/; // allow only letters and numbers
	if ((strng.length < 6) || (strng.length > 8)) {
		error = "La clave debe contener de 6 a 8 caracteres.\n";
		}
	else if (illegalChars.test(strng)) {
		error = "La clave contiene caracteres no validos.\n";
		}
	else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
	error = "La clave debe por lo menos contener unamayuscula, una minuscula y un numero.\n";
		}
	return error;
	}

// Verify email
function verifica_email (strng) {
	var error="";
	if (strng == "") {
		error = "No ha escrito una direccion de e-mail.\n";
		}
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) {
		error = "Por favor escriba un e-mail valido.\n";
		}
else {
//test email for illegal characters
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
	if (strng.match(illegalChars)) {
		error = "El e-mail contiene caracteres no validos.\n";
		}
	}
return error;
}


// Verify phone number - strip out delimiters and verify for 10 digits
function verifica_telefono (strng) {
	var error = "";
	if (strng == "") {
		error = "No ha escrito un numero de telefono.\n";
		}
//strip out acceptable non-numeric characters
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
	if (isNaN(parseInt(stripped))) {
		error = "El numero de telefono contiene caracteres no validos.";
		}
	if (!(stripped.length == 11)) {
		error = "El numero de teléfono tiene un formato no válido. Por favor incluya el codigo de area o de celular (p.e. 0412-1234567).\n";
		}
	return error;
}
