// function to execute JS on page load
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

// target blank replacement
function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}


function tooltip() {
	if(document.getElementById('ebook_purchase')) {
		var div = document.getElementById('ebook_purchase').getElementsByTagName('div');
		var tip = document.createElement('div');
		tip.setAttribute('id','tip');
		var inner = document.createElement('div');
		var tiptext = document.createTextNode('If you\u2019ve purchased this package please leave the \u201CBecome an Escort\u201D book unchecked as it\u2019s already included here.');
		tip.appendChild(tiptext);
		tip.appendChild(inner);
		
		div[2].appendChild(tip);
		div[2].style.position = 'relative';
		tip.style.position = 'absolute';
		tip.style.bottom = '75px';
		tip.style.right = '999em';
		tip.style.background = 'url(https://exoticpublishing.com/images/bg_tooltip_top.png) no-repeat';
		tip.style.height = 'auto';
		tip.style.fontSize = '.9em';
		tip.style.padding = '5px 8px 0 5px';
		tip.style.width = '190px';
		
		inner.style.height = '19px';
		inner.style.position = 'absolute';
		inner.style.left = '0';
		inner.style.bottom = '-19px';
		inner.style.background = 'url(https://exoticpublishing.com/images/bg_tooltip_bottom.png) no-repeat';
		inner.style.width = '204px';
		
		div[2].onmouseover = function() {tip.style.right = '-80px';}
		div[2].onmouseout = function() {tip.style.right = '999em';}
	}
}

addLoadEvent(externalLinks);
addLoadEvent(tooltip);
