/*! Widget: math - updated 11/22/2015 (v2.24.6) */ !function(a){"use strict";var b=a.tablesorter,c={error:{0:"Infinity result: Divide by zero",1:"Need more than one element to make this calculation",undef:"No elements found"},invalid:function(a,b,d){return console.log(b,c.error[d]),a&&a.widgetOptions.math_none||"none"},events:"tablesorter-initialized update updateAll updateRows addRows updateCell filterReset filterEnd ".split(" ").join(".tsmath "),processText:function(a,c){var d=c.attr(a.textAttribute);return"undefined"==typeof d&&(d=c[0].textContent||c.text()),d=b.formatFloat(d.replace(/[^\w,. \-()]/g,""),a.table)||0,isNaN(d)?0:d},getRow:function(b,d){var e,f=b.widgetOptions,g=[],h=d.closest("tr"),i=h.hasClass(f.filter_filteredRow||"filtered"),j=h.attr(f.math_dataAttrib+"-filter")||f.math_rowFilter;return j&&(h=h.filter(j)),(!i||j)&&(e=h.children().not("["+f.math_dataAttrib+"=ignore]"),f.math_ignore.length&&(e=e.not("[data-column="+f.math_ignore.join("],[data-column=")+"]")),g=e.not(d).map(function(){return c.processText(b,a(this))}).get()),g},getColumn:function(a,b,d){var e,f,g,h,i,j,k=a.widgetOptions,l=[],m=b.closest("tr"),n=k.math_dataAttrib,o=m.attr(n+"-filter")||k.math_rowFilter,p=k.filter_filteredRow||"filtered",q=parseInt(b.attr("data-column"),10),r=a.$table.children("tbody").children();if("above"===d)for(h=r.index(m),e=h;e>=0;)g=r.eq(e),o&&(g=g.filter(o)),f=g.children().filter("[data-column="+q+"]"),j=f.filter("["+n+"^=above]").length,((!g.hasClass(p)||o)&&g.not("["+n+"=ignore]").length&&e!==h||j&&e!==h)&&(j?e=0:f.length&&l.push(c.processText(a,f))),e--;else if("below"===d)for(h=r.length,e=r.index(m)+1;h>e&&(g=r.eq(e),o&&(g=g.filter(o)),f=g.children().filter("[data-column="+q+"]"),!f.filter("["+n+"^=below]").length);e++)(!g.hasClass(p)||o)&&g.not("["+n+"=ignore]").length&&f.length&&l.push(c.processText(a,f));else for(i=r.not("["+n+"=ignore]"),h=i.length,e=0;h>e;e++)g=i.eq(e),o&&(g=g.filter(o)),f=g.children().filter("[data-column="+q+"]"),g.hasClass(p)&&!o||!f.not("["+n+"^=above],["+n+"^=below],["+n+"^=col]").length||f.is(b)||l.push(c.processText(a,f));return l},getAll:function(b){var d,e,f,g,h,i,j,k,l=[],m=b.widgetOptions,n=m.math_dataAttrib,o=m.filter_filteredRow||"filtered",p=m.filter_rowFilter,q=b.$table.children("tbody").children().not("["+n+"=ignore]");for(h=q.length,g=0;h>g;g++)if(f=q.eq(g),p&&(f=f.filter(p)),!f.hasClass(o)||p)for(i=f.children().not("["+n+"=ignore]"),k=i.length,j=0;k>j;j++)d=i.eq(j),e=parseInt(d.attr("data-column"),10),!d.filter("["+n+"]").length&&a.inArray(e,m.math_ignore)<0&&l.push(c.processText(b,d));return l},setColumnIndexes:function(c){c.$table.after('
');var d=c.$table.detach();b.computeColumnIndex(d.children("tbody").children()),a("#_tablesorter_table_placeholder").after(d).remove()},recalculate:function(a,d,e){if(a&&(!d.math_isUpdating||e)){var f,g,h,i;a.debug&&(g=new Date),e&&c.setColumnIndexes(a),d.math_dataAttrib="data-"+(d.math_data||"math"),h=d.math_dataAttrib,i=a.$tbodies.children("tr").children("["+h+"]"),c.mathType(a,i,d.math_priority),i=a.$table.children("."+a.cssInfoBlock+", tfoot").children("tr").children("["+h+"]"),c.mathType(a,i,d.math_priority),i=a.$table.children().children("tr").children("["+h+"^=all]"),c.mathType(a,i,["all"]),d.math_isUpdating=!0,a.debug&&console[console.group?"group":"log"]("Math widget triggering an update after recalculation"),b.update(a,f,function(){c.updateComplete(a)}),a.debug&&console.log("Math widget update completed"+b.benchmark(g))}},updateComplete:function(a){var b=a.widgetOptions;b.math_isUpdating&&a.debug&&console.groupEnd&&console.groupEnd(),b.math_isUpdating=!1},mathType:function(d,e,f){if(e.length){var g,h,i,j,k,l,m,n,o=d.widgetOptions,p=o.math_dataAttrib,q=b.equations;"all"===f[0]&&(k=c.getAll(d)),d.debug&&console[console.group?"group":"log"]("Tablesorter Math widget recalculation"),a.each(f,function(a,b){if(l=e.filter("["+p+"^="+b+"]"),n=l.length){for(d.debug&&console[console.group?"group":"log"](b),m=0;n>m;m++)i=l.eq(m),i.parent().hasClass(o.filter_filteredRow||"filtered")||(g=(i.attr(p)||"").replace(b+"-",""),j="row"===b?c.getRow(d,i):"all"===b?k:c.getColumn(d,i,b),q[g]&&(j.length?(h=q[g](j,d),d.debug&&console.log(i.attr(p),j,"=",h)):h=c.invalid(d,g,"mean"===g?0:"undef"),c.output(i,o,h,j)));d.debug&&console.groupEnd&&console.groupEnd()}}),d.debug&&console.groupEnd&&console.groupEnd()}},output:function(a,c,d,e){var f=a.attr("data-"+c.math_data+"-mask")||c.math_mask,g=b.formatMask(f,d,c.math_wrapPrefix,c.math_wrapSuffix);"function"==typeof c.math_complete&&(g=c.math_complete(a,c,g,d,e)),g!==!1&&a.html(g)}};b.formatMask=function(a,b,c,d){if(!a||isNaN(+b))return b;var e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t="",u=a.length,v=a.search(/[0-9\-\+#]/),w=v>0?a.substring(0,v):"",x=w;if(v>0&&c&&(x=/\{content\}/.test(c||"")?(c||"").replace(/\{content\}/g,w||""):(c||"")+w),s=a.split("").reverse().join(""),r=s.search(/[0-9\-\+#]/),q=u-r,q+="."===a.substring(q,q+1)?1:0,w=r>0?a.substring(q,u):"",t=w,""!==w&&d&&(t=/\{content\}/.test(d||"")?(d||"").replace(/\{content\}/g,w||""):w+(d||"")),a=a.substring(v,q),b="-"==a.charAt(0)?-b:+b,e=0>b?b=-b:0,f=a.match(/[^\d\-\+#]/g),g=f&&f[f.length-1]||".",h=f&&f[1]&&f[0]||",",a=a.split(g),b=b.toFixed(a[1]&&a[1].length),b=+b+"",j=a[1]&&a[1].lastIndexOf("0"),l=b.split("."),(!l[1]||l[1]&&l[1].length<=j)&&(b=(+b).toFixed(j+1)),m=a[0].split(h),a[0]=m.join(""),i=a[0]&&a[0].indexOf("0"),i>-1)for(;l[0].lengthq;q++)o+=n.charAt(q),!((q-p+1)%k)&&u-k>q&&(o+=h);b[0]=o}return b[1]=a[1]&&b[1]?g+b[1]:"",x+((e?"-":"")+b[0]+b[1])+t},b.equations={count:function(a){return a.length},sum:function(a){var b,c=a.length,d=0;for(b=0;c>b;b++)d+=a[b];return d},mean:function(a){var c=b.equations.sum(a);return c/a.length},median:function(a,b){var d,e=a.length;return e>1?(a.sort(function(a,b){return a-b}),d=Math.floor(e/2),e%2?a[d]:(a[d-1]+a[d])/2):c.invalid(b,"median",1)},mode:function(a){var b,c,d,e={},f=1,g=[a[0]];for(b=0;bf?(g=[c],f=d):d===f&&(g.push(c),f=d);return g.sort(function(a,b){return a-b})},max:function(a){return Math.max.apply(Math,a)},min:function(a){return Math.min.apply(Math,a)},range:function(a){var b=a.sort(function(a,b){return a-b});return b[a.length-1]-b[0]},variance:function(a,d,e){for(var f,g=b.equations.mean(a),h=0,i=a.length;i--;)h+=Math.pow(a[i]-g,2);return f=a.length-(d?0:1),0===f?c.invalid(e,"variance",0):h/=f},varp:function(a,c){return b.equations.variance(a,!0,c)},vars:function(a,c){return b.equations.variance(a,!1,c)},stdevs:function(a,c){var d=b.equations.variance(a,!1,c);return Math.sqrt(d)},stdevp:function(a,c){var d=b.equations.variance(a,!0,c);return Math.sqrt(d)}},b.addWidget({id:"math",priority:100,options:{math_data:"math",math_ignore:[],math_mask:"#,##0.00",math_complete:null,math_priority:["row","above","below","col"],math_prefix:"",math_suffix:"",math_none:"N/A",math_event:"recalculate",math_rowFilter:""},init:function(a,d,e,f){var g=b.hasWidget(a,"filter")?"filterEnd":"updateComplete";e.$table.off((c.events+" updateComplete.tsmath "+f.math_event).replace(/\s+/g," ")).on(c.events+" "+f.math_event,function(a){var b="tablesorter-initialized"===a.type;(!f.math_isUpdating||b)&&(/filter/.test(a.type)||c.setColumnIndexes(e),c.recalculate(e,f,b))}).on(g+".tsmath",function(){setTimeout(function(){c.updateComplete(e)},40)}),f.math_isUpdating=!1,a.hasInitialized&&c.recalculate(e,f,!0)},remove:function(a,b,d,e){e||b.$table.off((c.events+" updateComplete.tsmath "+d.math_event).replace(/\s+/g," ")).children().children("tr").children("[data-"+d.math_data+"]").empty()}})}(jQuery);