//  Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)
//
//  Written by:  Bill Dortch, hIdaho Design <bdortch@hidaho.com>
//  The following functions are released to the public domain.
//
// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
//
//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to SetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!
//
function fixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
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;
}
//
//  Function to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//
function setCookie (name,value,expires) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "")
}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//
function deleteCookie (name) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
//
// function to show new/updated if change is recent
//
function chkR(theDate, nu) {
	var days = 14;	// number of days after change date to display the image
	var today = new Date();
	fixCookieDate(today);
// First check if Last Visit cookie before date of change
	if (LastVisit && (LastVisit <= Date.parse(theDate) + 24*60*60*1000)) {
		if (nu == "N") {
			document.write('<img src="new2u.gif" height=16 width=56 border=0 alt="New since your last visit">');
		} else {
			document.write('<img src="new2u.gif" height=16 width=56 border=0 alt="Updated since your last visit">');
		}
	} else {
// If not, check date of change less than n days ago
		if (Date.parse(theDate) > today.valueOf() - (days*24*60*60*1000)) {
			if (nu == "N") {
				document.write('<img src="new.gif" height=16 width=39 border=0 alt="New">');
			} else {
				document.write('<img src="updated.gif" height=16 width=67 border=0 alt="Updated recently">');
			}
		}
	}
}
//
// Check and reset the cookie
//
function checkCookie() {
	var lv = getCookie(thisScript + "lv");
	var today = new Date();
	fixCookieDate(today);
	var expdate = new Date();
	fixCookieDate(expdate);
	expdate.setTime(expdate.getTime() + (365 * 24 * 60 * 60 * 1000)); //  expires 1 year from now 
	setCookie(thisScript + "lv", Date.parse(today), expdate);
	return lv;
}	
// Always identify script name
var thisURL=window.location.pathname;
var thisScript=thisURL.substring(thisURL.lastIndexOf("/")+1, thisURL.indexOf("."));
// Always set LastVisit to the value of the lv Cookie
var LastVisit=checkCookie();


