// JavaScript Document
//get values from querystring
	var zargs = new Object();
	var zquery = location.search.substring(1); 		// get query string.
	//alert("quesrystring=" + zquery);
	if (zquery == ""){
		//alert("No querystring");
		zquery="amy=nowords";
		//alert("querysting now is=" + zquery);
	}
	//var zpairs = "";
	var zpairs = zquery.split(",");					//break at comma
	//alert("zpairs=" + zpairs);

		//var zhairs = zquery.split("&");
		var zpairs = zquery.split("=");
		//alert("zpairs=" + zpairs);
		var zhairs = zquery.split("&");
		//alert("zhairs = " + zhairs);
		//if(zhairs == ""){
			//alert("No one home")
			//zhairs = "lead=organic,kw=organic";
			//alert("zhairs=" + zhairs);
			//zpairs = "aaa,nowords&bbb,nokeywords";
			//alert("zpairs=" + zpairs.split("&"));
		//}
		//alert("zhairs = " + zhairs);
		//alert("zpairs[1]=" + zpairs[1]);
		//var ztwopart = zhairs[2].split("=");					//break at &	
	//alert(firstpart);
	
	//alert(firstpart[1]);
	//alert(twopart[1]);

function cook() {		
	name="referrer";
	keywordname="keyword";
	//alert("zhairs=" + zhairs);
	//alert("zpairs=" + zpairs);
	//cookvalue=zpairs[1].split("&")[0];
	//alert("cookvalue=" + cookvalue);
	//alert("ppc from=" + cookvalue.split("&")[0]);
	
	//string1.search(myRegExp)
	
	if (zquery.search("adwords") != -1 || zquery.search("googleppc") != -1) {
		cookvalue = "GOOGLE"
	}
	else if(zquery.search("overture") != -1 || zquery.search("overtureppc") != -1 || zquery.search("yahooppc") != -1 || zquery.search("yahookeyword") != -1) {
		cookvalue = "YAHOO"	
	}
	else if(zquery.search("msnppc") != -1) {
		cookvalue = "MSN"	
	}
	else if(zquery.search("aol") != -1) {
		cookvalue = "AOL"
	}
	else {cookvalue = "Powerbilt Website"}	

	value2=zpairs[2];
	//alert("keyword=" + value2.replace(/%20/g, " "));
	days="365";	
	
	theCookie = cookieVal(name);
	//theKeyword = cookieVal(keywordname);
	//alert("theCookie=" + theCookie);			//what is the current cookie value
	if(theCookie == "") {//if there is no cookie value for the "referrer" create one
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		document.cookie = name + "=" + cookvalue + expires + "; path=/";
		//document.cookie = keywordname + "=" + value2.replace(/%20/g, " ") + expires + "; path=/";
	}	
	//alert("theCookie again = " + theCookie);
}

function cookieVal(cookieName) {
	thisCookie = document.cookie.split("; ")
	for (i=0; i<thisCookie.length; i++) {
		if (cookieName == thisCookie[i].split("=")[0]) {
			return thisCookie[i].split("=")[1]
		}
	}
	return 0
}
			//what is the current cookie value

//========================get cookie value ========================//

function getCook() {
	name="referrer";
	keywordname="keyword";
	value=zpairs[1];
	value2=zpairs[2];
	days="365";	
	
	
	theCookie = cookieVal(name);
	//theKeyword = cookieVal(keywordname)
	//alert("theCookie=" + theCookie + " and keyword=" + theKeyword);
	
	/*
	if (theCookie == "adwords" || theCookie == "googleppc") {
		theCookie = "GOOGLE"
	}
	else if(theCookie == "overture" || theCookie == "overtureppc" || theCookie == "yahooppc" || theCookie == "yahookeyword") {
		theCookie = "YAHOO"	
	}
	else if(theCookie == "msnppc") {
		theCookie = "MSN"	
	}
	else if(theCookie == "aol") {
		theCookie = "AOL"
	}
	else if(theCookie != "adwords" || theCookie != "googleppc" || theCookie != "overture" || theCookie != "overtureppc" || theCookie != "msnppc" || theCookie != "aol" || theCookie != "yahooppc" || theCookie != "yahookeyword") {
		theCookie = "Powerbilt Website"
	}
	*/
	//var bc = document.cookie.split("=")[2];
	//alert(bc);
	document.write("<input type='hidden' name='lead_source' id=\"lead_source\" value='" + theCookie + "' />")
	//document.write("<input type='hidden' name='keywordtext' id='keywordtext' value='" + theKeyword + "' />")
}