/*************************************************************
* Page: contact_us.js v 1.0  
* Description: Contact us Validation
* 
* Hospitality Recruitment - Online Strategies
* Copyright (C) 2005 Online Strategies, All rights reserved
* Email  info@hospitalityonline.co.uk
* 
*************************************************************/
function validate_contact(e){
	if ((VALIDATE_CONTACT == 0 && JAVASCRIPT_ON == 1) || (VALIDATE_CONTACT == 0 && JAVASCRIPT_ON == 0)){ // override javascript
	
		return true; // Send the form through without Javascript DEBUG
	
	}
	else if ((VALIDATE_CONTACT == 1 && JAVASCRIPT_ON == 1) || (VALIDATE_CONTACT == 1 && JAVASCRIPT_ON == 0)){ // Validate the form
		// Validate the form
		String.prototype.trim = function()
		{
			return this.replace(/^\s*|\s*$/g, '');
		}
		
		var grp, focus_el = null, msg = '';
	
		// Your Name is empty
		e.your_name.value = e.your_name.value.trim();
		if (is_empty(e.your_name))
		{
			msg += error[42];
			focus_el = focus_el || e.your_name;
		}
		// Email address is empty
		e.your_email_address.value = e.your_email_address.value.trim();
		if (is_empty(e.your_email_address))
		{
			msg += error[43];
			focus_el = focus_el || e.your_email_address;
		}
		// Email address is empty
		e.your_email_address.value = e.your_email_address.value.trim();
		if (!is_empty(e.your_email_address))
		{
			if(!is_valid_email(e.your_email_address))
			{
				msg += error[44];
				focus_el = focus_el || e.your_email_address;
			}
		}
		// if telephone field is filled in make sure its a number
		e.your_telephone_number.value = e.your_telephone_number.value.trim();
		if (!is_empty(e.your_telephone_number))
		{
			if (!is_valid_phone(e.your_telephone_number))
				{
					msg += error[45];
					focus_el = focus_el || e.your_telephone_number;
				}
		}
		// Comment must be filled in
		e.comments.value = e.comments.value.trim();
		if (is_empty(e.comments))
		{
			msg += error[46];
			focus_el = focus_el || e.comments;
		}
		// If there is an error then send through an alert (var msg) and return false
		if (msg != '')
		{
			var prefix = "The form has been incorrectly completed:\n";
			alert(prefix + msg);
			if (focus_el.focus)
			{
				focus_el.focus();
			}
			return false;
		}
		// If there are no errors send through the form and process it.
		if (CHANGE_PROCESS == 1){
			showprocess('show','hide');
		}
		else {
			document.getElementbyId('sub').disabled = true;
		}
		return true;

	}
	else {
		// There has been an error
		alert ("Error reported to: " + ADMIN_EMAIL);
		return false;
	}
}