
    var SKIP_LOADING        = {};
    var AFTER_LOADING_FUNCS = [];

    //
    // for CGI::Ajax loading calls
    //
	if (typeof(pjx) != 'undefined'){
    	pjx.prototype.pjxInitialized = function(el){
        	if (SKIP_LOADING[el]) { return 1; }
   
            show_loading();
    	}
   
    	pjx.prototype.pjxCompleted = function(el){

            hide_loading();

        	// run any functions defined in AFTER_LOADING_FUNCS
        	for (var i=0;i<AFTER_LOADING_FUNCS.length;i++) {
            	var this_func = AFTER_LOADING_FUNCS[i];
            	if (!this_func) continue;

            	// run the function
            	this_func();
        	}
    	}
	}

    //
    // for jQuery ajax calls
    //
    var NO_LOADING = 0;
    $(document).ready( function() {
        $('#loading_container').ajaxStart(function() {
            if (!NO_LOADING) show_loading();
            // reset loading flag
            NO_LOADING = 0;
        });
    
        $('#loading_container').ajaxStop(function() {
            hide_loading();

            // init help
            help_init();
        });

    });


    //
    // show/hide loading function
    //
    function show_loading() {
        $('#loading_container').show();
        $(document).css('cursor','wait');
    }

    function hide_loading() {
        $('#loading_container').hide();
        $(document).css('cursor','auto');
    }
