/*

>>>> DO NOT EDIT THIS SCRIPT <<<<

Name: Google Analytics Keyword Sleuth 1.0.8 - SetVar Version with Cleanup
Author: Michael Harrison
Created: 01/02/2008
Description: If a visitor arrives from a search engine, grab their exact search query and store it in the user defined variable.

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>
<script src="http://www.[yoursitehere].com/path/to/ga_keyword.js" type="text/javascript"></script>
<script type="text/javascript">
_uacct = "UA-XXXXX-X";
urchinTracker();
</script>

~~~~~~
Last modified by Michael Harrison/Jeremy Aube on 03/24/2008 to utilize noescape function to clean up exact keywords
*/

function noPercent(x)
{
	x = unescape(x);
	return x.replace(/\+/g," ").replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}
	
function getRef()
{
	ref = document.referrer;
	re = /(\?|&)(q|p|query)=([^&]*)/;
	searchq = re.exec(ref);
	if(searchq) {
		searchq[3] = noPercent(searchq[3]);
		__utmSetVar(searchq[3]);
	}
}

function sleuth()
{
	if(document.location.search.indexOf("gclid")!=-1||document.location.search.indexOf("cpc")!=-1) {
		getRef();
	}
}