//*****************************************************************************
// File:    /_generic/code/js/cookies.js
// Purpose: This file has the library of cookies javascript functions.
// Functions
// ----------------------------------------------------------------------------
// setCookie(strName, strValue) - sets a cookie.
// getCookie(strName) - gets a cookie's value.
// delCookie(strName) - deletes a cookie.
//*****************************************************************************
// Author   Date       Comments
// -------- ---------- --------------------------------------------------------
// JGP/V    2003.03.28 Creation of the file.
//*****************************************************************************

/******************************************************************************
'Function: setCookie()
'Purpose:  This function sets a cookie.
'Inputs:   strName - cookie's name;
'          strValue - value associated to the cookie.
'Returns:  nothing.
'******************************************************************************
' Author   Date       Comments
' -------- ---------- ---------------------------------------------------------
' JGP/V    2003.03.28 Creation of the function.
******************************************************************************/
function setCookie(strName, strValue)
{
  dteNow = new Date();
  dteNow.setTime(dteNow.getTime() + 365*24*60*60*1000);
  document.cookie = strName + "=" + escape(strValue) + "; expires="
                  + dteNow.toGMTString();
}

/******************************************************************************
'Function: getCookie()
'Purpose:  This function gets a cookie value.
'Inputs:   strName - cookie's name.
'Returns:  The cookie's value..
'******************************************************************************
' Author   Date       Comments
' -------- ---------- ---------------------------------------------------------
' JGP/V    2003.03.28 Creation of the function.
******************************************************************************/
function getCookie(strName)
{
  // cookies are separated by semicolons
  var astrCookie = document.cookie.split("; ");
  for (var i = 0; i < astrCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var astrCrumb = astrCookie[i].split("=");
    if (strName == astrCrumb[0]) return unescape(astrCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

/******************************************************************************
'Function: delCookie()
'Purpose:  This function deletes a cookie.
'Inputs:   strName - cookie's name.
'Returns:  nothing.
'******************************************************************************
' Author   Date       Comments
' -------- ---------- ---------------------------------------------------------
' JGP/V    2003.03.28 Creation of the function.
******************************************************************************/
function delCookie(strName)
{
  document.cookie = strName + "=null;";
}

