// 03/01/09  PATH always =/ . this way there is only one C, U, L ( i.e. site wide).     (_) what to do  re:letters/calendars
//                                                                seems like may need document specific cookie too(_)?
// bump  invoke via <script src=bump.js defer ></script>  path=document.location  7/17/06
// 03/02/08 setCookie L for new user since it will be geted, add bump to version, use mod 9000 when C >9999; 
//          chk Cnt sooner

function setCookie (name, value){  // 6 months =24 * 7 *26 = 4368 (about)   60*60 milliseconds
 var expDate = (new Date(      (new Date()).getTime()    +   4368*3600000)).toGMTString(); 
 document.cookie = name + "=" + value +  ";expires=" + expDate + ";path=/" ;
// did he accept a persistant cookie ?  nope a try session cookie (i.e. date=0)
if ( document.cookie == null ) { document.cookie = name + "=" + value + ";path=/"  }; // omit date     
}

function getCookieValue(name) {	//    or  .FALSE.
  var firstChar, lastChar;
  var CookieString = document.cookie;    // make it a string 
  firstChar  = CookieString.indexOf(name);  if(firstChar == -1) return false;
  firstChar += name.length + 1;
  lastChar = CookieString.indexOf(";", firstChar);
  if(lastChar == -1) lastChar = CookieString.length; 
                                                       // no ending ; so must be last n=v pair
  return CookieString.substring(firstChar, lastChar);  
}  	
	
var User, Cnt, LastVisit, now ;   //-------- bump counter & set lastvisit
now = new Date().getTime(); 
if(    !(  getCookieValue("U") )   ){  setCookie("U",now); setCookie("L",now); setCookie("C",0);  };  
                                        // new user; assign him U#### aka firstVisit
User= getCookieValue("U");   Cnt = getCookieValue("C"); 
LastVisit = getCookieValue("L"); // usable later in the HTML
if(isNaN(Cnt) ) {Cnt =1000; User=now; LastVisit=now;}; /* cnt is Junk? assume all junk How? */     
Cnt = parseInt( Cnt );  
if(Cnt>9999)     Cnt %= 9000;/* Junk? How? */     
Cnt++; 
setCookie("U",User );   // UserID is put back out with new expire         
setCookie("C",Cnt  );   // Cnt 
setCookie("L",now  );   // LastVisit 	(note that   var LastVisit is not now )
setCookie("V","bump_090301" );  // Version
//     ///  end of bump.js ///      ////// 
