
// Cookies etc. (c) 2000, 2001 KO Development, Seattle, WA
// Author: Owen Reddecliffe, ko.development@gte.net
//

var tupSession = "TUPSession"; // Thumbs up session cookie

//
//  Function to return the value of the cookie specified by "name".
//
function GetCookie (name) {
  var arg = name + "=";
  var cookies = document.cookie;
  var end, start = cookies.indexOf(arg);
  if (start < 0) return null;
  start += arg.length;
  end = cookies.indexOf(";", start);
  if (end < 0) end = cookies.length;
  return unescape(cookies.substring(start, end));
}


//
//  Function to give correct basic date
//
function NewDate (v) {
  var rs = ((v == null)? new Date(): new Date(v));     // today
  var base = new Date(0);  // base time - should be zero
  rs.setTime(rs.getTime() - base.getTime()); // allow for mac bug
  return rs;
}

// 
// Functions returns an expiry date string life days beyond the present, 
// with an appropriate prefix
function ExpDate(life, pref)
{
   if ((life == null)) return "";
   var prefix = ((pref == null)? "; expires=": pref);
   var exp = NewDate();
   exp.setTime(exp.getTime() + (life * 24 * 60 * 60 * 1000));
   return prefix + exp.toGMTString();
}

//
//  Function to create or update a cookie.
//
function SetCookie (name,value,life,path,domain,secure) {
  var txt = name + "=" + escape (value) + ExpDate(life) +
    ((path != null) ? "; path=" + path : "") +
    ((domain != null) ? "; domain=" + domain : "") +
    ((secure != null) ? "; secure" : "");
    document.cookie = txt;
}

//
//  Function to delete a cookie. 
//
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path != null) ? "; path=" + path : "") +
      ((domain != null) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

