function clearQuotes(theForm) {
	for (i=0;i<theForm.elements.length;i++) {
		if (theForm.elements[i].value) {
			theForm.elements[i].value = theForm.elements[i].value.replace(/'/gi,"`");
		}
	}
}

function checkEmail(theEmail) {
	if (theEmail.indexOf('.')==-1) return false;
	if (theEmail.indexOf('@')==-1) return false;
	if (theEmail.length<6) return false;
	return true;
}



/*** EMPLOYMENT FORM ***/

function checkJobForm() {
	theForm = document.jobFormName;
	clearQuotes(theForm);
	if (theForm.fname.value.length<1) {alert("Please enter your first name.");return false;}
	if (theForm.lname.value.length<1) {alert("Please enter your last name.");return false;}
	var theEmail = theForm.email.value;
	if (checkEmail(theEmail)==false) {alert("Please enter a valid email address.");return false;}
	if (theForm.phone1.value.length<1) {alert("Please enter a contact phone number.");return false;}
	return true;
}

/*** COMP FORM ***/

function checkComp() {
	var theForm = document.CompetitionForm;
	clearQuotes(theForm);
	var theMode = theForm.mode.value;

	if (theForm.fname.value.length<2) {alert("Please enter your first name");return false;}
	if (theForm.lname.value.length<2) {alert("Please enter your last name");return false;}
	if (theForm.email.value.length<2) {alert("Please enter your email address");return false;}
	var theEmail = theForm.email.value;
	if (checkEmail(theEmail)==false) {alert("Please enter a valid email address.");return false;}
	if (theForm.postcode.value.length<4) {alert("Please enter your postcode");return false;}

	if (theForm.data01.checked==false) {alert("You must agree to the terms and conditions to enter");return false;}

	if (theMode==0) {
		var state = "Unknown";
		if (theForm.postcode.value.length==4 && !isNaN(theForm.postcode.value/2)) {
			var postSort = theForm.postcode.value.substring(0,1);
			switch(postSort) {
				case "0": state="NT"; break;
				case "2": state="NSW"; break;
				case "8":
				case "3": state="VIC"; break;
				case "9":
				case "4": state="QLD"; break;
				case "5": state="SA"; break;
				case "6": state="WA"; break;
				case "7": state="TAS"; break;
				default: state="Unknown"; break;
			}
			theForm.cat.value = state;
			theForm.subcat.value = theForm.postcode.value;
		}
	}
	return true;
}


function checkCompHBF() {
	var theForm = document.CompetitionForm;
	clearQuotes(theForm);
	if (theForm.fname.value.length<2) {alert("Please enter your first name");return false;}
	if (theForm.lname.value.length<2) {alert("Please enter your last name");return false;}
	if (theForm.org.value.length<2) {alert("Please enter your HBF Member Number");return false;}
	if (theForm.email.value.length<2) {alert("Please enter your email address");return false;}
	var theEmail = theForm.email.value;
	if (checkEmail(theEmail)==false) {alert("Please enter a valid email address.");return false;}
	if (theForm.postcode.value.length<4) {alert("Please enter your postcode");return false;}
	return true;
}
