// form validation functions
function ValidateQ2(form) {

	if (form.MagBuy[0].checked) {
		if (form.MagRead.value.length < 1) {
			alert("How thoroughly did you read the magazine?");
			return false;
		}
		if (form.MagFinish.value.length < 1) {
			alert("What did you do after you read the magazine?");
			return false;
		}
		if (form.MagLike.value.length < 1) {
			alert("What did you like about the magazine?");
			form.MagLike.focus();
			return false;
		}
	}
	if (count > 0 && count < 15) {
		alert("Please finish rating the fashion guides!");
		return false;
	}
	if (form.Age.value.length < 1) {
		alert("Please select your age group!");
		return false;
	}
	if (form.Income.value.length < 1) {
		alert("Please select your income group!");
		return false;
	}
	if (form.Language.value.length < 1) {
		alert("Please select your home language!");
		return false;
	}
	if (form.Area.value.length < 1) {
		alert("Where do you live?");
		return false;
	}
	
	return true;
}

function ValidateQ1(form) {

	if (form.Age.value.length < 1) {
		alert("Please select your age!");
		return false;
	}
	if (form.MakeUp_R.value.length < 1 && form.SkinCare_R.value.length < 1) {
		alert("How much do you spend on makeup and skincare per month?");
		return false;
	}
	if (form.BuyBefore[1].checked && form.Brands.value.length < 1) {
		alert("Please fill in your brands!");
		form.Brands.focus();
		return false;
	}
	if (form.Complimentary[0].checked && form.Rate.value.length < 1) {
		alert("Please rate your consultation!");
		return false;
	}
	if (form.BuyAfter[0].checked && (form.EL_MakeUp_R.value.length < 1 && form.EL_SkinCare_R.value.length < 1)) {
		alert("How much did you spend on Estee Lauder makeup and skincare?");
		form.EL_MakeUp_R.focus();
		return false;
	}
	if (form.BuyAfter[0].checked && form.Information.value.length < 1) {
		alert("Where did you get information from?");
		return false;
	}
	
	return true;
}

function ValidateOrder(form) {

	if (form.firstname.value.length < 1) {
		alert("Please fill in your name!");
		form.firstname.focus();
		return false;
	}
	if (form.lastname.value.length < 1) {
		alert("Please fill in your surname!");
		form.lastname.focus();
		return false;
	}
	if (form.address1.value.length < 1) {
		alert("Please fill in your address!");
		form.address1.focus();
		return false;
	}
	if (form.city.value.length < 1) {
		alert("Please fill in your city!");
		form.city.focus();
		return false;
	}
	if (form.province.value.length < 1) {
		alert("Please fill in your province!");
		form.province.focus();
		return false;
	}
	if (form.postcode.value.length < 1) {
		alert("Please fill in your postal code!");
		form.postcode.focus();
		return false;
	}
	if (form.phone.value.length < 1) {
		alert("Please fill in your phone number!");
		form.phone.focus();
		return false;
	}
	if (form.fax.value.length < 1) {
		alert("Please fill in your fax number!");
		form.fax.focus();
		return false;
	}
	if (!ValidEmail(form.email.value)) {
		alert("Please fill in a valid email address!");
		form.email.focus();
		return false;
	}
	if (form.cardtype.value.length < 1) {
		alert("Please select your credit card!");
		return false;
	}
	if (form.expmonth.value.length < 1 || form.expyear.value.length < 1) {
		alert("Please select your expiry date!");
		return false;
	}
	
	return true;
}

function validateEnquiry(frm){
	if (frm.fname.value.length == 0){
		alert('Please enter your first name.');
		frm.fname.focus();
		return false;
	}
	if (frm.lname.value.length == 0){
		alert('Please enter your last name.');
		frm.lname.focus();
		return false;
	}
	if (!ValidEmail(frm.email.value)){
		alert('Please enter a valid email address.');
		frm.email.focus();
		return false;
	}
	if (frm.suburb.value.length == 0){
		alert('Please enter your suburb/town.');
		frm.suburb.focus();
		return false;
	}
	if (frm.state.value.length == 0){
		alert('Please enter your state.');
		frm.state.focus();
		return false;
	}
	if (frm.phone.value.length == 0){
		alert('Please enter your telephone number.');
		frm.phone.focus();
		return false;
	}
}

// validate an email address
function ValidEmail(email)
{
	var re = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	return re.test(email);
}
