/******************************************************
 *Cookie Functions by Bryan English 11-3-00
 ******************************************************/


//*GLOBALS**********************************************
var seconds = 1000,
    minutes = 60 * 1000,
    hours   = 60 * 60 * 1000,
    days    = 24 * 60 * 60 * 1000,
    weeks   = 7 * 24 * 60 * 60 * 1000,
    months  = 30 * 24 * 60 * 60 * 1000;

//*COOKIE FUNCTIONS*************************************


/************************************
 *This returns the value of a cookie
 *by the name of "cookieName"
 ************************************/
function getCookie(cookieName)
   {
   var cookieBeg, cookieEnd;
   var cookieJar = document.cookie;
   
   //look for the cookie//
   cookieBeg = cookieJar.indexOf(cookieName,0);
   if(cookieBeg < 0)return null;
   else cookieBeg +=  cookieName.length + 1;
   
   //get value of cookie//
   cookieEnd = cookieJar.indexOf(";",cookieBeg);
   if(cookieEnd < 0)cookieEnd = cookieJar.length;

   //alert (unescape(cookieJar.substring(cookieBeg,cookieEnd)));
   
   //return value of cookie//
   return unescape(cookieJar.substring(cookieBeg,cookieEnd));

   }


/***********************************
 *This sets a cookie with all the
 *available properties
 ***********************************/
function setCookie(name,value,expires,path,domain,secure)
   {
   var theDate = new Date();
   theDate.setTime(theDate.getTime() + expires);
   var expCrumb = ((expires == null) ? "" : ("; expires=" + theDate.toGMTString()));
   var pathCrumb = ((path == null) ? "" : ("; path=" + path));
   var domainCrumb = ((domain == null) ? "" : ("; domain=" + domain));
   var secureCrumb = ((secure == true) ? "; secure" : "");
   document.cookie = name + "=" + escape(value) + expCrumb + pathCrumb + domainCrumb + secureCrumb;
   }


/***********************************
 *This is an easy why to set a cookie
 ***********************************/
function setQuickCookie(name,value)
   {
   document.cookie = name + "=" + escape(value);
   }


/***********************************
 *This deletes a cookie
 ***********************************/
function trashCookie(cookieName)
   {
   setCookie(cookieName,"deleteMe",-1 * weeks)
   }


/***********************************
 *This updates a cookie if it exists
 ***********************************/
function touchCookie(name,expires)
   {
   if(getCookie(name) == null)return;
   var theDate = new Date();
   theDate.setTime(theDate.getTime() + expires);
   var expCrumb = ((expires == null) ? "" : ("; expires=" + theDate.toGMTString()));
   document.cookie = name + "=" + escape(getCookie(name)) + expCrumb;
   }
