var GIS = {};

GIS.idPat = /o([0-9]+)c([0-9]+)/;

GIS.filter = function(offset, count) {
	var params = PHI.getReqParams();
	params.patt = $.trim($("#pattInput").focus().val());
	if (offset) {
		params.offset = offset;
		params.count = count;
	}
	$("#bc").load( "phikey", params, function() {
		$("li.range").each( function(){
			var e = $(this);
			var res = e.attr("id").match(GIS.idPat);
			e.click(function() {
				GIS.filter(res[1], res[2]);
			});
		});
		// This is to force Safari to redraw bkgd
		$("body").height( $("body").height());
	});
};

GIS.filterOnKeyup = function(e) {
	// printing char or backspace
	if ( e.keyCode >= 40 || e.keyCode == 8 ) {
		window.clearTimeout(GIS.filterTimer);
		GIS.filterTimer = window.setTimeout("GIS.filter();", 300);
	}
};

GIS.submit = function(e) {
	$("div#bc li:first").click().find("a").each( function() {
		window.location.href = this.href;
	});
	return false;
};

$(document).ready( function() {
	$("form").submit(GIS.submit);
	$("#pattInput").keyup(GIS.filterOnKeyup).click(GIS.filterOnKeyup);
	GIS.filter();
});
