var whitespace = " \t\n\r";

function isValidEmail(s)
{   
	if (isEmptyET(s)) return false;
   
	if (isWhitespace(s)) return false;
	    
	var i = 1;
	var sLength = s.length;

	while ((i < sLength) && (s.charAt(i) != "@"))
	{ i++
	}

	if ((i >= sLength) || (s.charAt(i) != "@")) return false;
	else i += 2;

	while ((i < sLength) && (s.charAt(i) != "."))
	{ i++
	}

	if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
	else return true;
}

function isEmptyET(s)
{   
	return ((s == null) || (s.length == 0))
}

function isWhitespace(s)
{   
	var i;

    if (isEmptyET(s)) return true;

    for (i = 0; i < s.length; i++)
    {   
		var c = s.charAt(i);

		if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

function checkEmailForm() { 
	z=0;
	celements=document.getElementsByName('lid');
		for (c=0;c<celements.length;c++){
		if (celements[c].checked){
			z=z+1;
			}
		}
	if (z<1){
	alert("Please select at least one list.");
		return false;
	}
	if (!isValidEmail(document.subscribeForm.elements['Email Address'].value)) {
	document.subscribeForm.elements['Email Address'].style.backgroundColor='yellow';
		alert("Please enter a valid Email Address. (name@host.com)");
		document.subscribeForm.elements['Email Address'].focus();
		return false;
	}
}
