function reDetectCheckboxesGroup(){ checkboxCollection = new TagCollection("checkboxCollection"); DetectCheckboxesGroup();} function DetectCheckboxesGroup(){ var inputs = $$('input[rel^=checkbox]'); inputs.each(function(tag){ var rel = tag.getAttribute("rel"); group = rel.substring(9, rel.length-1); checkboxCollection.Add(group, tag); Event.observe(tag, 'click', CheckMainCheckbox);}); PostCheckboxesGroup();}; function getCheckboxesGroup(tag){ rel = tag.getAttribute("rel"); var i = rel.indexOf('['); if (i != -1){ group = rel.substring(i+1, rel.length-1);} return group;} function CheckMainCheckbox(){ group = getCheckboxesGroup(this); CheckingMainCheckBox(group);} function CheckingMainCheckBox(group){ var len = checkboxCollection.groups[group].length; var j = 0, k = 0, flag = false; checkboxCollection.groups[group].each(function(tag){ if (tag.checked) j++; if (tag.id && !flag){ mainTag = tag; flag = true;}}); if (j < len && mainTag.checked) mainTag.checked = false; else if (j == len - 1) mainTag.checked = true;} function CheckCheckBoxes(ch, group){ checkboxCollection.groups[group].each(function(tag){ tag.checked = ch;});} function PostCheckboxesGroup(){ checkboxCollection.groups.each(function(group){ CheckingMainCheckBox(group);});} var checkboxCollection = new TagCollection("checkboxCollection"); document.observe('dom:loaded', function (){DetectCheckboxesGroup();} );
