// JavaScript Document
$(document).ready(
	function(){
		$("#submit").click(findClosest);
		$("#postal").keypress(function(e){
			if(e.keyCode==13)
				findClosest();
		});
});

function findClosest(){
	var re1 = new RegExp(/^\s*[a-ceghj-npr-tvxy]\d[a-ceghj-npr-tv-z](\s)?\d[a-ceghj-npr-tv-z]\d\s*$/i);
	var re2 = new RegExp(/^\d{5}([\-]\d{4})?$/);
	if($("#postal").val() && (re1.test($("#postal").val()) || re2.test($("#postal").val()))){
		//alert("Valid");
		$("#err").html("<img src='images/ajax-loader.gif'/>");
		$.ajax({
		   type: "POST",
		   url: "scripts/locator/pp.php",
		   data: "pc="+$("#postal").val(),
		   success: function(msg){
			   //alert(msg);
			   $("#err").html("");
			   $("#cont").html(msg);
		   }
		});
	}
	else
	{
		$("#err").html("Enter a valid postal code");
		 $("#cont").html("");
	}
}