function checkContact(){
	if(document.contactForm.email.value=="" ||document.contactForm.subject.value=="" || document.contactForm.message.value==""){
		alert("You must fill in all fields");
		return false;
	}
	return checkEmail(document.contactForm.email.value);
}

function checkMailingList(){
	if(document.mailingList.agree.checked!=true){
		alert("You must agree to give your consent for Artlink to store your personal information");
		return false;
	}
	if(document.mailingList.functionsuite.checked!=true && document.mailingList.review.checked!=true && document.mailingList.volunteering.checked!=true && document.mailingList.artist.checked!=true && document.mailingList.audioDescribed.checked!=true && document.mailingList.BSLCaptioned.checked!=true){
		alert("You must select at least one mailing list to subscribe to");
		return false;
	}
	if(document.mailingList.name.value=="" ||document.mailingList.address.value=="" || document.mailingList.postCode.value=="" || document.mailingList.email.value==""){
		alert("You must fill in all fields");
		return false;
	}
	if(checkPostCode()==false)
		return false;
	if(checkTelephone()==false)
		return false;
	if(checkChars9()==false)
		return false;
	if(checkEmail(document.mailingList.email.value)==false)
		return false;
}

function checkEmail(email) {
	AtPos = email.indexOf("@")
	StopPos = email.lastIndexOf(".")
	Message = ""

	if (AtPos == -1 || StopPos == -1) {
		alert("Please enter a valid Email address" + "\n")
		return false
	}
	
	if (StopPos < AtPos) {
		alert("Please enter a valid Email address" + "\n")
		return false
	}
	
	if (StopPos - AtPos == 1) {
		alert("Please enter a valid Email address" + "\n")
		return false
	}
}

function checknumber(){
	var x=document.mailingList.telephone.value
	var anum=/(^\d+$)|(^\d+\.\d+$)/
	if (!anum.test(x)){
		alert("Your telephone number cannot have characters other than numbers.\nPlease check and resubmit.")
		return false;
	}
}


function checkTelephone(){
	if(document.mailingList.telephone.value!=""){
		if (document.layers||document.all||document.getElementById)
			return checknumber()
	}
}

function checkPostCode(){
	if(document.mailingList.postCode.value.length<6 || document.mailingList.postCode.value.length>8){
		alert("Please ensure your Post Code contains the right amount of digits");
		return false;
	}
}

function checkChars9(){
	var minlength=9
	if(document.mailingList.telephone.value!=""){
		if (document.mailingList.telephone.value.length<minlength){
			alert("Your Telephone number seems to be too short, please check and resubmit with full area code.")
			return false
		}
	}
}