




var beaconed = false;

function beacon() {

	var loc, ref;
	if(!document.all) dump("beacon running \n");
	datatag = '';
	//datatag += '&time=" + new Date().getTime();
	datatag += '&projectid=2'
	datatag += '&title=' + escape(document.title);
	loc = document.location +'';
	ref = document.referrer + '';
	loc = replaceAll(loc, "&", "|");
	ref = replaceAll(ref, "&", "|");
	datatag += '&addy=' + loc;
	datatag += '&ref=' + ref;
		document.write("<img src='http://uzilla.net/uzilla/beacon/pixel.cfm?" + datatag + "' height='2' width='2'/>"); 
			

}

if(document.all) {
	if(document.title) {
		beacon();
	} else {
		document.onload = beacon;	
	}
} else {
	dump("beacon listening \n");
	if(document.title) {
		if(!beaconed) beacon();
		dump("running starting with title\n");
	} else {
		dump("adding listener\n");
		if(!beaconed) document.addEventListener("load", beacon, true);
	}
}


function replaceAll(string,text,by) {
// Replaces text with by in string
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replaceAll(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}
