var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");

function runGA() {
	var pageTracker,
		nexLinks, 
		i,	
		kristenblake = /kristenblake\.com/,
		dogla = /dogla\.com/,
		nexternal = /nexternal\.com/;

	function readCookie(name) {		// function to read cookie
		var nameRegex = new RegExp("(?:;\\s|^)" + name + "=([^;]+)"), 
			nameValue;	// match name of cookie and store value in $1
			
		nameValue = nameRegex.exec(document.cookie);				
		return nameValue && nameValue[1];
	}

	function noPercent(x) {
		x = unescape(x);
		return x.replace(/\+/g, " ").replace(/(^ +| +$)/g, "");
	}

	function sleuth() {
		var cpcValue = "cpc - ", 
			userdef, 
			cpcregexp, 
			ref, 
			re, 
			searchq;
	
		if (location.search.indexOf("gclid") !== -1 || location.search.indexOf("cpc") !== -1) {	
			userdef = readCookie("__utmv");
			cpcregexp = new RegExp(/^cpc - /);
			if (!userdef || !cpcregexp.exec(userdef)) {
				ref = document.referrer;
				re = new RegExp(/(?:\?|&)(?:q|p|query|encquery|qt|terms|rdata|qs|wd|text|szukaj|k|searchExpr|search_for|string|search_query|searchfor)=([^&]+)/);
				searchq = re.exec(ref);
				if (searchq) { 
					cpcValue += noPercent(searchq[1]);
				} else {
					cpcValue += "Paid Referral: "; 
					cpcValue += ref;
				}
				pageTracker._setVar(cpcValue);
			}
		}
	}

    if (typeof(_gat) === "object") {
	    try {
		    if (dogla.test(location.hostname)) {
				pageTracker = _gat._getTracker("UA-1169349-1");
				pageTracker._setDomainName("dogla.com");
			} else if (kristenblake.test(location.hostname)) {
				pageTracker = _gat._getTracker("UA-2391306-1");
				pageTracker._setDomainName("kristenblake.com");
			} else {
				pageTracker = _gat._getTracker("UA-1234567-1");
			}
			
			pageTracker._setAllowHash(false);
			pageTracker._setAllowLinker(true);
			pageTracker._trackPageview();
			
			sleuth();
			
			nexLinks = document.getElementsByTagName("a");
			for (i = 0; i < nexLinks.length; i+= 1) {
				if (nexternal.test(nexLinks[i].href)) {
					nexLinks[i].onclick = function() { 
						this.href = pageTracker._getLinkerUrl(this.href);
					}
				}
			}
		} catch (err) {}
	} else {
        setTimeout(function () { 
		    runGA(); 
		}, 100);
    }
}

document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
runGA();