var AjaxTCRExamples = {};
AjaxTCRExamples.linkReportingURL = "http://ajaxref.com/ch2/recordlink.php";
AjaxTCRExamples.encodeValue = function(val)
{
var encodedVal;
if (!encodeURIComponent)
{
encodedVal = escape(val);
encodedVal = encodedVal.replace(/@/g, '%40');
encodedVal = encodedVal.replace(/\
encodedVal = encodedVal.replace(/\+/g, '%2B');
}
else
{
encodedVal = encodeURIComponent(val);
encodedVal = encodedVal.replace(/~/g, '%7E');
encodedVal = encodedVal.replace(/!/g, '%21');
encodedVal = encodedVal.replace(/\(/g, '%28');
encodedVal = encodedVal.replace(/\)/g, '%29');
encodedVal = encodedVal.replace(/'/g, '%27');
}
/* clean up the spaces and return */
return encodedVal.replace(/\%20/g,'+');
}
AjaxTCRExamples.sendRequest = function(url, payload)
{
var img = new Image();
img.src = url+"?"+payload;
}
AjaxTCRExamples.logURL = function(URI)
{
var payload = "site=" + AjaxTCRExamples.encodeValue(URI);
AjaxTCRExamples.sendRequest(AjaxTCRExamples.linkReportingURL, payload);
}
AjaxTCRExamples.regLinks = function()
{
var outLinks;
var curURL = document.domain;
outLinks = document.body.getElementsByTagName('a');
for (var i=0;i<outLinks.length;i++)
{
/* we only want to log the external links, so we check for that first */
var regxp = /^http|https/i;
if (regxp.test(outLinks[i].href) && outLinks[i].href.indexOf(curURL) == -1)
{
if (outLinks[i].addEventListener)
outLinks[i].addEventListener('click', function() { AjaxTCRExamples.logURL(this.href); }, false);
else if (outLinks[i].attachEvent)
outLinks[i].attachEvent('onmousedown', function() { AjaxTCRExamples.logURL(window.event.srcElement.href); return false; });
}
}
}
if (window.addEventListener)
window.addEventListener('load', AjaxTCRExamples.regLinks, false);
else if (window.attachEvent)
window.attachEvent('onload', AjaxTCRExamples.regLinks);