//----------------------------------------------------------------------------
// Add all checkbox selector
//----------------------------------------------------------------------------

$.fn.applyAllCheckbox = function(name) { 
  $("input[@type='checkbox'][@name^='all.checkbox.for']")
    .checkDynamic('on');
  $("input[@type='checkbox'][@name='"+name+"']")
    .checkDynamic('on');
  $("input[@type='checkbox'][@name='all.checkbox.for."+name+"']")
      .click(function(){
            $.checkAllCheckbox(name, this.checked);}
  );
}; 

$.fn.checkDynamic = function(mode) { 
    return this.each(function() { 
        if($(this).is("input[@type='checkbox']")){ 
            switch(mode) { 
                case false: 
                case 'off': 
                    this.checked = false; 
                    break; 
                case 'toggle': 
                    this.checked = !this.checked; 
                    break; 
                case true: 
                default://'on' 
                    this.checked = true; 
                    break; 
            } 
        } 
    }); 
}; 

$.checkAllCheckbox = function(name, checked){ 
    // check all the boxes based on clicked element 
    $("input[@type='checkbox'][@name^='"+name+"']").checkDynamic(checked); 
    // make sure all the CheckAll boxes are set the same also 
    $().checkDynamic(checked); 
}; 

