﻿jQuery.fn.dataTableExt.oSort['custom-string-sort-asc'] = function (a, b) {
    var x = a;
    var y = b;

    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};

jQuery.fn.dataTableExt.oSort['custom-string-sort-desc'] = function (a, b) {
    var x = a;
    var y = b;

    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};

jQuery.fn.dataTableExt.oSort['custom-numeric-sort-asc'] = function (a, b) {
    var x = a.replace(/<.*?>/g, "") * 1;
    var y = b.replace(/<.*?>/g, "") * 1;
    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};

jQuery.fn.dataTableExt.oSort['custom-numeric-sort-desc'] = function (a, b) {
    var x = a.replace(/<.*?>/g, "") * 1;
    var y = b.replace(/<.*?>/g, "") * 1;
    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};

jQuery.fn.dataTableExt.oSort['custom-date-sort-asc'] = function (a, b) {
    var x = a.replace(/<.*?>/g, "");
    var y = b.replace(/<.*?>/g, "");

    var d1 = new Date(x);
    var d2 = new Date(y);

    return ((d1 < d2) ? -1 : ((d1 > d2) ? 1 : 0));
};

jQuery.fn.dataTableExt.oSort['custom-date-sort-desc'] = function (a, b) {
    var x = a.replace(/<.*?>/g, "");
    var y = b.replace(/<.*?>/g, "");

    var d1 = new Date(x);
    var d2 = new Date(y);

    return ((d1 < d2) ? 1 : ((d1 > d2) ? -1 : 0));
};

jQuery.fn.dataTableExt.oSort['custom-percentage-sort-asc'] = function (a, b) {
    a = a.replace(/<.*?>/g, "");
    var x = a.replace('%', "") * 1;
    b = b.replace(/<.*?>/g, "");
    var y = b.replace('%', "") * 1;

    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};

jQuery.fn.dataTableExt.oSort['custom-percentage-sort-desc'] = function (a, b) {
    a = a.replace(/<.*?>/g, "");
    var x = a.replace('%', "") * 1;
    b = b.replace(/<.*?>/g, "");
    var y = b.replace('%', "") * 1;

    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};

jQuery.fn.dataTableExt.oSort['custom-currency-sort-asc'] = function (a, b) {
    a = a.replace(/<.*?>/g, "").substring(1);
    var x = a.replace(',', "") * 1;
    b = b.replace(/<.*?>/g, "").substring(1);
    var y = b.replace(',', "") * 1;

    return ((x < y) ? -1 : ((x > y) ? 1 : 0));
};

jQuery.fn.dataTableExt.oSort['custom-currency-sort-desc'] = function (a, b) {
    a = a.replace(/<.*?>/g, "").substring(1);
    var x = a.replace(',', "") * 1;
    b = b.replace(/<.*?>/g, "").substring(1);
    var y = b.replace(',', "") * 1;

    return ((x < y) ? 1 : ((x > y) ? -1 : 0));
};
