$(document).ready(
    function() {
        $('.toolbar .delete a').click(onActionClick);
        $('.toolbar .relocate a').click(onActionClick);
        $('.toolbar .go a').click(onActionClick);
        $('.toolbar .refresh_db a').click(onRefreshDb);
        $('.toolbar .payout a').click(onPayout);
    }
);

function onActionClick() {
    var form = $(this).parents('form')[0];
    form.action = this.href;
    form.submit();
    return false;
}

function onPayout() {
    $(this).unbind('click');
    $(this).parent().addClass('busy');

    $.ajax({
        url: this.href,
        type: 'POST',
        data: 'payout=1',
        dataType: 'html',
        timeout: 10000,
        error: function() {
            document.location.reload(true);
        },
        success: function(html) {
            document.location.reload(true);
        }
    });

    return false;
}

function onRefreshDb() {
    $(this).unbind('click');
    $(this).parent().addClass('busy');

    $.ajax({
        url: this.href,
        type: 'POST',
        data: 'update=1',
        dataType: 'html',
        timeout: 10000,
        error: function() {
            document.location.reload(true);
        },
        success: function(html) {
            document.location.reload(true);
        }
    });

    return false;
}
