$j(document).ready(function(){
	// Place ID's of all required fields here.
	required = ["billpay_name", "billpay_account", "billpay_amount"];
	// If using an ID other than #email or #error then replace it here
	errornotice = $j("#error");
	// The text to show up within a field when it is incorrect
	emptyerror = "Please fill out this field.";

	$j("#billpay_form").submit(function(){	
		//Validate required fields
		for (i=0;i<required.length;i++) {
			var input = $j('#'+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 ($j(":input").hasClass("needsfilled")) {
			return false;
		} else {
			errornotice.hide();
			return true;
		}
	});
	
	// Clears any fields in the form when the user clicks on them
	$j(":input").focus(function(){		
	   if ($j(this).hasClass("needsfilled") ) {
			$j(this).val("");
			$j(this).removeClass("needsfilled");
	   }
	});
});
