var DetectCheckboxesGroup = function(tag){ if (tag.getAttribute && tag.getAttribute("rel")){ var rel = tag.getAttribute("rel"); var i = rel.indexOf('checkbox'); if (i != -1){ group = rel.substring(i+9, rel.length-1); this.Add(group, tag); Event.observe(tag, 'click', CheckMainCheckbox);}} }; 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"); checkboxCollection.SetDetector(DetectCheckboxesGroup); checkboxCollection.SetPostFunction(PostCheckboxesGroup); TagDetect.Add(checkboxCollection);