// JS Functions
function emailCloak() {
	if (document.getElementById) {
		var alltags = document.all? document.all : document.getElementsByTagName("*");
		for (i=0; i < alltags.length; i++) {
			if (alltags[i].className == "emailCloak") {
			var oldText = alltags[i].firstChild;
			var emailAddress = alltags[i].firstChild.nodeValue;
			var user = emailAddress.substring(0, emailAddress.indexOf("("));
			var website = emailAddress.substring(emailAddress.indexOf(")")+1, emailAddress.length);
			var newText = user+"@"+website;
			var a = document.createElement("a");
			a.href = "mailto:"+newText;
			var address = document.createTextNode(newText);
			a.appendChild(address);
			alltags[i].replaceChild(a,oldText);
			}
		}
	}
}
window.onload = emailCloak;

// Form Validation
function isValidEmail(str) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str)){
		return true;
	}
	else {
		return false;
	}
}

function checkenquiry(){
	var ftxt = "";
	
	if (document.enquiry.Name.value==''){
		ftxt += '\n- Please enter your Name.';
	}
				
	if (document.enquiry.Telephone.value==''){
		ftxt += '\n- Please enter your Telephone Number.';
	}
	
	if (isValidEmail(document.enquiry.email.value)==false){
		ftxt += '\n- Please enter your Email Address.';
	}
	
	if (document.enquiry.subject.value==''){
		ftxt += '\n- Please select the subject of this Enquiry.';
	}
	
	if (ftxt!==''){
		alert('One or more errors were found while submitting this form. The errors found are displayed below.\n' + ftxt + '\n\nPlease correct the above errors and try again');
		return false		
	}
	else{
		return true;
	}
}

function bookonline(){
	var booklink = 'http://www.ownersdirect.co.uk/canaries/C776.htm';
	var activebuttonimg = 'Images/BookOnline_Active.gif';
	var inactivebuttonimg = 'Images/BookOnline_InActive.gif';
	
	var termsagreed = document.getElementById("TermsAgreed").checked;
	
	if (termsagreed){
		document.getElementById("BookLink").href = booklink;
		document.getElementById("BookImg").src = activebuttonimg;
	}
	else {
		document.getElementById("BookLink").href = '#';
		document.getElementById("BookImg").src = inactivebuttonimg;
	}
}
