function _nbtVoid() { return; }

function _nbtEscape(string, url) {
	if (typeof(encodeURIComponent) == "function") {
		if (url) { 
			return encodeURI(string); 
		} else { 
			return encodeURIComponent(string); 
		}
	} else {
		return escape(string);
	}
}

function _nbtUnescape(string) {
	if (typeof(decodeURIComponent) == "function") {
		return decodeURIComponent(string);
	} else {
		return unescape(string);
	}
}

function _nbtHash(d) {
	if (!d || d==="") { return 1; }
	var h=0,g=0;
	for (var i=d.length-1;i>=0;i--) {
		var c = parseInt(d.charCodeAt(i), 10);
 		h=((h << 6) & 0xfffffff) + c + (c << 14);
 		if ((g=h & 0xfe00000)!==0) {
 			h=(h ^ (g >> 21));
 		}
 	}
	return h;
}

function _nbtGetDomain() {
	var d = document.domain;
	if (d.substring(0,4) === "www.") {
		d = d.substring(4, d.length);
	}
	d = d.toLowerCase();
	return d; 
}

function _nbtSetCookie() {
	var randNr = Math.round(Math.random()*2147483647);
	var now = new Date();
	var randDate = Math.round(now.getTime()/1000);
	var seed = "nbt" + randNr + randDate;
	var hash = _nbtHash(seed);
	var expires_date = new Date( now.getTime() + 1000*60*60*24*365*2 ); //2 years
	
	document.cookie = "__nbtC=" + escape( hash ) +
	";expires=" + expires_date.toGMTString() + 
	";path=/" + 
	";domain=" + _nbtGetDomain();
	
	return hash;
}

function _nbtGetCookie(c_name) {
	if (document.cookie.length>0){
		var c_start = document.cookie.indexOf(c_name + "=");
		if (c_start!==-1){
			c_start=c_start + c_name.length+1; 
			var 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 nbtTracker() {
	var _nbtURL = "";
	if(document.location) { _nbtURL = document.location; }
	
	var _nbtReferer = "";
	if(document.referrer) { _nbtReferer = document.referrer; }

	var _nbtTrackingId = _nbtGetCookie("__nbtC");
	if(_nbtTrackingId===null || _nbtTrackingId==="") {
		_nbtTrackingId = _nbtSetCookie();
	}

	var i=new Image(1,1);
	i.src="https://www.nichebot.com/tracker/image.php?nbtMemberId=" + _nbtEscape(_nbtMemberId) + "&nbtProjectId=" + _nbtEscape(_nbtProjectId) + "&nbtURL=" + _nbtEscape(_nbtURL) + "&nbtReferer=" + _nbtEscape(_nbtReferer) + "&nbtTrackingId=" + _nbtEscape(_nbtTrackingId);
	i.onload=function() { _nbtVoid(); };
}
