/* AJAX responders and associated functions for Boost */

Ajax.Responders.register({
	onCreate:   showLoader, 
	onComplete: hideLoader,
	onFailure: function() { Ajax.activeRequestCount--; hideLoader(); },
	onException: function() { Ajax.activeRequestCount--; hideLoader(); }
});

var __loader_state = 0;

function showLoader() {
    __loader_state++;
    if(__loader_state > 1) {
        return;
    }
    Element.show('loader-background');
	Element.show('loader');

    var height = (document.height !== undefined) ? document.height : document.body.offsetHeight;
    var width = (document.width !== undefined) ? document.width : document.body.offsetWidth;
    var viewportHeight = self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);

    var el = $("loader-background");
    el.style.width = width + "px";
    el.style.height = Math.max(height, viewportHeight) + "px";
}

function hideLoader() {
    __loader_state--;
    if(__loader_state > 0) {
        return;
    }
	Element.hide('loader');
    Element.hide('loader-background');
}


