function getLevel(name) { level = 0; while (name.substr(0,2) == "- "){ level++; name = name.substr(2); } return level; } var allSelected = 0; function countSelected() { $('#pages\\[\\] option:selected').each(function(){ allSelected++; var optIndex = $(this).index(); var parentLevel = getLevel($(this).text()); var subLevel = getLevel($('#pages\\[\\] option').eq(optIndex+1).text()); while(subLevel > parentLevel) { allSelected++; optIndex++; subLevel = getLevel($('#pages\\[\\] option').eq(optIndex+1).text()); }; }); } function sendForm(message) { if ($('#checkdel').prop("checked")) { allSelected = 0; countSelected(); if (confirm(message.replace(/#/, allSelected))) return false; else return false; } } $(document).ready(function () { $('input[id*="checkgroup"]').change(function() { $('input[id*="checkgroup"]').not($(this)).prop("checked", false); }); $('input[id*="checkdescription"]').change(function() { $('input[id*="checkdescription"]').not($(this)).prop("checked", false); }); $('input[id*="checkkeywords"]').change(function() { $('input[id*="checkkeywords"]').not($(this)).prop("checked", false); }); $('#checkdel').change(function() { if ($(this).prop("checked")) $('input[id*="check"]').not($(this)).prop("checked", false); }); $('#read_more, #read_hide').click(function() { $('#read_more, #read_hide').toggle(); $('#pages_hint').slideToggle('slow'); }); $('#pages\\[\\]').change(function() { $('#parent option').removeAttr('disabled'); $('#pages\\[\\] option:selected').each(function(){ var optIndex = $(this).index(); $('#parent option').eq(optIndex+1).attr('disabled','disabled'); var menuText = $('#parent option').eq(optIndex+1).text() var parentLevel = getLevel(menuText); var subLevel = getLevel($('#parent option').eq(optIndex+2).text()); while(subLevel > parentLevel) { $('#parent option').eq(optIndex+2).attr('disabled','disabled'); optIndex++; subLevel = getLevel($('#parent option').eq(optIndex+2).text()); }; }); }); $('#parent').change(function() { var optIndex = this.selectedIndex; $('#pages\\[\\] option').eq(optIndex-1).attr('disabled','disabled').siblings().removeAttr('disabled'); var menuText = $('#pages\\[\\] option').eq(optIndex-1).text() var parentLevel = getLevel(menuText); var subLevel = getLevel($('#pages\\[\\] option').eq(optIndex).text()); while(subLevel > parentLevel) { $('#pages\\[\\] option').eq(optIndex).attr('disabled','disabled'); optIndex++; subLevel = getLevel($('#pages\\[\\] option').eq(optIndex).text()); }; }); });