/**
 * Toggle the state of an object
 *
 * @param string id The ID of the object to toggle
 */
function toggleCollapseState(id,image)
{
    var obj = getObj(id);

    if(!obj)
        return false;

    if(obj.style.display == 'none')
    {
        var state = 1;
        obj.style.display = '';
		document.getElementById(image).src="images/collapse_1.gif";
		document.getElementById(image).alt="Click to collapse" + id;
    }

    else
    {
        var state = 0;
        obj.style.display = 'none';
        document.getElementById(image).src="images/collapse_0.gif";
		document.getElementById(image).alt="Click to expand" + id;
    }

    saveCollapseState(id, state);

    return true;
}





/**
 * Modify the document cookie to remember the state of an object
 *
 * @param string id The ID of the object
 * @param integer state The state of the object
 */
function saveCollapseState(id, state)
{
    var cookie = readCookie('collapseState');

    if(!cookie)
        cookie = '';

    var search = new RegExp('(' + id + ')=([01]{1}),');

    if(search.test(cookie))
        cookie = cookie.replace(search, '$1$2=' + state + ',');
    else
        cookie += id + '=' + state + ',';

    setCookie('collapseState', cookie, new Date('January 1, 2020'));
}