// gascript 1.1.0

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

var x = location.hostname;

function noPercent(x) {
	if (x) {
		x = unescape(x);
		return x.replace(/\+/g," ").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	} else {
		return x;
	}
}

function setCookie(name, value, expires, path, domain, overwrite) {
	var today = new Date();
	today.setTime(today.getTime());
	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	else {
		expires = 365 * 24 * 60 * 60 * 1000;
	}
	var expires_date = new Date(today.getTime() + (expires));
	if(overwrite == true || !document.cookie.match('(^|;\\s)' + name)){
		document.cookie = name + "=" + value + ((expires) ? ";expires=" + expires_date.toGMTString() : "") + ((path) ? ";path=" + path: ";path=/") + ((domain) ? ";domain=" + domain: "");
	}
}

function readSubCookie(name) {      
      var nameRegex = RegExp("(?:\\||\\.|^|; )" + name + "=([^|;]+)"),
            nameValue;
      nameValue = nameRegex.exec(noPercent(document.cookie));
      if (nameValue) {
            return nameValue[1];
      } else {
            return null;
      }
}

function readQuery(name) { 
	var nameRegex = RegExp("(?:\\?|&)" + name + "=([^&]+)");
	nameValue = nameRegex.exec(noPercent(location.search));
	if(nameValue) {
		return nameValue[1];
	} else {
		return null;
	}
}

function exactQuery() {
	var re = new RegExp(/(?:\?|&)(?:q|p|query|encquery|qt|terms|rdata|qs|wd|text|szukaj|k|searchExpr|search_for|string|search_query|searchfor)=([^&]+)/);
	var searchq = re.exec(document.referrer);
	if (searchq) {
		searchq = "|" + noPercent(searchq[1]);
		return searchq;
	} else {
		return "|(not set)";
	}
}

function sleuth() {
	if(readQuery("gclid")||readQuery("utm_medium")=="cpc") {
		if (!pageTracker._getVisitorCustomVar(1)) {
			pageTracker._setCustomVar(1, "exact_keyword", exactQuery() , 1);
		}
	}
}

function modifyForm(name) {
	if (name) {
		var fieldNames = ["ga_source", "ga_campaign", "ga_adgroup", "ga_keyword", "ga_landingpage"];
		if (document.forms[name]) {
			for (i = 0; i < fieldNames.length; i+= 1) {
				var gaField = document.createElement("input");
				gaField.setAttribute("name", fieldNames[i]);
				gaField.setAttribute("value", noPercent(pageTracker._getVisitorCustomVar(i + 1)));
				gaField.setAttribute("type", "hidden");
				document.forms[name].appendChild(gaField);
			}
		}
	} 
}

function isFirstVisit() {
    var acookie = readCookie('__utma').split('.');
    var bcookie = readCookie('__utmb').split('.');
    if (acookie[5] == 1 && bcookie[1] < 1) {
        return true;
    }
    else {
        return false;
    }
}

var pageTracker, firstTracker;

function runGA(accountid1, accountid2, leadcapform) {
	var re, re2, reAll, utmz, utmz2, utmAll, exdate, initial, 
		myDomain = "auto",	// if you're using subdomains, change this to [yourdomain].com
		currentDomain, 
		// ==============================================================================
		// REMOVE COMMENT FOR AUTO MULTIPLE DOMAIN TRACKING
		// ==============================================================================
		// siteDomains = { // for multiple domains, list root level site domains - set to domain.com when not in use
		//		"domain.com": true
		//		"otherdomain.com": true
		// },
		rootDomain = /^(?:\/\/|[^\/])*?([^.\/]*\.([a-z]{3}|[a-z]{2}\.[a-z]{2}))(\/|$)/,
		N = function (i) { 
            if (!i || i=="" || i=="none") { 
				i=""; 
				return i; 
			}
		 	if (i=="auto") {
  				var d = document.domain;
	  			if (d.substring(0,4) === "www.") {
   					d = d.substring(4,d.length);
			  	}
		  		i = d;
			}
			i = i.toLowerCase(); 
			return i;
		},
		cookieNames = {	
			"utma": 63072E6, 
			"utmb": 18E5, 
			"utmz": 15768E6
		},
		cookieDomain, i,
		noUpdateZ = false,
		allLinks = document.getElementsByTagName("a"),
		count;
	
	// ==============================================================================
	// REMOVE COMMENT FOR AUTO SUBDOMAIN TRACKING
	// ==============================================================================
	// try {
		// myDomain = rootDomain.exec(location.hostname)[1];	
	// } catch(e) { myDomain = "auto"; }
	
	try {	
		currentDomain = myDomain === "auto" ? rootDomain.exec(location.hostname)[1] : /[^.].*/.exec(myDomain)[0];
	} catch(e) { currentDomain = "domain.com"; }

	// ==============================================================================
	// REMOVE COMMENT FOR AUTO MULTIPLE DOMAIN TRACKING
	// ==============================================================================
	// siteDomains[currentDomain] = false;

	myDomain = N(myDomain);
	cookieDomain = myDomain ? "domain=" + N(myDomain) + ";" : "";
	initial = /\^first/.test(noPercent(document.cookie)) && /(?:^|;\s)__utmz=/.test(noPercent(document.cookie));
	
	var pageURI = "";

	function conversionPage(pageRegexp, cookieName, cookieDomain, addParam) {  // regexp, cookie, ?optin=true
		if(pageRegexp.exec(location.pathname)) {
			if(document.cookie.indexOf(cookieName) == -1){ // Track an opt-in if it's their first visit to the page
				pageURI = location.pathname + addParam;
				setCookie(cookieName,'true', '', '', cookieDomain);
			} // else don't modify page URI
		}
	}
	function conversionPageSpecial(pageRegexp, cookieName, cookieDomain, addParam, cookieTag, addParam2) {  // regexp, cookie, ?optin=true
		if(pageRegexp.exec(location.pathname)) {
			if(document.cookie.indexOf(cookieName) == -1){
				if(document.cookie.indexOf(cookieTag) == -1){
					pageURI = location.pathname + addParam; // email traffic sale
				} else {
					pageURI = location.pathname + addParam2; // normal traffic sale
				}
				setCookie(cookieName,'true', '', '', cookieDomain);
			} // else don't modify page URI
		}
	}
			
	if (typeof(_gat) === "object") {
		try {
			optinregexp = new RegExp(/(\/FreeKit\.html)/i); // Opt-in
			conversionPage(optinregexp, '__utmo', myDomain, '?optin=true'); // Opt-in
			
			emailregexp = new RegExp(/(\/e\/freekit\.php)/i); // Tag email traffic 
			conversionPage(emailregexp, '__utme', myDomain, ""); // Tag email traffic
			
			purchaseregexp = new RegExp(/(\/offer1\.php)/i); // CD sale 
			conversionPageSpecial(purchaseregexp, '__utmr', myDomain, '?purchase=true', '__utme', '?emailpurchase=true'); // CD sale
			
			pageTracker = _gat._getTracker(accountid1);
			if (myDomain) {
				pageTracker._setDomainName(myDomain);
			}
			// ==============================================================================
			// REMOVE COMMENT FOR MULTIPLE DOMAIN CONFIG
			// ==============================================================================
			// pageTracker._setAllowHash(false);
			// pageTracker._setAllowLinker(true);
			// pageTracker._setAllowAnchor(true);
			pageTracker._initData();
			if (!pageTracker._getVisitorCustomVar(1) || pageTracker._getVisitorCustomVar(1).indexOf("cpc") === -1) {
				pageTracker._setCustomVar(1, "s/m", (noPercent(readQuery("gclid")) ? "google/cpc" : noPercent(readSubCookie("utmcsr")) + "/" + noPercent(readSubCookie("utmcmd"))) || "(not set)", 1);
				pageTracker._setCustomVar(2, "c", noPercent(readQuery("ga_campaign") || readSubCookie("utmccn")) || "(not set)", 1);
				pageTracker._setCustomVar(3, "ag", noPercent(readQuery("ga_adgroup") || readSubCookie("utmcct")) || "(not set)", 1);
				pageTracker._setCustomVar(4, "kw", (noPercent(readQuery("ga_keyword") || readSubCookie("utmctr")) || "(not set)") + exactQuery(), 1);
				pageTracker._setCustomVar(5, "lp", location.pathname || "(not set)", 1);
			}
			pageTracker._trackPageview(pageURI);

			if(leadcapform) {
				modifyForm(leadcapform);
			}

			// ==============================================================================
			// REMOVE COMMENT FOR MULTIPLE DOMAIN CONFIG
			// ==============================================================================
			// if (location.hash) {
				// location.replace(location.pathname + location.search + "#" + location.hash.substring(location.hash.indexOf("first=true")));
			// }
			firstTracker = _gat._getTracker(accountid2);
			if (myDomain) {
				firstTracker._setDomainName(myDomain);
			}
			// ==============================================================================
			// REMOVE COMMENT FOR MULTIPLE DOMAIN CONFIG 
			// ==============================================================================
			// firstTracker._setAllowHash(false);
			// firstTracker._setAllowLinker(true);
			// firstTracker._setAllowAnchor(true);
			
			firstTracker._setNamespace("first");
			if (/\^first\.[^^;]*(utmgclid=|utmcmd=(cpc|ppc))/.test(noPercent(document.cookie))) {
				firstTracker._setReferrerOverride(); 
				firstTracker._setCampNameKey(); 
				firstTracker._setCampMediumKey(); 
				firstTracker._setCampSourceKey(); 
				firstTracker._setCampTermKey(); 
				firstTracker._setCampContentKey(); 
				firstTracker._setCampCIdKey();
				noUpdateZ = true;
			}
			
			firstTracker._initData();

			if (!firstTracker._getVisitorCustomVar(1)) {
				firstTracker._setCustomVar(1, "first_visit_is_cpc", pageTracker._getVisitorCustomVar(1).indexOf("%2Fcpc") === -1 ? "No" : "Yes", 1);
			}
			
			re = new RegExp(/(?:^|;\s)__utmz=[^;]*\.([^;.]*);/);
			re2 = new RegExp(/(?:^|;\s)2__utmz=([^;]*)\^first\.([^^;]*)\.[^^;.]*([^;]*)/);
			utmz = re.exec(noPercent(document.cookie));
			utmz2 = re2.exec(noPercent(document.cookie));
						
			if (!initial && utmz && utmz2 && /utmgclid=|utmcmd=(cpc|ppc)/.test(utmz[1])) {
				exdate = new Date();
				exdate.setTime(exdate.getTime() + 15768000000);
				document.cookie = "2__utmz=" + utmz2[1] + "^first." + utmz2[2] + "." + utmz[1] + utmz2[3] + ";expires=" + exdate.toGMTString() + ";path=/;" + cookieDomain;
			}
			
			firstTracker._trackPageview(pageURI);
			
			// ==============================================================================
			// REMOVE COMMENT FOR MULTIPLE DOMAIN CONFIG
			// ==============================================================================
			// if (location.hash) {
				// location.replace(location.pathname + location.search + "# ");
			// }
		
			for (i in cookieNames) {
				if (i !== "utmz" || noUpdateZ === false) {
					reAll = new RegExp("(?:^|;\\s)2__" + i + "(=[^;]*)");
					utmAll = reAll.exec(noPercent(document.cookie));
					exdate = new Date();
					exdate.setTime(exdate.getTime() + cookieNames[i]);
					document.cookie = "2__" + i + utmAll[1] + ";expires=" + exdate.toGMTString() + ";path=/;" + cookieDomain;
				}
			}

			// ==============================================================================
			// REMOVE COMMENT FOR MULTIPLE DOMAIN CONFIG
			// ==============================================================================
			// for (count = 0; count < allLinks.length; count += 1) {
				// try {
					// if (siteDomains[rootDomain.exec(allLinks[count].href)[1]]) {
						// allLinks[count].onclick = function () {
							// this.href = pageTracker._getLinkerUrl(this.href, true);
							// if (typeof(firstTracker) === "object") {
								// this.href += "&first=true" + firstTracker._getLinkerUrl("",true).replace("#","&");
							// }
						// }
					// }
				// } catch(e) {}
			// }
		} catch(err) {}
	} else {
		setTimeout(function () {
			runGA(accountid1,accountid2,leadcapform);
		} ,100);
      }
}

runGA("UA-507646-6","UA-507646-7");