﻿function focusField(thisfield) { 
	thisfield.select(); 
	thisfield.style.border='1px solid #47c047'; 
}

function blurField(thisfield) { 
	thisfield.style.border='1px solid #A5ACB2'; 
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function validateAurionApplication() {
	if (SurnameOK() == false) return false;		
	
	return true;
}

function SurnameOK() {	
	var name = trim(document.recaction.T309F020_SURNAME.value);
	if (name.length == 0 || name=="") {
		alert("Please enter your Surname.");
		return false;
	}
	return true;
}


function validateApplication() {
	if (firstpreferenceOK() == false) return false;
	if (secondpreferenceOK() == false) return false;
	if (positiontypeOK() == false) return false;
	if (nameOK() == false) return false;		
	if (addressOK() == false) return false;	
	if (suburbOK() == false) return false;	
	if (phoneOK() == false) return false;	
	if (dobOK() == false) return false;	
	if (licenseOK() == false) return false;	
	if (vehicleOK() == false) return false;	
	
	return true;
}

function nameOK() {	
	var name = trim(document.applicationform.Applicants_Name.value);
	if (name.length == 0 || name=="") {
		alert("Please enter your Name.");
		return false;
	}
	return true;
}
function firstpreferenceOK() {	
	if(document.applicationform.First_Pref.value == "notset") {
		alert("Please select your First Preference.");
		return false;
	}	
	return true;
}
function secondpreferenceOK() {	
	if(document.applicationform.Second_Pref.value == "notset") {
		alert("Please select your Second Preference.");
		return false;
	}	
	return true;
}
function positiontypeOK() {	
	if(document.applicationform.Type_Pos.value == "notset") {
		alert("Please select the type of position.");
		return false;
	}	
	return true;
}
function addressOK() {	
	var address = trim(document.applicationform.Address_ln1.value);
	if (address.length == 0 || address=="") {
		alert("Please enter your Address.");
		return false;
	}
	return true;
}
function suburbOK() {	
	var suburb = trim(document.applicationform.Location.value);
	if (suburb.length == 0 || suburb=="") {
		alert("Please enter your Suburb / City.");
		return false;
	}
	return true;
}
function phoneOK() {	
	var phone = trim(document.applicationform.Phone.value);
	if (phone.length == 0 || phone=="") {
		alert("Please enter your Phone Number.");
		return false;
	}
	return true;
}
function dobOK() {	
	if(document.applicationform.DOB.value == "dd" || document.applicationform.DOB.value.length == 0 || String(Number(document.applicationform.DOB.value)) == "NaN") {
		alert("Please enter the day you were born.");
		return false;
	}
	if(document.applicationform.DOB_Month.value == "notset") {
		alert("Please select the month you were born.");
		return false;
	}
	if(document.applicationform.DOB_Year.value == "YYYY" || document.applicationform.DOB_Year.value.length == 0 || String(Number(document.applicationform.DOB_Year.value)) == "NaN") {
		alert("Please specify the year you were born.");
		return false;
	}

	return true;
}
function licenseOK() {	
	if(document.applicationform.Drivers_License.value == "notset") {
		alert("Please indicate if you have a Driver's License.");
		return false;
	}
	
	return true;
}
function vehicleOK() {	
	if(document.applicationform.Own_Vehicle.value == "Own_Vehicle-Yes") {
		if(document.applicationform.Car_Type.value.length == 0 || document.applicationform.Car_Type.value == "") {
			alert("Since you specified that you do have your own vehicle,\nPlease specify what type of car it is.");
			return false;
		}
	} else if(document.applicationform.Own_Vehicle.value == "notset") {
		alert("Please indicate weather you have your own vehicle.");
		return false;
	}
	return true;
}