// JavaScript Document
function IsEmpty(sStr) {
	return (sStr.length < 1);
}
function IsValidEmail(sEmail)
{
	var sStr = new String(sEmail);
	var index1 = sStr.indexOf("@");
	if (index1 > 0)
	{
		var index2 = sStr.lastIndexOf(".");
		return ((index2 > index1 + 1) && (sStr.length > index2 + 1));
	}
	return false;
}
function ValidateForm()
{
	if (IsEmpty(document.subscribeform.email.value))
	{
		alert("No email address has been provided. Please enter an email address before subscribing to the newsletter.");
		return false;
	}
	if (!IsValidEmail(document.subscribeform.email.value))
	{
		alert("The email address provided is not valid. Please enter a valid email address before subscribing to the newsletter.");
		return false;
	}
	
	return true;
}



// from http://www.perlscriptsjavascripts.com/js/check_email.html - BC 23Mar07
function check_form(f) { // f is the form (passed using the this keyword)

    if (f.email.value == "")
    {
	alert("Please enter your email address to subscribe!");
	f.email.focus();
	return false;
    }

    if (! check_email(f.email.value))
    {
	alert("Please check - that doesn't look like an email address!");
	f.email.focus();
	// if the browser is Netscape 6 or IE
	if(document.all || document.getElementByID)
	{
	    // change the color of text field
	    f.email.style.background = "yellow";
	}
	// make sure the form is not submitted
	return false;
    }

}

// Email Validation. Written by PerlScriptsJavaScripts.com
function check_email(e)
{
    ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

    for(i=0; i < e.length; i++)
    {
	if(ok.indexOf(e.charAt(i))<0)
	{
	    return (false);
	}
    }

    if (document.images)
    {
	re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
	re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	if (!e.match(re) && e.match(re_two))
	{
	    return (-1);
	}
    }
}


