﻿function getPosition(pselementId) {

    this.top = 0;
    this.left = 0;
    this.bottom = 0;
    this.right = 0;

    var x = document.getElementById(pselementId);
    var i = x.offsetHeight;
    var j = x.offsetWidth;
    while (x != null) {
        this.top += x.offsetTop;
        this.left += x.offsetLeft;
        x = x.offsetParent;
    }
    this.bottom = this.top + i;
    this.right = this.left + j;
}

function windowSize() {

    this.totalWidth = 0;
    this.totalHeight = 0;
    this.windowWidth = 0;
    this.windowHeight = 0;
    this.scrollTop = 0;
    this.scrollLeft = 0;

    var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;

    if (typeof (window.innerWidth) == 'number') {
        // Netscape compliant: (mozilla/netscape/opera)
        this.totalWidth = document.body.scrollWidth;
        this.totalHeight = document.body.scrollHeight;
        if (window.outerWidth > this.totalWidth) { this.totalWidth = window.outerWidth }
        if (window.outerHeight > this.totalHeight) { this.totalHeight = window.outerHeight }
        this.windowWidth = window.innerWidth;
        this.windowHeight = window.innerHeight;
        this.scrollTop = window.pageYOffset;
        this.scrollLeft = window.pageXOffset;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+:
        this.totalWidth = document.documentElement.scrollWidth;
        this.totalHeight = document.documentElement.scrollHeight;
        this.windowWidth = document.documentElement.clientWidth;
        this.windowHeight = document.documentElement.clientHeight;
        this.scrollTop = document.documentElement.scrollTop;
        this.scrollLeft = document.documentElement.scrollLeft;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4:
        this.totalWidth = document.body.scrollWidth;
        this.totalHeight = document.body.scrollHeight;
        this.windowWidth = document.body.clientWidth;
        this.windowHeight = document.body.clientHeight;
        this.scrollTop = document.body.scrollTop;
        this.scrollLeft = document.body.scrollLeft;
    }
}

