help with check all and unselect all

help with check all and unselect all

Hello ..Can someone please help me out with this check all /uncheck all I'm trying to accomplish.
 
I currently have this javascript function that handles check and uncheckall..
 
  1. function

    jqCheckAll(id, pID) {

    $(

    "#" + pID + " :checkbox").attr('checked', $('#' + id).is(':checked'));

    }

    input

    type="checkbox" name="checkAllSH701" id="checkAllSH701" onclick="jqCheckAll( this.id, 'SH701_ChkBoxTBL' );"/>

    I'm having trouble handling unchecking the checkall checkbox if the user manually deselects one of the checkboxes.I was able to find this which would work but I can't hardcode the "GRIDVIEW1" as I will have an accordion UI with mutiple checkall checkboxes on each accordion panel..so each accordion panel will have a checkall checkbox which checks all of the checkboxes for that panel. So, I was able to find this:
      // To deselect CheckAll when a GridView CheckBox
            // is unchecked
           

    $("#GridView1 INPUT[type='checkbox']").click(
            function(e) {
                if (!$(this)[0].checked) {
                    chkBox.attr("checked", false);
                }
            });





    I need something along the line of determining which checkall box needs to be unchecked depending on which checkboxes the user unchecks.. and what exactly does this )[0].checked represent?