﻿$.tablesorter.addWidget(
{
    id: "zebra2",
    format: function(table)
    {
        $("tr:visible", table.tBodies[0]).removeClass('odd').filter(':odd').addClass('odd');
        //$("tr:visible:has([highlight=true])", table.tBodies[0]).addClass('highlight');
    }
});

// add parser through the tablesorter addParser method
$.tablesorter.addParser({
    // set a unique id         
    id: 'zeroNumber',
    is: function(s)
    {
        if (s == '0')
        {
            return true;
        }

        return false;
    },
    format: function(s)
    {
        // format your data for normalization             
        return s;
    },
    // set type, either numeric or text
    type: 'numeric'
});

function pageLoad(sender, args)
{
    $get("__SORTEXP").scrollTop
    $('table[id$=Grid]:not([class])').tablesorter(
        {
            //debug: true, //enables debug mode
            widgets: ['zebra2'],
            textExtraction: extractValue
        });

    $('table[id$="Grid"].BlooMail').tablesorter(
        {
            //debug: true, //enables debug mode
            //widgets: ['sortexp'],
            textExtraction: extractValue
        });
}

function extractValue(node)
{
    var s = node.getAttribute("Sort");

    if (s == null)
    {
        s = "";
    }

    return s;
}

$.tablesorter.addWidget(
{
    id: 'sortexp',
    format: function(table)
    {
        var sortExpControl = $get("__SORTEXP");
        var sortList = table.config.sortList;
        if (sortList.length > 0)
        {
            sortExpControl.value = sortList;
            //tablesorterCookieJar.set($(table).attr('id'), sortList);
        }
        else
        {
            //var sortList = tablesorterCookieJar.get($(table).attr('id'));
            var sortList = sortExpControl.value;
            if (sortList && sortList.length > 0)
            {
                //table.config.sortList = sortList;
                $(table).trigger('sorton', [1,1]);
            }
        }
    }
});