/**
 * Requires confirm of an action and places
 * a spinner during the action
 * 
 * There can be only one action with confirm_with_spinner per page.
 */

var actions_in_progress = 0;

function action_completed() {
    actions_in_progress -= 1;
    if (actions_in_progress == 0) {
        window.location = window.location;
    }
}

function confirm_with_spinner(who, msg, spinner_type) {
    actions_in_progress += 1;
    if ((!msg) || confirm(msg)) {
        action = jQuery(who).attr('href');
        if (!spinner_type)
            spinner_type = 'big';
        
        jQuery(who).parent().parent().html('<div class="action_spinner"><img src="/images/spinner_'+spinner_type+'.gif"/></div>');
        jQuery(who).parent().hide();
        jQuery.get(action, action_completed);
    }
    else
        action_completed();
    
    return false;
}