var validation = retrieveValidationArray();
var validatedThisPage = false;
if (validation == null)
{
	validation = new Array();
	validation[0] = new ValidateObject("emailAddress", "E-mail Address", true, false, "isEmail", "Please specify your e-mail address to receive updates about MylesPinkney.com");
	validation[1] = new ValidateObject("referral", "Referral", true, false, "isNotEmpty", "Please specify how you heard about or found this site");
	validation[2] = new ValidateObject("otherReferral", "Referral", true, false, "isOtherReferral", "If 'Other' is chosen as the referral, then the referral must be specified");
}

function onLoadEvent()
{
	document.getElementById("username").value = getMailingListEmailAddress();
	document.getElementById("sender").value = getMailingListEmailAddress();
	document.getElementById("recipient").value = getMailingListEmailAddress();
	
	findValidateObject(validation, "emailAddress").validate = true;
	findValidateObject(validation, "referral").validate = true;
	findValidateObject(validation, "otherReferral").validate = true;
	
	document.getElementById("otherReferral").onfocus = new Function('selectRadio(document.forms[0].referral, "Other")');
}

function onUnloadEvent()
{
	if (validatedThisPage == false)
	{
		deleteValidationCookie();
	}
}

function submitForm()
{
	validatedThisPage = true;
	var group = document.forms[0].referral;
	var selection = null;
	for (var i = 0; i < group.length; i++)
	{
		if (group[i].checked)
		{
			selection = group[i].value;
			break;
		}
	}
	findValidateObject(validation, "referral").value = selection;
	
	var obj = findValidateObject(validation, "emailAddress");
	obj.value = document.getElementById(obj.id).value;
	obj = findValidateObject(validation, "otherReferral");
	obj.value = document.getElementById(obj.id).value;
	
	if (validateArray(validation))
	{
		deleteValidationCookie();
		document.forms[0].action = getFormMailAction();
		document.forms[0].submit();
	}
	else
	{
		persistValidationArray(validation);
		document.location = document.location.href;
	}
}

function isOtherReferral(value)
{
	if (findValidateObject(validation, "referral").value == "Other")
	{
		return isNotEmpty(value);
	}
	else
	{
		return true;
	}
}
