(function () {
    window.Zap = {};

    // Hack for WebForms:
    var initScripts = [];
    var loadScripts = [];
    var originalAddInit = Sys.Application.add_init;
    var originalAddLoad = Sys.Application.add_load;
    Sys.Application.add_init = function (fn) { initScripts.push(fn); };
    Sys.Application.add_load = function (fn) { loadScripts.push(fn); };

    window.addEventListener('load', function() {
        if (window.startApp) {
            startApp();
            initScripts.forEach(function (fn) {
                originalAddInit.call(Sys.Application, fn);
            });
            loadScripts.forEach(function (fn) {
                originalAddLoad.call(Sys.Application, fn);
            });
            Sys.Application.add_init = originalAddInit;
            Sys.Application.add_load = originalAddLoad;
            Sys.Application.raiseLoad();
        } else {
            console.error('startApp is not defined');
            document.getElementById('appBrokenMessage')?.classList.add('is-appBroken');
        }
    });
})();