﻿function CheckBoxCheckAll(bcheck, chkboxID) {
    for (var i = 0; i < document.aspnetForm.elements.length; i++) {
        if (document.aspnetForm.elements[i].type == "checkbox" && document.aspnetForm.elements[i].name.indexOf(chkboxID) != -1) {
            document.aspnetForm.elements[i].checked = bcheck.checked;
        }
    }
}

function toggleGroup(e, numberOfRows) {
    //  get a reference to the row and table
    var tr = e.parentNode.parentNode;
    var table = tr.parentNode.parentNode;

    //  do some simple math to determine how many
    //  rows we need to hide/show
    var startIndex = tr.rowIndex + 1;
    var stopIndex = startIndex + parseInt(numberOfRows);

    //  if the img src ends with plus, then we are expanding the
    //  rows.  go ahead and remove the hidden class from the rows
    //  and update the image src
    if (Sys.UI.DomElement.containsCssClass(e, 'expand')) {
        for (var i = startIndex; i < stopIndex; i++) {
            Sys.UI.DomElement.removeCssClass(table.rows[i], 'hidden');
        }

        //  remove expand class and add collapse
        Sys.UI.DomElement.removeCssClass(e, 'expand');
        Sys.UI.DomElement.addCssClass(e, 'collapse');
    }
    else {
        for (var i = startIndex; i < stopIndex; i++) {
            Sys.UI.DomElement.addCssClass(table.rows[i], 'hidden');
        }

        //  remove collapse class and add expand
        Sys.UI.DomElement.removeCssClass(e, 'collapse');
        Sys.UI.DomElement.addCssClass(e, 'expand');
    }

    return false;
}

function toggleMainGroup(e, numberOfRows) {
    //  get a reference to the row and table
    var tr = e.parentNode.parentNode;
    var table = tr.parentNode.parentNode;

    //  do some simple math to determine how many
    //  rows we need to hide/show
    var startIndex = tr.rowIndex + 1;
    var stopIndex = startIndex + parseInt(numberOfRows);

    //  if the img src ends with plus, then we are expanding the
    //  rows.  go ahead and remove the hidden class from the rows
    //  and update the image src
    if (Sys.UI.DomElement.containsCssClass(e, 'expand')) {
        for (var i = startIndex; i < stopIndex; i++) {
            if (Sys.UI.DomElement.containsCssClass(table.rows[i], 'group')) {
                Sys.UI.DomElement.removeCssClass(table.rows[i], 'hidden');
                var headers = table.rows[i].getElementsByTagName("th");
                for (var j = 0; j < headers.length; j++) {
                    if (headers[j].className == 'first') {
                        var links = headers[j].getElementsByTagName("a");
                        Sys.UI.DomElement.removeCssClass(links[0], 'collapse');
                        Sys.UI.DomElement.addCssClass(links[0], 'expand');
                    }
                }
            }
            else if (Sys.UI.DomElement.containsCssClass(table.rows[i], 'total')) {
                Sys.UI.DomElement.removeCssClass(table.rows[i], 'hidden');
            }
            else {
                if (Sys.UI.DomElement.containsCssClass(table.rows[i], 'hidden') == false) {
                    Sys.UI.DomElement.addCssClass(table.rows[i], 'hidden');
                }
            }

        }

        //  remove expand class and add collapse
        Sys.UI.DomElement.removeCssClass(e, 'expand');
        Sys.UI.DomElement.addCssClass(e, 'collapse');
    }
    else {
        for (var i = startIndex; i < stopIndex; i++) {
            Sys.UI.DomElement.addCssClass(table.rows[i], 'hidden');
        }

        //  remove collapse class and add expand
        Sys.UI.DomElement.removeCssClass(e, 'collapse');
        Sys.UI.DomElement.addCssClass(e, 'expand');
    }

    return false;
}
