/**************************
/*	JS For the Main
/*	navigation menu
****/
var timeout  = 500;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open()
{  jsddm_canceltimer();
 jsddm_close();
 ddmenuitem = $(this).find('ul').css('visibility', 'visible');}

function jsddm_close()
{  if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');}

function jsddm_timer()
{  closetimer = window.setTimeout(jsddm_close, timeout);}

function jsddm_canceltimer()
{  if(closetimer)
 {  window.clearTimeout(closetimer);
  closetimer = null;}}

$(document).ready(function(){
	$('#mainnav > li').bind('mouseover', jsddm_open);
	$('#mainnav > li').bind('mouseout',  jsddm_timer);
	
	$(".btn-slide").click(function(){
	  $("#featuredPanel").slideToggle("slow");
	  $(this).toggleClass("active");
	  return false;
	});
	
});

document.onclick = jsddm_close;

/**************************
/*	Verifies the contact form
/*	submissions
****/
function verify_form(theform, type) {

	var	error = "",
		e_regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,})+$/;

	if (type == 'recover') {

		if(theform.email.value == "" || theform.email.value == "Email") {
			error += "You did not enter your email.\n";
		} else if (!e_regex.test(theform.email.value)) {
			error += "Invalid email address. Please check for typing mistakes.\n";
		}
	}
	
	if (type == 'login') {
		
		if(theform.email.value == "" || theform.email.value == "Email") {
			error += "You did not enter your email.\n";
		} else if (!e_regex.test(theform.email.value)) {
			error += "Invalid email address. Please check for typing mistakes.\n";
		}
		
		if (theform.password.value == "" || theform.password.value == "Password") {
			error += "You did not enter your password.\n";
		}
	}
	
	if (type == 'register') {
		
		if (theform.firstname.value == "" || theform.firstname.value == "First name") {
			error += "You did not enter your first name.\n";
		}
		
		if (theform.lastname.value == "" || theform.lastname.value == "Last name") {
			error += "You did not enter your last name.\n";
		}
		
		if(theform.email.value == "" || theform.email.value == "Email") {
			error += "You did not enter your email.\n";
		} else if (!e_regex.test(theform.email.value)) {
			error += "Invalid email address. Please check for typing mistakes.\n";
		}
		
		if (theform.phone.value == "" || theform.phone.value == "Phone" || theform.phone.value.length < 10) {
			error += "You did not enter your Phone (must include area code).\n";
		}
		
		if (theform.password.value == "" || theform.password.value == "Password") {
			error += "You did not enter your password.\n";
		}
			
	}
	
	if (type == 'contact') {
	
		if (theform.firstname.value == "" || theform.firstname.value == "First name") {
			error += "You did not enter your first name.\n";
		}
		
		if (theform.lastname.value == "" || theform.lastname.value == "Last name") {
			error += "You did not enter your last name.\n";
		}
		
		if(theform.email.value == "" || theform.email.value == "Email") {
			error += "You did not enter your email.\n";
		} else if (!e_regex.test(theform.email.value)) {
			error += "Invalid email address. Please check for typing mistakes.\n";
		}
		
		if (theform.phone.value == "" || theform.phone.value == "Phone" || theform.phone.value.length < 10) {
			error += "You did not enter your Phone (must include area code).\n";
		}
		
			
		if (theform.comment.value == "") {
			error += "You did not enter any comments for us.\n";
		}
	}
	
	if (error) {
		alert("**The form returned the following errors, please fix them to send your comments:**\n\n" + error);
		error="";
		
		return false;
	} else {
		return true;
	}
}
