// -----------------------------------------------------------------------------

function SetCookie_ExpirationDate(
            c_cookie_name,
            c_cookie_value,
            date_of_expiration) {
// Purpose :
//    The following function sets a cookie value.
// Input :
//    c_cookie_name :  Cookie name.
//    c_cookie_value :  Cookie value.
//    date_of_expiration :  Expiration date.
// Output :
//    <Return value> :  None.
// Note :
//    Notes on cookies...
//       Cookies are a mechanism for storing persistent data on the client
//          in a file called cookies.txt
//       Each cookie is a small item of information with an optional expiration date
//       and is added to the cookie file in the following format:
//          name=value;expires=expDate;
//       Where :
//          name is the name of the datum being stored
//          value is its value.
//          expDate is the expiration date, in GMT date format:
//             Wdy, DD-Mon-YY HH:MM:SS GMT
//       If name and value contain any semicolon, comma, or blank (space) characters,
//          you must use the escape() to encode them and unescape() to decode them.
// Author :  Jerome Daoust, 1999/10/22.

   var c_tmp = new String("")
   c_tmp = c_cookie_name
         + "="
         + escape( c_cookie_value)
   if ( null != date_of_expiration ) {
      c_tmp += "; expires=" + date_of_expiration.toGMTString()
   }

   document.cookie = c_tmp
}
// -----------------------------------------------------------------------------

function SetCookie_DaysValid(
            c_cookie_name,
            c_cookie_value,
            days_to_expiration) { 
// Purpose :
//    The following function sets a cookie value.
// Input :
//    c_cookie_name :  Cookie name.
//    c_cookie_value :  Cookie value.
//    days_to_expiration :  Quantity of days before expiration.
// Output :
//    <Return value> :  None.
// Note :
//    For understanding what a "cookie" is, see notes in SetCookie().
// Author :  Jerome Daoust, 1999/10/22.

   if ( days_to_expiration < 10 ) {
      alert( "( days_to_expiration < 10 ) in SetCookie_DaysValid()")
   }

   var date_today = new Date()
   var date_expiration = new Date()

   // Set the cookie with an expiration date
   seconds_to_expiration = 60 * 60 * 24 * days_to_expiration
   date_expiration.setTime( date_today.getTime() + seconds_to_expiration)
   SetCookie_ExpirationDate( c_cookie_name, c_cookie_value, date_expiration)
}
// -----------------------------------------------------------------------------

function GetCookie(
            c_cookie_name) {
// Purpose :
//    The following function returns a cookie value, given the name of the cookie.
// Input :
//    c_cookie_name :  Cookie name.
// Output :
//    <Return value> :
//       if found :  Value of the cookie.
//       "", if not found. 
// Note :
//    For understanding what a "cookie" is, see notes in SetCookie().
// Author :  Jerome Daoust, 1999/10/22.

   // Set output value.
   var c_return_val = ""

   var c_search = c_cookie_name + "="

   // Look for existence of cookies.
   if ( 0 < document.cookie.length ) {
      // There are cookies.

      // Try to locate the specific cookie.
      offset = document.cookie.indexOf( c_search) 
      if ( -1 != offset ) {
         // The cookie exists.

         // set index of beginning of value
         offset += c_search.length

         // set index of end of cookie value
         end = document.cookie.indexOf(";", offset) 
         if (end == -1) end = document.cookie.length

         // Return the cookie's value.
         c_return_val = unescape( document.cookie.substring( offset, end) )
      } 
   }

   return c_return_val
}
// -----------------------------------------------------------------------------

