function checkboxChangeAll(theForm, name)
{
    var allcheckbox = document.getElementById(name + '_all');

    for (var loop=0; loop < theForm.elements.length; loop++)
    {
        var e = theForm.elements[loop];
        if (e.type == 'checkbox' && e.name == name)
        {
            e.checked = allcheckbox.checked;
        }
    }
    
    if (window.checkboxHook)
    {
        window.checkboxHook();
    }
}

function checkboxClear(theForm, name)
{
    var allcheckbox = document.getElementById(name + '_all');
    if (allcheckbox == null)
    {
        return;
    }
    
    allcheckbox.checked = false;

    for (var loop=0; loop < theForm.elements.length; loop++)
    {
        var e = theForm.elements[loop];
        if (e.type == 'checkbox' && e.name == name)
        {
            e.checked = false;
        }
    }
}

function checkboxChangeOne(theForm, name)
{
    var totalCount = 0;
    var totalCheck = 0;

    for (var loop = 0; loop < theForm.elements.length; loop++)
    {
        var e = theForm.elements[loop];
        if (e.type == 'checkbox' && e.name == name)
        {
            totalCount++;
            if (e.checked)
            {
                totalCheck++;
            }
        }
    }

    var allcheckbox = document.getElementById(name + '_all');
    if (totalCount == totalCheck)
    {
        allcheckbox.checked = true;
    }
    else
    {
        allcheckbox.checked = false;
    }
    
    if (window.checkboxHook)
    {
        window.checkboxHook();
    }
}

function checkboxChangeAllId(theForm, id)
{
    var allcheckbox = document.getElementById(id + '_all');

    for (var loop=0; loop < theForm.elements.length; loop++)
    {
        var e = theForm.elements[loop];
        if (e.type == 'checkbox' && e.id.indexOf(id) == 0)
        {
            e.checked = allcheckbox.checked;
        }
    }
}

function checkboxChangeOneId(theForm, id)
{
    var totalCount = 0;
    var totalCheck = 0;

    for (var loop = 0; loop < theForm.elements.length; loop++)
    {
        var e = theForm.elements[loop];
        if (e.type == 'checkbox' && e.id.indexOf(id) == 0)
        {
        	if (e.id == (id + "_all") == false)
        	{
        		// ignore the all checkbox
				totalCount++;
				if (e.checked)
				{
					totalCheck++;
				}
			}
        }
    }

    var allcheckbox = document.getElementById(id + '_all');
    if (totalCount == totalCheck)
    {
        allcheckbox.checked = true;
    }
    else
    {
        allcheckbox.checked = false;
    }
}


