// Date/Time Methods

function GetTodayPlusDaysAsDate(days)
{
  // One day = (24 hours * 60 minutes * 60 seconds * 1000 milliseconds).
  return new Date(new Date().getTime() + (days * 24 * 60 * 60 * 1000));
}

// Cookie Methods

// See
//   http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/properties/cookie.asp
// for a good description of the actual structure of a cookie.

function SetCookie(name, value, expirationDate)
{
  document.cookie = name + "=" + escape(value) + "; expires=" + expirationDate.toGMTString() + ";";
}

function GetCookie(name /* required */ , subName /* optional*/ )
{
  // Cookies are separated by a semicolon and a space.
  var cookies = document.cookie.split("; ");

  for (var i = 0; i < cookies.length; i++)
  {
    // A name/value pair (a crumb) is separated by an equal sign.
    var crumb = cookies[i].split("=");

    if (name == crumb[0])
    {
      // Check if the caller wants the "sub" value of a ASP.Net multivalued cookie.
      if (arguments.length == 1)
        return unescape(crumb[1]);
      else
      {
        // The name/value pairs in a multivalued cookie are separated by an ampersand.
        var miniCrumbs = crumb[1].split("&");
        for (var j = 0; j < miniCrumbs.length; j++)
        {
          if (subName == miniCrumbs[0])
            return unescape(miniCrumbs[1]);
        }
      }
    }
  }

  // A cookie with the requested name does not exist.
  return null;
}

function DeleteCookie(name, value)
{
  // Delete a cookie by setting its expiration date to sometime in the past.
  // The browser will see this and will not send the cookie to the server.
  document.cookie = name + "=" + escape(value) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
}

