var cen_ref = document.referrer;
var cen_thisDomain = document.domain;
var cen_enteredSiter = new Date();
var cen_key = "";
var cen_all = "";
cen_all2 = "";
var cen_prev = "";
var cen_new = "";
var cen_new2 = "";
var cen_id = "";
var cen_thisDomainClean = "";
var cen_thisDomainDotIndex = cen_thisDomain.indexOf(".");
var cen_Path = "lp=" + window.location.pathname;
var cen_starter = new Date();
var cen_ajax = null;  




   





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 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);}}           
if (y[0] == "partner") {{SetCookie("partner",y[1],21,cen_thisDomainClean);}}         
        			
	}
}	
	
  
	cen_utmz = ReadCookie("__utmz");
	
     
    
	
// Deprecated start	
    if (ReadCookie("ck").length > 1024) {
    SetCookie("ck",ReadCookie("ck").substr(0,1023),500,cen_thisDomainClean);
}	
	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);
// Deprecated end 	
     
      
     
    cen_prev2 = ReadCookie("ck2");
    cen_all2 = cen_ref + "|" + cen_key + "|" +  cen_enteredSite + "|" + cen_utmz + "|" + cen_Path;
       
    
                 
    if (cen_prev2 != "") { 
        cen_id = ReadCookie("ckid"); 
        
      
        
        safeKeep(cen_all2,cen_id,cen_thisDomainClean);
    }  else {
     SetCookie("ck2",cen_all2,500,cen_thisDomainClean);    
    }
    
}	

function safeKeep(cValue,cid,DomainClean) {
  returncid = "";

            
               
          try{
    cen_ajax = new XMLHttpRequest();
    } catch (e){
    try{
    cen_ajax = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
    try{
    cen_ajax = new ActiveXObject("Microsoft.XMLHTTP");
    } catch (e){
    alert("Please use the site with a recent browser.");
    return false;
}
}
}

       

cen_ajaxQS = "/common_library/ajaxcookie.php?cookie=" + escape(cValue) + "&cid=" + cid + "&dom=" + DomainClean + "&ts="  + cen_starter.getTime();                   

cen_ajax.open("GET", cen_ajaxQS, true);
cen_ajax.onreadystatechange = handlecen_ajaxResponseText;
cen_ajax.send(null);
        

}



function handlecen_ajaxResponseText()
{
              
   
           if((cen_ajax.readyState == 4)&& (cen_ajax.status == 200))  
            {
               
          try{     
                
    cen_response = cen_ajax.responseText;
           
    
    var cen_responsesplit = cen_response.split("|");

    SetCookie("ckid",cen_responsesplit[0],500,cen_responsesplit[1]); 
     
  }    
      catch(e){
             }
              
 } 
  
 

          
  
}  


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;
   
   //  alert(cookieName);      
}


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;
}




