/* Left panel categories */

function ajax_set_left_category(dic)
{
    var sstr = dic.toJSON();
    new Ajax.Request('/ajax/categories/set_category/' + sstr + '/',
        {
            method:'get',
            onSuccess: doset_left_category ,
            onFailure: function(){ 
            alert('Ajax error.');
            return;
            }
        }
    );
}
function doset_left_category(http)
{
    var dic = $H(http.responseText.evalJSON(true));
    if (dic.keys().include('success'))  
        if (dic.get('success') == 'true')
            if (ajax_update_count_panel) ajax_update_count_panel();
    return; 
}


function left_cat_handle_click(my_input) {
        var dic = $H();
        dic.set(my_input.id, my_input.checked);
        ajax_set_left_category(dic);
}

function left_cat_reset()
{
    //TODO
}

/* Left panel's category initialisation */
function left_cat_init() {

    /* Set categories */
    $('left_cat_all').onclick = function() {
        var dic = $H();
        $$('#left_cat_list input').each( function(elt) { 
            dic.set(elt.id, true);
            elt.checked = true; } );
        ajax_set_left_category(dic);
    };
    /* Clear categories */
    $('left_cat_none').onclick = function() {
        var dic = $H();
        $$('#left_cat_list input').each( function(elt) { 
            dic.set(elt.id, false);
            elt.checked = false; } );
        ajax_set_left_category(dic);
    };

    if ($('left_cat_update_page'))
        $('left_cat_update_page').onclick = function() { $('but_submit_search').click(); } 

}
onload_add_function(left_cat_init);

