﻿jQuery.fn.extend({
    AjaxReady: function (fn) {
        if (fn) {
            return jQuery.event.add(this[0], "AjaxReady", fn, null);
        } else {
            var ret = jQuery.event.trigger("AjaxReady", null, this[0], false, null);
            // if there was no return value then the even validated correctly
            if (ret === undefined)
                ret = true;
            return ret;
        }
    }
});

var pbControl = null;
prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_beginRequest(BeginRequestHandler);
prm.add_endRequest(EndRequest);

function BeginRequestHandler(sender, args) {
    pbControl = args.get_postBackElement();  //the control causing the postback
    if (pbControl.className.indexOf("not-one-click") == -1)
        pbControl.disabled = true;	
}

function EndRequest(sender, args) {
    pbControl.disabled = false;
    pbControl = null;
    $(document).AjaxReady();
}
