var jQuery_1_8_2 = jQuery_1_8_2 || $.noConflict();
(function ($, undefined) {
	$(function () {
		"use strict";
		var 
			$frmCreateBooking = $('#frmCreateBooking'),
			$frmUpdateBooking = $('#frmUpdateBooking'),
			$modalCancellation = $("#modalCancellation"),
			$modalConfirmation = $("#modalConfirmation"),
			$modalSmsConfirmation = $("#modalSmsConfirmation"),
			datagrid = ($.fn.datagrid !== undefined),
			datetimeOptions = null;;
	

		if ($("#grid").length > 0 && datagrid) {
			
			
			var $grid = $("#grid").datagrid({
				buttons: [
				          {type: "delete", url: "index.php?controller=pjActionUserSearch&action=pjActionDeleteUserSearch&id={:id}"}
						  ],
				columns: [
				         
				          {text: myLabel.fleet, type: "text", sortable: false},
				          {text: myLabel.distance, type: "text", sortable: false},
						  {text: myLabel.pickup_address, type: "text", sortable: false},
						  {text: myLabel.return_address, type: "text", sortable: false},
						  {text: myLabel.price_id, type: "text", sortable: false},
				           {
							text: myLabel.booking_date,
							type: "text",
							sortable: false,
							editable: false
						  },
						   {
							text: myLabel.luggage_trolleys,
							type: "text",
							sortable: false,
							editable: false
						  },
						   {
							text: myLabel.luggage_koffers,
							type: "text",
							sortable: false,
							editable: false
						  },
						  {
							text: myLabel.return_status,
							type: "text",
							sortable: false,
							renderer: function(val) {
								return val == 1 ? "Yes" : "No";
							}
						},
						{
							text: myLabel.extra_stop,
							type: "text",
							sortable: false,
							renderer: function(val) {
								return val == 1 ? "Yes" : "No";
							}
						},
				          ],
				dataUrl: "index.php?controller=pjActionUserSearch&action=pjActionGetSearch" + pjGrid.queryString,
				dataType: "json",
				fields: ['fleet', 'distance', 'pickup_address', 'return_address', 'price_id', 'booking_date', 'luggage_trolleys','luggage_koffers', 'return_status', 'extra_stop'],
				paginator: {
					actions: [
					   {text: myLabel.delete_selected, url: "index.php?controller=pjActionUserSearch&action=pjActionDeleteUserSearchBulk", render: true, confirmation: myLabel.delete_confirmation},
					],
					gotoPage: true,
					paginate: true,
					total: true,
					rowCount: true
				},
				select: {
					field: "id",
					name: "record[]",
					cellClass: 'cell-width-2'
				},
			});
		}
		
		$(document).on("focusin", ".timepick", function (e) {
			var minDateTime, maxDateTime,
				$this = $(this),
				custom = {},
				o = {
					timeFormat: $this.attr("lang"),
					stepMinute: 5,
					timeOnly: true
				};
			$(this).datetimepicker(o);
		}).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(),
				status: $this.find("select[name='status']").val()
			});
			$grid.datagrid("option", "cache", cache);
			$grid.datagrid("load", "index.php?controller=pjActionUserSearch&action=pjActionGetSearch" + pjGrid.queryString, "created", "DESC", content.page, content.rowCount);
			return false;
		});

	});
})(jQuery_1_8_2);