// Copyright 2003-9 Richard W. Adams

//----------------------------------------------------
function deleteCookie
(
	name, 	// Name of the cookie
	path, 	// Path of the cookie (must be same as path used to create cookie)
	domain	// Domain of the cookie (must be same as domain used to create cookie)
){
	if (getCookie(name))
	{
		document.cookie = name + "=" + 
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}
}
//----------------------------------------------------
function getAutostartCookie()
{
	return getCookie(AUTOSTART_COOKIE, "true")
}
//----------------------------------------------------
function getCookie(name, defaultValue)
{
	var cookieValue = defaultValue
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex != -1)
	{
		var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
		if (cookieEndIndex == -1)
			cookieEndIndex = document.cookie.length
		cookieValue = unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
	}
	return cookieValue
}
//----------------------------------------------------
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" : "")
	if ((name + "=" + escape(value)).length <= 4000)
		document.cookie = curCookie
	else
		if (confirm("Cookie exceeds 4KB and will be cut!"))
			document.cookie = curCookie
}
//----------------------------------------------------
function setPersistentCookie(name, value)
{
	var currentYear = new Date().getYear() + 1900 
	var expirationDate = new Date()
	expirationDate.setYear(currentYear + 1)
	setCookie(name, value, expirationDate)
}
//----------------------------------------------------
function setAutostartCookie(value)
{
	setPersistentCookie(AUTOSTART_COOKIE, value ? "true" : "false")
}
//----------------------------------------------------
