var PageRequestManagerEx =
{
  _initialized : false, init : function()
  {
    if (!PageRequestManagerEx._initialized)
    {
      var _prm = Sys.WebForms.PageRequestManager.getInstance();
      var _callQueue = new Array();
      var _executingElement = null;

      _prm = Sys.WebForms.PageRequestManager.getInstance();
      _prm.add_initializeRequest(initializeRequest);
      _prm.add_endRequest(endRequest);

      PageRequestManagerEx._initialized = true;
    }
    function initializeRequest(sender, args)
    {
      if (_prm.get_isInAsyncPostBack())
      {
        var postBackElement = args.get_postBackElement();

        //Need to check, otherwise it will abort the request which we made from the end request
        if (_executingElement != postBackElement)
        {
          var evArg = $get("__EVENTARGUMENT").value;

          //add to queue
          args.set_cancel(true);
          Array.enqueue(_callQueue, new Array(postBackElement, evArg));
        }
        _executingElement = null;
      }
    }
    function endRequest(sender, args)
    {
      //Take first in line and fire
      if (_callQueue.length > 0)
      {
        _executingElement = Array.dequeue(_callQueue);
        var _element = _executingElement[0];
        var _eventArg = _executingElement[1];
        _prm._doPostBack(_element.id, _eventArg);
      }
    }
  }
}
if (typeof(Sys) != 'undefined')
{
  Sys.Application.notifyScriptLoaded();
}