//var ajax_url = "index.php?module=EcmReports&action=summary_javahelper&to_pdf=1";
var isHide = true;
var vatIsHide = true;
var showAndHideButton;
$(document).ready(function(){
	$.blockUI({ css: { 
        border: 'none', 
        padding: '15px', 
        backgroundColor: '#000', 
        '-webkit-border-radius': '10px', 
        '-moz-border-radius': '10px', 
        opacity: .5, 
        'font-weight': 'bold',
        'font-size': '16px',
        color: '#fff',
    	},
    	message: "Trwa generowanie pliku..."
    }); 


	$("#excelEksport").click( excelExport );
	$("#pdfEksport").click( pdfExport );
	
	$.tablesorter.addParser({
		  // use a unique id
		  id: 'saas',
		  is: function(s, table, cell) {
		    // s is the text from the cell
		    // table is the current table (as a DOM element; not jQuery object)
		    // cell is the current table cell (DOM element)
		    // return false if you don't want this parser to be auto detected
		    return false;
		  },
		  format: function(s, table, cell, cellIndex) {
		    // s is the text from the cell
		    // table is the current table (as a DOM element; not jQuery object)
		    // cell is the current table cell (DOM element)
		    // cellIndex is the current cell's column index
		    // format your data for normalization
		    // (i.e. do something to get and/or modify your data, then return it)
		    return s.replace('.', '').replace(',', '.');
		  },
		  // flag for filter widget (true = ALWAYS search parsed values; false = search cell text)
		  parsed: false,
		  // set the type to either numeric or text (text uses a natural sort function
		  // so it will work for everything, but numeric is faster for numbers
		  type: 'numeric'
	});

	  // call the tablesorter plugin
	  $("table").tablesorter({
		  // extra css class applied to the table row containing the filters & the inputs within that row
	      filter_cssFilter   : '',

	      // If there are child rows in the table (rows with class name from "cssChildRow" option)
	      // and this option is true and a match is found anywhere in the child row, then it will make that row
	      // visible; default is false
	      filter_childRows   : false,

	      // if true, filters are collapsed initially, but can be revealed by hovering over the grey bar immediately
	      // below the header row. Additionally, tabbing through the document will open the filter row when an input gets focus
	      filter_hideFilters : false,

	      // Set this option to false to make the searches case sensitive
	      filter_ignoreCase  : true,

	      // jQuery selector string of an element used to reset the filters
	      filter_reset : '.reset',

	      // Use the $.tablesorter.storage utility to save the most recent filters
	      filter_saveFilters : true,

	      // Delay in milliseconds before the filter widget starts searching; This option prevents searching for
	      // every character while typing and should make searching large tables faster.
	      filter_searchDelay : 300,

	      // Set this option to true to use the filter to find text from the start of the column
	      // So typing in "a" will find "albert" but not "frank", both have a's; default is false
	      filter_startsWith  : false,

	      // if false, filters are collapsed initially, but can be revealed by hovering over the grey bar immediately
	      // below the header row. Additionally, tabbing through the document will open the filter row when an input gets focus
	      filter_hideFilters : false,

	    theme: 'blue',
	    dateFormat : "dd.mm.yyyy",
	    widthFixed : false,
	    // initialize zebra striping of the table
	    widgets: ['zebra','stickyHeaders', 'filter'],
	    // change the default striping class names
	    // updated in v2.1 to use widgetOptions.zebra = ["even", "odd"]
	    // widgetZebra: { css: [ "normal-row", "alt-row" ] } still works
	    widgetOptions : {
	      zebra : [ "normal-row", "alt-row" ]
	    }
	  });
	$.unblockUI();

}); 

function excelExport() {
	var url =  $(location).attr('href').replace("ListDailySales", "ListDailySalesToExcelFile");
	url = url + "&to_pdf=1";

	var fileUrl = url.slice(0, url.indexOf("index")) + "modules/EcmReports/ExcelFiles/DailySales.xls";

	
    $.blockUI({ css: { 
        border: 'none', 
        padding: '15px', 
        backgroundColor: '#000', 
        '-webkit-border-radius': '10px', 
        '-moz-border-radius': '10px', 
        opacity: .5, 
        'font-weight': 'bold',
        'font-size': '16px',
        color: '#fff',
    	},
    	message: "Trwa generowanie pliku..."
    }); 
    
	$.ajax({
		  url: url,
		  success: function(data){
            $.unblockUI();
		    window.location.href = fileUrl
		  },
		  error: function(){
            $.unblockUI();
		    alert('Eksport zakończony niepowodzeniem!');
		  }
	});
	
}

function pdfExport() {
	var url =  $(location).attr('href');
	url = url + "&to_pdf=1";
	window.open(url,'_blank'); 
}