/*
Created 09/27/09 jorenrapini@gmail.com
Copyright 2009 Joren Rapini
*/

$(document).ready(function(){
	// Place ID's of all required fields here.
	required = ["Name", "Address"];
	// If using an ID other than #email or #error then replace it here
$("#error").html('Please correct the following errors.');
	errornotice = $("#error");
	// The text to show up within a field when it is incorrect
	emptyerror = "This field is required.";

	$("#requestform").submit(function(){	
		//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);
				errornotice.fadeIn(750);
			} else {
				input.removeClass("needsfilled");
			}
		}

		//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").focus(function(){		
	   if ($(this).hasClass("needsfilled") ) {
			$(this).val("");
			$(this).removeClass("needsfilled");
	   }
	});
});

