﻿function Dimension(_window) {
    this.GetClientWidth = function() {
        if (typeof _window.innerWidth != 'undefined') {
            return _window.innerWidth;
        }
        else if (typeof _window.document.documentElement != 'undefined' &&
                 typeof _window.document.documentElement.clientWidth != 'undefined' &&
                 _window.document.documentElement.clientWidth != 0) {
            return _window.document.documentElement.clientWidth;
        }
        else {
            return _window.document.getElementsByTagName('body')[0].clientWidth;
        }
    },

    this.GetClientHeight = function() {
        if (typeof _window.innerHeight != 'undefined') {
            return _window.innerHeight;
        }
        else if (typeof _window.document.documentElement != 'undefined' &&
                 typeof _window.document.documentElement.clientHeight != 'undefined' &&
                 _window.document.documentElement.clientHeight != 0) {
            return _window.document.documentElement.clientHeight;
        }
        else {
            return _window.document.getElementsByTagName('body')[0].clientHeight;
        }
    },

    this.GetObjNN4 = function(obj, name) {
        var x = obj.layers;
        var foundLayer;
        for (var i = 0; i < x.length; i++) {
            if (x[i].id == name)
                foundLayer = x[i];
            else if (x[i].layers.length)
                var tmp = this.GetObjNN4(x[i], name);
            if (tmp) foundLayer = tmp;
        }
        return foundLayer;
    },

    this.GetElementHeight = function(elem) {
        if (ns4) {
            var elem = this.GetObjNN4(document, elem);
            return elem.clip.height;
        }
        else {
            if (_window.document.getElementById)
                var elem = _window.document.getElementById(elem);
            else if (_window.document.all)
                var elem = _window.document.all[elem];
            if (op5)
                xPos = elem.style.pixelHeight;
            else
                xPos = elem.offsetHeight;
            return xPos;
        }
    },

    this.GetElementWidth = function(elem) {
        if (ns4) {
            var elem = this.GetObjNN4(document, elem);
            return elem.clip.width;
        }
        else {
            if (_window.document.getElementById)
                var elem = _window.document.getElementById(elem);
            else if (document.all)
                var elem = _window.document.all[elem];
            if (op5)
                xPos = elem.style.pixelWidth;
            else
                xPos = elem.offsetWidth;
            return xPos;
        }
    },

    this.GetElementLeft = function(elem) {
        if (ns4) {
            var elem = this.GetObjNN4(document, elem);
            return elem.pageX;
        }
        else {
            if (_window.document.getElementById)
                var elem = _window.document.getElementById(elem);
            else if (_window.document.all)
                var elem = _window.document.all[elem];
            xPos = elem.offsetLeft;
            tempEl = elem.offsetParent;
            while (tempEl != null) {
                xPos += tempEl.offsetLeft;
                tempEl = tempEl.offsetParent;
            }
            return xPos;
        }
    },

    this.GetElementTop = function(elem) {
        if (ns4) {
            var elem = this.GetObjNN4(document, elem);
            return elem.pageY;
        }
        else {
            if (_window.document.getElementById)
                var elem = _window.document.getElementById(elem);
            else if (_window.document.all)
                var elem = _window.document.all[elem];
            yPos = elem.offsetTop;
            tempEl = elem.offsetParent;
            while (tempEl != null) {
                yPos += tempEl.offsetTop;
                tempEl = tempEl.offsetParent;
            }
            return yPos;
        }
    },

    this.GetScrollXY = function() {
        var scrOfX = 0, scrOfY = 0;
        if (typeof (window.pageYOffset) == 'number') {
            //Netscape compliant
            scrOfY = window.pageYOffset;
            scrOfX = window.pageXOffset;
        } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
            //DOM compliant
            scrOfY = document.body.scrollTop;
            scrOfX = document.body.scrollLeft;
        } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
            //IE6 standards compliant mode
            scrOfY = document.documentElement.scrollTop;
            scrOfX = document.documentElement.scrollLeft;
        }
        return [scrOfX, scrOfY];
    }
}

function getPageDimensions() {
    var body = document.getElementsByTagName('body')[0];
    var bodyOffsetWidth = 0;
    var bodyOffsetHeight = 0;
    var bodyScrollWidth = 0;
    var bodyScrollHeight = 0;
    var pageDimensions = [0, 0];

    if (typeof document.documentElement != 'undefined' && typeof document.documentElement.scrollWidth != 'undefined') {
        pageDimensions[0] = document.documentElement.scrollWidth;
        pageDimensions[1] = document.documentElement.scrollHeight;
    }
    bodyOffsetWidth = body.offsetWidth;
    bodyOffsetHeight = body.offsetHeight;
    bodyScrollWidth = body.scrollWidth;
    bodyScrollHeight = body.scrollHeight;

    if (bodyOffsetWidth > pageDimensions[0]) {
        pageDimensions[0] = bodyOffsetWidth;
    }
    if (bodyOffsetHeight > pageDimensions[1]) {
        pageDimensions[1] = bodyOffsetHeight;
    }
    if (bodyScrollWidth > pageDimensions[0]) {
        pageDimensions[0] = bodyScrollWidth;
    }
    if (bodyScrollHeight > pageDimensions[1]) {
        pageDimensions[1] = bodyScrollHeight;
    }
    return pageDimensions;
}

