// JavaScript Document
function clearField() {
	if (document.submitEmail.emailaddress.value == 'Join Our E-mail List') {
		document.submitEmail.emailaddress.value='';
	}
}
function addEmail() {
	var emailAddr = document.submitEmail.emailaddress.value;
	if(emailAddr == '') {
		window.alert('You must enter an email address.');
	}
	else {
		if(isEmailValid(emailAddr)) {
			document.submitEmail.submit();
		}
		else {
			window.alert('The email address you entered is not valid.');
		}
	}
	document.submitEmail.emailaddress.focus();	
}

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

function isEmailValid(str) {
    var c, count, domain;

    for (c = 0;  c < str.length;  c++) {
        if (str.charAt(c) == "\"" &&
            (!c || str.charAt(c - 1) == "." || str.charCharAt(c - 1) == "\""))
        {
            while (++c < str.length)  {
                if (str.charAt(c) == "\"") break;
                if (str.charAt(c) == "\\" && (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) == ".")
        {
            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);
}