$(document).ready(function(){
	$('li.subnav').hover(
		function() {$('ul:first', this).css('display', 'block');},
		function() {$('ul:first', this).css('display', 'none');}
	);
	
	// Place ID's of all required fields here. If using ID's other than #email, #cardnum, or #card_brand, replace them here
	required = ["first_name", "last_name", "company", "email" , "phone"];
	errornotice = $("#error");
			
	$("#contactform").submit(function(){	
		email = $("#email");
		
		//Validate required fields
		for (i=0;i<required.length;i++) {
			var input = $('#'+required[i]);
			if ((input.val() == "") || (input.val() == "Please fill out this field")) {
				input.addClass("needsfilled");
				input.val("Please fill out this field");
				errornotice.slideDown(750);
			} else {input.removeClass("needsfilled");}
		}
		// Validate the e-mail.
		if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
			email.addClass("needsfilled");
			email.val("Please enter a valid e-mail.");
		}
		//if any inputs on the page have the class 'needsfilled' the form will not submit
		if ($(":input").hasClass("needsfilled")) {
			return false;
		} else {
			errornotice.hide();
			return true;
		}
	});
	
	// Clears any fields in the form when the user clicks on them
	$(":input").click(function(){		
	   if ($(this).hasClass("needsfilled") ) {
			$(this).val("");
	   }
	});	

});

