// Line to make sure we don't bomb on console commands if it hasn't been configured
try { console.log('init console... done'); } catch(e) { console = { log: function() {} } }
Ajax.Responders.register({
  onCreate: function() {
    if($('busy_indicator') && Ajax.activeRequestCount>0) {
      Element.show('busy_indicator');
      windowHandler.centerInWindow('busy_indicator')
      // Only the spinner going for a few seconds max (sometimes it gets stuck)
      setTimeout(function() {Element.hide('busy_indicator')} , 6000);
    }
  },
  onComplete: function() {
    // console.log("completed request "+Ajax.activeRequestCount)
    if($('busy_indicator') && Ajax.activeRequestCount==0)
      Element.hide('busy_indicator');
  }
});


// Time is in milliseconds
// f is the function to run if there is no double-click
// object is the item to disable
// Returns true if the action should be disabled for this item b/c of double-click prevention
NPB = {
  prevented: [],
  prevent_double_click_ok: function(object,time) {
    var time = time || 300;
  
    if( this.prevented[object] )
      return false
    else {
      this.prevented[object] = true;
      setTimeout(function() { this.prevented[object] = false; }.bind(this),time)
      return true;
    }
  }
}