function checkCPCCookie (cltID) {
	
	var tmpSrc;
	var tmpKw;
	var tmpAd;
	var tmpSplit;
	
	var tmpID = cltID.split("txtSrc");

	var tmpCPCCookie = readCookie("SEOCPC");
    var tmpCPCParams = tmpCPCCookie.split("&");
	for (i = 0; i < tmpCPCParams.length; i++) {
		tmpSplit = tmpCPCParams[i].split("=");
		if (tmpSplit[0] == "WT.sp") 
		{
			tmpSrc = tmpSplit[1];
			document.getElementById(tmpID[0]+'txtSrc').value=tmpSrc;
		}
		if (tmpSplit[0] == "kw") 
		{
			tmpKw = tmpSplit[1];
	        document.getElementById(tmpID[0]+'txtKw').value=tmpKw;		
		}
		if (tmpSplit[0] == "ad") 
		{
			tmpAd = tmpSplit[1];
			document.getElementById(tmpID[0]+'txtAd').value=tmpAd;
		}
		if (tmpSplit[0] == "mkwid") 
		{
			tmpKw = tmpSplit[1];
	        document.getElementById(tmpID[0]+'txtKw').value=tmpKw;		
		}
		if (tmpSplit[0] == "pcrid") 
		{
			tmpAd = tmpSplit[1];
			document.getElementById(tmpID[0]+'txtAd').value=tmpAd;
		}
		if (tmpSplit[0].toLowerCase() == "aid") 
		{
			tmpAd = tmpSplit[1];
			document.getElementById(tmpID[0]+'txtLinkID').value=tmpAd;
		}
		if (tmpSplit[0].toLowerCase() == "pid") 
		{
			tmpAd = tmpSplit[1];
			document.getElementById(tmpID[0]+'txtPublisherID').value=tmpAd;
		}
		if (tmpSplit[0].toLowerCase() == "sid") 
		{
			tmpAd = tmpSplit[1];
			document.getElementById(tmpID[0]+'txtShopperID').value=tmpAd;
		}
		if (tmpSplit[0].toLowerCase() == "psid") 
		{
			tmpAd = tmpSplit[1];
			document.getElementById(tmpID[0]+'txtShopperID').value=tmpAd;
		}
	}
	
	return tmpCPCCookie;	
}

function checkCPC () {	
	var tmpSrc = "";
	var tmpKw = "";
	var tmpAd = "";
	var tmpAID = "";
	var tmpPID = "";
	var tmpSID = "";
	var tmpSplit;
	var tmpCPCCookie = readCookie("SEOCPC");
	
	var tmpURL = window.location.href;
	var tmpCPC = tmpURL.split("?");
	if (tmpCPC.length == 2) {
		var tmpParams = tmpCPC[1].split("&");
		for (i = 0; i < tmpParams.length; i++) {
			tmpSplit = tmpParams[i].split("=");
			if (tmpSplit[0] == "WT.sp") {
				tmpSrc = tmpSplit[1];
			}
			if (tmpSplit[0] == "kw") {
				tmpKw = tmpSplit[1];
			}
			if (tmpSplit[0] == "ad") {
				tmpAd = tmpSplit[1];
			}
			if (tmpSplit[0] == "mkwid") {
				tmpKw = tmpSplit[1];
			}
			if (tmpSplit[0] == "pcrid") {
				tmpAd = tmpSplit[1];
			}
			if (tmpSplit[0].toLowerCase() == "aid") {
				tmpAID = tmpSplit[1];
			}
			if (tmpSplit[0].toLowerCase() == "pid") {
				tmpPID = tmpSplit[1];
			}
			if (tmpSplit[0].toLowerCase() == "sid") {
				tmpSID = tmpSplit[1];
			}
			if (tmpSplit[0].toLowerCase() == "psid") {
				tmpSID = tmpSplit[1];
			}
		}
	}
	
	if ((tmpCPCCookie.indexOf("cj935") >= 0) || (tmpCPCCookie.indexOf("ls936") >= 0)) {
	    if (tmpSrc.indexOf("cj") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("ls") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	} else {
	    if (tmpSrc.indexOf("google") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
		if (tmpSrc.indexOf("GG") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("g827") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("GPEO") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
		if (tmpSrc.indexOf("BPEO") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
		if (tmpSrc.indexOf("BA") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
		if (tmpSrc.indexOf("b826") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("emedia937") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("msn") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("bing") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("yahoo") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("APA") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("ask") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("bdc") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("bz") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("cj") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("godaddy") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("LK") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
		if (tmpSrc.indexOf("ls") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("spages") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("wikipedia") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	    if (tmpSrc.indexOf("ypages") >= 0) {
	        writeCookie("SEOCPC",tmpCPC[1]);
	    }
	}
}

function writeCookie(name, value)
{
	var expDays = 90;
	var expDate = new Date();
	expDate.setTime (expDate.getTime() + (expDays*24*60*60*1000));
	var selPath = "/";
	
	var argv = writeCookie.arguments;
	var argc = writeCookie.arguments.length;
	
//    var currSite = location.href;
//    if ((currSite.indexOf("localhost") == 7) || (currSite.indexOf("smallbusinessimp") == 7)) {
//        var selDomain="wwwimp.paychex.com";
//    } else {
//        var selDomain="www.paychex.com";
//    }
    selDomain = "paychex.com";
    
	var clicksrc = (argc > 1) ? argv[1] : null;
	
	document.cookie = name + "=" + escape (value) + "; expires=" + expDate.toGMTString() + "; path=" + selPath + "; domain=" + selDomain +
		((clicksrc == null) ? "" : ("; clicksrc=" + clicksrc));
}
	
function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

