function CheckUncheckAll(checkBoxAll, webPartId, color)
{
    var checkboxes = document.getElementsByName('CWActionBox'+webPartId);
    var i = 0;
    var checked = checkBoxAll.checked;
    
    for(i = 1; i<checkboxes.length; i++)
    {
        checkboxes[i].checked = checked; 
        CWHighlightRow(checkboxes[i],color);
    }

    checkboxes[0].checked = checked; 
    //put this back when you add footer checkbox
    //checkboxes[checkboxes.length-1].checked = checked;
 }
 
function ResetAllChecks(webPartId)
{
    var checkboxes = document.getElementsByName('CWActionBox'+webPartId);
    var i;
    
    checkboxes[0].checked = false; 
    for(i = 1; i<checkboxes.length; i++)
    {
        checkboxes[i].checked = false; 
        CWHighlightRow(checkboxes[i], '');
    }

    //put this back when you add footer checkbox
    //checkboxes[checkboxes.length-1].checked = false; 
 }
 
 function CheckUncheckAllEvents(checkBoxAll, webPartId)
 {
    var checkboxes = document.getElementsByName('CWActionBox'+webPartId);
    var i = 0;
    var checked = checkBoxAll.checked;
    
    for(i = 0; i<checkboxes.length; i++)
    {
        if(checkboxes[i].checked != checked)
            checkboxes[i].checked = checked; 
    }
 }
 
 function GetCheckedItems(webPatId)
 {
    var checkboxes = document.getElementsByName('CWActionBox'+webPatId);
    var i = 0;
    var j = 0;
    var checkedItems = new Array();
    
    for(i = 0; i < checkboxes.length; i++)
    {
        if(checkboxes[i].checked)
        {
            checkedItems[j] = checkboxes[i].getAttribute("itemUrl");
            j++;
        }
    }
    return checkedItems;
 }

function CWHighlightRow(checkbox, color)
{
	var row = checkbox.parentElement;
	
	if (row != null)
	{
	    while(row != null)
	    {
	        if(row.type == 'Record' || (row.attributes.getNamedItem('type') && row.attributes.getNamedItem('type').value == 'Record'))
	            break;
	        else
    		    row = row.parentElement;
    	}
    	
	    if (row != null)
	    {
	        var cells = row.getElementsByTagName('td');

            for (var i = 0; i < cells.length; i++)
            {
                if(cells[i].type == 'Cell' || (cells[i].attributes.getNamedItem('type') && cells[i].attributes.getNamedItem('type').value == 'Cell'))
                {
	                if(checkbox.checked)
		                cells[i].style.backgroundColor = color;
	                else
		                cells[i].style.backgroundColor = '';
	            }
	        }
	    }
	}
}

function CWHighlightEvent(checkbox, rootEvent)
{
	if(rootEvent)
	{
		var eventUrl = checkbox.getAttribute("itemUrl");
		var webPartId = checkbox.getAttribute("webPartId");
		var checkboxes = document.getElementsByName('CWActionBox'+webPartId);

		for(i = 0; i < checkboxes.length; i++)
		{
			if(checkboxes[i].getAttribute("itemUrl") == eventUrl && checkboxes[i].checked != checkbox.checked)
			{
				checkboxes[i].checked = checkbox.checked;
				//removing higlighting because InterSoft's highlighting looks ugly
				//CWHighlightCell(checkboxes[i]);
    		}
		}
	}
	//else
	//{
		//CWHighlightCell(checkbox);
	//}	
}

function CWHighlightCell(checkbox)
{
	var cell = checkbox.parentElement;
	
	while(cell.tagName != 'td' && cell.tagName != 'TD')
		cell = cell.parentElement;

	if(checkbox.checked)
	{
	    checkbox.setAttribute('cwBgColor', cell.style.backgroundColor);
		cell.style.backgroundColor = 'lightyellow';
	}
	else
	{
	    var bgColor = checkbox.getAttribute('cwBgColor');
	    
	    if(bgColor != '')
		    cell.style.backgroundColor = bgColor;
		else
		    cell.style.backgroundColor = 'white';
	}
}