// Функция вывода на печать
$(function(){
    $('#print').click(function(){
		var printing_css='<style media=print>*{font-size:14pt;font-family: arial, sans-serif;} table{width:100%;} table tr td {line-height:30px;padding:0px;} input, button, select, .bootstrap-filestyle, .progress_left, .progress_right, #progress {display:none;}</style>';
        var html_to_print=printing_css+$('#to_print').html();
        var iframe=$('<iframe id="print_frame">');
        $('body').append(iframe);
        var doc = $('#print_frame')[0].contentDocument || $('#print_frame')[0].contentWindow.document;
        var win = $('#print_frame')[0].contentWindow || $('#print_frame')[0];
        doc.getElementsByTagName('body')[0].innerHTML=html_to_print;
        win.print();
        $('iframe').remove();
    });
});
$(function(){
    $('.navbar-toggle').click(function(){
		$('.bg_menu').toggle(0);
    });
});
$(function(){
    $('button[type="submit"]').click(function(){
		$('.loader').fadeIn(1000);
    });
	$('input[type="submit"]').click(function(){
		$('.loader').fadeIn(1000);
    });
	$('a[class*="btn"]').click(function(){
		$('.loader').fadeIn(1000);
    });
	$('a[href*="/"]').click(function(){
		$('.loader').fadeIn(1000);
    });
	$('a[data-toggle="tab"]').click(function(){
		$('.loader').fadeOut(0);
    });
});


// Запрет на ввод точки и букв для стоимости
function checkdot(input) {
	input.value = input.value.replace(/[^\d.]/g, '');
}

// Функция выбора даты
addEventListener('DOMContentLoaded', function () {
	pickmeup('.dateS', {
		format	: 'Y-m-d',
		default_date: false
	});
	pickmeup('.dateE', {
		format	: 'Y-m-d',
		default_date: false
	});
	pickmeup('.dateE1', {
		format	: 'Y-m-d',
		default_date: false
	});
});

// Автозаполнение правил пользования
function userrule(){
	var userrule = $('input[name=inputCRMuname]').val()
	$('#user_rule').text(userrule);
}

// Автозаполнение формы оплаты пакета
/*
function paymentcheck(){
	var paymentpack 	= $('form.payment  select[name=paymentPack] option:selected').text();
	var paymentpack2	= $('form.payment  select[name=paymentPack] option:selected').val();
	var paymentdate		= $('form.payment  select[name=paymentDate] option:selected').text();
	var paymentdate2	= $('form.payment  select[name=paymentDate] option:selected').val();
	var paymentdomain	= $('form.payment  input[name=paymentDomain]').val();
	var paymentsecure	= $('form.payment  input[name=paymentSecure]').val();
	
	if(paymentdate2>23){
		var paymentsale = '0.90';
	}else{
		if(paymentdate2>35){
			var paymentsale = '0.80';
		}else{
			if(paymentdate2>47){
				var paymentsale = '0.70';
			}else{
				var paymentsale = '1';
			}
		}
	}
	
	var paymentprice	= parseFloat(paymentpack2 * paymentdate2 * paymentsale).toFixed(2);
	var paymentcomment	= paymentpack + ' (' + paymentdate + ') ' + paymentdomain;
	
	$('form.payment input[name=formcomment]').val(paymentcomment);
	$('form.payment input[name=short-dest]').val(paymentcomment);
	$('form.payment input[name=comment]').val(paymentsecure);
	$('form.payment input[name=sum]').val(paymentprice);
	$('#payment_price').html(paymentprice);
}
*/
// Функция при прокрутке страницы
$(window).scroll(function () {
	var scroll = $(document).scrollTop(), ptop = $('.navbar').height(), pbottom = $('#footer').height();
	var h = document.documentElement;
	var scrollTop = this.pageYOffset || h.scrollTop;
	if (scroll > ptop) {
		$('.up').css('bottom','10px').css('-khtml-opacity','1.0').css('-moz-opacity','1.0').css('opacity','1.0').css('filter','progid:DXImageTransform.Microsoft.Alpha(opacity=100)');
	}
	else {
		$('.up').css('bottom','-50px').css('-khtml-opacity','0.0').css('-moz-opacity','0.0').css('opacity','0.0').css('filter','progid:DXImageTransform.Microsoft.Alpha(opacity=000)');
	}
});

bkLib.onDomLoaded(function() {
	new nicEditor().panelInstance('inputComment');
});

/* ПОЛЬЗОВАТЕЛИ */
$('.send-mail').click(function() {
	$('#modal-mail').modal('show');
	$('form[name=form_mail]').trigger('reset');
});
/* ПОЛЬЗОВАТЕЛИ */

$(document).ready(function() {
	
	$('#NewTempl').click(function(){
		if ($(this).is(':checked')){
			$('.nicEdit-main').parent('div').addClass('template').addClass('on');
			$('.input-group.template').addClass('on');
			$('input, select, textarea').removeAttr('required');
			$('input[name="inputName"]').attr('required', 'required');
			/*$('textarea[name="inputComment"]').attr('required', 'required');*/
			$('input[name="inputSubject"]').attr('required', 'required');
			$('button[name="LetterSend"], button[name="TaskAdd"], button[name="TaskEdit"], button[name="DealAdd"], button[name="DealEdit"]').removeClass('btn-info').addClass('btn-success');
			$('button[name="LetterSend"] .text, button[name="TaskAdd"] .text, button[name="TaskEdit"] .text, button[name="DealAdd"] .text, button[name="DealEdit"] .text').html('Сохранить шаблон');
		} else {
			$('.input-group.template.on').removeClass('on');
			$('.nicEdit-main').parent('div').removeClass('template').removeClass('on');
			$('input, select, textarea').removeAttr('required');
			$('input[name="inputName"]').attr('required', 'required');
			$('input[name="inputDateStart"]').attr('required', 'required');
			$('select[name="selectType"]').attr('required', 'required');
			$('select[name="selectUserTo"]').attr('required', 'required');
			$('input[name="inputNumber"]').attr('required', 'required');
			$('input[name="inputPrice"]').attr('required', 'required');
			$('input[name="inputSubject"]').attr('required', 'required');
			$('input[name="selectClient"]').attr('required', 'required');
			$('input[name="inputDateStart"]').attr('required', 'required');
			$('button[name="LetterSend"], button[name="TaskAdd"], button[name="TaskEdit"], button[name="DealAdd"], button[name="DealEdit"]').removeClass('btn-success').addClass('btn-info');
			$('button[name="LetterSend"] .text').html('Отправить');
			$('button[name="TaskAdd"] .text, button[name="DealAdd"] .text').html('Добавить');
			$('button[name="TaskEdit"] .text, button[name="DealEdit"] .text').html('Сохранить');
		}
	}); 

	// Строки фильтра отсутствуют
	$('.btn').each(function(i) {
		var oldclass = $(this).children('.fa').attr('class');
		var newclass = 'fa fa-cog fa-spin fa-fw fa-active';
		$(this).on("click", function(){
			$(this).children('.fa').attr('class', newclass);
			setTimeout(function(){$('.fa-active').attr('class', oldclass);}, 4000);
		});
	});
	
	$('.persent-bar').each( function(){
		var heightBar 	= parseFloat($(this).css('height'));
		var heightLine 	= parseFloat($(this).children('.persent-bar-body').css('height'));
		var persent 	= heightLine * 100 / heightBar;
		if(persent >= '66'){
			$(this).children('.persent-bar-body').css('background','#7ab262');
		} else if('33' < persent && persent < '66'){
			$(this).children('.persent-bar-body').css('background','#d4db59');
		} else if(persent <= '33') {
			$(this).children('.persent-bar-body').css('background','#db5a59');
		}
	});
	
	// Изменение темы пользователем
	$('#uDarkTheme').click(function(){
		var checkTheme = $(this).prop('checked');
		if(checkTheme == true) {
			$.cookie('wbutheme', 'dark', { expires: 365, path: '/' });
			location.reload();
		} else {
			$.cookie('wbutheme', 'light', { expires: 365, path: '/' });
			location.reload();
		}
	});
	
	if($.cookie('wbutheme') == "dark"){
		$('#uDarkTheme').attr("checked", "checked");
	} else {
		$('#uDarkTheme').attr("checked", false);
	}
	
	// Перемещение формы выбора даты
	$('input[name*=inputDate]').focus( function(){
		$(this).parent('.date-pick').append( $('div.pickmeup.pmu-view-days') );
	});

	// Запрет редатирования ФИО пользователя
	if($('input[name=inputCRMuname]').val() != '') { $('input[name=inputCRMuname]').attr('readonly','readonly'); }
	
	// Автозаполнение правил пользования
	var userrule = $('input[name=inputCRMuname]').val()
	$('#user_rule').text(userrule);

	// Строки списка отсутствуют
	$('.table-responsive table tbody').each(function(i) {
		if ($(this).children('tr').length < 1) {
			$(this).parent().parent().after('<div class="empty-list centered">- нет данных для отображения -</div>');
		}
	});
	
	// Строки фильтра отсутствуют
	$('.filter-list').each(function(i) {
		if ($(this).children('li').length < 1) {
			$(this).parent().parent().hide();
		}
	});

	// Всплывающие подсказки
	$('*[title]').tipTip({maxWidth: "250px", defaultPosition: "bottom"});
	
	// Сортировка <select>
	/*
	$('.filters select').each( function(){
		var emptyoption = $(this).find('option[value=""]')
		$(this).html( $(this).find('option').sort(function(a, b) {
			return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
		}) );
		if(emptyoption.length){$(this).val('').trigger('chosen:updated');}
	});*/

	//Включение <select>
	$('form#filter-list input[name="checkClient"]').click(function(){
		var checkClient = $(this).prop('checked');
		if(checkClient == true) {
			$('form#filter-list select[name=selectClient]').prop('disabled',false);
		} else {
			$('form#filter-list select[name=selectClient]').prop('disabled',true);
		}
	});
	$('form#filter-list input[name="checkDeal"]').click(function(){
		var checkDeal = $(this).prop('checked');
		if(checkDeal == true) {
			$('form#filter-list select[name=selectDeal]').prop('disabled',false);
		} else {
			$('form#filter-list select[name=selectDeal]').prop('disabled',true);
		}
	});
	$('form#filter-list input[name="checkCom"]').click(function(){
		var checkCom = $(this).prop('checked');
		if(checkCom == true) {
			$('form#filter-list select[name=selectCom]').prop('disabled',false);
		} else {
			$('form#filter-list select[name=selectCom]').prop('disabled',true);
		}
	});
	$('form#filter-list input[name="checkYear"]').click(function(){
		var checkYear = $(this).prop('checked');
		if(checkYear == true) {
			$('form#filter-list select[name=selectYear]').prop('disabled',false);
		} else {
			$('form#filter-list select[name=selectYear]').prop('disabled',true);
		}
	});
	$('form#filter-list input[name="checkDealType"]').click(function(){
		var checkDealType = $(this).prop('checked');
		if(checkDealType == true) {
			$('form#filter-list select[name=selectDealType]').prop('disabled',false);
		} else {
			$('form#filter-list select[name=selectDealType]').prop('disabled',true);
		}
	});
	$('form#filter-list input[name="checkPrice"]').click(function(){
		var checkPrice = $(this).prop('checked');
		if(checkPrice == true) {
			$('form#filter-list input[name=inputPriceS]').prop('disabled',false);
			$('form#filter-list input[name=inputPriceE]').prop('disabled',false);
		} else {
			$('form#filter-list input[name=inputPriceS]').prop('disabled',true);
			$('form#filter-list input[name=inputPriceE]').prop('disabled',true);
		}
	});
	$('form#filter-list input[name="checkVal"]').click(function(){
		var checkVal = $(this).prop('checked');
		if(checkVal == true) {
			$('form#filter-list input[name=inputValS]').prop('disabled',false);
			$('form#filter-list input[name=inputValE]').prop('disabled',false);
		} else {
			$('form#filter-list input[name=inputValS]').prop('disabled',true);
			$('form#filter-list input[name=inputValE]').prop('disabled',true);
		}
	});
	
	// Фильтрация материалов
	$('form#filter-list input[type=radio], form#filter-list input[type=checkbox], form#filter-list select').click(function(){
		$('.filter-buttons').fadeIn('500');
	});
	
	// Сброс активного фильтра
	$('.btn-freset').click(function(){
		$('form#filter-list')[0].reset();
		$('.filter-buttons').fadeOut('500');
	});

	// Выделение строки с ошибкой входа
	$('#index-logs tr[session*="#"]').css('color','#e00000')
	
	// Выделение активного пункта меню
	$('ul.menu_select li a').each(function(){
		var href = $(this).attr('href');
		var pos = document.location.pathname.indexOf(href);
		if( pos >= 0 && href != '/' || href == document.location.pathname ){
			$(this).parent().addClass('active');
		}
	});
	
	// Шаблон заполнения текстовых форм
	$("input[name=inputDATE]").mask("9999-99-99");
	$("input[name=inputDateEnd]").mask("9999-99-99");
	$("input[name=inputDateStart]").mask("9999-99-99");
	$("input[placeholder*=Телефон]").mask("9 (999) 999-9999");

	$('a[data-toggle="tab"]').on('shown.bs.tab', function () {
		var url = location.pathname
		url+=$(this).attr('href');
	});
	
	var hash = window.location.hash;
	hash && $('.nav-tabs a[href="' + hash + '"]').tab('show');
	$('.nav-tabs a').on('shown.bs.tab', function(e) {
			window.location.hash = this.hash;
		$("html, body").scrollTop(0);
	});	
	
	// Блок загрузки
	$('.loader').fadeOut(1000);
	$('.loader_qchat').fadeOut(1500);
	$('.loader_smphoto').fadeOut(2000);
	
	// Сортировка списков
	var pagerOptions = {
		// target the pager markup - see the HTML block below
		container: $(".pager"),
		// use this url format "http:/mydatabase.com?page={page}&size={size}&{sortList:col}"
		ajaxUrl: null,
		// modify the url after all processing has been applied
		customAjaxUrl: function(table, url) { return url; },
		// ajax error callback from $.tablesorter.showError function
		// ajaxError: function( config, xhr, settings, exception ){ return exception; };
		// returning false will abort the error message
		ajaxError: null,
		// add more ajax settings here
		// see http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings
		ajaxObject: { dataType: 'json' },
		// process ajax so that the data object is returned along with the total number of rows
		ajaxProcessing: null,
		// Set this option to false if your table data is preloaded into the table, but you are still using ajax
		processAjaxOnInit: true,
		// output string - default is '{page}/{totalPages}'
		// possible variables: {size}, {page}, {totalPages}, {filteredPages}, {startRow}, {endRow}, {filteredRows} and {totalRows}
		// also {page:input} & {startRow:input} will add a modifiable input in place of the value
		// In v2.27.7, this can be set as a function
		// output: function(table, pager) { return 'page ' + pager.startRow + ' - ' + pager.endRow; }
		output: '{startRow} – {endRow} из {totalRows}',
		// apply disabled classname (cssDisabled option) to the pager arrows when the rows
		// are at either extreme is visible; default is true
		updateArrows: true,
		// starting page of the pager (zero based index)
		page: 0,
		// Number of visible rows - default is 10
		size: 10,
		// Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
		savePages : true,
		// Saves tablesorter paging to custom key if defined.
		// Key parameter name used by the $.tablesorter.storage function.
		// Useful if you have multiple tables defined
		storageKey:'tablesorter-pager',
		// Reset pager to this page after filtering; set to desired page number (zero-based index),
		// or false to not change page at filter start
		pageReset: 0,
		// if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty
		// table row set to a height to compensate; default is false
		fixedHeight: false,
		// remove rows from the table to speed up the sort of large tables.
		// setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled.
		removeRows: false,
		// If true, child rows will be counted towards the pager set size
		countChildRows: false,
		// css class names of pager arrows
		cssNext: '.next', // next page arrow
		cssPrev: '.prev', // previous page arrow
		cssFirst: '.first', // go to first page arrow
		cssLast: '.last', // go to last page arrow
		cssGoto: '.gotoPage', // select dropdown to allow choosing a page
		cssPageDisplay: '.pagedisplay', // location of where the "output" is displayed
		cssPageSize: '.pagesize', // page size selector - select dropdown that sets the "size" option
		// class added to arrows when at the extremes (i.e. prev/first arrows are "disabled" when on the first page)
		cssDisabled: 'disabled', // Note there is no period "." in front of this class name
		cssErrorRow: 'tablesorter-errorRow' // ajax error information row
	};
	var pagerOptions2 = {
		// target the pager markup - see the HTML block below
		container: $(".pager2"),
		// use this url format "http:/mydatabase.com?page={page}&size={size}&{sortList:col}"
		ajaxUrl: null,
		// modify the url after all processing has been applied
		customAjaxUrl: function(table, url) { return url; },
		// ajax error callback from $.tablesorter.showError function
		// ajaxError: function( config, xhr, settings, exception ){ return exception; };
		// returning false will abort the error message
		ajaxError: null,
		// add more ajax settings here
		// see http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings
		ajaxObject: { dataType: 'json' },
		// process ajax so that the data object is returned along with the total number of rows
		ajaxProcessing: null,
		// Set this option to false if your table data is preloaded into the table, but you are still using ajax
		processAjaxOnInit: true,
		// output string - default is '{page}/{totalPages}'
		// possible variables: {size}, {page}, {totalPages}, {filteredPages}, {startRow}, {endRow}, {filteredRows} and {totalRows}
		// also {page:input} & {startRow:input} will add a modifiable input in place of the value
		// In v2.27.7, this can be set as a function
		// output: function(table, pager) { return 'page ' + pager.startRow + ' - ' + pager.endRow; }
		output: '{startRow} – {endRow} из {totalRows}',
		// apply disabled classname (cssDisabled option) to the pager arrows when the rows
		// are at either extreme is visible; default is true
		updateArrows: true,
		// starting page of the pager (zero based index)
		page: 0,
		// Number of visible rows - default is 10
		size: 5,
		// Save pager page & size if the storage script is loaded (requires $.tablesorter.storage in jquery.tablesorter.widgets.js)
		savePages : true,
		// Saves tablesorter paging to custom key if defined.
		// Key parameter name used by the $.tablesorter.storage function.
		// Useful if you have multiple tables defined
		storageKey:'tablesorter-pager',
		// Reset pager to this page after filtering; set to desired page number (zero-based index),
		// or false to not change page at filter start
		pageReset: 0,
		// if true, the table will remain the same height no matter how many records are displayed. The space is made up by an empty
		// table row set to a height to compensate; default is false
		fixedHeight: false,
		// remove rows from the table to speed up the sort of large tables.
		// setting this to false, only hides the non-visible rows; needed if you plan to add/remove rows with the pager enabled.
		removeRows: false,
		// If true, child rows will be counted towards the pager set size
		countChildRows: false,
		// css class names of pager arrows
		cssNext: '.next', // next page arrow
		cssPrev: '.prev', // previous page arrow
		cssFirst: '.first', // go to first page arrow
		cssLast: '.last', // go to last page arrow
		cssGoto: '.gotoPage', // select dropdown to allow choosing a page
		cssPageDisplay: '.pagedisplay', // location of where the "output" is displayed
		cssPageSize: '.pagesize', // page size selector - select dropdown that sets the "size" option
		// class added to arrows when at the extremes (i.e. prev/first arrows are "disabled" when on the first page)
		cssDisabled: 'disabled', // Note there is no period "." in front of this class name
		cssErrorRow: 'tablesorter-errorRow' // ajax error information row
	};
	
	$("#index-tasks").tablesorter({sortList: [[4,0]], headers: { 0:{sorter: false}, 5:{sorter: false}, 6:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#informer-tasks").tablesorter({sortList: [[3,1]], headers: { 0:{sorter: false}, 5:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions2);
	
	$("#all-tasks").tablesorter({sortList: [[4,0]], headers: { 0:{sorter: false}, 5:{sorter: false}, 6:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#archive-tasks").tablesorter({dateFormat : "yyyymmdd", sortList: [[3,1]], headers: { 0:{sorter: false}, 5:{sorter: false}, 6:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#all-tasks-search").tablesorter({sortList: [[3,1]], headers: { 0:{sorter: false}, 4:{sorter: false}, 5:{sorter: false}, 6:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);

	$("#all-users").tablesorter({sortList: [[1,0]], headers: { 0:{sorter: false}, 2:{sorter: false}, 5:{sorter: false}, 6:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#all-letters").tablesorter({sortList: [[3,1]], headers: { 0:{sorter: false}, 2:{sorter: false}, 4:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#all-clients").tablesorter({sortList: [[4,1]], headers: { 0:{sorter: false}, 5:{sorter: false}, 6:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#all-clients-req").tablesorter({sortList: [[3,1]], headers: { 0:{sorter: false}, 4:{sorter: false}, 5:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#all-deals").tablesorter({sortList: [[4,1]], headers: { 0:{sorter: false}, 6:{sorter: false}, 7:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#informer-deals").tablesorter({sortList: [[4,1]], headers: { 0:{sorter: false}, 5:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#all-payments").tablesorter({sortList: [[4,1]], headers: { 0:{sorter: false}, 5:{sorter: false}, 6:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#all-vacations").tablesorter({sortList: [[2,1]], headers: { 0:{sorter: false}, 4:{sorter: false}, 5:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#all-payments-page").tablesorter({sortList: [[3,1]], headers: { 0:{sorter: false}, 4:{sorter: false}, 5:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#all-deals-search").tablesorter({sortList: [[4,1]], headers: { 0:{sorter: false}, 5:{sorter: false}, 6:{sorter: false}, 7:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#all-offers-sm").tablesorter({sortList: [[3,1]], headers: { 0:{sorter: false}, 4:{sorter: false}, 5:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions2);
	
	$("#all-notes").tablesorter({sortList: [[2,1]], headers: { 0:{sorter: false}, 3:{sorter: false}, 4:{sorter: false}}})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#all-subjects").tablesorter({sortList: [[0,0]]})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);
	
	$("#all-events").tablesorter({sortList: [[3,0]], headers: { 0:{sorter: false}, 5:{sorter: false}, 4:{sorter: false}}});
	
	$("#index-logs").tablesorter({sortList: [[0,1]]})
    .bind('pagerChange pagerComplete pagerInitialized pageMoved', function(e, c){
      var msg = '"</span> event triggered, ' + (e.type === 'pagerChange' ? 'going to' : 'now on') +
        ' page <span class="typ">' + (c.page + 1) + '/' + c.totalPages + '</span>';
      $('#display')
        .append('<li><span class="str">"' + e.type + msg + '</li>')
        .find('li:first').remove();
    }).tablesorterPager(pagerOptions);

});