function GetTable( obj ){
    var curTable = obj;
    while(curTable && curTable.tagName != "TABLE")
        curTable = curTable.parentNode;

    return curTable;
}


function ObjAt(x, y, element){
    var items = document.getElementsByTagName(element);

    for (var i = 0, n = items.length; i < n; i++) {
        if (!items[i].id) continue;
        if ( 
            x >= findPosX(items[i]) && 
            x <= findPosX(items[i]) +items[i].offsetWidth && 
            y >= findPosY(items[i]) &&
            y <= findPosY(items[i]) +items[i].offsetHeight 
        ){
            return items[i];
        }
    }

    return false;
}


function GetAbsScrollTop( obj ){
    var curTop=0;
    while( obj ){
        obj = obj.parentNode;
        if(obj && obj.scrollTop) curTop += parseInt(obj.scrollTop);
    }
    return curTop;
}


function GetAbsScrollLeft( obj ){
    var curLeft=0;
    while( obj ){
        obj = obj.parentNode;
        if(obj && obj.scrollLeft) curLeft += parseInt(obj.scrollLeft);
    }
    return curLeft;
}


function findPosY(obj){
    var curTop = 0 -GetAbsScrollTop(obj);

    if (obj.offsetParent){
        while (obj.offsetParent){
            curTop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    } else if (obj.y) {
        curTop += obj.y;
    }
    return curTop;
}

function findPosX(obj){
    var curLeft = 0 -GetAbsScrollLeft(obj);

    if (obj.offsetParent){
        while (obj.offsetParent){
            curLeft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    } else if (obj.x) {
        curLeft += obj.x;
    }
    return curLeft;
}
