function checkFirstName(fnval) {
	var result = true;
	if (fnval == "") {
		result = false;
	}
	return result;
}
function checkLastName(lnval) {
	var result = true;
	if (lnval == "") {
		result = false;
	}
	return result;
}
function checkAddress(addressval) {
	var result = true;
	if (addressval == "") {
		result = false;
	}
	return result;
}
function checkCity(cityval) {
	var result = true;
	if (cityval == "") {
		result = false;
	}
	return result;
}
function checkState(stateval, canval, auststateval, ukprovinceval) {
	var result = true;
	if ((stateval == "nothing") && (canval == "nothing") && (auststateval == "nothing") && (ukprovinceval == "nothing")) {
		result = false;
	}
	return result;
}
function checkZip(zipval) {
	var result = true;
	if (zipval.length < 5) { 
		result = false; 
	}
	return result;
}
function checkEmail(emailval) {
	var result = true;
	if((emailval.indexOf("@") == -1)||(emailval.indexOf(".") == -1)) {
		result = false;
	}
	return result;
}


// The text of all error messages is below:

function validateAll(theForm) {
	//alert(theForm.state.options[theForm.state.selectedIndex].value);
	if(!(checkFirstName(theForm.firstname.value))) {
		alert("Please enter your first name.");
		theForm.firstname.focus();
		return false;
	} else if(!(checkLastName(theForm.lastname.value))) {
		alert("Please enter your last name.");
		theForm.lastname.focus();		
		return false;
	} else if(!(checkAddress(theForm.address1.value))) {
		alert("Please enter an address.");
		theForm.address1.focus();
		return false;
	} else if(!(checkCity(theForm.city.value))) {
		alert("Please enter a city.");
		theForm.city.focus();
		return false;
	} else if(!(checkState(theForm.state.options[theForm.state.selectedIndex].value,theForm.canprovince.options[theForm.canprovince.selectedIndex].value,theForm.auststate.options[theForm.auststate.selectedIndex].value,theForm.ukprovince.options[theForm.ukprovince.selectedIndex].value))) {
		alert("Please select a state or province.");
		return false;
	} else if(!(checkZip(theForm.zip.value))) {
		alert('Please enter a valid zip or postal code.'); 
		theForm.zip.focus();
		return false;
	} else if(!(checkEmail(theForm.email.value))) {
		alert("Please enter a valid email address.");
		theForm.email.focus();
		return false;
	}  else {
		return true;
	}
	
}

function validateFriends(theForm) {
	if(!(checkEmail(theForm.friendemail1.value))) {
		alert("Please enter a valid email address in the first box.");
		theForm.friendemail1.focus();
		return false;
	} else if((!(checkEmail(theForm.friendemail2.value))) && (theForm.friendemail2.value != "")) {
		alert("Please enter a valid email address in the second box.");
		theForm.friendemail2.focus();
		return false;
	} else if((!(checkEmail(theForm.friendemail3.value))) && (theForm.friendemail3.value != "")) {
		alert("Please enter a valid email address in the third box.");
		theForm.friendemail3.focus();
		return false;
	} else if((!(checkEmail(theForm.friendemail4.value))) && (theForm.friendemail4.value != "")) {
		alert("Please enter a valid email address in the fourth box.");
		theForm.friendemail4.focus();
		return false;
	} else if((!(checkEmail(theForm.friendemail5.value))) && (theForm.friendemail5.value != "")) {
		alert("Please enter a valid email address in the fifth box.");
		theForm.friendemail5.focus();
		return false;
	} else if(!(checkLastName(theForm.yourname.value))) {
		alert("Please enter your name.");
		theForm.yourname.focus();
		return false;
	} else if(!(checkEmail(theForm.youremail.value))) {
		alert("Please double-check your email address.");
		theForm.youremail.focus();
		return false;
	} else {
		return true;
	}


}