function Validate(theForm)
{
	var errMesg = "";
	var diplayMesg = "";

	var loginName = theForm.username.value = theForm.username.value.toLowerCase();

	//Validate the login name
	if ( !isCharsInBag( loginName, "abcdefghijklmnopqrstuvwxyz0123456789.-_" ))
	{
		errMesg += "Login name has invalid characters.\n" ;
	}
	else if ( loginName.length < 3 )
	{
		errMesg += "Login name must be 3 or more characters.\n" ;
	}
	else
	{
		var count;
		for (count=0; count < loginName.length; count++)
		{
			if (loginName.charAt(count) == "_")
			{
				if (loginName.charAt(count+1) == "_")
				{
					errMesg += "Login name may not contain more than one consecutive underscore.\n";
				}
			}
		}
	}


	//Check for password
	if ( theForm.password.value.length < 5 )
		{
		errMesg += "Password must be at least 5 characters.\n";
		}
	else if ( theForm.password.value != theForm.retypepassword.value )
		{
		errMesg += "Your passwords do not match. Please retype and try again.\n" ;
		}



	// Check all the Required Information fields.
	{
	var Q = ""; // this block determines lifespan of Q
	if (isWhitespace(theForm.firstname.value))
		{
		Q += "  First Name\n";
		}
	if (isWhitespace(theForm.lastname.value))
		{
		Q += "  Last Name\n";
		}
	if (isWhitespace(theForm.email.value))
		{
		Q += "  Email Address\n";
		}
	else if(echeck(theForm.email.value))
	{
	   errMesg += "Invalid Email Address\n";
	}	
	else if(!isCharsInBag( theForm.email.value, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@._-"))
	{
	  errMesg += "Email Address contains Invalid Characters\n";
	}
	/*if (isWhitespace(theForm.telephone.value))
		{
		Q += "  Telephone\n";
		}	*/
	if (isWhitespace(theForm.username.value))
		{
		Q += "  Username\n";
		}				
	if (isWhitespace(theForm.password.value))
		{
		Q += "  Password\n";
		}
		if (isWhitespace(theForm.retypepassword.value))
		{
		Q += "  Retype Password\n";
		}
		
	if ( Q.length > 0 )
		{
		diplayMesg = "Please provide Valid values for\n" + Q ;
		//errMesg += "Please provide Valid values for\n" + Q ;
		}
	}

 	if (errMesg == "" && diplayMesg == "")
	{
		//theForm.submit();
	}		
	else
	{
	
			if(diplayMesg!="")
			{
				alert(diplayMesg);
				return false;			
			}
			else
			{
				alert(errMesg);
				return false;
			}	
	}
}

