function makeRequest(param)
{
   var request = false;
   try {
     request = new XMLHttpRequest();
   } catch (trymicrosoft) {
     try {
       request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         request = false;
       }  
     }
   }

   if (!request)
     alert("Error initializing XMLHttpRequest!");

   request.open("GET", param, true);
   request.send(null);
}

function logIt () {
	exitLinkGone = 1;
	makeRequest( variablescodees + '&lastpage=' + this.href );
}

function logItO (addr) {
	exitLinkGone = 1;
	makeRequest( variablescodees + '&lastpage=' + addr );
}

function logItL (addr) {
	exitLinkGone = 1;
}

var host = location.host;
if (host.indexOf('www')==0) host = host.substring(host.indexOf('.')+1); // strip the www
host = host.replace(/\./g,'\\.'); // you may need \\\\. here
var str = "^http(s?):\/\/([a-z0-9]+\\.)?\"+host+\"(\/|$)";
var reg = new RegExp(str);

for (var iLink = document.links.length - 1; iLink >= 0; iLink--) 
{		
	if (document.links[iLink].onclick)
	{
		if (!document.links[iLink].href.match(reg)) {
			var cur = (document.links[iLink].attributes["onclick"]) ? document.links[iLink].attributes["onclick"].value : '';
			var href = document.links[iLink].attributes["href"].value;
			var ocf = new Function(cur + "logItO(this.href);window.location.href=this.href;return false;");
			document.links[iLink].onclick = ocf;
		} else {
			var cur = (document.links[iLink].attributes["onclick"]) ? document.links[iLink].attributes["onclick"].value : '';
			var href = document.links[iLink].attributes["href"].value;
			var ocf = new Function(cur + "logItL(this.href);window.location.href=this.href;return false;");
			document.links[iLink].onclick = ocf;
		}
	} else {
		if (!document.links[iLink].href.match(reg)) {
			var exitLink = document.links[iLink].href;
			document.links[iLink].onclick = logIt;
		} else {
			document.links[iLink].onclick = logItL;	
		}
	}
}
window.onbeforeunload=function (evt) {
	if (exitLinkGone=='0') {
		makeRequest( variablescodees + '&lastpage=Left Website' );
	}
}