/*
JQuery script that controls the Find Parcel form.
Written by Noah Zehr of TCT Computer Solutions
Created 09/19/2011
*/

$(document).ready(function() {
	//Initialize input to "Enter your parcel ID" with a lighter font color.
	$("#fp_field").attr("style", "color:#999999;").val("Enter your parcel ID");

	//When the input box has the focus, erase the intial setting and darken the font color.
	$("#fp_field").focus(function(){
		if ($(this).val() == "Enter your parcel ID") {
			$(this).attr("style", "color:#000000;").val("");
		}
	});

	//If there is no input, return to the initial setting.
	$("#fp_field").blur(function(){
		if ($(this).val() == "" || $(this).val() == null) {
			$(this).attr("style", "color:#999999;").val("Enter your parcel ID");
		}
	});

	//AJAX form post when button is pressed.
	$("#fp_button").click(function(){
		//Disables button while request is sent.
		$(this).attr("disabled", "disabled");

		//Get user's input.
		var parcel_num = $("#fp_field").val();

		//Posts user input to find_parcel.php and returns the response generated by find_parcel.php. If the request cannot complete an error is returned. Re-enables button.
		$.ajax({
			type: "POST",
			url: "/mod_fp/find_parcel.php",
			data: "parcel_num=" + parcel_num,
			success: function(html){
				$("#fp_result").empty();
				$("#fp_result").append(html);
				$("#fp_button").removeAttr("disabled");
			},
			error: function(){
				$("#fp_result").empty();
				$("#fp_result").append("There was an error processing the request, please try again.");
				$("#fp_button").removeAttr("disabled");
			}
		});
	});
});

