'use strict';function ResponsiveDatatablesHelper(tableSelector,breakpoints,options){if(typeof tableSelector==='string'){this.tableElement=$(tableSelector);}else{this.tableElement=tableSelector;}
this.api=this.tableElement.dataTable().api();this.columnIndexes=[];this.columnsShownIndexes=[];this.columnsHiddenIndexes=[];this.currentBreakpoint='';this.lastBreakpoint='';this.lastColumnsHiddenIndexes=[];var fileName=window.location.pathname.split("/").pop();var context=this.api.settings().context[0];this.tableId=context.sTableId;this.saveState=context.oInit.bStateSave;this.cookieName='DataTablesResponsiveHelper_'+ this.tableId+(fileName?'_'+ fileName:'');this.lastStateExists=false;this.expandColumn=undefined;this.origBreakpointsDefs=undefined;this.breakpoints={};this.options={hideEmptyColumnsInRowDetail:false,clickOn:'icon',showDetail:null,hideDetail:null};this.expandIconTemplate='<span class="responsiveExpander"></span>';this.rowTemplate='<tr class="row-detail"><td><ul><!--column item--></ul></td></tr>';this.rowLiTemplate='<li><span class="columnTitle"><!--column title--></span>: <span class="columnValue"><!--column value--></span></li>';this.disabled=true;this.skipNextWindowsWidthChange=false;this.init(breakpoints,options);}
ResponsiveDatatablesHelper.prototype.init=function(breakpoints,options){this.origBreakpointsDefs=breakpoints;this.initBreakpoints();this.disable(false);$.extend(this.options,options);};ResponsiveDatatablesHelper.prototype.initBreakpoints=function(){if(this.saveState){this.getState();}
if(!this.lastStateExists){var breakpointsSorted=[];for(var prop in this.origBreakpointsDefs){breakpointsSorted.push({name:prop,upperLimit:this.origBreakpointsDefs[prop],columnsToHide:[]});}
breakpointsSorted.sort(function(a,b){return a.upperLimit- b.upperLimit;});var lowerLimit=0;for(var i=0;i<breakpointsSorted.length;i++){breakpointsSorted[i].lowerLimit=lowerLimit;lowerLimit=breakpointsSorted[i].upperLimit;}
breakpointsSorted.push({name:'always',lowerLimit:lowerLimit,upperLimit:Infinity,columnsToHide:[]});this.breakpoints={};var i,l;for(i=0,l=breakpointsSorted.length;i<l;i++){this.breakpoints[breakpointsSorted[i].name]=breakpointsSorted[i];}
var columns=this.api.columns().header();var visibleColumnsHeadersTds=[];for(i=0,l=columns.length;i<l;i++){if(this.api.column(i).visible()){this.columnIndexes.push(i);visibleColumnsHeadersTds.push(columns[i]);}}
for(var index=0;index<visibleColumnsHeadersTds.length;index++){var col=$(visibleColumnsHeadersTds[index]);if(col.attr('data-class')==='expand'){this.expandColumn=this.columnIndexes[index];}
var dataHide=col.attr('data-hide');if(dataHide!==undefined){var splitBreakingPoints=dataHide.split(/,\s*/);for(var i=0;i<splitBreakingPoints.length;i++){var bp=splitBreakingPoints[i];if(bp==='always'){for(var prop in this.breakpoints){if(this.breakpoints[prop].name!=='default'){this.breakpoints[prop].columnsToHide.push(this.columnIndexes[index]);}}}else if(this.breakpoints[bp]!==undefined){this.breakpoints[bp].columnsToHide.push(this.columnIndexes[index]);}}}}}};ResponsiveDatatablesHelper.prototype.setWindowsResizeHandler=function(bindFlag){if(bindFlag===undefined){bindFlag=true;}
if(bindFlag){var that=this;$(window).bind("resize",function(){that.respond();});}else{$(window).unbind("resize");}};ResponsiveDatatablesHelper.prototype.respond=function(){if(this.disabled){return;}
var that=this;var newWindowWidth=$(window).width();var newColumnsToHide=[];for(var prop in this.breakpoints){var element=this.breakpoints[prop];if((!element.lowerLimit||newWindowWidth>element.lowerLimit)&&(!element.upperLimit||newWindowWidth<=element.upperLimit)){this.currentBreakpoint=element.name;newColumnsToHide=element.columnsToHide;}}
var columnShowHide=false;if(!this.skipNextWindowsWidthChange){if(this.lastBreakpoint.length===0&&newColumnsToHide.length){columnShowHide=true;}else if(this.lastBreakpoint!=this.currentBreakpoint){columnShowHide=true;}else if(this.columnsHiddenIndexes.length!==newColumnsToHide.length){columnShowHide=true;}else{var d1=this.difference(this.columnsHiddenIndexes,newColumnsToHide).length;var d2=this.difference(newColumnsToHide,this.columnsHiddenIndexes).length;columnShowHide=d1+ d2>0;}}
if(columnShowHide){this.skipNextWindowsWidthChange=true;this.columnsHiddenIndexes=newColumnsToHide;this.columnsShownIndexes=this.difference(this.columnIndexes,this.columnsHiddenIndexes);this.showHideColumns();this.lastBreakpoint=this.currentBreakpoint;this.setState();this.skipNextWindowsWidthChange=false;}
if(this.columnsHiddenIndexes.length){this.tableElement.addClass('has-columns-hidden');$('tr.detail-show',this.tableElement).each(function(index,element){var tr=$(element);if(tr.next('.row-detail').length===0){ResponsiveDatatablesHelper.prototype.showRowDetail(that,tr);}});}else{this.tableElement.removeClass('has-columns-hidden');$('tr.row-detail').each(function(event){ResponsiveDatatablesHelper.prototype.hideRowDetail(that,$(this).prev());});}};ResponsiveDatatablesHelper.prototype.showHideColumns=function(){for(var i=0,l=this.columnsShownIndexes.length;i<l;i++){this.api.column(this.columnsShownIndexes[i]).visible(true);}
for(var i=0,l=this.columnsHiddenIndexes.length;i<l;i++){this.api.column(this.columnsHiddenIndexes[i]).visible(false);}
var that=this;$('tr.row-detail').each(function(){ResponsiveDatatablesHelper.prototype.hideRowDetail(that,$(this).prev());});if(this.tableElement.hasClass('has-columns-hidden')){$('tr.detail-show',this.tableElement).each(function(index,element){ResponsiveDatatablesHelper.prototype.showRowDetail(that,$(element));});}};ResponsiveDatatablesHelper.prototype.createExpandIcon=function(tr){if(this.disabled){return;}
var tds=$('td',tr);for(var i=0,l=tds.length;i<l;i++){var td=tds[i];var tdIndex=this.api.cell(td).index().column;td=$(td);if(tdIndex===this.expandColumn){if($('span.responsiveExpander',td).length==0){td.prepend(this.expandIconTemplate);switch(this.options.clickOn){case'cell':td.on('click',{responsiveDatatablesHelperInstance:this},this.showRowDetailEventHandler);break;case'row':$(tr).on('click',{responsiveDatatablesHelperInstance:this},this.showRowDetailEventHandler);break;default:td.on('click','span.responsiveExpander',{responsiveDatatablesHelperInstance:this},this.showRowDetailEventHandler);break;}}
break;}}};ResponsiveDatatablesHelper.prototype.showRowDetailEventHandler=function(event){var responsiveDatatablesHelperInstance=event.data.responsiveDatatablesHelperInstance;if(responsiveDatatablesHelperInstance.disabled){return;}
var td=$(this);if(!td.closest('table').hasClass('has-columns-hidden')){return;}
var tr=td.closest('tr');if(tr.hasClass('detail-show')){ResponsiveDatatablesHelper.prototype.hideRowDetail(responsiveDatatablesHelperInstance,tr);}else{ResponsiveDatatablesHelper.prototype.showRowDetail(responsiveDatatablesHelperInstance,tr);}
tr.toggleClass('detail-show');event.stopPropagation();};ResponsiveDatatablesHelper.prototype.showRowDetail=function(responsiveDatatablesHelperInstance,tr){var api=responsiveDatatablesHelperInstance.api;var columns=api.columns().header();var newTr=$(responsiveDatatablesHelperInstance.rowTemplate);var ul=$('ul',newTr);for(var i=0;i<responsiveDatatablesHelperInstance.columnsHiddenIndexes.length;i++){var index=responsiveDatatablesHelperInstance.columnsHiddenIndexes[i];var rowIndex=api.row(tr).index();var td=api.cell(rowIndex,index).node();if(!responsiveDatatablesHelperInstance.options.hideEmptyColumnsInRowDetail||td.innerHTML.trim().length){var li=$(responsiveDatatablesHelperInstance.rowLiTemplate);var hiddenColumnName=$(columns[index]).attr('data-name');$('.columnTitle',li).html(hiddenColumnName!==undefined?hiddenColumnName:columns[index].innerHTML);var contents=$(td).contents();var clonedContents=contents.clone();for(var n=0,m=contents.length;n<m;n++){var node=contents[n];if(node.nodeType===Node.ELEMENT_NODE&&node.tagName==='SELECT'){clonedContents[n].selectedIndex=node.selectedIndex}}
$('.columnValue',li).append(clonedContents).data('originalTdSource',td);li.attr('data-column',index);var tdClass=$(td).attr('class');if(tdClass!=='undefined'&&tdClass!==false&&tdClass!==''){li.addClass(tdClass)}
ul.append(li);}}
var colspan=responsiveDatatablesHelperInstance.columnIndexes.length- responsiveDatatablesHelperInstance.columnsHiddenIndexes.length;newTr.find('> td').attr('colspan',colspan);tr.after(newTr);if(responsiveDatatablesHelperInstance.options.showDetail){responsiveDatatablesHelperInstance.options.showDetail(newTr);}};ResponsiveDatatablesHelper.prototype.hideRowDetail=function(responsiveDatatablesHelperInstance,tr){var rowDetail=tr.next('.row-detail');if(responsiveDatatablesHelperInstance.options.hideDetail){responsiveDatatablesHelperInstance.options.hideDetail(rowDetail);}
rowDetail.find('li').each(function(){var columnValueContainer=$(this).find('span.columnValue');var tdContents=columnValueContainer.contents();var td=columnValueContainer.data('originalTdSource');$(td).empty().append(tdContents);});rowDetail.remove();};ResponsiveDatatablesHelper.prototype.disable=function(disable){this.disabled=(disable===undefined)||disable;if(this.disabled){this.setWindowsResizeHandler(false);$('tbody tr.row-detail',this.tableElement).remove();$('tbody tr',this.tableElement).removeClass('detail-show');$('tbody tr span.responsiveExpander',this.tableElement).remove();this.columnsHiddenIndexes=[];this.columnsShownIndexes=this.columnIndexes;this.showHideColumns();this.tableElement.removeClass('has-columns-hidden');this.tableElement.off('click','span.responsiveExpander',this.showRowDetailEventHandler);}else{this.setWindowsResizeHandler();}};ResponsiveDatatablesHelper.prototype.getState=function(){if(typeof(Storage)){var value=JSON.parse(localStorage.getItem(this.cookieName));if(value){this.columnIndexes=value.columnIndexes;this.breakpoints=value.breakpoints;this.expandColumn=value.expandColumn;this.lastBreakpoint=value.lastBreakpoint;this.lastStateExists=true;}}else{}};ResponsiveDatatablesHelper.prototype.setState=function(){if(typeof(Storage)){var d1=this.difference(this.lastColumnsHiddenIndexes,this.columnsHiddenIndexes).length;var d2=this.difference(this.columnsHiddenIndexes,this.lastColumnsHiddenIndexes).length;if(d1+ d2>0){var tt;var value={columnIndexes:this.columnIndexes,columnsHiddenIndexes:this.columnsHiddenIndexes,breakpoints:this.breakpoints,expandColumn:this.expandColumn,lastBreakpoint:this.lastBreakpoint};localStorage.setItem(this.cookieName,JSON.stringify(value));this.lastColumnsHiddenIndexes=this.columnsHiddenIndexes.slice(0);}}else{}};ResponsiveDatatablesHelper.prototype.difference=function(a,b){var arr=[],i,hash={};for(i=b.length- 1;i>=0;i--){hash[b[i]]=true;}
for(i=a.length- 1;i>=0;i--){if(hash[a[i]]!==true){arr.push(a[i]);}}
return arr;};

/**
 * Change the number of records that can be viewed on a single page in 
 * DataTables.
 *
 * DataTables 1.10 provides the `dt-api page.len()` method to get and set the
 * page length using the built-in API. As such this method is marked deprecated,
 * but is available for use with legacy version of DataTables. Please use the
 * new API if you are used DataTables 1.10 or newer.
 *
 *  @name fnLengthChange
 *  @summary Change the paging display length
 *  @author [Pedro Alves](http://www.webdetails.pt/)
 *  @deprecated
 *
 *  @example
 *    $(document).ready(function() {
 *        var table = $('#example').dataTable();
 *        table.fnLengthChange( 100 );
 *    } );
 */

jQuery.fn.dataTableExt.oApi.fnLengthChange = function ( oSettings, iDisplay )
{
    oSettings._iDisplayLength = iDisplay;
    oSettings.oApi._fnCalculateEnd( oSettings );

    /* If we have space to show extra rows (backing up from the end point - then do so */
    if ( oSettings._iDisplayEnd == oSettings.aiDisplay.length )
    {
        oSettings._iDisplayStart = oSettings._iDisplayEnd - oSettings._iDisplayLength;
        if ( oSettings._iDisplayStart < 0 )
        {
            oSettings._iDisplayStart = 0;
        }
    }

    if ( oSettings._iDisplayLength == -1 )
    {
        oSettings._iDisplayStart = 0;
    }

    oSettings.oApi._fnDraw( oSettings );

    if ( oSettings.aanFeatures.l )
    {
        $('select', oSettings.aanFeatures.l).val( iDisplay );
    }
};