﻿function findPosX(obj)
{
  var leftCoor;
  leftCoor = 0;
  while( obj != null )  {
    leftCoor += obj.offsetLeft ;
    obj = obj.offsetParent ;
  }
  return leftCoor;
}

function findPosY(obj)
{
  var topCoor;
  topCoor = 0;
  while( obj != null )  {
    topCoor += obj.offsetTop ;
    obj = obj.offsetParent ;
  }
  return topCoor;
}

function moveElementRelative(id, idTo, offsetX, offsetY) {
    var curX, curY, e;
    e = document.getElementById(idTo);
    curX = findPosX(e);
    curY = findPosY(e);
    document.getElementById(id).style.visibility = 'hidden';
    document.getElementById(id).style.left = (curX + offsetX) + 'px';
    document.getElementById(id).style.top = (curY + offsetY) + 'px';
    document.getElementById(id).style.visibility = 'visible';
}