var REGEXP = Array();
REGEXP['Email'] = /^[_A-Za-z0-9-]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*$/;


var errBox;
var msgBox;
var queryParam = window.location.search.toQueryParams();

Behaviour.register
(
	{
		'#boxErrors' : function(element)
		{
			errBox = new jsMsgBox(element, 'Errors');
		},
		'#boxMessages' : function(element)
		{
			msgBox = new jsMsgBox(element, '');
			
			switch (queryParam.action)
			{
				case 'done':
					msgBox.show('\nThank you for contacting us\n');
				break;
			}
		},
		'#contact_submit' : function(element)
		{
			$(element).observe('click', function(event)
			{
				var Error = '';

				if ($F('contact_name').strip().length < 2)
				{
					Error += '  - Name is required and appears too short\n';
				}

				if ($F('contact_title').strip().length < 2)
				{
					Error += '  - Title is required and appears too short\n';
				}

				if ($F('contact_city').strip().length < 2)
				{
					Error += '  - City is required and appears too short\n';
				}

				if ($F('contact_state').strip().length < 2)
				{
					Error += '  - State is required\n';
				}

				if ($F('contact_email').strip() == '' || ! valEmail($F('contact_email').strip()))
				{
					Error += '  - Email is required and appears invalid\n';
				}

				if (Error != '')
				{
					errBox.show('The following errors occurred while trying to submit your information\n\n' + Error);
					return false;
				}
				
				$('action').setValue('contactus');
				$('contact_form').submit();
			});
		}
	}
);