$(document).ready(function(){
	$('#navigation li:has(ul)').hover(
		function() { $('ul', this).css('display', 'block'); },
		function() { $('ul', this).css('display', 'none'); }
	);
});


// The text to show up within a field when it is incorrect
emptyerror = "Please fill out this field.";
emailerror = "Please enter a valid e-mail.";

// Clears any fields in the form when the user clicks on them
$(document).ready(function(){
	$(":input").focus(function(){		
	   if ($(this).hasClass("needsfilled") ) {
			$(this).val("");
			$(this).removeClass("needsfilled");
	   }
	});
});

function validate(theForm) {
	var required = [];
	
	$(theForm+' .required').each(function() {
		required[required.length] = $(this).attr('id');
	});
	//Validate required fields
	for (i=0;i<required.length;i++) {
		var input = $('#'+required[i]);
		if ((input.val() == "") || (input.val() == emptyerror)) {
			input.addClass("needsfilled");
			input.val(emptyerror);
		// Validate the e-mail.
		} else if (input.hasClass('email')) {
			if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(input.val())) {
				input.addClass("needsfilled");
				input.val(emailerror);
			}	
		} else {
			input.removeClass("needsfilled");
		}
	}
	//if any inputs on the page have the class 'needsfilled' the form will not submit
	if ($(":input").hasClass("needsfilled")) {
		$('#output').html('There were errors on the form,<br />please correct them and try again').slideDown(750);
		return false;
	}  else {
		$('#output').hide();
		return true;
	}
}