
// Ported from Recipe 3.9 in Secure Programming Cookbook for C and C++ by
// John Viega and Matt Messier (O'Reilly 2003)

var rfc822_specials = "()<>@,;L\\\"[]";

function isEmailAddressValid(str)
{
    var c, count, domain;
    var quot = '"';
    var backslash = "\\";

    for (c = 0;  c < str.length;  c++)
    {
        if (str.charAt(c) == ' ') continue;

		if (str.charAt(c) == quot &&
            (!c || str.charAt(c - 1) == "." || str.charCharAt(c - 1) == quot))
        {
            while (++c < str.length)
            {
                if (str.charAt(c) == quot) break;
                if (str.charAt(c) == backslash && (str.charAt(++c) == ' ')) continue;
                if (str.charCodeAt(c) <= 32 || str.charCodeAt(c) >= 127)
                    return false;
            }
            if (c++ >= str.length) return false;
            if (str.charAt(c) == "@") break;
            if (str.charAt(c) != ".") return false;
            continue;
        }
        if (str.charAt(c) == "@") break;
        if (str.charCodeAt(c) <= 32 || str.charCodeAt(c) >= 127) return false;
        if (rfc822_specials.indexOf(str.charAt(c)) != -1) return false;
    }
    if (!c || str.charAt(c - 1) == ".") return false;

    if ((domain = ++c) >= str.length) return false;
    count = 0;
    do
    {
        if (str.charAt(c) == ' ') continue;

        if (str.charAt(c) == ".")
        {
            if (c == domain || str.charAt(c - 1) == ".") return false;
            count++;
        }
        if (str.charCodeAt(c) <= 32 || str.charCodeAt(c) >= 127) return false;
        if (rfc822_specials.indexOf(str.charAt(c)) != -1) return false;
    } while (++c < str.length);

    return (count >= 1 ? true : false);
}
function send()
{

var outMessage = "";
var email = document.queries.Email.value;

if ((document.queries.Name.value.length==0) || 
	(document.queries.Name.value == "Name") ||
    	(document.queries.PhoneNumber.value.length==0) || 
	(document.queries.PhoneNumber.value == "Phone Number") ||
    	(document.queries.Email.value=="E-mail") ||
    	(document.queries.Email.value.length==0) )
{
	window.alert("Please submit your name, phone number and email address so we can reply to you");
	return false;
}
email = email.toLowerCase();
if (!isEmailAddressValid(email))

{
    outMessage = 'We are unable to proceed as your email address:\n';
    outMessage += email + '\n';
    outMessage += "appears to be invalid.:\n";

    window.alert(outMessage);
    return false;
}
document.queries.Submit.disabled = true;
document.queries.submit();
return true;
}
