
/**
 * Called by onLoad() and sets Other to disabled for default value of Area Manager
 */
function setControls()
{
	var ctlOther = document.getElementById("vacancy_sought_other");
	ctlOther.disabled = true;
}

/**
 * If "Other" is selected then enable the "Other" textbox
 */
function checkOther(ctl)
{
	var ctlOther = document.getElementById("vacancy_sought_other");
	ctlOther.disabled = !(ctl.value == "Other");
}

/**
 * Check that all compulsory fields are correctly completed
 * prior to allowing submission
 */
function validateForm(theForm)
{
	//Compulsory fields that could be empty (excludes SELECT items that are populated automatically)
	var fldNotEmpty = new Array("full_name", "home_address", "lived_at_address", "d_o_b", "nationality");
	var fldErrorList = new Array("Your full name and title", "Your home address", "Length of time at address", "Your data of birth", "Your nationality");
	var errors = "";
	var tmpField = "";
	
	//Check that "Other" box is not empty if "Other" selected for vacancy sought
	if (theForm["vacancy_sought"].value == "Other")
	{
		if ( fieldIsEmpty(theForm["vacancy_sought_other"].value) )
		{
			errors += "\tDescription of 'other' type of vacancy sought\n";
		}
	}
	
	//Check rest of compulsory fields
	for (var i=0; i < fldNotEmpty.length; i++)
	{
		if (fieldIsEmpty(theForm[fldNotEmpty[i]].value))
		{
			errors += "\t" + fldErrorList[i] + "\n";
		}
	}
	
	if (errors != "")
	{
		alert("Please supply the following information:\n\n" + errors + "\n");
		return false;
	}
	else
	{
		theForm.action = "http://ccgi.turnersind.plus.com/mail_recruitment.php";
		theForm.submit();
		return true;
	}
	
	
	
	
}

function fieldIsEmpty(fieldValue)
{
	fieldValue = fieldValue.trim();
	return (fieldValue == "" || fieldValue == null);
}


/**
 * TRIM function for strings
 */
String.prototype.trim = function ()
{
	return this.replace(/^\s*/,"").replace(/\s*$/,"");
}

