var UELcomScore;
if (!UELcomScore) UELcomScore = {};
//..................................................................................:UELcomScore.class_Stats
UELcomScore.class_Stats = function () {
	
	this.Initialise();
	
	//create a stats image based on a protocol
	switch (this.Protocol) {
		case "http":	
		case "https":	
			if (this.isLive) { 
				document.write(this.AsImage()); 
				//document.write(this.AsURL() + ' Live');
			} else {
				document.write(this.AsURL() + ' - SiteStat reporting is skipped in development environments');
			}
			break;
		default:
			//document.write(this.AsURL());
			document.write(this.AsImage());
	}
}

//..................................................................................:
//properties
UELcomScore.class_Stats.prototype.Tag = '';
UELcomScore.class_Stats.prototype.Protocol = '';
UELcomScore.class_Stats.prototype.ProtocolDelimiter = '://';
UELcomScore.class_Stats.prototype.SubmissionLink = 'uk.sitestat.com/uel/uel/s?';
UELcomScore.class_Stats.prototype.isLive = true;

//..................................................................................:Initialise
UELcomScore.class_Stats.prototype.Initialise = function () {
	// Retrieve document path, e.g. http://www.abc.uel.ac.uk/level/sublevel/page
	var DocumentPath = new String(document.URL);
	DocumentPath = DocumentPath.toLowerCase();

	//Add default index page after trailing slash
	var iL = DocumentPath.lastIndexOf('/');
	if (iL >= 0 && iL == (DocumentPath.length - 1)) {
		DocumentPath += 'index.htm';
	}

	this.isLive = !(DocumentPath.indexOf("localhost") >= 0 || DocumentPath.indexOf("uel-iis-b") >= 0);
	
	// Find protocol and remove protocol from the path, e.g. www.abc.uel.ac.uk/level/sublevel/page
	var i = DocumentPath.indexOf(this.ProtocolDelimiter);
	if ( i>=0 ) {
		this.Protocol = DocumentPath.substr(0, i);
		DocumentPath =  DocumentPath.substr(i + this.ProtocolDelimiter.length);
	}
	
	//remove www from hostname, e.g. abc.uel.ac.uk/level/sublevel/page
	DocumentPath = DocumentPath.replace('www.', '');
	
	//remove domaing from the path, e.g. abc.level/sublevel/page
	//
	var Domain = 'uel.ac.uk/';
	var i = DocumentPath.indexOf(Domain);
	if ( i>=0 ) {
		DocumentPath = DocumentPath.substr(i + Domain.length);
	}
	
	//create a tag with special characters replaced
	var DocumentTag = DocumentPath;
	
	//global find / and change to .
	DocumentTag = DocumentTag.replace(/\//g, ".");
	//global find ... and change to .
	DocumentTag = DocumentTag.replace(/\.+/g, ".");
	//global find + and change to _
	DocumentTag = DocumentTag.replace(/\+/g, "_");
	//global find ? and change to _
	DocumentTag = DocumentTag.replace(/\?/g, "_");
	//global find & and change to _
	DocumentTag = DocumentTag.replace(/\&/g, "_");
	//global find = and change to _
	DocumentTag = DocumentTag.replace(/\=/g, "_");
	//global find %20 and change to _
	DocumentTag = DocumentTag.replace(/%20/g, "_");
	//global find # and change to _
	DocumentTag = DocumentTag.replace(/\#/g, "_");


	this.Tag = DocumentTag;
}
//..................................................................................:AsURL
UELcomScore.class_Stats.prototype.AsURL = function () {
	return this.Protocol + this.ProtocolDelimiter + this.SubmissionLink + this.Tag;
}
//..................................................................................:AsImage
UELcomScore.class_Stats.prototype.AsImage = function () {
	ns_l = this.AsURL();
	ns_l+='&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+='&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="">');
	*/
	return '<img src="'+ ns_l +'" width="1" height="1" alt="" />';
}
//..................................................................................:UELcomScore.Stats
if (!UELcomScore.Stats) UELcomScore.Stats = new UELcomScore.class_Stats();


