
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;
}

function checkCompetition() {
	theForm=document.CompetitionForm;
	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;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}
	if (theForm.phone1.value.length<1) {alert("Please enter your phone number.");return false;}

	if (theForm.verificationCode) {
		if (theForm.verificationCode.value.length<1) {alert("Please enter the verification code.");return false;}
	}

	return true;
}

function checkSubscription()
{
	theForm=document.SubscriptionForm;
	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;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}
	if (theForm.phone1.value.length<1) {alert("Please enter your phone number.");return false;}

	if (theForm.verificationCode) {
		if (theForm.verificationCode.value.length<1) {alert("Please enter the verification code.");return false;}
	}
	catcount = 0;
	
	for (i = 0; i < theForm.catcount.value; i++)
	{
		index   	= (i < 10) ? "0"+i : ""+i;
		cat 		= eval("theForm.cat"+index);

		if (!cat.checked)   catcount++;
	}
	if (catcount == theForm.catcount.value)
	{
		alert('Please choose at least one newsletter subscription');
		return false;
	}
	for (i = 0; i < theForm.miscfieldcount.value; i++)
	{
		index   	= (i < 10) ? "0"+i : ""+i;
		cat 		= eval("theForm.cat"+index);
		misclabel 	= eval("theForm.label"+index);
		miscdata 	= eval("theForm.data"+index);
		response 	= eval("theForm.response"+i);

		if (!cat.checked)
		{
			misclabel.value = '';
			miscdata.value = '';
			response.value = '';
		}
	}
	return true;
}

function checkEnquiry() {
	theForm=document.EnquiryForm;
	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;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}
	if (theForm.phone1.value.length<1) {alert("Please enter your phone number.");return false;}

	if (theForm.subject.value.length<1) {alert("Please enter a subject for your enquiry.");return false;}
	if (theForm.notes.value.length<1) {alert("Please enter a message.");return false;}

	if (theForm.verificationCode) {
		if (theForm.verificationCode.value.length<1) {alert("Please enter the verification code.");return false;}
	}

	return true;
}

function checkMember() {
	theForm=document.MemberForm;
	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;}
	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}
	if (theForm.phone1.value.length<1) {alert("Please enter your phone number.");return false;}

	if (theForm.password.value.length<1) {alert("Please enter a password.");return false;}
	if (theForm.password2.value.length<1) {alert("Please enter your password again.");return false;}
	if (theForm.password.value != theForm.password2.value) {alert("Your passwords do not match. Please retype them.");return false;}

	if (theForm.verificationCode) {
		if (theForm.verificationCode.value.length<1) {alert("Please enter the verification code.");return false;}
	}

	return true;
}

function checkJoinNow(f)
{
	with(f)
	{
		if (checkEmail(email.value) == false)
		{
			alert("The email address you have entered does not seem to be valid.");
			return false;
		}
	}
	
}



function checkRequest() {
	theForm=document.RequestForm;
	clearQuotes(theForm);

	if (theForm.data00.checked==false) {alert("Please indicate that you would like to receive our information kit.");return false;}
	
	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;}

	if (theForm.street.value.length<1) {alert("Please enter your street address and number.");return false;}
	if (theForm.suburb.value.length<1) {alert("Please enter your town or suburb.");return false;}
	if (theForm.postcode.value.length<1) {alert("Please enter your post or zip code.");return false;}
	if (theForm.state.value.length<1) {alert("Please enter your state or region.");return false;}

	if (theForm.country.selectedIndex==0) {alert("Please select your country.");return false;}

	if (theForm.email.value.length<1) {alert("Please enter your email address.");return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");return false;}
	if (theForm.phone1.value.length<1) {alert("Please enter your phone number.");return false;}

	if (theForm.data06.value.length<1) {alert("Please tell us how you found out about us.");return false;}

	if (theForm.verificationCode) {
		if (theForm.verificationCode.value.length<1) {alert("Please enter the verification code.");return false;}
	}

	return true;
}



function doDOB() {
	var theForm = document.applicationForm;
	var theDay   = theForm.dob_d.options[theForm.dob_d.selectedIndex].value;
	var theMonth = theForm.dob_m.options[theForm.dob_m.selectedIndex].value;
	var theYear  = theForm.dob_y.options[theForm.dob_y.selectedIndex].value;
	theForm.dob.value = theYear+"-";
	if (theMonth.length==1) theForm.dob.value += "0";
	theForm.dob.value += theMonth+"-";
	if (theDay.length==1) theForm.dob.value += "0";
	theForm.dob.value += theDay;
}

function checkApplication() {
	theForm=document.applicationForm;
	clearQuotes(theForm);
	
	if (theForm.fname.value.length<1) {alert("Please enter your given name.");theForm.fname.focus();return false;}
	if (theForm.lname.value.length<1) {alert("Please enter your surname.");theForm.lname.focus();return false;}
	if (theForm.street.value.length<1) {alert("Please enter your street address and number.");theForm.street.focus();return false;}
	if (theForm.suburb.value.length<1) {alert("Please enter your town or suburb.");theForm.suburb.focus();return false;}
	if (theForm.postcode.value.length<1) {alert("Please enter your post or zip code.");theForm.postcode.focus();return false;}

	var checkSum = 0;
	if (theForm.phone1.value.length>1) checkSum++;
	if (theForm.phone2.value.length>1) checkSum++;
	if (theForm.mobile.value.length>1) checkSum++;
	if (theForm.fax.value.length>1) checkSum++;	
	if (checkSum==0) {alert("Please enter a contact phone number.");theForm.phone1.focus();return false;}

	if (theForm.email.value.length<1) {alert("Please enter your email address.");theForm.email.focus();return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");theForm.email.focus();return false;}
	if (theForm.phone1.value.length<1) {alert("Please enter your phone number.");return false;}

	if (theForm.data02.value.length<1) {alert("Please tell us how you found out about our programs.");theForm.data02.focus();return false;}
	if (theForm.position.value.length<1) {alert("Please enter your occupation.");theForm.position.focus();return false;}
	if (theForm.data03.value.length<1) {alert("Please tell us how many years of experience you have.");theForm.data03.focus();return false;}
	if (theForm.data04.value.length<1) {alert("Please enter your qualifications.");theForm.data04.focus();return false;}

	doDOB();

	if (theForm.data05.value.length<1) {alert("Please enter a summary of your work experience and qualifications.");theForm.data05.focus();return false;}
	if (theForm.data06.value.length<1) {alert("Please tell us what has led you to participate in our programs.");theForm.data06.focus();return false;}
	if (theForm.data07.value.length<1) {alert("Please tell us what you seek to gain from our programs.");theForm.data07.focus();return false;}

	return true;
}



function checkApplication3() {
	theForm=document.applicationForm;
	clearQuotes(theForm);
	
	if (theForm.fname.value.length<1) {alert("Please enter your given name.");theForm.fname.focus();return false;}
	if (theForm.lname.value.length<1) {alert("Please enter your surname.");theForm.lname.focus();return false;}
	if (theForm.street.value.length<1) {alert("Please enter your street address and number.");theForm.street.focus();return false;}
	if (theForm.suburb.value.length<1) {alert("Please enter your town or suburb.");theForm.suburb.focus();return false;}
	if (theForm.postcode.value.length<1) {alert("Please enter your post or zip code.");theForm.postcode.focus();return false;}

	var checkSum = 0;
	if (theForm.phone1.value.length>1) checkSum++;
	if (theForm.phone2.value.length>1) checkSum++;
	if (theForm.mobile.value.length>1) checkSum++;
	if (theForm.fax.value.length>1) checkSum++;	
	if (checkSum==0) {alert("Please enter a contact phone number.");theForm.phone1.focus();return false;}

	if (theForm.email.value.length<1) {alert("Please enter your email address.");theForm.email.focus();return false;}
	if (checkEmail(theForm.email.value)==false) {alert("The email address you have entered does not seem to be valid.");theForm.email.focus();return false;}
	if (theForm.phone1.value.length<1) {alert("Please enter your phone number.");return false;}

	if (theForm.data02.value.length<1) {alert("Please tell us how you found out about Leadership Odyssey 120");theForm.data02.focus();return false;}
	if (theForm.position.value.length<1) {alert("Please enter your occupation.");theForm.position.focus();return false;}
	if (theForm.data03.value.length<1) {alert("Please tell us how many years of experience you have.");theForm.data03.focus();return false;}
	if (theForm.data04.value.length<1) {alert("Please enter your qualifications.");theForm.data04.focus();return false;}

	doDOB();

	return true;
}
