// WIDGETS -------------------------------------------------------------------------------------------------------------------------


// add new widget called repeatHeaders 
$.tablesorter.addWidget({
    // give the widget a id 
    id: "repeatHeaders",
    // format is called when the on init and when a sorting has finished 
    format: function(table) {
        // cache and collect all TH headers 
        if (!this.headers) {
            var h = this.headers = [];
            $("thead th", table).each(function() {
                h.push(
                    "" + $(this).text() + ""
                );

            });
        }

        // remove appended headers by classname. 
        $("tr.repated-header", table).remove();

        // loop all tr elements and insert a copy of the "headers"     
        for (var i = 0; i < table.tBodies[0].rows.length; i++) {
            // insert a copy of the table head every 10th row 
            if ((i % 5) == 4) {
                $("tbody tr:eq(" + i + ")", table).before(
                    $("").html(this.headers.join(""))

                );
            }
        }
    }
});



// PARSERS ---------------------------------------------------------------------------------------------------------------------------

// sorting numbers with commas
$.tablesorter.addParser({
    id: 'englishNumber',
    is: function(s) {
        // return false so this parser is not auto detected 

    },
    format: function(s) {
        while (s.indexOf(",") > 0)
            s = s.substring(0, s.indexOf(",")) + s.substring(s.indexOf(",") + 1, s.length);
        return s;
    },
    type: 'numeric'
});

$.tablesorter.addParser({
    id: 'commaNum',
    is: function(s) {
        return false;
    },
    format: function(s) {
        s = s.replace(/,/g, "");
        s = s.replace("$", "");
        return s;
    },
    type: "numeric"
});  
