function IsValidEmail(email)
{
	// Used to check if the address fits the user@domain format, and separate the user from the domain.
	var emailPattern = /^(.+)@(.+)$/;
	
	// Represents all special characters not allowed in the user name or domain name of the address:
	// ( ) < > @ , ; : \ " . [ ]
	var specialCharsPattern = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	
	// Represents all characters allowed in the user name or domain name.
	var validCharsPattern = "\[^\\s" + specialCharsPattern + "\]";
	
	// Applies if the user name is a quoted string, in which case all characters are allowed.
	// This is because "A (Random) User"@somewhere.com is technically a valid address.
	var quotedUserPattern = "(\"[^\"]*\")";
	
	// Applies for domains that are an IP address, instead of a symbolic name.
	// This is because user@[123.124.233.4] is a legal address.  Note the square brackets are required.
	var ipDomainPattern = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	
	// Represents an "atom" -- basically a series of non-special characters.
	var atomPattern = validCharsPattern + "+";
	
	// Represents one word in a user name.  A word is either an atom or a quoted string.
	// Example: in a.b.c@somewhere.com, a, b, and c are words.
	var wordPattern = "(" + atomPattern + "|" + quotedUserPattern + ")";
	
	// Describes the structure of the user name.
	var userNamePattern = new RegExp("^" + wordPattern + "(\\." + wordPattern + ")*$");
	
	// Describes the structure of a normal symbolic domain.
	var domainPattern = new RegExp("^" + atomPattern + "(\\." + atomPattern +")*$");
	
	// Break up user@domain into user and domain.
	var matchArray = email.match(emailPattern);
	
	if(matchArray == null)
	{
		// Too few @s or something, this address doesn't even fit the general format of e-mail addresses.
		return false;
	}

	var userName	= matchArray[1];
	var domain		= matchArray[2];
	
	// See if the user name is valid.
	if(userName.match(userNamePattern) == null)
	{
		// User name is invalid.
		return false;
	}
	
	// If the domain is an IP address, make sure the IP address is valid.
	var ipArray = domain.match(ipDomainPattern)

	if(ipArray != null)
	{
		// Check to see if this IP address is valid.
		for(var piece = 1; piece <= 4; piece++)
		{
			if(ipArray[piece] > 255)
			{
				return false;
			}
		}
		
		// If it is, then this address is valid.
		return true;
	}
	
	// Since the domain is a symbolic name, see if it's valid.
	var domainArray = domain.match(domainPattern);
	
	if(domainArray == null)
	{
		// Domain name is invalid.
		return false;
	}
	
	// Break up the domain and get a count of the number of atoms it consists of.
	var atomRegEx	= new RegExp(atomPattern, "g");
	domainArray		= domain.match(atomRegEx);
	var numAtoms	= domainArray.length;
	
	if(domainArray[domainArray.length - 1].length < 2 || domainArray[domainArray.length - 1].length > 3)
	{
		// The address does not end in a two- or three-letter word.
		return false;
	}
	
	if(numAtoms < 2)
	{
		// The address is missing a host name before the domain suffix.
		return false;
	}
	
	// If this point was reached, the address is good.
	return true;
}

function ValidateForm()
{
	if(! IsValidEmail(document.SubscriptionForm.Email.value) )
	{
		alert("The E-mail field must be a valid e-mail address. Please correct this and submit the form again.");
		return false;
	}
	
	return true;
}

function SubmitForm()
{
	if(ValidateForm())
	{
		document.SubscriptionForm.submit();
		return true;
	}
	
	return false;
}

function SubmitForm2()
{
	document.PhotoLibraryForm.submit();
	return true;
}
