// Email address must be of form a@b.c ... in other words:
    // * there must be at least one character before the @
    // * there must be at least one character before and after the .
    // * the characters @ and . are both required
    function isValidEmail(s)
    {   
        if (isEmpty(s)) return false;

        // is s whitespace?
        if (isWhitespace(s)) return false;
            
        // there must be >= 1 character before @, so we
        // start looking at character position 1 
        // (i.e. second character)
        var i = 1;
        var sLength = s.length;

        // look for @
        while ((i < sLength) && (s.charAt(i) != "@"))
        { i++;
        }

        if ((i >= sLength) || (s.charAt(i) != "@")) return false;
        else i += 2;

        // look for .
        while ((i < sLength) && (s.charAt(i) != "."))
        { i++;
        }

        // there must be at least one character after the .
        if ((i >= sLength - 3) || (s.charAt(i) != ".")) return false;
        else return true;
    }

    // Check whether string s is empty.
    function isEmpty(s)
    {   
        return ((s == null) || (s.length == 0));
    }

    // Returns true if string s is empty or 
    // whitespace characters only.
    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);
				var whitespace = " \t\n\r";
                if (whitespace.indexOf(c) == -1) return false;
    }
    // All characters are whitespace.
    return true;
    }

    function checkForm() { 
		/*
		//Test first name
		test = isWhitespace(document.subscribeForm.First_Name.value);
		if (test){
			document.subscribeForm.First_Name.style.backgroundColor="#fff9bo";
			alert("Please enter your first name.");
			document.subscribeForm.First_Name.focus();
			return false;
		}
		document.subscribeForm.First_Name.style.backgroundColor='white';

		//Test last name
		test = isWhitespace(document.subscribeForm.Last_Name.value);
		if (test){
			document.subscribeForm.Last_Name.style.backgroundColor="#fff9bo";
			alert("Please enter your last name.");
			document.subscribeForm.Last_Name.focus();
			return false;
		}
		document.subscribeForm.Last_Name.style.backgroundColor='white';
		*/
		//Test email addresses
		
		if (!isValidEmail(document.subscribeForm.elements[6].value)) {
			document.subscribeForm.elements[6].style.backgroundColor="#fff9bo";
            alert("Please enter a valid email address. (e.g. yourname@domain.com)");
            document.subscribeForm.elements[6].focus();
                return false;
        }	
		document.subscribeForm.elements[6].style.backgroundColor='white';
		
		if (document.subscribeForm.elements[6].value != document.subscribeForm.elements[7].value){
			alert("The email addresses provided do not match.  Please confirm that your email address is correct.");
			return false;
		}
		/*
		//Test Company
		test = isWhitespace(document.subscribeForm.Company.value);
		if (test){
			document.subscribeForm.Company.style.backgroundColor="#fff9bo";
			alert("Please enter your company name.");
			document.subscribeForm.Company.focus();
			return false;
		}
		document.subscribeForm.Company.style.backgroundColor='white';
		
		//Test State
		if (document.subscribeForm.State.value == "default"){
			document.subscribeForm.State.style.backgroundColor="#fff9bo";
			alert("Please select your state.");
			document.subscribeForm.State.focus();
			return false;
		}
		document.subscribeForm.State.style.backgroundColor='white';
		*/
		//Test Role
		test = document.subscribeForm.Role.value;
		if (document.subscribeForm.Role.value == "default"){
			document.subscribeForm.Role.style.backgroundColor="#fff9bo";
			alert("Please let us know if you are a Zenith Policyholder or Agent.  If you are neither, please select \"Other.\"");
			document.subscribeForm.Role.focus();
			return false;
		}
		document.subscribeForm.Role.style.backgroundColor='white';
		
		if (test == "other"){
			if (document.subscribeForm.elements[11].value == "default"){
				document.subscribeForm.elements[11].style.backgroundColor="#fff9bo";
				alert("We'd love to know how you heard about Zenith.");
				document.subscribeForm.elements[11].focus();
				return false;
			}
			document.subscribeForm.elements[11].style.backgroundColor='white';
		}
		
		//Test newsletters
        z=0;
        celements=document.getElementsByName('lid');
        for (c=0;c<celements.length;c++){
			if (celements[c].checked){
                z=z+1;
			}
        }
        if (z==0){
			alert("Please select at least one newsletter.");
            return false;
        }
        
    }
