/* ================================================================================================ */
function emailCheck (emailStr) 
{
	/* 1 means check two country letter, 0 means don't. */
	var checkTLD=1;
	/* The following is the list of known TLDs that an e-mail address must end with. */
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	/* Does the address fit the user@domain format.  Used to separate the username from the domain. */
	var emailPat=/^(.+)@(.+)$/;
	/* Don't allow these characters include ( ) < > @ , ; : \ " . [ ] */
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	/* The range of characters allowed.*/
	var validChars="\[^\\s" + specialChars + "\]";
	/* A quoted email address in not a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")";
	/* E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	/* The following string represents an atom (basically a series of non-special characters.) */
	var atom=validChars + '+';
	/* In john.doe@somewhere.com, john and doe are words. A word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")";
	/* The following pattern describes the structure of the user */
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	/* The following pattern describes the structure of a normal symbolic domain. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	/* Break up user@domain into different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat);
	
	if (matchArray==null) 
		{
			/* If there are too many or too few @'s, this address doesn't fit. */
			alert("Email address seems incorrect (check @ and .'s)");
			return false;
		}
		
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).
	for (i=0; i<user.length; i++) 
		{
			if (user.charCodeAt(i)>127) 
				{
					alert("Ths username contains invalid characters.");
					return false;
   				}
		}
		
	for (i=0; i<domain.length; i++) 
		{
			if (domain.charCodeAt(i)>127) 
				{
					alert("Ths domain name contains invalid characters.");
					return false;
   				}
		}

	// See if "user" is valid 
	if (user.match(userPat)==null) 
		{
			alert("The username doesn't seem to be valid.");
			return false;
		}

	/* if the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
		{
			// this is an IP address
			for (var i=1;i<=4;i++) 
				{
					if (IPArray[i]>255) 
						{
							alert("Destination IP address is invalid!");
							return false;
   						}
				}
		return true;
		}

	// Domain is symbolic name.  Check if it's valid.
 	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) 
		{
			if (domArr[i].search(atomPat)==-1) 
				{
					alert("The domain name does not seem to be valid.");
					return false;
   				}
		}

	/* At this point the domain name seems valid, but now make sure that it ends in a known top-level domain. */
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) 
		{
			alert("The address must end in a well-known domain or two letter " + "country.");
			return false;
		}

	// Make sure there's a host name preceding the domain.
	if (len<2) 
		{
			alert("This address is missing a hostname!");
			return false;
		}

// Everything's valid!
return true;
}

// whitespace characters
	  var whitespace = " \t\n\r";

      // Check whether string s is empty.
      function isEmpty(s)
      { return ((s == null) || (s.length == 0)) }

      /****************************************************************/

      function isWhitespace (s)
      {
           var i;

           // Is s empty?
           if (isEmpty(s)) return true;

           // Search through string's characters one by one
           // until we find a non-whitespace character.
           // When we do, return false; if we don't, return true.

           for (i = 0; i < s.length; i++)
           {
                // Check that current character isn't whitespace.
                var c = s.charAt(i);
                if (whitespace.indexOf(c) == -1) return false;
           }
           // All characters are whitespace.
           return true;
      }
	  
		var numb = '0123456789';
		var lwr = 'abcdefghijklmnopqrstuvwxyz';
		var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
		
		function isValid(parm,val) {
			if (parm == "") return true;
			for (i=0; i<parm.length; i++) 
				{
				if (val.indexOf(parm.charAt(i),0) == -1) return false;
				}
			return true;
			}
		
		function isNum(parm) {return isValid(parm,numb);}
		function isLower(parm) {return isValid(parm,lwr);}
		function isUpper(parm) {return isValid(parm,upr);}
		function isAlpha(parm) {return isValid(parm,lwr+upr);}
		function isAlphanum(parm) {return isValid(parm,lwr+upr+numb);}

function inputValidation()
{	

	// Last Name cannot be left blank
	if ( isWhitespace(myForm.firstName.value)) 
	{
		myForm.firstName.focus();
		alert('First Name cannot be left blank');
		return false;
	}

	// Last Name cannot be left blank
	if ( isWhitespace(myForm.lastName.value)) 
	{
		myForm.lastName.focus();
		alert('Last Name cannot be left blank');
		return false;
	}

	// Last Name cannot be left blank
	if ( isWhitespace(myForm.email.value)) 
	{
		myForm.email.focus();
		alert('Please enter your email address.');
		return false;
	}
	
	// Last Name cannot be left blank
	if(!emailCheck(myForm.email.value))
	{
		return false;
	}
		
	if ( isWhitespace(myForm.captcha.value)) 
	{
		myForm.captcha.focus();
		alert('Please fill out the letters from the graphic.');
		return false;
	}
	
	// All is well, submit the form
	return true;
}

