// cookie.js
/*
This script contains 3 Javascript functions 1) setCookie() 2) getCookie() 3) deleteCookie()
USAGE:
1) setCookie("name", value, days, hours, minutes, makePersistent);
where:	name = name of cookie to be set
	value = value to be recorded against cookie name
	days = number of days until cookie expires (can be 0)
	hours = number of hours until cookie expires (can be 0)
	minutes = number of minutes until cookie expires (can be 0)
	makePersistent = if set to 0, cookie will dropped at end of session
			 if set to 1, cookie will be stored according to time period specified
NOTES: values for time must be entered even if they are 0.
       if value = the string "now" the current time string will be recorded, this is useful for recording
       the date and time of a visit. It is stored in default format for use in comparisons when retrieved.

2) getCookie("name") will return the value recorded against a cookie on this domain with the specified name.
   Should be used as per this example: var userName = getCookie("userName");

3) deleteCookie("name") resets the expiry date of a cookie with the specified name to a point in the past
   the value is also reset to 0 because the value will not be forgotten until the end of the current session
*/

var today = new Date();
var rightNow = new Date(today.getTime());
var expiry = 0;
function setCookie(name, value, dys, hrs, mins, makePersistent)
{
var futureTime = dys * 24 + hrs * 60 + mins * 60000;
if (value == "now")
{
  value = rightNow;
}
  if (value != null && value != "")
  {
    if (makePersistent == 1)
    {
      today = new Date();
      expiry = new Date(today.getTime() + futureTime)
      document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
    }
    else
    {
      document.cookie=name + "=" + escape(value);
    }
  }
}

function getCookie(name) // use: getCookie("name");
{
  var index = document.cookie.indexOf(name + "=");
  if (index == -1)
  {
    return null;
  }
  index = document.cookie.indexOf("=", index) + 1;
  var endstr = document.cookie.indexOf(";", index);
  if (endstr == -1)
  {
    endstr = document.cookie.length;
  }
return unescape(document.cookie.substring(index, endstr));
}

function deleteCookie(name) // use: deleteCookie("name");
{
  document.cookie=name + "=0; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
