﻿(function($) {
	$.fn.extend({
        tablesorter: $.tablesorter.construct
	});
	var ts = $.tablesorter;
	
    //Sorts Digits by removing commas
    ts.addParser({
        id:"digitComma",
        is: function(s) {
            return false;
        },
        format: function(s) {
            return $.tablesorter.formatFloat(s.replace(/,/,""));
        },
        type: "numeric"
    });

    //Sorts ranges by the first number (ex: 1020-1440)
    ts.addParser({
        id:"digitRange",
        is: function(s) {
            return false;
        },
        format: function(s) {
            return $.tablesorter.formatFloat(s.replace(/out /,"").replace(new RegExp(/-[0-9]*/),"").replace(new RegExp(/ \(of 1600\)/),"").replace(new RegExp(/ \(of 2400\)/),""));
        },
        type:"numeric"
    });

    //Sorts Dates in the format of (ex: August 15)
    ts.addParser({
        id:"dateMonth",
        is: function(s) {
            return false;
        },
        format: function(s) {
            return $.tablesorter.formatFloat(s.replace(/Not Reported/,15).replace(/Rolling/,0).replace(/ (?=([0-9](?![0-9])))/,0).replace(/ /,"").replace(/January/,1).replace(/February/,2).replace(/March/,3).replace(/April/,4).replace(/May/,5).replace(/June/,6).replace(/July/,7).replace(/August/,8).replace(/September/,9).replace(/October/,10).replace(/November/,11).replace(/December/,12));
        },
        type: "numeric"
    });

    //Grade Sorter
    ts.addParser({
        id: "grade",
        is: function(s) {
            return false;
        },
        format: function(s) {
            return s.replace(/A\+/,0).replace(/A\-/,2).replace(/B\+/,3).replace(/B\-/,5).replace(/C\+/,6).replace(/C\-/,8).replace(/D\+/,9).replace(/D\-/,11).replace(/N\/A/,13).replace(/A/,1).replace(/B/,4).replace(/C/,7).replace(/D/,10).replace(/F/,12);
        },
        type: "numeric"
    });

    //BP Status Sorter
    ts.addParser({
        id: "status",
        is: function(s) {
            return false;
        },
        format: function(s) {
            return s.replace(/Not Applying/, 0).replace(/Just Looking/, 1).replace(/Visited/, 2).replace(/Planning To Apply/, 3).replace(/Applied/, 4).replace(/Rejected/, 5).replace(/Waitlisted/, 6).replace(/Accepted/, 7).replace(/Going/, 8);
        },
        type: "numeric"
    });
})(jQuery);
