function initialiseCounter() {
	siteRoot = 'http://www.alexandramedical.com/';
	siteDomain = 'www.alexandramedical.com';
	useCounter = true;
	useURI = true;
	counterTitle = '';
}

initialiseCounter();

function setCounter() {
	if( useCounter ) {
		if( useURI ) {
			if( document.location.href.indexOf('cgi-') > -1 ) {
				useCounter = false;
			} else {
				docLocation = document.location.href;
				startIndex = docLocation.lastIndexOf( siteDomain ) + siteDomain.length + 1;
				if( docLocation.lastIndexOf('.') > docLocation.lastIndexOf('/') ) {
					endIndex = docLocation.lastIndexOf('.');
				} else {
					endIndex = docLocation.lastIndexOf('/') + 1;
				}
				counterTitle = docLocation.substring( startIndex, endIndex );
				if( counterTitle.charAt(counterTitle.length-1) == '/' || counterTitle == '' ) {
					counterTitle += 'index';
				}
			}
		} else if( counterTitle == '' ) {
			useCounter = false;
		}
	}

	if( useCounter ) {
		counterImage = new Image();
		counterImage.src = siteRoot + 'cgi-local/sqlcounter.pl?page=' + counterTitle + '&referrer=' + escape(top.document.referrer);
	}
}

function addEvent(obj, evType, fn, useCapture){
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent){
		var r = obj.attachEvent("on"+evType, fn);
		return r;
	} else {
		// alert('Handler could not be attached');
		return false;
	}
}

addEvent( window, 'load', setCounter, false );
