﻿
var common = function() {
    var pub = {};

    pub.initAjaxProgress = function() {
        var pageHeight = (document.documentElement && document.documentElement.scrollHeight) ? document.documentElement.scrollHeight : (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
        //SET HEIGHT OF BACKGROUND
        var bg = document.getElementById('ajaxProgressBg');
        bg.style.height = (pageHeight + 1000) + 'px';
        //POSITION THE PROGRESS INDICATOR ON INITIAL LOAD
        pub.reposAjaxProgress();
        //REPOSITION THE PROGRESS INDICATOR ON SCROLL
        window.onscroll = pub.reposAjaxProgress;
    }

    pub.reposAjaxProgress = function() {
        var div = document.getElementById('ajaxProgress');
        var st = document.body.scrollTop;
        if (st == 0) {
            if (window.pageYOffset) st = window.pageYOffset;
            else st = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
        }
        div.style.top = 150 + st + "px";
    }

    pub.alert = function(message, callback) {
        alert(message);
        if (typeof (callback) == "function") {
            callback();
        }
    };

    pub.displayError = function(message, callback) {
        pub.alert(message, callback);
    }

    pub.ajaxRequestFailed = function(error) {
        pub.displayError(error.get_message());
    }

    return pub;
} ();


