var cen_ref = document.referrer;
var cen_thisDomain = document.domain;
var cen_enteredSiter = new Date();
var cen_key = "";
var cen_all = "";
var cen_prev = "";
var cen_new = "";
var cen_thisDomainClean = "";
var cen_thisDomainDotIndex = cen_thisDomain.indexOf(".");
var cen_Path = "lp=" + window.location.pathname;




cen_localTime = cen_enteredSiter.getTime();
cen_localOffset = cen_enteredSiter.getTimezoneOffset() * 60000;
cen_utc = cen_localTime + cen_localOffset;
cen_offset = 0;   
cen_fltz = cen_utc + (3600000*cen_offset);

cen_GMTDateTime = new Date(cen_fltz);

cen_month = cen_GMTDateTime.getMonth() + 1;

cen_year = cen_GMTDateTime.getYear();

if (cen_year < 2000) {
	cen_year += 1900;
	}

cen_enteredSite =  "GMT@" + cen_month + "/" + cen_GMTDateTime.getDate() + "/" +  cen_year;

cen_hours = cen_GMTDateTime.getHours();
if (cen_hours < 10) {cen_hours = "0" + cen_hours; }

cen_minutes = cen_GMTDateTime.getMinutes();
if (cen_minutes < 10) {cen_minutes = "0" + cen_minutes; }

cen_seconds = cen_GMTDateTime.getSeconds();
if (cen_seconds < 10) {cen_seconds = "0" + cen_seconds; }

cen_enteredSite += " " + cen_hours + ":" + cen_minutes + ":" + cen_seconds;




if (cen_thisDomain.substr(cen_thisDomainDotIndex) != ".com") {
		cen_thisDomainClean = cen_thisDomain.substr(cen_thisDomainDotIndex);
} else {
		cen_thisDomainClean = "." + cen_thisDomain;
	}



	

if (cen_ref == "") {cen_ref="dir";}


if (ReadCookie("ck").length > 1024) {
	SetCookie("ck",ReadCookie("ck").substr(0,1023),500,cen_thisDomainClean);
}

// if referrer is external site then do it
if (cen_ref.indexOf(cen_thisDomainClean) == -1) {

cen_ref = getDomain(cen_ref);



if (location.search != "")
{

	var x = location.search.substr(1).split("&")
	for (var i=0; i<x.length; i++)
	{
		var y = x[i].split("=");
			
		if (i > 0) { cen_key	+= "&" };
				
		cen_key += y[0] + "=" + y[1];
		
if (y[0] == "quote_trackSRC") {SetCookie("quote_trackSRC",y[1],21,cen_thisDomainClean);}
if (y[0] == "quote_trackSUB") {{SetCookie("quote_trackSUB",y[1],21,cen_thisDomainClean);}}
if (y[0] == "quote_trackADV"){{SetCookie("quote_trackADV",y[1],21,cen_thisDomainClean);}}
if (y[0] == "quote_trackV1"){{SetCookie("quote_trackV1",y[1],21,cen_thisDomainClean);}}
if (y[0] == "quote_trackV2"){{SetCookie("quote_trackV2",y[1],21,cen_thisDomainClean);}}
if (y[0] == "quote_trackV3"){{SetCookie("quote_trackV3",y[1],21,cen_thisDomainClean);}}
if (y[0] == "quote_trackV4"){{SetCookie("quote_trackV4",y[1],21,cen_thisDomainClean);}} 
if (y[0] == "quote_trackV5") {{SetCookie("quote_trackV5",y[1],21,cen_thisDomainClean);}}           
        
        			
	}
}	
	


	

	cen_utmz = ReadCookie("__utmz");
	


	cen_prev = ReadCookie("ck");
	
	
	
 
	
	
	if (cen_prev != "") {
		cen_prev += "^";
		} 
	
	cen_all = cen_ref + "|" + cen_key + "|" +  cen_enteredSite + "|" + cen_utmz + "|" + cen_Path;
	cen_new = cen_prev + cen_all;
	
	
	
	
	SetCookie("ck",cen_new,500,cen_thisDomainClean);
	
}	



function SetCookie(cookieName,cookieValue,nDays,dmain) {
	

	
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString()
                 + ";path=;domain=" + dmain;
   
                 
}


function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length;  
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}


function getDomain (thestring) {
var returnVal = "";
var urlpattern = new RegExp("(http|ftp|https)://(.*?)/.*$");
var parsedurl = thestring.match(urlpattern);

if (parsedurl != null) {
	returnVal = parsedurl[2];
	
	} else {
		returnVal = thestring;
		}

return returnVal;
}



