function sitestat(ns_l){
	// update any pdf links
	var lightRegID=getLightRegID();
	if(lightRegID!="") updatePDFLinks(lightRegID);

	ns_l+='&amp;ns__t='+(new Date()).getTime();
	ns_pixelUrl=ns_l;
	ns_0=document.referrer;
	ns_0=(ns_0.lastIndexOf('/')==ns_0.length-1)?ns_0.substring(ns_0.lastIndexOf('/'),0):ns_0;

	if(ns_0.length > 0)ns_l+='&amp;ns_referrer='+escape(ns_0);
	ns_l+=lightRegID;
	if(document.images){
		ns_1=new Image();
		ns_1.src=ns_l;
	} else {
		 document.write('<img src="'+ns_l+'" width="1" height="1" alt="" />');
	}
} 

function getLightRegID(){
	var LightRegCookie = "PWCLIGHTREG";
	var userID = getCookie(LightRegCookie);
	if(userID!=""){
		return "&cookie_id="+userID;
	}else{
		return "";
	}
}
function updatePDFLinks(lightRegID){
	var links=document.links;
	for(l=0;l<links.length;l++){
		var url=links[l].href;
		var urlLS=url.toLowerCase();
		if(urlLS.indexOf("ns_type=pdf")>0 || urlLS.indexOf("ns_type=clickin")>0 || urlLS.indexOf("ns_type=clickout")>0){
			// if there is an ns_url entry we must put the lightreg cookie id
			// before it so it doesnt get mixed up with value of ns_url parameter
			// which is the url to return to after going to sitestat
			var u=urlLS.indexOf("&ns_url=");
			if(u==-1){
				url+=lightRegID;
			}else{
				url=url.substring(0,u)+lightRegID+url.substring(u);
			}
			links[l].href=url;
		}					
	}
}
function updatePDFLinksFromURL(pdflink){
	var sp = pdflink.indexOf("ukws.eng_publications");
	pdflink = pdflink.substr(0,sp+21)+".pdf"+pdflink.substr(sp+21)+"_pdf";
	var links=document.links;
	for(l=0;l<links.length;l++){
		if(links[l].href.toLowerCase().indexOf(".pdf")>0){
			url=pdflink+"&ns_type=pdf"+getLightRegID()+"&ns_url="+links[l].href;
			links[l].href=url;
		}					
	}
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
function hideEditLink(){
	var editLink = document.getElementById("LightRegEdit");
	if(editLink != null) {
		if(getLightRegID() == "") {
			editLink.style.display = "none";		 
		} else {
			editLink.style.display = "inline";		 
		}
	}
}
