// Function for navigation
function gotoLink(linkURL) {
	document.location.href = linkURL;
}

// Function to change the style on mouse over for the nav menu items
function changeMenuItem(tdID, tdClass) {
	document.getElementById(tdID).className = tdClass;
}

// Function to change the style on mouse over for the drop down menu items
function changeDropMenuItem(tdID, tdClass, linkID, linkClass) {
	document.getElementById(tdID).className = tdClass;
	document.getElementById(linkID).className = linkClass;
}

// Dynamically set the top position of the drop down menus
function setMenuTop(topNavID, menuID) {
	if(document.getElementById(topNavID)) {
		var topnav = document.getElementById(topNavID);
		var menu = document.getElementById(menuID);
		var navOffTop = getPosTop(topnav);
		var padding = 20;
		menu.style.top = (navOffTop+padding)+"px";
	}
}

// Used to get the position of the menu bar
function getPosTop(theObj) {
	var theTop,thePar;
	theTop = theObj.offsetTop;
	while(theObj.offsetParent!=null) {
		thePar = theObj.offsetParent;
		theTop += thePar.offsetTop;
		theObj = thePar;
	}
	return theTop;
}

// Clear the email field on the newsletter form
function checkDefaultEmail() {
	if (document.newsletterForm.email_address.value == "Enter Your E-Mail Address") {
		document.newsletterForm.email_address.value = "";
	}
}

// Validate the email address being entered
function validateEmail (email) {
	
	if (email == "" || email.indexOf("@") == -1	|| email.indexOf(" ") != -1	|| email.indexOf("@") == 0
		|| email.indexOf("@") == (email.length - 1) || email.indexOf(".") == -1	|| email.indexOf(".") == (email.length - 1)	
		|| email.indexOf("@") + 1 == email.indexOf(".")	|| email.indexOf(".") + 1 == email.indexOf("@")) {
	
			return false;
	}	else {
		return true;
	}
	
}

// Validate a contact form submission
function validateContact() {
	
	if (!validateEmail(document.forms['contactForm'].contact_email_address.value)) {
		alert ("Please enter a valid email adddress.");
		document.forms['contactForm'].contact_email_address.focus();
		document.forms['contactForm'].contact_email_address.select();
		return false;
	} else {
		return true;
	}
	
}

// Validate a newsletter signup form submission
function validateNewsletterSignup() {
	
	if (!validateEmail(document.forms['newsletterForm'].email_address.value)) {
		alert ("Please enter a valid email adddress.");
		document.forms['newsletterForm'].email_address.focus();
		document.forms['newsletterForm'].email_address.select();
		return false;
	} else {
		return true;
	}
	
}