$(document).ready(function()
{
    $('.finishDating').click(function()
    {
        var url = $(this).attr('href');
        bootbox.confirm(v.lang.confirmFinish, function(result)
        {
            if(result)
            {
                $.getJSON(url, function(response)
                {
                    location.reload();
                });
            }
        });
        return false;
    });

    $('.histories a').click(function()
    {
        return openEntry($(this));
    });

    var onlyRecordKey   = v.account + v.objectType + v.objectID + 'onlyRecord';
    var onlyRecordValue = $.cookie(onlyRecordKey);

    $('input[name=onlyRecord]').change(function()
    {
        $('.histories-list > li').not('.record').toggle(!$(this).prop('checked'));

        if($(this).prop('checked'))
        {
            $.cookie(onlyRecordKey, true, {expires: config.cookieLife, path: config.webRoot});
        }
        else
        {
            $.cookie(onlyRecordKey, '', {expires: config.cookieLife, path: config.webRoot});
        }
    });

    if(onlyRecordValue) $('input[name=onlyRecord]').prop('checked', true).change();

    $.fn.switchStage = function(stage)
    {
        if(stage == 'detail')
        {
            $('.onlyRecord').show();
            $('.histories-list > li').show();
            $('input[name=onlyRecord]').change();
        }
        else
        {
            $('.onlyRecord').hide();
            $('.histories-list > li[data-stage=' + stage + ']').show();
            $('.histories-list > li[data-stage!=' + stage + ']').hide();
        }
    }
});
