var $j = jQuery.noConflict();

// this is for testing with selenium purposes only to make sure all ajax requests finish off before going to the next step 
$j.activeAjaxRequestCount = 0;

$j().ajaxSend(function() {
  $j.activeAjaxRequestCount++;
  // register lazily to make sure it's the last one and get executed after all other handlers
  if (!$j._ajaxErrorHandlerAdded) {
    $j().ajaxError(function() {
      $j.activeAjaxRequestCount--;
    });
    $j._ajaxErrorHandlerAdded = true;
  }
})
.ajaxSuccess(function() {
  $j.activeAjaxRequestCount--;
});
