angle from P to T.

dx
dy
theta
just view-source to see the whole code,
but here's the workhorse function:
function oxe_DoAngleMath(px, py, tx, ty)
  {
  var dx;
  var dy;

  dx = tx - px;
  dy = ty - py;
  dy = -dy;  // convert from screen-space
             // to proper mathematical space.

  if (dx == 0)
    {
    theta = 0.0;
    }
  else
    {

/*  if not using atan2
    theta = Math.atan(dy/dx);
*/


    theta = Math.atan2(dy,dx);
    theta = theta * 360 * 0.5 / 3.14159265359;


/*  if not using atan2
    if (dx < 0)
      {
      if (dy > 0)
        theta += 180.0;
      else
        theta -= 180.0;
      }
*/
    }

  document.f1.i1.value = dx;
  document.f1.i2.value = dy;
  document.f1.i3.value = theta;
  }