var d = new Date();
var id = CookieRead();
var myCookie = "";
var randomnumber = "";

function Cookie(document, name, days, path, domain, secure) {
    this.$doc = document
    this.$name = name
    if (days) this.$expiration = new Date((new Date()).getTime()+days*86400000); 
    	else this.$expiration = null
    if (path) this.$path   = path;                                             
	else this.$path       = null
    if (domain) this.$domain = domain;                                           
	else this.$domain     = null
    if (secure) this.$secure = true;                                             
	else this.$secure     = false
}

function CookieWrite() {
    var cookieval=""

    randomnumber = Math.floor(Math.random()*50) //a random integer between 0 - 49

    var cookie = this.$name + "=" + d.getTime() + randomnumber
    if (this.$expiration) cookie+='; expires=' + this.$expiration.toGMTString()
    if (this.$path)       cookie+='; path='    + this.$path
    if (this.$domain)     cookie+='; domain='  + this.$domain
    if (this.$secure)     cookie+='; secure'

    this.$doc.cookie=cookie
}

function CookieRead() {
    var re = /keeca_freeStats=(\d+)/;
    var a = re.exec(document.cookie);
    return a==null?'':a[1];
}


new Cookie()
Cookie.prototype.write = CookieWrite
//alert("old id = " + id);

if (id == '') {
    myCookie = new Cookie(document,"keeca_freeStats", 10*365, "/"); 	//cookie name = keeca_freeStats
									//expiration  = 10 years
									//path        = "/", client site root
    myCookie.write(); 
}

//alert("new id = " + CookieRead());

document.write("<img width=0 height=0 src='http://loyalty.keeca.com/loyalty/BehaviorCollector?" + d.getTime() + "&referrer="+escape(document.referrer)+"&cid="+CookieRead()+ "&url=" + escape(document.URL) + "'>");

