/*************************************************************
* Page: request_account.js v 1.0  
* Description: Request an account validation
* 
* Hospitality Recruitment - Online Strategies
* Copyright (C) 2005 Online Strategies, All rights reserved
* Email  info@hospitalityonline.co.uk
* 
*************************************************************/
function validate_request_account(e){
	// Validate the form
	String.prototype.trim = function()
	{
		return this.replace(/^\s*|\s*$/g, '');
	}
	
	var grp, focus_el = null, msg = '';

	// Your Name is empty
	e.first_name.value = e.first_name.value.trim();
	if (is_empty(e.first_name))
	{
		msg += error[1];
		focus_el = focus_el || e.first_name;
	}
	e.surname.value = e.surname.value.trim();
	if (is_empty(e.surname))
	{
		msg += error[2];
		focus_el = focus_el || e.surname;
	}
	e.company_name.value = e.company_name.value.trim();
	if (is_empty(e.company_name))
	{
		msg += error[10];
		focus_el = focus_el || e.company_name;
	}
	e.position_in_company.value = e.position_in_company.value.trim();
	if (is_empty(e.position_in_company))
	{
		msg += error[247];
		focus_el = focus_el || e.position_in_company;
	}

	// Email address is empty
	e.email.value = e.email.value.trim();
	if (is_empty(e.email))
	{
		msg += error[43];
		focus_el = focus_el || e.email;
	}
	// Email address is empty
	e.email.value = e.email.value.trim();
	if (!is_empty(e.email))
	{
		if(!is_valid_email(e.email))
		{
			msg += error[44];
			focus_el = focus_el || e.email;
		}
	}
	// if telephone field is filled in make sure its a number
	e.telephone.value = e.telephone.value.trim();
	if (!is_empty(e.telephone))
	{
		if (!is_valid_phone(e.telephone))
			{
				msg += error[45];
				focus_el = focus_el || e.telephone;
			}
	}

	// 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;
}