// ***************************************************************
// * setCookie function                                          *
// ***************************************************************
// * name         - name of the cookie                           *
// * value        - value of the cookie                          *
// * [expires]    - expiration date of the cookie                *
// * [path]       - path for which the cookie is valid           *
// * [domain]     - domain for which the cookie is valid         * 
// * [secure]     - Boolean value indicating if the cookie       *
// *                transmission requires a secure transmission  *
// ***************************************************************

function setCookie(name, value, expires, path, domain, secure) 
{
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// ***************************************************************
// * getCookie function                                          *
// ***************************************************************
// * name         - name of the cookie                           *
// *-------------------------------------------------------------*
// * returns string containing value of specified cookie or null *
// * if cookie does not exist                                    *
// ***************************************************************

function getCookie(name) 
{
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) 
  {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } 
  else begin += 2;

  var end = document.cookie.indexOf(";", begin);
  if (end == -1) end = dc.length;

  return unescape(dc.substring(begin + prefix.length, end));
}

// ***************************************************************
// * deleteCookie function                                       *
// ***************************************************************
// * name         - name of the cookie                           *
// * [path]       - path for which the cookie is valid           *
// * [domain]     - domain for which the cookie is valid         * 
// *-------------------------------------------------------------*
// * returns string containing value of specified cookie or null *
// * if cookie does not exist                                    *
// ***************************************************************

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// ***************************************************************
// * setUserName function                                        *
// *-------------------------------------------------------------*
// * Used to reset the username cookie                           *
// ***************************************************************

function rememberUserName()
{
  var now = new Date();
  now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);

  var username = document.myform.UserName.value;

  if (username) {
    setCookie("username", username, now);
  }
}

