function validateForms(whichform)
{
	for(var i=0; i<whichform.elements.length; i++)
	{
		var element = whichform.elements[i];
		if(element.className.indexOf("required") != -1)
		{
			if(!isFilled(element))
			{
				alert("Please fill in the " + element.name + " field.");
				return false;
			}
		}
		if(element.className.indexOf("email") != -1)
		{
			if(!isEmail(element))
			{
				alert("The " + element.name + " field must be a valid email address.");
				return false;
			}
		}
	}
	/////////////////////////////////////////
	// validate user email addresses match //
	/////////////////////////////////////////
	if(whichform.email2)
	{
		if(whichform.email.value != whichform.email2.value)
		{
			alert("Your email addresses do not match.");
			return false;
		}
	}
	//////////////////////////////////////////////
	// validate recipient email addresses match //
	//////////////////////////////////////////////
	if(whichform.rec_email)
	{
		if(whichform.rec_email.value != whichform.rec_email2.value)
		{
			alert("Your recipient's email addresses do not match.");
			return false;
		}
	}
	//////////////////////////////////////////////
	// validate recipient email addresses match //
	//////////////////////////////////////////////
	if(whichform.password2)
	{
		if(whichform.password.value != whichform.password2.value)
		{
			alert("Your passwords do not match.");
			return false;
		}
	}
	return true;
}

function prepareForms()
{
	for(var i = 0; i < document.forms.length; i++)
	{
		var thisform = document.forms[i];
		thisform.onsubmit = function()
		{
			return validateForms(this);
		}
	}
}

function isFilled(field)
{
	if(field.value.length < 1)
		return false;
	else
		return true;
}

function isEmail(field)
{
	if(field.value.indexOf("@") == -1 || field.value.indexOf(".") == -1)
		return false;
	else
		return true;
}

addLoadEvent(prepareForms);