function addScrollListener(func) {
    var oldonscroll = window.onscroll;
    if (typeof window.onscroll != 'function') {
        window.onscroll = func;
    } else {
        window.onscroll = function() {
            if (oldonscroll) {
                oldonscroll();
            }
            func();
        }
    }
}

function getViewportWidth()
{
    return window.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
}

function getViewportHeight()
{
    return window.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
}

function getScrollX()
{
    return (document.documentElement.scrollLeft || document.body.scrollLeft);
}

function getScrollY()
{
    return (document.documentElement.scrollTop || document.body.scrollTop);
}