/*---------------------------------------------------------------------------------------
 * Validate.js
 *
 * This validates forms via javascript.
 * 
 * Required:
 *   <div id="status"></div>
 *   <input ... class="required" title="VALUENAME" id="VALUENAME" />
 * 
 *-------------------------------------------------------------------------------------*/
function validateForm(form) 
{
	for(i = 0; i < form.elements.length; i++) {
		if(form.elements[i].className.match('required') == "required" && form.elements[i].value == "") {
			if(document.getElementById && document.appendChild && document.createElement) {
				document.getElementById('status').innerHTML = "<p>'" + form.elements[i].title + "' is required and has not been filled in. Please enter a value and resubmit.</p>";
			} else {
				alert("'" + form.elements[i].title + "' is required and has not been filled in. Please enter a value and resubmit.");
			}
			
			document.location.href = "#status";
			form.elements[i].focus();
			return false;
		}
	}

	//contact form extra check.
	if(form.name == "frmcontact")
	{
		if( form.email.value != form.confirm_email.value){
			
			document.getElementById('status').innerHTML = "<p>The 'Email' and 'Confirm Email' fields are not identical.</p>";
			document.location.href = "#status";
			form.elements['confirm_email'].focus();
			return false;
		}
	}
	
	//below are further checks for the application process.	
	if(form.step.value == "step1")
	{
		if( form.email.value != form.confirm_email.value)
		{
			document.getElementById('status').innerHTML = "<p>The 'Email' and 'Confirm Email' fields are not identical.</p>";
			document.location.href = "#status";
			form.elements['email'].focus();
			return false;
		}

		if(!form.elements['field[declarationcheck]'].checked)
		{
			
			document.getElementById('status').innerHTML = "<p>Please tick the confirmation checkbox to proceed.</p>";
			document.location.href = "#status";
			form.elements['field[declarationcheck]'].focus();
			return false;			
		}


	}
	
	if(form.step.value == "step6")
	{
		if(!form.finaldeclaration.checked)
		{
			
			document.getElementById('status').innerHTML = "<p>Please tick the confirmation checkbox to proceed.</p>";
			document.location.href = "#status";
			form.elements['finaldeclaration'].focus();
			return false;			
		}
	}

	return true;	
}