﻿/*
* Queued Ajax requests.
* A new Ajax request won't be started until the previous queued 
* request has finished.
* Taken from http://plugins.jquery.com/files/jquery-ajax-queue_1.0.js.txt on 15 June 2010
*/
$.ajaxQueue = function (o) {
    var body = $(document.body);
    var startQueue = body.queue("ajax").length == 0;
    var _old = o.complete;
    o.complete = function () {
        if (_old) _old.apply(this, arguments);
        body.dequeue("ajax");
    };

    body.queue("ajax", function () {
        $.ajax(o);
    });

    if (startQueue) body.dequeue("ajax");
};

function ajaxRenderAction(url, replaceId, onload) {
    $(function () {
        $.ajaxQueue({
            url: url,
            dataType: 'html',
            success: function (data) {
                $('#' + replaceId).replaceWith(data);
                if (onload) onload();
            }
        });
    });
}
