/*

Title:	Google Analytics Ad Keyword Tracker
Author:	Blowback web-design
Update: 04/21/2010

This script grabs visitors exact search phrase and stores it in the user defined variable.
Modified from Michael Harrison's Google Analytics Keyword Sleuth for full unicode support.

<script type="text/javascript">
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"));
</script>
<script src="http://www.yoursite.com/path/to/ga_ad_keyword.js" type="text/javascript"></script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-XXXXXX-X");
pageTracker._initData();
pageTracker._trackPageview();
</script>

*/

function cleanAdKeyword(x) {
	x = decodeURIComponent(x);
	x = x.replace(/\+/g," ").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
	return x.toLowerCase();
}

function setAdKeyword() {
	ref = document.referrer;
	squ = ref.match(/(\?|&)(q|p|query|encquery|qt|terms|rdata|qs|wd|text|szukaj|k|searchExpr|search_for|string|search_query|searchfor)=([^&]+)/);
	if (squ) {
		adSearchPhrase = cleanAdKeyword(squ[3]);
		adKeywordTracker._setVar(adSearchPhrase);
	}
	else {
		if (ref) adKeywordTracker._setVar('Re: ' + decodeURIComponent(ref));
	}
}

function getAdKeyword() {
	if (document.location.search.match("gclid")||document.location.search.match("cpc")) {
		setAdKeyword();
	}
}

if (typeof(_gat)=="object") {
	var adKeywordTracker = _gat._getTracker("UA-1");
	adKeywordTracker._initData();
	getAdKeyword();
}