//Code for identifying WAM links and tagging so they show up in Google Analytics

function sendHit() {
   
   var theURL = window.location.pathname;
   theURL += '/downloads/';
   theURL += this.innerHTML;
   theURL.toString(); 
   if (theURL.indexOf("aspx")>0) {      
      theURL = theURL.replace(/\.aspx/,"");
   }   
   try {
      pageTracker._trackPageview(theURL); 
   }
   catch(err) {}
       //comment out last line once ready
       //return false;
}

function findLinks() { 
   
   var link = document.links;
   var regex = /idoc\.ashx\?docId/i;   
	 //Test regular expression for on NAOcopy
	 //var regex2 = /^http:\/\/cmscore\/naocopy/i;
	 var regex2 = /^http:\/\/www\.nao\.org\.uk/i;
   for(var i=0;i<link.length;i++){
      if (link[i].href.match(regex) && link[i].href.match(regex2)) {
      link[i].onclick = sendHit;
      }
   }
}