$(document).ready
(
	function()
	{
		var processSearchQuery;
		var handleSearchButtonClick;
		var handleSearchFieldKeypress;

		processSearchQuery = function(field)
		{
			var keyword;
			keyword = field.value;
	
			if (keyword.length === 0) return;
			window.location = "/tool/search.aspx?kw=" + keyword;
		};
	
		handleSearchButtonClick = function(evt)
		{
			processSearchQuery($get("searchField"));
			evt.preventDefault();
		};
	
		handleSearchFieldKeypress = function(evt)
		{
			if (this.value.length === 0) return;
			if (evt.which !== 13) return;
			processSearchQuery(this);
			evt.preventDefault();
		};

		$("#searchButton").click( handleSearchButtonClick );
		$("#searchField").keypress( handleSearchFieldKeypress );
	}
);
