
/**
     @param obj
     @param state if -1: toggle, 0: hide, 1: visible
   */
function toggleVisibility( obj, state )
{
    if (document.layers)
    {
        if (state!=0 && (obj.display=='none' || state==1))
            obj.display = '';
        else
            obj.display='none';
    }
    else
    {
        if (state!=0 && (obj.style.display=='none' || state==1))
            obj.style.display = '';
        else
            obj.style.display='none';
    }
}

function toggleRowsVisibility( obj, state )
{
    obj = obj.firstChild; //td
    obj = obj.firstChild; //table
    if (obj.tagName == 'TBODY') obj = obj.firstChild;

    for (var i=0; i<obj.rows.length; i++)
    {
        toggleVisibility(obj.rows[i], state);
    }
}
  
function categoryToggle( catid, save )
{
    var state=1;
    if (save)
    {
        c = readCookie('holnap_bookshelf');
        if (c != null && c[0]!=' ') c = ' '+c;
        if (c==null)
        {
            c = ' '+catid+',';
        }
        else if (c.match(new RegExp(' '+catid+','))!=null)
        {
            c = c.replace(new RegExp(' '+catid+',', 'g'), '');
            state = 0;
        }
        else
        {
            c = c + ' '+catid+',';
        }
        createCookie('holnap_bookshelf', c, 7);
    }

    var obj = document.getElementById( 'cattree-'+catid );
    if (obj)
    {
        toggleRowsVisibility( obj, state );
    }
    obj = document.getElementById( 'booktree-'+catid );
    if (obj)
    {
        toggleVisibility( obj, state );
    }
	
    var tri = document.getElementById( 'oc-'+catid );
    if (tri)
    {
        if (state || tri.innerHTML == "►")
        {
            tri.innerHTML = "▼";
        }
        else
        {
            tri.innerHTML = "►";
        }
    }

}

function initCategories(c)
{
    if (c==undefined || c.length==0) return;
    s = c.split(',');
    for (var i=0; i<s.length; i++)
    {
        catid=parseInt(s[i]);
        categoryToggle(catid, false);
    }
    createCookie('holnap_bookshelf', c, 7);
}
  