// JavaScript Document  Contols the Multiselect checkboxes
function setcbval(ownerform, unit, lesson, parval)
{
   for ( i=0; i < ownerform.elements.length; i++)
   {

	currelem = ownerform.elements[i].name

	if ( unit == -1 )
	{
	   unitid = 'Unit'
	   if ( unitid == currelem.substring(0, unitid.length) )
	   	ownerform.elements[i].checked = parval;

	   lessonid = 'Lesson'
	   if ( lessonid == currelem.substring(0, lessonid.length) )
	   	ownerform.elements[i].checked = parval;

	   topicid = 'Topic';
 	   if ( topicid == currelem.substring(0, topicid.length) )
	      ownerform.elements[i].checked = parval;

	}
	else
	{
  	   if ( lesson == -1 )
	   {
		unitid = 'Unit' + unit
	   	if ( unitid == currelem.substring(0, unitid.length) )
		   ownerform.elements[i].checked = parval;

		lessonid = 'Lesson' + unit
	   	if ( lessonid == currelem.substring(0, lessonid.length) )
	   	   ownerform.elements[i].checked = parval;
	   }


	   if ( lesson == -1 )
	      topicid = 'Topic' + unit;
 	   else
	      topicid = 'Topic' + unit + lesson;

	   if ( topicid == currelem.substring(0, topicid.length) )
	      ownerform.elements[i].checked = parval;
	}
   }

}

function dochildren(parent) 
{
 
   //Look for Lesson level
   level = "Lesson"
   x = parent.name.indexOf(level);
   if ( x == 0 )
   {
   	unit = parent.name.substring(level.length, level.length + 1);
	lesson = parent.name.substring(level.length + 1, level.length + 2);
	parval = parent.checked;
	setcbval(parent.form , unit, lesson, parval);
	return;
   }

   //Look for Unit level
   level = "Unit"
   x = parent.name.indexOf(level);
   if ( x == 0 )
   {
   	unit = parent.name.substring(level.length, level.length + 1);
	parval = parent.checked;
	setcbval(parent.form , unit, -1, parval);
	return;
   }



   //Look for whole units
   level = "EntireCourse"
   x = parent.name.indexOf(level);
   if ( x == 0 )
   {
   	unit = parent.name.substring(level.length, level.length + 1);
	parval = parent.checked;
	setcbval(parent.form , -1, -1, parval);
	return;
   }

   //Look for Tutorial
   level = "TUTOR"
   x = parent.name.indexOf(level);
   if ( x == 0 )
   {
      parval = parent.checked;
      for ( i=0; i < parent.form.elements.length; i++)
      {
	currelem = parent.form.elements[i].name
	if ( currelem == "TUTOR")
           parent.form.elements[i].checked = parval;
      }
      return;
   }
}
