$.widget("ui.dialog", $.extend({}, $.ui.dialog.prototype, {
    _title: function(title) {
        if (!this.options.title ) {
            title.html("&#160;");
        } else {
            title.html(this.options.title);
        }
    }
}));	
    
$(document).ready(function() {
			
	pageSetUp();
	
	/*
	 * BASIC
	 */
     
	var oTbl = $('#dt_basic').dataTable({
		"sPaginationType" : "bootstrap_full",
        "pagingType": "full_numbers",
        //"bFilter": false,
        "sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-12 hidden-xs'l>r>"+
				"t"+
				"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
        "lengthMenu": [ [10, 25, 50, -1], [10, 25, 50, "הכל"] ],
        "oLanguage": {
            "sProcessing":   "מעבד...",
           //"sLengthMenu":   "הצג _MENU_ פריטים",
            "sZeroRecords":  "לא נמצאו רשומות מתאימות",
            "sInfo": "_START_ עד _END_ מתוך _TOTAL_ רשומות" ,
            "sInfoEmpty":    "0 עד 0 מתוך 0 רשומות",
            "sInfoFiltered": "(מסונן מסך _MAX_  רשומות)",
            "sInfoPostFix":  "",
            //"sSearch":       "חפש:",
            "sUrl":          "",
            "oPaginate": {
                "sFirst":    "ראשון",
                "sPrevious": "קודם",
                "sNext":     "הבא",
                "sLast":     "אחרון"
            },
        },
        "bStateSave": true,
        "fnStateSave": function (oSettings, oData) {
            localStorage.setItem( 'DataTables_'+window.location.pathname, JSON.stringify(oData) );
        },
        "fnStateLoad": function (oSettings) {
            return JSON.parse( localStorage.getItem('DataTables_'+window.location.pathname) );
        },
        "order": [[ 0, 'desc' ]], 
                        
	});
    /*
    if(oTbl.hasClass('table')) {
        if(oTbl.hasClass('customers_table') || oTbl.hasClass('drivers_table')) {
            oTbl.fnSort( [ [1,'asc'] ]);
        } else if(oTbl.hasClass('users-table')) {    
            oTbl.fnSort( [ [0,'asc'] ]); 
        } else if(oTbl.hasClass('events_table')) {    
            oTbl.fnSort( [ [9,'desc'] ]);    
        } else if (oTbl.hasClass('leadsTableCustomer')){
            oTbl.fnSort( [ [5,'desc'] ]);
        } else {
            oTbl.fnSort( [ [0,'desc'] ]);    
        }
    }
    */
    $('.input-group .input-group-addon:not(:first-child)').hide();
    $('input[aria-controls="dt_basic"]').attr('placeholder', 'חיפוש...').addClass('form-control');
    $('#dt_basic_info').css('float', 'left').parent().css('float', 'left');
    $('.dataTables_paginate ').parent().css('float', 'right');
    $('.dataTables_paginate ').css('text-align', 'right');   
	/* END BASIC */

    /*
	 * BASIC
	 */
     
	var oTbl = $('#dt_basic1').dataTable({
		"sPaginationType" : "bootstrap_full",
        "pagingType": "full_numbers",
        //"bFilter": false,
        "sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-12 hidden-xs'l>r>"+
				"t"+
				"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
        "oLanguage": {
            "sProcessing":   "מעבד...",
           //"sLengthMenu":   "הצג _MENU_ פריטים",
            "sZeroRecords":  "לא נמצאו רשומות מתאימות",
            "sInfo": "_START_ עד _END_ מתוך _TOTAL_ רשומות" ,
            "sInfoEmpty":    "0 עד 0 מתוך 0 רשומות",
            "sInfoFiltered": "(מסונן מסך _MAX_  רשומות)",
            "sInfoPostFix":  "",
            //"sSearch":       "חפש:",
            "sUrl":          "",
            "oPaginate": {
                "sFirst":    "ראשון",
                "sPrevious": "קודם",
                "sNext":     "הבא",
                "sLast":     "אחרון"
            },
        },
        "sLengthMenu": [ [10, 25, 50, 100, -1], [10, 25, 50, 100, "הכל"] ],
        "bStateSave": true,
        "fnStateSave": function (oSettings, oData) {
            localStorage.setItem( 'DataTablesB1_'+window.location.pathname, JSON.stringify(oData) );
        },
        "fnStateLoad": function (oSettings) {
            return JSON.parse( localStorage.getItem('DataTablesB1_'+window.location.pathname) );
        },
        "order": [[ 0, 'desc' ]], 
        "aoColumnDefs": [
          { "iDataSort": 0, "aTargets": [ 1 ] },
          { "bVisible": false, "aTargets": [0] },
          { "iDataSort": 3, "aTargets": [ 4 ] },
          { "bVisible": false, "aTargets": [3] }
        ]   
                        
	});
    
	var oTbl2 = $('#customers_table').dataTable({
		//"sPaginationType" : "two_button",
        "pagingType": "simple_numbers",
        //"bFilter": false,
        "sDom": "<'dt-toolbar'<'col-xs-12 col-sm-6'f><'col-sm-6 col-xs-12 hidden-xs'l>r>"+
				"t"+
				"<'dt-toolbar-footer'<'col-sm-6 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-6'p>>",
        "oLanguage": {
            "sProcessing":   "מעבד...",
           //"sLengthMenu":   "הצג _MENU_ פריטים",
            "sZeroRecords":  "לא נמצאו רשומות מתאימות",
            "sInfo": "_START_ עד _END_ מתוך _TOTAL_ רשומות" ,
            "sInfoEmpty":    "0 עד 0 מתוך 0 רשומות",
            "sInfoFiltered": "(מסונן מסך _MAX_  רשומות)",
            "sInfoPostFix":  "",
            //"sSearch":       "חפש:",
            "sUrl":          "",
            "oPaginate": {
                "sFirst":    "ראשון",
                "sPrevious": "קודם",
                "sNext":     "הבא",
                "sLast":     "אחרון"
            },
        },
        "bStateSave": true,
        "fnStateSave": function (oSettings, oData) {
            localStorage.setItem( 'DataTablesCT_'+window.location.pathname, JSON.stringify(oData) );
        },
        "fnStateLoad": function (oSettings) {
            return JSON.parse( localStorage.getItem('DataTablesCT_'+window.location.pathname) );
        },
        "order": [[ 3, 'desc' ]],
                        
	});  
    $('input[aria-controls="customers_table"]').attr('placeholder', 'חיפוש...').addClass('form-control');  
    
    /*
    if(oTbl.hasClass('table')) {
        if(oTbl.hasClass('customers_table') || oTbl.hasClass('drivers_table')) {
            oTbl.fnSort( [ [1,'asc'] ]);
        } else if(oTbl.hasClass('users-table')) {    
            oTbl.fnSort( [ [0,'asc'] ]); 
        } else if(oTbl.hasClass('events_table')) {    
            oTbl.fnSort( [ [9,'desc'] ]);    
        } else if (oTbl.hasClass('leadsTableCustomer')){
            oTbl.fnSort( [ [5,'desc'] ]);
        } else {
            oTbl.fnSort( [ [0,'desc'] ]);    
        }
    }
    */
    $('.input-group .input-group-addon:not(:first-child)').hide();
    $('input[aria-controls="dt_basic1"]').attr('placeholder', 'חיפוש...').addClass('form-control');
    $('#dt_basic1_info').css('float', 'right').parent().css('float', 'right');
    $('.dataTables_paginate ').parent().css('float', 'right');
    $('.dataTables_paginate ').css('text-align', 'right');
    $('#dt_basic1 tbody tr td:nth-child(2)').each(function() {
        $(this).css('height', $(this).parent().css('height'));    
    });
	/* END BASIC */

	/* Add the events etc before DataTables hides a column 
	$("#datatable_fixed_column thead input").keyup(function() {
		oTable.fnFilter(this.value, oTable.oApi._fnVisibleToColumnIndex(oTable.fnSettings(), $("thead input").index(this)));
	});

	$("#datatable_fixed_column thead input").each(function(i) {
		this.initVal = this.value;
	});
	$("#datatable_fixed_column thead input").focus(function() {
		if (this.className == "search_init") {
			this.className = "";
			this.value = "";
		}
	});
	$("#datatable_fixed_column thead input").blur(function(i) {
		if (this.value == "") {
			this.className = "search_init";
			this.value = this.initVal;
		}
	});	*/	
	
    //var info = oTbl.page.info();
    //console.log(info);


/* END TABLE TOOLS */
});
;