// Function: CheckAllSelection
// Parameters:
//			checkBoxListID		: the ID of the CheckBoxList
//			checkBoxID			: the ID of the All selection CheckBox
//			fromCheckBoxList	: if true then event is from CheckBoxList, otherwise it is from the All CheckBox
// Author: Michael S. McIntosh - 7/21/2007
function CheckAllSelection(checkBoxListID, checkBoxID, fromCheckBoxList) 
{ 
	// Get the Element objects using the passed in ID's
	var checkBoxList = document.getElementById(checkBoxListID); 
	var currentCheckBox = document.getElementById(checkBoxID); 
	var currentRow = null;
	var currentCell = null;
	var currentItem = null;
	
	var allSelected = true;
	
	// In the DOM we get a table so start processing rows
	for(var i=0;i<checkBoxList.rows.length;i++) 
	{ 
		// Set the current row
		currentRow = checkBoxList.rows[i];
		// The childNodes of the row is a cell
		for(var z=0;z<currentRow.childNodes.length;z++)
		{
			// set the current Cell
			currentCell = currentRow.childNodes[z];
			// the cells childNodes are the items in the cell
			for(var x=0;x<currentCell.childNodes.length;x++)
			{
				// set the current Item
				currentItem = currentCell.childNodes[x];
				// if this item is a checkbox then process it
				if(currentItem.type == "checkbox")
				{
					// if the click came from the CheckBoxList
					// then we check to make sure the Check All
					// correctly reflects the state of the checkboxes
					// selected in the the CheckBoxList
					if(fromCheckBoxList == true)
					{
						// If the current item is not checked
						if(currentItem.checked == false)
						{
							// All is not selected and we save the allSelected state
							// so we can reset at the end
							currentCheckBox.checked = false;
							allSelected = false;
						}
					}
					else
					{
						// if the click came from the Select All then the current
						// checkbox selected state matches the state of the select All
						currentItem.checked = currentCheckBox.checked;
					}
				}
			}
		}
	}
	
	// If all of the values in the CheckBoxList are selected then re-select the 
	// All selection for that category
	if(fromCheckBoxList == true && allSelected == true)
	{
		currentCheckBox.checked = true;
	}
}
