function validate(form)
{
	var errorMessage = "The following problems were found with the form: \n";
	errorMessage += "\n";
	
	var valid = true;
	
	// check if we have an email address
	if (form.emailTextBox.value.length > 0)
	{
		// check for valid email
		if (!validEmail(form.emailTextBox.value))
		{
			valid = false;
			errorMessage += " - Please supply a valid email address.\n";
		}
	}
	else if (form.telephoneTextBox.value.length == 0)
	{
		valid = false;
		errorMessage += " - Please supply either an email address or telephone number\n";
	}	
	
	// if the form is invalid, print the error message
	if (!valid)
	{
		errorMessage += "\n";
		errorMessage += "Please correct the problems and try again - Thank You.";
		alert(errorMessage);

	}
	
	return valid;
}

function validEmail(email)
{
	var valid = true;
	
	// cannot be empty
	if (email == "") 
	{
		valid = false;					
		return valid;
	}
	
	var invalidChars = " /:,;";
	
	for (var i = 0; i < invalidChars.length; i++) 
	{	
		// does it contain any invalid characters?
		var badChar = invalidChars.charAt(i);
		
		if (email.indexOf(badChar, 0) > -1) 
		{
			valid = false;
			return valid;
		}
	}

	// there must be one "@" symbol
	var atPos = email.indexOf("@", 1);
				
	if (atPos == -1) 
	{
		valid = false;
		return valid;
	}
	
	// and only one "@" symbol
	if (email.indexOf("@", atPos+1) != -1) 
	{	
		valid = false;
		return valid;
	}

	var periodPos = email.indexOf(".", atPos);
	
	// and at least one "." after the "@"
	if (periodPos == -1) 
	{					
		valid = false;
		return valid;
	}
	
	// must be at least 2 characters after the "."
	if (periodPos + 3 > email.length)	
	{		
		valid = false;
		return valid;
	}
	
	return valid;
}
