var today = new Date();
var expiry = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000);
var data = getData();
var ref = getRef();
var id = getID();
var count = getCount();
document.cookie ="date="+(data)+"; path=/; expires="+expiry.toGMTString(); // first visit time
document.cookie ="ref="+(ref)+"; path=/; expires="+expiry.toGMTString(); // ref
document.cookie ="id="+(id)+"; path=/; expires="+expiry.toGMTString(); // user id
document.cookie ="count="+(count)+"; path=/; expires="+expiry.toGMTString(); // page visited

function getData() {
var data = GetCookie('date');
if(data == null) {
var day = today.getDate()+"/";
var month = today.getMonth()+"";
data = day+month;
}
return data;
}

function getRef() {
var ref = GetCookie('ref');
if(ref == null) {
ref = document.referrer;
}
return ref;
}

function getID() {
var id = GetCookie('id');
if(id == null) {
id = today.getTime();
}
return parseInt(id);
}

function getCount() {
var count = GetCookie('count');
if(count == null) {
return 1;
}
else {
var newcount = parseInt(count) + 1;
return newcount;
}
}

function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}
