function ast_mouseover(e){
  ast_mouseoverurl = e.target.src;
}
function ast_mouseout(){
  ast_mouseoverurl = null;
}
function ast_docunload(e){
  if(ast_mouseoverurl){
    ast_createBug(1,ast_mouseoverurl);
  }
}
function ast_logclick(){
  ast_mouseoverurl = event.srcElement.src;
  ast_createBug(1,ast_mouseoverurl);
  document.body.focus();
}
function ast_createBug(clk, d){
  img = new Image();
  ast_docHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;
  ast_docWidth = (document.width !== undefined) ? document.width : document.body.offsetWidth;
  if(d.indexOf("ads.auctionads.com")>-1){
    d += '&u=' + escape(document.location.href);
  }
  img.src = 'http://wama.info/itb/sst/at.php?c=' + clk + '&d=' + escape(d) + '&r=' + escape(document.referrer) + '&ph=' + ast_docHeight + '&pw=' + ast_docWidth + '&uh=' + screen.height + '&uw=' + screen.width + '&mx=' + ast_mouseX + '&my=' + ast_mouseY + '&dt='+ new Date().valueOf();
}
function ast_logsearch(e){
  if(e){
    frm = e.target;
  }
  else{
    frm = event.srcElement;
  }
  if(frm.channel){
    ch = frm.channel.value;
  }
  else{
    ch = '';
  }
  ast_createBug(1, 'http://www.google.com/custom/?q=' + escape(frm.q.value) + '&channel=' + ch + '&u=' + document.location.href);
}
function ast_searchkey(e){
  if(e){
    k = e.which;
    if(k==13){
      frm = e.target.parentNode.parentNode.parentNode.parentNode.parentNode;
      ast_createBug(1, 'http://www.google.com/custom/?q=' + escape(frm.q.value) + '&channel=' + frm.channel.value + '&u=' + escape(document.location.href));
    }
  }
}
function ast_getVariable(o, name) {
  var dc = o.src;
  var prefix = name + "=";
  var begin = dc.indexOf("&" + prefix);
  if (begin == -1) {
    begin = dc.indexOf("?" + prefix);
    if (begin == -1) return null;
  } else
    begin += 1;
  var end = o.src.indexOf("&", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}
function ast_getMouseXY(e){
  if(ast_altclicks){
    ast_mouseX = e.pageX;
    ast_mouseY = e.pageY;
  }
  else{
    ast_mouseX = event.clientX + document.body.scrollLeft;
    ast_mouseY = event.clientY + document.body.scrollTop;
  }
  return true;
}
function ast_linkClicked(e){
  if(e){
    ao = e.target;
  }
  else{
    ao = event.srcElement;
  }
  ast_createBug(1, ao.href);
}
function ast_peelClick(e){
  if(!ast_peelClicked){
    ast_peelClicked = true;
    ast_createBug(1, "http://peelawayads.com/" + '?u=' + document.location.href);
  }
}

var ast_peelClicked = false;
var ast_mouseX = 0;
var ast_mouseY = 0;
var ast_mouseoverad = null;
var ast_mouseoverurl = null;
var elements;
var agnt = navigator.userAgent.toLowerCase();
var ast_altclicks = (document.layers | agnt.indexOf("firefox")>-1 | agnt.indexOf("mozilla")>-1) && agnt.indexOf("msie")==-1;
if(ast_altclicks){
  if(document.layers){
    window.captureEvents(Events.ONUNLOAD);
    document.captureEvents(Event.MOUSEMOVE)
  }
}
window.onunload = ast_docunload;
document.onmousemove = ast_getMouseXY;

elements = document.getElementsByTagName("iframe");
gpage = null;
cpage = null;
lpage = null;
ypage = null;
spage = null;
apage = null;
for(var i=0;i<elements.length;i++){
  isg = elements[i].src.indexOf('googlesyndication.com');
  iscpa = elements[i].src.indexOf('&cpa_choice');
  isal = -1;
  fmt = ast_getVariable(elements[i], 'format');
  if(fmt){
    if(fmt.indexOf('ads_al_s')>-1){
      lpage = elements[i].src;
      isal = 1;
      isg = -1;
    }
  }
  if(iscpa>-1){
    cpage = elements[i].src;
    isg = -1;
  }
  if(isg>-1 && !gpage){
    gpage = elements[i].src;
  }
  isy = elements[i].src.indexOf('ypn-js.overture.com');
  if(isy>-1 && !ypage){
    ypage = elements[i].src;
  }
  isaa = elements[i].src.indexOf('ads.auctionads.com');
  if(isaa>-1 && !apage){
    apage = elements[i].src;
  }
  if(isg>-1 | isal >-1 | isy>-1 | isaa>-1){
    if(document.layers){
      elements[i].captureEvents(Events.ONFOCUS);
      elements[i].captureEvents(Events.ONMOUSEOVER);
      elements[i].captureEvents(Events.ONMOUSEOUT);
    }
    if(ast_altclicks){
      elements[i].onmouseover = ast_mouseover;
      elements[i].onmouseout = ast_mouseout;
    }
    else{
      elements[i].onfocus = ast_logclick;
      elements[i].onmouseout = ast_mouseout;
    }
  }
}

elements = document.getElementsByTagName("form");
for(var i=0;i<elements.length;i++){
  if(elements[i].action){
    iss = false;
    if(elements[i].action){
      iss1 = elements[i].action.indexOf('google');
      iss2 = elements[i].action.indexOf('/custom');
    }
    if(iss1>-1 && iss2>-1){
      if(document.layers){
        elements[i].captureEvents(Events.ONSUBMIT);
      }
      elements[i].onsubmit = ast_logsearch;
      if(ast_altclicks){
        elements[i].q.onkeypress = ast_searchkey;
      }
      ast_createBug(0,elements[i].action + '?u=' + document.location.href);
    }
  }
}

element = document.getElementById('eselcornerBig');
if(element){
  if(document.layers){
    element.captureEvents(Events.ONCLICK);
  }
  if(ast_altclicks){
    element.onclick = ast_peelClick;
  }
  else{
    element.onmousedown = ast_peelClick;
    //elements = element.getElementsByTagName('object');
    //elements[0].onmousedown = ast_peelClick;
  }
  ast_createBug(0, "http://peelawayads.com/" + '?u=' + document.location.href);
}

if(gpage != null){
  ast_createBug(0,gpage);
}
if(cpage != null){
  ast_createBug(0,cpage);
}
if(lpage != null){
  ast_createBug(0,lpage);
}
if(ypage != null){
  ast_createBug(0,ypage);
}
if(apage != null){
  ast_createBug(0,apage);
}

ast_createBug(0,document.location.href);
elements = document.getElementsByTagName("a");
for(var i=0;i<elements.length;i++){
  if(!elements[i].onclick){
    if(document.layers){
      elements[i].captureEvents(Events.ONCLICK);
    }
    elements[i].onclick = ast_linkClicked;
  }
}
