var timeout="15768000";		// set timeout in seconds (6 months)
function trackme(trackloc) {
  var tracker_host="http://replaymachines.com";
  var pathstr = "domain=stanford.edu; path=~sbansal";
  //var tracker_host="http://localhost";
  //var pathstr = "path=/";
  var curdate = new Date();
  var expdate = new Date(curdate.getTime() + (timeout*1000));
  var cookstr = "; expires=" + expdate.toGMTString() + "; " + pathstr;
  //var locstr = "location=" + document.location;
  var refstr = "referrer=" + document.referrer;
  var visitorId = getVisitorId();
  //document.cookie = locstr + cookstr;
  document.cookie = refstr + cookstr;
  document.cookie = visitorId + cookstr;
  //document.write(document.cookie);
  //the following line deletes the cookie <cookiename>
  //document.cookie = "__utma=afd; expires=Fri, 27 Jul 2001 02:47:11 UTC; path=/";

  var i = new Image(1,1);
  if (typeof trackloc == 'undefined') {
    i.src = tracker_host + "/tracker.html?"+visitorId+"&"+refstr;
  } else {
    i.src = tracker_host + "/tracker.html?"+visitorId+"&"+refstr+"&"+trackloc;
  }
  i.onload=function() { voidfn(); }
}
function getVisitorId() {
  //read document.cookie to obtain visitor id. If we cannot find a
  //visitor Id, simply generate a random number.
  var ret = readCookie("visitorId");
  if (ret == null) return ("visitorId="+Math.round(Math.random()*2147483647));
  return "visitorId="+ret;
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  }
  return null;
}
function voidfn() { return; }
