function error(message)
{
	alert(message);
	return false;
}

function isempty(obj)
{
	if (obj.value.length == 0)
		return false;
	else
		return true;
}

function onlyspaces(obj)
{
	if (obj.value.search(/[^ ]/) != -1)
		return false;
	else
		return true;
}

function isselected(obj)
{
	if (obj.selectedIndex == 0)
		return false;
	else
		return true;
}

function validemail(obj)
{
	if (obj.value.search(/^([\'_A-Za-z0-9-]+(\.[\'_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.(([A-Za-z]{2,3})|(aero|AERO|coop|COOP|info|INFO|museum|MUSEUM|name|NAME)))?$/) == -1)
		return false;
	else
		return true;
}

function range(val, minval, maxval)
{
	if (val < minval || val > maxval)
		return false;
	else
		return true;
}

function formvalidate(theform)
{
	if (!isempty(theform.name) || onlyspaces(theform.name))
	{
		if (!error("Please enter your name."))
		{
			theform.name.select();
			return false;
		}
	}
	
	if (!isempty(theform.title) || onlyspaces(theform.title))
	{
		if (!error("Please enter your job title."))
		{
			theform.title.select();
			return false;
		}
	}
	
	if (!isempty(theform.organization) || onlyspaces(theform.organization))
	{
		if (!error("Please enter your organization."))
		{
			theform.organization.select();
			return false;
		}
	}
	
	if (!isempty(theform.address) || onlyspaces(theform.address))
	{
		if (!error("Please enter your address."))
		{
			theform.address.select();
			return false;
		}
	}
	
	if (!isempty(theform.city) || onlyspaces(theform.city))
	{
		if (!error("Please enter your city."))
		{
			theform.city.select();
			return false;
		}
	}
	
	if (!isempty(theform.state) || onlyspaces(theform.state))
	{
		if (!error("Please enter your state."))
		{
			theform.state.select();
			return false;
		}
	}
	
	if (!isempty(theform.zip) || onlyspaces(theform.zip))
	{
		if (!error("Please enter your zip."))
		{
			theform.zip.select();
			return false;
		}
	}
	
	if (!isselected(theform.contactMethod))
	{
		if (!error("Please select a contact method."))
		{
			theform.contactMethod.focus();
			return false;
		}
	}
	
	if (theform.contactMethod.options[1].selected == true)
	{
		if (!isempty(theform.phone) || onlyspaces(theform.phone))
		{
			if (!error("Please enter your phone."))
			{
				theform.phone.select();
				return false;
			}
		}
		
		if (isempty(theform.email) && !validemail(theform.email))
		{
			if (!error("Please enter a valid e-mail address."))
			{
				theform.email.select();
				return false;
			}
		}
	}
	else if (theform.contactMethod.options[2].selected == true)
	{
		if (!isempty(theform.email) || !validemail(theform.email))
		{
			if (!error("Please enter a valid e-mail address."))
			{
				theform.email.select();
				return false;
			}
		}
	}
	
	if (!range(theform.heardAbout.value.length, 0, 3000))
	{
		if (!error("Please enter no more than 3000 characters in the \"How did you hear about us?\" field."))
		{
			theform.heardAbout.select();
			return false;
		}
	}
	
	if (!range(theform.comments.value.length, 0, 3000))
	{
		if (!error("Please enter no more than 3000 characters in the \"Additional comments\" field."))
		{
			theform.comments.select();
			return false;
		}
	}
	
	return true;
}