var k_div_prefix = "div_";

function checkchildren( parent )
{

var divlist;
var cboxlist;
var i;

// Find the division that matches the parent checkbox ID ...
divlist = document.getElementById( k_div_prefix + parent.id );
if ( divlist == null )
   return;

// Find all checkboxes within the division ...
cboxlist = divlist.getElementsByTagName( "input" )
if ( cboxlist == null )
   return;

// Set all child checkboxes to match the parent ...
for ( i = 0; i < cboxlist.length; i++ )
   cboxlist[ i ].checked = parent.checked;

}


function checktree( current, root )
{

var all_checked;
var cboxlist;
var i;

var divnode;
var pnode;
var id;

if ( current == null )
   return;
if ( current.id == root )
   return;

while ( 1 )
   {

// Get the division id the current checkbox is in ...
   divnode = current.parentNode;
   if ( divnode == null )
      break;

   id = divnode.getAttribute( "id" );   
   if ( id.length == 0 )
      break;

// Find the parent checkbox using the division id
// less the division prefix ...
   id = id.substring( k_div_prefix.length );    
   cboxnode = current.form[ id ];
   if ( cboxnode == null )
      break;

// Check all checkboxes in the division and set the parent
// checkbox to checked or unchecked depending on the state
// of its children ...
   cboxlist = divnode.getElementsByTagName( "input" );
   if ( cboxlist == null )
      break;

   all_checked = true;
   for ( i = 0; i < cboxlist.length; i++ )
      {
      if ( ! cboxlist[ i ].checked )
         {
         all_checked = false;
         break;
         }
      }
   
   cboxnode.checked = all_checked;

// Exit if we hit the root ...
   if ( cboxnode.id == root )
      break;

// Process parent ...
   current = cboxnode;

   }

}