// Scripts developed by Nick Beech
// www.nbbs.co.uk; www.nbwebsitedesign.co.uk
// http://LookAndLearnTraining.com; http://LookAndLearnTraining.co.uk

// scripts to clear field and check that email address is correct format


// check additions to mailing list ~~~not required just yet~~~
function checkEmailAdd() {
	var okToSend = true;
	// checks for @ sign and "."
	atfound = document.emailsignupform.email.value.indexOf("@");
	dotfound = document.emailsignupform.email.value.indexOf(".");
	if (atfound < 1 || dotfound < 2) {
			okToSend = false;
			alert("Invalid email address: please re-enter correct address");
		}
	// sends form if no errors
	if (okToSend == true)
			{document.emailsignupform.submit();}
	}

	
// checks enquiry form
	// clears enquiry detail box
	function clearEnqText(){
		if (document.emailsignupform.email.value == "Enter email address") {
			document.emailsignupform.email.value = "";
		}
	}
	
// function to check enquiry form

function checkEnquiryNow(){
	
// check for name
if(document.contactform.name.value == ""){
	window.alert("Please enter your name.");
	document.contactform.name.focus();
	return (false);
}
	
// check for drop down selection
if(document.contactform.howToContact.value == 0){
	window.alert("Please tell us how you would like to be contacted.");
	document.contactform.howToContact.focus();
	return (false);
}
	
	// check for contact number
if(document.contactform.howToContact.value == "Phone only" && document.contactform.contactNo.value == ""){
	window.alert("Please enter your telephone or mobile no.");
	document.contactform.contactNo.focus();
	return (false);
}
	
	// check for email address 
if(document.contactform.howToContact.value == "Email only" && document.contactform.email.value == ""){
	window.alert("Please enter your email address.");
	document.contactform.email.focus();
	return (false);
}
	
	// check for contact number if either way is selected  
if(document.contactform.howToContact.value == "Phone or email" && document.contactform.contactNo.value == ""){
	window.alert("Please enter your telephone or mobile no.");
	document.contactform.contactNo.focus();
	return (false);
}
	
	// check for email address if either way is selected
if(document.contactform.howToContact.value == "Phone or email" && document.contactform.email.value == ""){
	window.alert("Please enter your email address.");
	document.contactform.email.focus();
	return (false);
}

	// check for valid email address
if(document.contactform.email.value != ""){
	atfound = document.contactform.email.value.indexOf("@");
	dotfound = document.contactform.email.value.indexOf(".");
	if (atfound < 1 || dotfound < 2) {
		window.alert("Invalid email address: please re-enter correct address");
		document.contactform.email.focus();
		return (false);}
	}


	// check that at least one enquiry type is checked
if(document.contactform.makeDonation.checked == false && document.contactform.adoptingAnimals.checked == false && document.contactform.volunteering.checked == false && document.contactform.friendsScheme.checked == false&& document.contactform.corporateSponsorship.checked == false && document.contactform.other.checked == false){
	window.alert("Please tell us the type of your enquiry.");
		return (false);
}
	
	// check for enquiry details
if(document.contactform.other.checked == true && document.contactform.details.value == ""){
	window.alert("Please tell us about your enquiry.");
	document.contactform.details.focus();
	return (false);
}	

	// check for enquiry details
	document.contactform.securitycheck.value = document.contactform.securitycheck.value.toUpperCase();
if(document.contactform.securitycheck.value != "WILMSLOW"){
	window.alert("Please enter the text from the image correctly \nto confirm your enquiry is genuine.");
	document.contactform.securitycheck.focus();
	return (false);
}	

}
