/*Drop Menu Script (SuckerFish Hover Fix)*/
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

/*Bookmark Me Fix*/
function bookmarksite(title, url){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}
/* Banner Image */
var theImages = new Array()
theImages[0] = 'images/DevonBanners/Bench.jpg'
theImages[1] = 'images/DevonBanners/Bluebells.jpg'
theImages[2] = 'images/DevonBanners/Bridge.jpg'
theImages[3] = 'images/DevonBanners/Cottages.jpg'
theImages[4] = 'images/DevonBanners/Driveway.jpg'
theImages[5] = 'images/DevonBanners/Farmhouse.jpg'
theImages[6] = 'images/DevonBanners/Fence.jpg'
theImages[7] = 'images/DevonBanners/Field.jpg'
theImages[8] = 'images/DevonBanners/Flowerbeds.jpg'
theImages[9] = 'images/DevonBanners/Forest.jpg'
theImages[10] = 'images/DevonBanners/Leaf.jpg'
theImages[11] = 'images/DevonBanners/Plough.jpg'
theImages[12] = 'images/DevonBanners/Sunbeams.jpg'
var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write('<img src="'+theImages[whichImage]+'">');
}

/*Validate email forms*/
function validate_form(formname){
    if(formname=="contact"){
        if(document.getElementById("name").value==""){
            alert("Please enter your name");
						document.getElementById("name").focus();
        }
        else{ 
            if (! checkEmail(document.getElementById("from").value)){
            	alert("Please enter a valid email address");
							document.getElementById("from").focus();
            }
            else{
            	document.getElementById(formname).submit();
            }
        }
    }
	   else if (formname=="bookaretreat"){
        if (document.getElementById("name").value==""){
            alert("Please enter your name");
						document.getElementById("name").focus();
        }
        else if (! checkEmail(document.getElementById("from").value)){
            alert("Please enter a valid email address");
						document.getElementById("from").focus();
        }
       else if (document.getElementById("tel").value==""){
					  alert("Please enter your Telephone Number");
						document.getElementById("tel").focus();
        }
        else if (document.getElementById("mob").value==""){
            alert("Please enter your Mobile Number");
						document.getElementById("mob").focus();
        }
        else if(document.getElementById("source").value=="Please Select"){
            alert("Please select where you heard of us");
						document.getElementById("source").focus();
        }
        else if (document.getElementById("retreat").value==""){
            alert("Please enter the retreat you want to book on");
						document.getElementById("retreat").focus();
        }
        else if (document.getElementById("room").value==""){
            alert("What is your choice of room");
						document.getElementById("room").focus();
        }
        else{ 
            	document.getElementById(formname).submit();
        }
    }
    else if(formname=="waiting"){
        if(document.getElementById("name").value==""){
            alert("Please enter your name");
						document.getElementById("name").focus();
        }
        else if(! checkEmail(document.getElementById("from").value)){
            alert("Please enter a valid email address");
						document.getElementById("from").focus();
        }
        else if (document.getElementById("Notice").value==""){
            alert("How close to the retreat can you know");
						document.getElementById("Notice").focus();
        }        
				else if(document.getElementById("source").value=="Please Select"){
            alert("Please select where you heard of us");
						document.getElementById("source").focus();
        }
        else if (document.getElementById("room").value==""){
            alert("What is your choice of room");
						document.getElementById("room").focus();
        }
        else if (document.getElementById("retreat").value==""){
            alert("Which retreat are you waiting for");
						document.getElementById("retreat").focus();
        }
        else{ 
//            alert("passed");
            	document.getElementById(formname).submit();
        }
    }
	   else if (formname=="intros"){
        if (document.getElementById("name").value==""){
            alert("Please enter your name");
						document.getElementById("name").focus();
        }
        else if(document.getElementById("age").value==""){
            alert("Please enter your age");
						document.getElementById("age").focus();
        }							
				else if (isNaN(document.intros.age.value)) {
						alert("Please enter a numeric value only!");
						document.getElementById("age").focus();
				}
  				else if(document.getElementById("weight").value==""){
            alert("Please enter your weight");
						document.getElementById("weight").focus();
        }
        else if(document.getElementById("retreat").value==""){
            alert("Please enter the retreat dates you are on");
						document.getElementById("retreat").focus();
        }
        else if(document.getElementById("source").value=="Please Select"){
            alert("Please select where you heard of us");
						document.getElementById("source").focus();
        }
        else if (! document.getElementById("final").checked){
            alert("Please tick the final box, confirming the validity of your statements");
						document.getElementById("final").focus();
        }
        else{ 
            	document.getElementById(formname).submit();
        }
		}
}

function checkEmail(email) {
	if( /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
		return (true);
}

function obfuscate(name,address,tld){
  document.write("<a href=" + "mail" + "to:" + email + "@" + address+ "." + tld+ ">" +email + "@" + address+ "." + tld + "</a>" );
}

