var track_script="/tally-it.php";

// Make it error-proof.
function tally_clicker(e) {
  try {
    return tally_do_clicker(e);
  }
  catch (err) {
     return true;
  }
}

function tally_do_clicker(e) {		// Grabs the link and redirects it to the php page.
  var tally_target = null;

  if (e != null) {
     tally_target = e.target;
  }
  else {
     tally_target = window.event.srcElement;
  }

  if (tally_target == null) return true;		// Can't track a link that doesn't exist.

  while (tally_target.nodeName.toUpperCase() != 'A') {		// Go up to the actual anchor.
    if (tally_target.parentNode == null) return true;
    else {
      tally_target = tally_target.parentNode;
    }
  }  	  
  	  
  if (tally_target.href == null) return true; 	// If we aren't going anywhere, don't track.

  var tally_href = tally_target.href;
  if (tally_href == null) return true;
  if (typeof(tally_href) != 'string') return true;  // What else it could be? An image??

  // See if the link is off the page.
  var tally_host = document.location.hostname.toLowerCase();
  if (tally_host==null || tally_host=="") tally_host="unknown";

  // If you want to track internal stuff, comment out this next line.
  if (tally_href.toLowerCase().indexOf(tally_host) >= 0) return true; // Don't track clicks to our own site.

  // Uncomment the next line to avoid tracking links to some other URL(s).
  // if (tally_href.toLowerCase().indexOf("anotherURL") >= 0) return true;

  tally_href = escape(tally_href);

  // A delay is necessary!
  var tally_start = new Date().getTime();
  var tally_stop = tally_start + 100;
  while (tally_start < tally_stop) {
    tally_start = new Date().getTime();		// Might be needed on slow systems
  }

  // We have a link. We have to mess with it.
  // It seems the best way to do this is to create a new image, but you can use an iFrame.
  var tally_newurl = track_script + "?url=" + tally_href;		// Create the ref to the new image
  try {											 				// Put it in a try/catch to avoid http errors.
    var tally_newimg = new Image();
    tally_newimg.src = tally_newurl;
  }
  catch(err) {
    return true;
  }

  return true; 	// Let the link do its job.
}