
var LinkTrack = function () {
  this.docLinks  = document.links;
  this.location= location.pathname;
}

LinkTrack.prototype.updateHrefs = function () {
  var currlink, hostname, protocol, linktext;
  if (!(!document.getElementsByTagName && document.all)) {
    for (var i=0; i<this.docLinks.length; i++) {
      currlink = this.docLinks[i];
      hostname = currlink.hostname ? currlink.hostname.toLowerCase() : ""; 
      protocol = currlink.protocol.toLowerCase();
      linktext = currlink.innerText;
      if (protocol == 'http:' && hostname != location.hostname.toLowerCase()) {
        currlink.href = this.getNewUrl(currlink.href);
        if (document.all && currlink.innerText.toLowerCase() == currlink.href.toLowerCase()) currlink.innerText = linktext;
      }
    }
  }
}

LinkTrack.prototype.getNewUrl = function (destination) {
  return '/JumpTo.aspx?url=' + urlencode(destination);
  return newUrl;
}

var myC = new LinkTrack();
myC.updateHrefs();



function urlencode (str) {
    var hexStr = function (dec) {
        return '%' + dec.toString(16).toUpperCase();
    };
 
    var ret = '',
            unreserved = /[\w.-]/; // A-Za-z0-9_.- // Tilde is not here for historical reasons; to preserve it, use rawurlencode instead
    str = (str+'').toString();
 
    for (var i = 0, dl = str.length; i < dl; i++) {
        var ch = str.charAt(i);
        if (unreserved.test(ch)) {
            ret += ch;
        }
        else {
            var code = str.charCodeAt(i);
            // Reserved assumed to be in UTF-8, as in PHP
            if (code == 32) {
                ret += '+'; // %20 in rawurlencode
            }
            else if (code < 128) { // 1 byte
                ret += hexStr(code);
            }
            else if (code >= 128 && code < 2048) { // 2 bytes
                ret += hexStr((code >> 6) | 0xC0);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 2048 && code < 65536) { // 3 bytes
                ret += hexStr((code >> 12) | 0xE0);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
            else if (code >= 65536) { // 4 bytes
                ret += hexStr((code >> 18) | 0xF0);
                ret += hexStr(((code >> 12) & 0x3F) | 0x80);
                ret += hexStr(((code >> 6) & 0x3F) | 0x80);
                ret += hexStr((code & 0x3F) | 0x80);
            }
        }
    }
    return ret;
}

