var AdSenseClicked=false;
var SrcLike="googlesyndication.com";
//var SrcLike="test";

function FireAction(Status) {
  if (AdSenseClicked) return;
  AdSenseClicked=true;
  Arr=Status.split(" ");
  Status=Arr[Arr.length-1];
  var nsAmp=unescape('%26');
  var nsTrackSrc=nsTrackPath;
  var nsRnd=Math.random();
  var nsCur=escape(window.location.href);
  nsTrackSrc+="st="+nsSiteId+nsAmp;
  nsTrackSrc+="rn="+nsRnd+nsAmp;
  nsTrackSrc+="cur="+nsCur+nsAmp;
  nsTrackSrc+="code=1"+nsAmp;
  nsTrackSrc+="eid="+nsEvent+nsAmp;
  nsTrackSrc+="itm="+escape(Status);
  var nsAction = new Image();
  nsAction.src = nsTrackSrc;
}

if (typeof(window.addEventListener) != 'undefined') {
  window.addEventListener('unload', OnUnload, false);
  window.addEventListener('mousemove', getMouse, false);
}
if (typeof(document.addEventListener) != 'undefined') {
  document.addEventListener('unload', OnUnload, false);
  document.addEventListener('mousemove', getMouse, false);
}
if (typeof(window.attachEvent) != 'undefined') {
  window.attachEvent('onunload', OnUnload);
  document.body.attachEvent('onmousemove', getMouse);
}

var px;
var py;


function getMouse(e) {
  if (!e) e=window.event;
  px=e.clientX;
  py=e.clientY;
}

function findY(obj) {
  var y = 0;
  while (obj) {
    y += obj.offsetTop;
    obj = obj.offsetParent;
  }
  return y;
}

function findX(obj) {
  var x = 0;
  while (obj) {
    x += obj.offsetLeft;
    obj = obj.offsetParent;
  }
  return x;
}

function OnUnload() {
  ad = document.getElementsByTagName("iframe");
  for (i=0; i<ad.length; i++) {
    var adLeft = findX(ad[i]);
    var adTop = findY(ad[i]);
    var ad_width=(ad[i].width)?parseInt(ad[i].width):parseInt(ad[i].style.width);
    var ad_height=(ad[i].height)?parseInt(ad[i].height):parseInt(ad[i].style.height);
    var inFrameX = (px > (adLeft - 10) && px < (parseInt(adLeft) + ad_width + 15));
    var inFrameY = (py > (adTop - 10) && py < (parseInt(adTop) + ad_height + 10));
    if (inFrameY && inFrameX && ad[i].src.indexOf(SrcLike)> -1) {
      FireAction(window.status);
    }
  }
}