﻿Event.observe(window, 'load', function() {
	Event.observe('frmSubscribe', 'submit', checkForm);
	Event.observe('email', 'focus', clearEmail);
	Event.observe('email', 'blur', resetEmail);
	Event.observe('community', 'focus', clearCommunityError);
});

function clearEmail()
{
	if($('email').value == 'Email Address') $('email').clear();
	
	$('email').className = '';
}

function resetEmail()
{
	if (!$('email').present()) $('email').value = 'Email Address';
}

function clearCommunityError()
{
	$('community').className = '';
}

function checkForm(e)
{
	if (!isValidEmail($('email').value))
	{
		e.stop();
		$('email').className = 'error';
	}
	if ($('community').value == "Select Community")
	{
		e.stop();
		$('community').className = 'error';
	}
}

function isValidEmail(str)
{
	return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
