﻿function getOffset(obj, dim) {
    var oLeft, oTop, oWidth, oHeight;
    if (dim == "left") {
        oLeft = obj.offsetLeft;
        while (obj.offsetParent != null) {
            oParent = obj.offsetParent;
            oLeft += oParent.offsetLeft;
            obj = oParent;
        }
        return oLeft;
    }
    else if (dim == "top") {
        oTop = obj.offsetTop;
        while (obj.offsetParent != null) {
            oParent = obj.offsetParent;
            oTop += oParent.offsetTop;
            obj = oParent;
        }
        return oTop;
    }
    else if (dim == "width") {
        oWidth = obj.offsetWidth;
        return oWidth;
    }
    else if (dim == "height") {
        oHeight = obj.offsetHeight;
        return oHeight;
    }
    else {
        alert("Error: invalid offset dimension '" + dim + "' in getOffset()");
        return false;
    }
}
