// Validate fields on "Meeting Room" (/meeting-room/index.php)

function validateForm(frm)
{
	if(trim(frm.meetingdate.value) == '')
	{
		alert("Please enter the Meeting Date.");
		frm.meetingdate.focus();
		return false;
	}
	
	if(trim(frm.meetingtime.value) == '')
	{
		alert("Please enter the Meeting Time.");
		frm.meetingtime.focus();
		return false;
	}
	
	if(trim(frm.timein.value) == '')
	{
		alert("Please enter the Time In.");
		frm.timein.focus();
		return false;
	}
	
	if(trim(frm.timeout.value) == '')
	{
		alert("Please enter the Time Out.");
		frm.timeout.focus();
		return false;
	}
	
	if(trim(frm.name.value) == '')
	{
		alert("Please enter your name or Organization.");
		frm.name.focus();
		return false;
	}
	
	if(trim(frm.address1.value) == '')
	{
		alert("Please enter your address.");
		frm.address1.focus();
		return false;
	}
	
	if(trim(frm.city.value) == '')
	{
		alert("Please enter your city.");
		frm.city.focus();
		return false;
	}
	
	if(frm.state.selectedIndex == 0)
	{
		alert("Please select a state.");
		frm.state.focus();
		return false;
	}
	
	if(trim(frm.zip.value) == '')
	{
		alert("Please enter your zip.");
		frm.zip.focus();
		return false;
	}
	
	if(trim(frm.email.value) == '')
	{
		alert("Please enter your e-mail address.");
		frm.email.focus();
		return false;
	}
	
	if (trim(frm.email.value) != '')
	{
		/**
		 * Test to see if regular expressions are supported.
		 * If so, test the email format.
		 * Email is not required. Check format only if something is entered.
		 * Email regex taken from http://www.cambiaresearch.com/cambia3/snippets/csharp/regex/email_regex.aspx
		 * I chose to go with a simple, lenient email regex to prevent user frustration.
		 * Some invalid emails may get through, but that's better than frustrating a user. - GR
		 */
		if (window.RegExp)
		{
			var regex=/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
			if (regex.test(frm.email.value) == false)
			{
				alert("The email address does not appear to be a valid format.\nPlease check your email address for typing errors.");
				frm.email.focus();
				return false;
			}
		}
	}
	
	if(trim(frm.contact.value) == '')
	{
		alert("Please enter the Contact Person.");
		frm.contact.focus();
		return false;
	}
	
	if(trim(frm.purpose.value) == '')
	{
		alert("Please enter the Purpose of Use.");
		frm.purpose.focus();
		return false;
	}
	
	return true;
}

/**
 * Support functions
 */

function trim(str)
{
   if (!window.RegExp)
   {
	   return str;
   }
   return str.replace(/^\s*|\s*$/g,"");
}
