﻿$(document).ready(function defaultpage() {
    ApplySortAndSearched();
    sortDropDownListByText();   //Sort all drop-down list alphabetically - should really be done on server - this is belts & braces approach
});

$(document).ready( //When document is ready
function timesheetPage() {
    $('.grid').unblock(); //unblock any elements with the class grid
    $('.block').change(function() { //attach method to change event of .block elements
        $('.grid').block();
    });
});

function ApplySortAndSearched() {

    $('.tablesorter').fixGridView().tablesorter();

    $('.tablesearch tbody tr').quicksearch({
        position: 'before',
        attached: 'table.tablesearch',
        stripeRowClass: ['odd', 'even'],
        labelText: 'Filter:',
        delay: 100
    });

    $('.tablesearch2 tbody tr').quicksearch({
        position: 'before',
        attached: 'table.tablesearch2',
        stripeRowClass: ['odd', 'even'],
        labelText: 'Filter:',
        delay: 100
    });

    $('.tablesearch3 tbody tr').quicksearch({
        position: 'before',
        attached: 'table.tablesearch3',
        stripeRowClass: ['odd', 'even'],
        labelText: 'Filter:',
        delay: 100
    });

    $('.ClientTableSearch1 tbody tr').quicksearch({
        position: 'before',
        attached: 'table.ClientTableSearch1',
        stripeRowClass: ['odd', 'even'],
        labelText: 'Filter:',
        delay: 100
    });

    $('.ClientTableSearch2 tbody tr').quicksearch({
        position: 'before',
        attached: 'table.ClientTableSearch2',
        stripeRowClass: ['odd', 'even'],
        labelText: 'Filter:',
        delay: 100
    });

    $('.ClientTableSearch3 tbody tr').quicksearch({
        position: 'before',
        attached: 'table.ClientTableSearch3',
        stripeRowClass: ['odd', 'even'],
        labelText: 'Filter:',
        delay: 100
    });

    $('.ClientTableSearch4 tbody tr').quicksearch({
        position: 'before',
        attached: 'table.ClientTableSearch4',
        stripeRowClass: ['odd', 'even'],
        labelText: 'Filter:',
        delay: 100
    });

}

//Sort all HTML Select controls by alphabetical order
function sortDropDownListByText() 
{
    // Loop for each select element on the page.
    $("select").each(function() {

        // Keep track of the selected option.
        var selectedValue = $(this).val();

        // Sort all the options by text. I could easily sort these by val.
        $(this).html($("option", $(this)).sort(function(a, b) {
            return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
        }));

        // Select one option.
        $(this).val(selectedValue);
    });
}




