logRequest('uwe-ext/');

// Version for INFO

//Identify Protol - if http then protocol = 4, if https then protocol = 5
var protocol = document.URL.indexOf(":");

function logRequest(ns_1){
	logRequest(ns_1,'');
}

function log404(ns_1){
	logRequest(ns_1,'&amp;ns_http_status=404');
}

function logRequest(ns_1,postfix){
				
	//remove http://
	var results=document.URL.replace('http://', "");
	//remove https://
	var results=results.replace('https://', "");

	//remove www from hostname

	//remove *.uwe.ac.uk from hostname
	results=results.replace('uwe.ac.uk', "");
	// results=results.replace('dev.', "");
	//results=results.replace('info.uwe.ac.uk', "");
	// results=results.replace('info', "");	
	results=results.replace('.aspx', '.page');
	results=results.replace('.asp', '.page');
	results=results.replace('www.uwe.ac.uk', "");
	results=results.replace('www', "");
	results=results.replace('.shtml', '.page');
	results=results.replace('.htm', '.page');
	results=results.replace('.html', '.page');

	//left with page directoy i.e. /central/students.shtml
	//or if virtual host left with hostname and page
	
	var counter_name=results;
	var queryStringIndex = results.indexOf('?')

	//global find / and change to .
    counter_name = counter_name.replace(/\//g, ".");
	//global find + and change to _
	 counter_name = counter_name.replace(/\+/g, "_");
	//global find ? and change to _
	 counter_name = counter_name.replace(/\?/g, "_");
	//global find & and change to _
	counter_name = counter_name.replace(/\&/g, "_");
	//global find = and change to _
    counter_name = counter_name.replace(/\=/g, "_");
	//global find %20 and change to _
	counter_name = counter_name.replace(/%20/g, "_");
	//global find # and change to _
	counter_name = counter_name.replace(/\#/g, "_");
	//global find ~ and change to _
	counter_name = counter_name.replace(/\~/g, "_");
	 	 
	//alert(counter_name);
	// replace first folder as it's not needed
	counter_name = counter_name.replace(".","");
	
	if (counter_name.indexOf('courses') == 0){
		
		counter_name = counter_name.toLowerCase();
		
		if (queryStringIndex > 0){
		// site is courses so remove querystring
		counter_name = counter_name.slice(0,queryStringIndex-1);
		}
		
		if (counter_name.lastIndexOf('.') == counter_name.length-1){
			counter_name = counter_name.slice(0,counter_name.length-1);
		}
				
		if (counter_name.lastIndexOf('.') > counter_name.indexOf('.')){
			counter_name = counter_name.slice(0,counter_name.lastIndexOf('.'));
		}
		
		if (counter_name.length == 7){
			counter_name = counter_name + ".index.page" ;
		}
	}
								
	if (counter_name.lastIndexOf('.') == counter_name.length-1) {
		counter_name = counter_name + "index.page" ;
	}
			
	//alert("http://uk.sitestat.com/uwe/" + ns_1 + "s?" + counter_name);	
	if (protocol==5) {
		sitestat("https://uk.sitestat.com/uwe/" + ns_1 + "s?" + counter_name);
	} else
	{
		sitestat("https://uk.sitestat.com/uwe/" + ns_1 + "s?" + counter_name);
	}
}

// Log exactly what is passed through - used for pages with funny names
// The s? needs to be passed through for this.  However, we should try and
// use the one above.
function logExact(ns_1){
	//alert("http://uk.sitestat.com/uwe/" + ns_1 + postfix);
	if (protocol==5) {
		sitestat("https://uk.sitestat.com/uwe/" + ns_1 + postfix); 
	} else {
		sitestat("http://uk.sitestat.com/uwe/" + ns_1 + postfix); 
	}
}

function sitestat(ns_l){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);
if(document.images){ns_1=new Image();ns_1.src=ns_l;}else
document.write('<img src="'+ns_l+'" width="1" height="1" alt="">');}
