﻿// JScript File

function MyGetLocation(a)
{
  if(a.self||a.nodeType===9) return new Sys.UI.Point(0,0);
  var d=a.getClientRects();
  if(!d||!d.length) return new Sys.UI.Point(0,0);
  var e=a.ownerDocument.parentWindow;
  try
  {
    g=e.screenLeft-top.screenLeft-top.document.documentElement.scrollLeft+2;
    h=e.screenTop-top.screenTop-top.document.documentElement.scrollTop+2;
    c=e.frameElement||null;
  } catch (ex) {
    g=e.screenLeft+2;
    h=e.screenTop+2;
    c=null;
  }
  
  if(c)
  {
    var b=c.currentStyle;
    g+=(c.frameBorder||1)*2+(parseInt(b.paddingLeft)||0)+(parseInt(b.borderLeftWidth)||0)-a.ownerDocument.documentElement.scrollLeft;
    h+=(c.frameBorder||1)*2+(parseInt(b.paddingTop)||0)+(parseInt(b.borderTopWidth)||0)-a.ownerDocument.documentElement.scrollTop;
  }
  var f=d[0];
  return new Sys.UI.Point(f.left-g,f.top-h);
}
Sys.UI.DomElement.getLocation=MyGetLocation;

function MapGetLocation(element) 
{
  var e = Function._validateParams(arguments, [
      {name: "element", domElement: true}
  ]);
  if (e) throw e;
  if (element.self || element.nodeType === 9) return new Sys.UI.Point(0,0);

  var clientRects = element.getClientRects();
  if (!clientRects || !clientRects.length) {
      return new Sys.UI.Point(0,0);
  }

  var w = element.ownerDocument.parentWindow;
  try
  {
    var offsetL = w.screenLeft - top.screenLeft - top.document.documentElement.scrollLeft + 2;
    var offsetT = w.screenTop - top.screenTop - top.document.documentElement.scrollTop + 2;
    var f = w.frameElement || null;
  }
  catch(ex)
  {
    var offsetL = w.screenLeft + 2;
    var offsetT = w.screenTop + 2;
    var f = null;
  }
  
  if (f) 
  {
      var fstyle = f.currentStyle;
      offsetL += (f.frameBorder || 1) * 2 +
          (parseInt(fstyle.paddingLeft) || 0) +
          (parseInt(fstyle.borderLeftWidth) || 0) -
          element.ownerDocument.documentElement.scrollLeft;
      offsetT += (f.frameBorder || 1) * 2 +
          (parseInt(fstyle.paddingTop) || 0) +
          (parseInt(fstyle.borderTopWidth) || 0) -
          element.ownerDocument.documentElement.scrollTop;
  }

  var clientRect = clientRects[0];
  return new Sys.UI.Point(clientRect.left - offsetL,clientRect.top - offsetT);
}


