function trim(strng)
{
	return strng.replace(/^\s+|\s+$/g, '') ;
}

function checkEmail (strng, required)
{
	strng = trim(strng);
    var error="";
    if (strng == "")
    {
    	if (required)
    	{
        	error = "You didn't enter an email address.\n";
       	}
    }
    else
    {
		var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng)))
		{
		   error = "Please enter a valid email address.\n\n";
		}
		else
		{
			//test email for illegal characters
			var illegalChars= /[ \(\)\<\>\,\;\:\\\"\[\]]/
			if (strng.match(illegalChars))
			{
				error = "The email address contains illegal characters.\n";
			}
		}
	}
    return error;
}


function checkEmail2 (emailStr, verifyEmailStr, required)
{
    var error = checkEmail(emailStr, required);
    if (error == "")
    {
        emailStr = trim(emailStr);
        verifyEmailStr = trim(verifyEmailStr);

        if (emailStr != verifyEmailStr)
        {
            error = "The e-mail address fields do not match.\n\n";
        }
    }
    return error;
}
