/* 
  Function:       isValidEmail
  Purpose:        Checks that a string is a valid email address.
  Author:         Cameron Junge
  Date Created:   16/8/2001
  Last Modified:  24/9/2001
  Based On:       IsValidEmail.js (Author: Jason Highet)
  Parameters In:  theEmail - the string to test
  Returns:        True if the string is a valid email address.
  				  False if the string is not valid.
*/
function isValidEmail(theEmail) {
	var validChars = "abcdefghijklmnopqrstuvwxyz0123456789-+~_@.";
	var checkStr = "";
	if (theEmail.length < 5) // too short (x@x.x)
		return false;
	atArray = theEmail.split("@"); // split email
	if (atArray.length != 2) // should have at least and only one @
		return false;
	mailbox = atArray[0].split("."); // split first part
	for (i=0; i < mailbox.length; i++)
		if (mailbox[i].length == 0) // each element must be atleast one character
			return false;
	domain = atArray[1].split("."); // split second part
	if (domain.length == 1) // must have at least one .
		return false;
	for (i=0; i < domain.length; i++)
		if (domain[i].length == 0) // each element must be atleast one character
			return false;
	for (i=0; i < theEmail.length; i++) // validate string
		if (validChars.indexOf(theEmail.charAt(i).toLowerCase()) == -1)
			return false;
	return true;
}
