function checkContactUs(theForm)  {
    var why = "";
    why += checkForNull(theForm.name.value, "Name");
    why += checkForNull(theForm.lastname.value, "Last Name");
    why += checkPhone(theForm.phone.value);
    why += checkEmail(theForm.email.value);

    if (why != "") {
    	 why = "There were some problems while sending your information:\n\n" + why; 
       alert(why);
       return false;
    }
	  return true;
}

function checkKeyword(theForm)  {
    var why = "";
    why += checkForNull(theForm.espanol.value, " valor de la palabra en espanol");
    why += checkForNull(theForm.ingles.value, " valor de la palabra en ingles");

    if (why != "") {
       alert(why);
       return false;
    }
	  return true;
}

function checkForNull(strng, fieldName)  {
	var error = "";
  if (strng == "") {
  	error = "Please make sure you input a " + fieldName + "\n";
 	}
 	return error;
}
function checkUsername (strng) {
	var error = "";
  if (strng == "") {
  	error = "Por favor ingrese un Nombre de Contacto\n";
 	}
 	return error;
}

function checkPhone(strng)  {
	var error = "";
	if (strng == "") {
	  error = "Please input a telephone number where you can be reached.\n";
	}
	var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
	//strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
	   error = "The phone you have entered seems to have invalid characters.\n";
	}
	return error;
}

function checkEmail(strng)  {
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	if (strng.match(illegalChars)) {
  	error = "El correo electronico contiene caracteres ilegales.\n";
	}
	var error = "";
	var emailFilter=/^.+@.+\..{2,3}$/;
	if (!(emailFilter.test(strng))) { 
		error = "Please enter a valid e-mail address.\n";
	}
	return error;
}

function checkPasswords(theForm)  {
	validated = false;
	if ((theForm.password1.value == "") || (theForm.password2.value == ""))  {
		alert("Por favor escriba la contraseña en ambos campos");
	}
	else if (theForm.password1.value != theForm.password2.value)  {
		alert("Las contraseñas no son iguales, por favor verificar.");
	}
	else  {
		validated = true;
	}
	return validated;
}

function checkMailAddresses(theForm)  {
		var why = "";
    why += checkInvalidCharacters(theForm.email1.value);
    why += checkInvalidCharacters(theForm.email2.value);
    why += checkInvalidCharacters(theForm.email3.value);
    why += checkInvalidCharacters(theForm.email4.value);
    why += checkInvalidCharacters(theForm.email5.value);

    if (why != "") {
       alert(why);
       return false;
    }
	  return true;	
}
function checkInvalidCharacters(strng)  {
	var error = "";
	var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
	if (strng.match(illegalChars)) {
  	error = "El correo electronico \"" + strng + "\" contiene caracteres ilegales.\n";
	}
	return error;
}
