String.prototype.trim = function()
{
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
};


function DoSearch()
{
	function SF(intype, f)
	{
		return f + "=" + escape($("[name=" + f + "]").attr("value"));
	}
	function SFS(f) { return SF("select", f); }
	function SFI(f) { return SF("input", f); }
	//    if ($("input[name=SearchText]").attr("value").length > 0) {
	var suri = "/standard/store/searchadvanced.aspx" +
		 '?SearchBy=' + $("input[name=SearchBy]:checked").val() + '&'
		 + SFS("SearchCategory".trim()) + '&'
		 + SFS("SearchManufacturer") + '&'
		 + SFI("SearchText");
	document.location = suri;
	//    }
}
function Manufacturer()
{
	var msel = $("select[name=SearchManufacturer]");
	if (msel) {
		$.get("/custom/content/JsonHelper.aspx?get=MANUFACTURER", function (result) {
			data = eval('(' + result + ')')
			$.each(data.items, function (i, item) {
				var s = "<option value=\"" + escape(item.mfg_id) + "\">" + item.mfg_name + "</option>";
				msel.append(s);
			});
		});
	}
}
function Categories()
{
	var msel = $("select[name=SearchCategory]");
	if (msel)
	{
		$.get("/custom/content/JsonHelper.aspx?get=CATEGORIES", function(result) {
			data = eval('(' + result + ')')
			$.each(data.items, function(i, item)
			{
				var s = "<option value=\"" + item.cat_id + "\">" + item.cat_descr + "</option>";
				msel.append(s);
			});
		});
	}
}
$(document).ready(function () {
	Manufacturer();
	Categories();
	$("#SearchGo").bind("click", function (e) { DoSearch(); });
	$("form").bind("submit", function (e) {
		e.preventDefault();
	});
	$(document).bind("keypress", function (e) {
		if (e.keyCode == 13) { // Enter on us-standard
			DoSearch();
		}
	});
});
