﻿//Pass in 'all' as the action to select all, otherwise will select none
function selectAllOrNone (listId, action) 
{
    //first get all the input controls within the html element with id listId
    var list = $(listId);
    var checkBoxes = list.getElements('input');
    //get the selectNone checkbox
    var selectNone = list.getElement('span[class=selectNone]');
    var selectNoneCheckBox = selectNone.getElement('input');
    
    var selectAll = true;
    if ( action != 'all' ) 
    {
        selectAll = false;
    }
    
    //loopvover the check boxes and set to checked if NOT the selectNone checkbox..
    checkBoxes.each( function (el, i) {
        if ( el.getProperty('id') == selectNoneCheckBox.getProperty('id') ) 
        {
            el.setProperty('checked', !selectAll);
        }
        else 
        {
            el.setProperty('checked', selectAll);
        }
    });
}

function checkAllOrNone (listId, sender) 
{
    //first get all the input controls within the html element with id listId
    var list = $(listId);
    var checkBoxes = list.getElements('input');
    
    //if the sender is now checked, then we MUST make sure that selectNone is NOT checked
    if ( sender.getProperty('checked') ) 
    {
        //get the selectNone checkbox
        var selectNone = list.getElement('span[class=selectNone]');
        var selectNoneCheckBox = selectNone.getElement('input');
        selectNoneCheckBox.setProperty('checked', false);
    }
    else
    {
        //otherwise, if the sender is UNchecked, then we MUST make sure that selectAll is NOT checked
        //get the selectAll checkbox
        var selectAll = list.getElement('span[class=selectAll]');
        var selectAllCheckBox = selectAll.getElement('input');
        selectAllCheckBox.setProperty('checked', false );
    }
    
    
}