//Function to calculate difference of time when visitor first visit the page and leave
function log() {
var URL = escape(document.referrer)
var URL1 = escape(document.domain)

   logged = new Image();
   var link = 'http://www.webmastersdesk.com/control/traffic/log.php?referrer=' + URL +'&cookie=' + cookieid +'&website=' + URL1 ;  
   logged.src = link
   //document.write(link)
   //alert(1)
   //alert(startt)
   //alert(endt)
} 

//Function To get Expiry date for cookie
function getexpirydate( nodays){
var UTCstring;
Today = new Date();
nomilli=Date.parse(Today);
Today.setTime(nomilli+nodays*24*60*60*1000);
UTCstring = Today.toUTCString();
return UTCstring;
}

//Function Set Cookie
function setcookie(name,value,duration){
cookiestring=name+"="+escape(value)+";EXPIRES="+getexpirydate(duration);
document.cookie=cookiestring;
}

//Function to get cookie
function getcookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

//Function To Check if Cookie present, if not then set a new cookie
function readcookie() {
if (!getcookie("logging"))
{
//Generate Random Number as Cookie ID
var randomnumber=Math.floor(Math.random()*1000000001)
setcookie("logging",randomnumber,"30");
}
cookieid = getcookie("logging")
return cookieid
}

