
<!--
/////////////////////////////////////// START FUNCTIONS ///////////////////////////////////////////
function premii_isExternalLink(url){
  if(!url){ return false; }
  if(typeof(url) != 'string'){ return true; }
  url = url.toLowerCase();
	
  /* what else is missing from the protocol list below? */
  if(url.indexOf('https://') == 0){ url = url.substring(8); }
  else if(url.indexOf('http://') == 0){ url = url.substring(7); }
  else if(url.indexOf('ftp://') == 0){ url = url.substring(6); }
  else if(url.indexOf('ssl://') == 0){ url = url.substring(6); }
  else if(url.indexOf('mailto:') == 0){ return true; }
  else{ return false; }

  if(url.indexOf('www.') == 0){ url = url.substring(4); } 
  var hn = document.location.hostname.toLowerCase();
  if(hn.indexOf('www.') == 0){ hn = hn.substring(4); };

  if(url.indexOf(hn) != 0){ return true; }
  return false;
}
function premii_getParentClickable(obj, flag){
  for(var j=0; j<=5; j++){
    if(flag == 1){ if(obj && obj.nodeName.toUpperCase() == 'A'){ return obj; } } //look for <A> tag
    if(flag == 2){ if(obj && obj.nodeName.toUpperCase() != 'BODY' && obj.onclick){ return obj; } } //look onclick tag
    obj = obj.parentNode;
  }
  return null;
}
function premii_context_click(e){//right click on link
  var tg = null;
  if(e){ tg = e.target; }
  else{ tg = window.event.srcElement; }
  premii_do_track(tg, false);
}
function premii_on_click(e){//left click
  var tg = null;
  if(e){ tg = e.target; }
  else{ tg = window.event.srcElement; }
  premii_do_track(tg, true);
}
function premii_do_track(tg, delay){
  var url = null;
  var text = null;
  try{
    if(tg){
      tgP = premii_getParentClickable(tg, 1);
      if(tgP && tgP.nodeName.toUpperCase() == 'A'){ tg = tgP; }

      if(tg.nodeName.toUpperCase() == 'A'){//A tag - most popular case
        url = tg.href;
        if(tg.innerHTML){ text = tg.innerHTML; } //most browsers
        else if(tg.innerText){ text = tg.innerText; } //ie only
        else if(tg.text){ text = tg.text; } //mozilla only
        else{}
      }else if(tg.nodeName.toUpperCase() == 'INPUT' && tg.type.toUpperCase() == 'SUBMIT'){//form submit button
        url = tg.form.action;
        text = tg.value;
      }else{
       /* this eliminates all other onclick events */

      }
      if(url == null || text == null){ return true; } //both url and text must not be NULL 

      if(premii_isExternalLink(url) || !premii_isExternalLink(url)){
        if(premii_mbl_isAOL_V8 && (tg.target == '_new' || tg.target == '_blank')){ return true; }
        url = escape(url);
        text = escape(text);
        premii_track_oc(text, url, delay);
      }
    }
  }catch(err){ }
}
// THIS FUNCTION TRACKS EXTERNAL URL CLICKS //
function premii_track_oc(text, url, delay){      
  try{
    var now = new Date();
	
    var trackURL = premii_url_trker + '?u=' + url + '&te=' + text; 
//	document.location = trackURL;
    var x = new Image();
    x.src = trackURL;
    if(delay){ premii_pause(900); }
  }catch(err){ }
}

// THIS FUNCTION RECORDS APACHE-LIKE LOG INFO ON EVERY PAGE LOAD //
function premii_track_onload(){
  try{
    url = escape(document.location.href);
    var trackURL = premii_url_trker + '?i=' + premii_mblID + '&t=1&u=' + url + '&a=' + escape(navigator.userAgent) + '&d=20050805';
    var x = new Image();
    x.src = trackURL;
  }catch(err){ }
}
function premii_pause(numberMillis) {
  var now = new Date();
  var exitTime = now.getTime() + numberMillis;
  while(true){
    now = new Date();
    if(now.getTime() > exitTime){ return; }
  }
}

/////////////////////////////////////// END FUNCTIONS ///////////////////////////////////////////
var premii_mbl_isAOL_V8 = false;
if(navigator.userAgent.indexOf('AOL 8.0') > 0){ premii_mbl_isAOL_V8 = true; }

var premii_mblID = '2005073116420360';
var premii_url_trker = 'http://premii.com/lab/urltrk.php';
if(document.body){//if the script is inside the body tag - which it should be
  document.body.onclick = premii_on_click;
  document.body.oncontextmenu = premii_context_click;
}else if(document){//script is outside the body tag - works in some browsers
  document.onclick = premii_on_click;
  document.oncontextmenu = premii_context_click;  
}else{}
//premii_track_onload();

// -->
