Code:
function whereAmI(who,wch){
var L=0, R=0;
var pa=who;
while(pa.parentNode){
L+= ( pa.offsetLeft)? pa.offsetLeft: 0;
R+= (pa.offsetTop)? pa.offsetTop: 0;
if(pa==document.body || wch===false)break;
pa= pa.parentNode;
}
var A=[L,R];
return(wch===1 || wch=== 2)? A[wch]: A;
}
This returns the left and top coordinates of the element sent
as the first argument. If the second argumentis a literal false,
it returns the position relative to its parent, otherwise it returns the
position relative to the body (includes the body offsets as well).
You can send an integer (1 or 2) if you just want the
first(left) or second(right) coordinate.