(function ($, undefined) {
	$(function () {
		var datagrid = ($.fn.datagrid !== undefined);

		if ($("#grid").length > 0 && datagrid) {

			var gridOpts = {
				buttons: [],
				columns: [{text: myLabel.created, type: "text", sortable: true, editable: false, width: 150},
				          {text: myLabel.reference_id, type: "text", sortable: true, editable: false, width: 160},
				          {text: myLabel.txn_id, type: "text", sortable: true, editable: false},
				          {text: myLabel.amount, type: "text", sortable: true, editable: false, width: 100},
				          {text: myLabel.currency, type: "text", sortable: true, editable: false, width: 90},
				          {text: myLabel.status, type: "text", sortable: true, editable: false, width: 110}
				          ],
				dataUrl: "index.php?controller=pjStripe&action=pjActionGetStripe" + pjGrid.queryString,
				dataType: "json",
				fields: ['created', 'reference_id', 'txn_id', 'amount', 'currency', 'status'],
				paginator: {
					actions: [],
					gotoPage: true,
					paginate: true,
					total: true,
					rowCount: true
				}
			};

			var $grid = $("#grid").datagrid(gridOpts);

			$(document).on("submit", ".frm-filter", function (e) {
				if (e && e.preventDefault) {
					e.preventDefault();
				}
				var $this = $(this),
					content = $grid.datagrid("option", "content"),
					cache = $grid.datagrid("option", "cache");
				$.extend(cache, {
					q: $this.find("input[name='q']").val()
				});
				$grid.datagrid("option", "cache", cache);
				$grid.datagrid("load", "index.php?controller=pjStripe&action=pjActionGetStripe", "id", "ASC", content.page, content.rowCount);
				return false;
			});
		}

	});
})(jQuery);
