// Cookies
// JavaScript for handling cookies

// Gets the data associated with the specified cookie name
// Returns null if the cookie isn't found
function GetCookie(Name)
{
	var Response = null;
	var Cookie = " " + window.document.cookie + ";";
	var Str = " " + Name + "=";
	var Start = Cookie.indexOf(Str);
	var End;

	if(Cookie!=" ;" && Start>=0)
	{
		Start += Str.length;			// Skip cookie name
		End = Cookie.indexOf(";", Start);
		Response = unescape(Cookie.substring(Start, End));	// Converts from Hex to ASCII
	}

	return(Response);
}

// Sets the data associated with the specified cookie name
function SetCookie(Name, Value)
{
	window.document.cookie = Name + "=" + escape(Value);    // Converts from ASCII to Hex
}

// Sets the data associated with the specified cookie name as well as the expiry date
//function SetCookie(Name, Value, ExpiryDays)
//{
//	window.document.cookie = Name + "=" + escape(Value) + "; expires=" + GetDate(ExpiryDays);
//}

// Deletes the specified cookie
function DeleteCookie(Name)
{
	window.document.cookie = Name + "=0; expires=" + GetDate(-3);
}

// Gets the date of the the specified number of days from today (which can be negative)
// It is used for cookie expiration dates
function GetDate(Days)
{
	Today = new Date();
	Today.setTime(Today.getTime() + (Days * 24 * 60 * 60 * 1000));
	return(Today.toLocaleString());
}
