function CheckAnalyticsCookie() {
	var cookiename = "__utma";
	var cookiecheck = 0;
	var cookies = document.cookie.split(';');
	for (var i=0;i<cookies.length;i++){
		while (cookies[i].charAt(0)==' ') cookies[i] = cookies[i].substring(1,cookies[i].length);
		if (cookies[i].indexOf(cookiename+'=') == 0){
			cookiecheck = 1;
		}
	}
	return cookiecheck;
}//CheckAnalyticsCookie

//truncate to 63 characters after URL encoding. Decode before returning - to avoid encoding twice
function rTruncate(input) {
	var byteLength = 63;
	return decodeURIComponent(encodeURIComponent(input).substr(0,byteLength));
}//rTruncate

function MozFirstTouch(pageTracker){
	if (CheckAnalyticsCookie() === 0){
	
		//note that setCustomVar has a max of 64 bytes for combination of variable name and value hence cryptic variable names
		//all variables are truncated to 63 characters after URL encoding to ensure we get as much information as possible in GA
		
		//l = original landing page (no query string)
		//s = original landing page query string
		//r = original referrer
		//q = if keyword information is found, this contains that part of the referrer (based on Google's list of query delimiters: http://code.google.com/apis/analytics/docs/tracking/gaTrackingTraffic.html#searchEngine)
  		
		pageTracker._setCustomVar(1, "l", rTruncate(window.location.pathname), 1);
		pageTracker._setCustomVar(2, "s", rTruncate(window.location.search), 1);
		
		//for the referrer, substring out the http:// from the beginning (the first 7 characters)
  		pageTracker._setCustomVar(3, "r", rTruncate(document.referrer.substr(7,document.referrer.length)), 1);
		pageTracker._setCustomVar(4, "q", rTruncate(document.referrer.match(/(?:([#]|[?]|[&]))(?:(encquery|k|p|q|qs|qt|query|rdata|search_word|szukaj|terms|text|wd|words))=[^&]*/i)[0]), 1);
		
 	} //if
}//MozFirstTouch