/**
 * <p>Title: cookies.js</p>
 * <p>Description: Collection of cookie management tools.</p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: Kreber Graphics, Inc.</p>
 * @author Charlie Reading
 *
 * NOTE: THIS IS LARGELY BASED ON BILL DORTCH'S COOKIE FUNCTIONS!!!
 */

//  Cookie Functions -- "Night of the Living Cookie" Version (25-Jul-96)
//
//  Written by:  Bill Dortch, hIdaho Design <bdortch@hidaho.com>
//  The following functions are released to the public domain.


// Includes
var cookies_js = 1;
var includes = "";
if (includes != "")
{
	alert("cookies.js: you must first include:\n" + includes);
}


var Cookies =
{
	// Checks if cookies can be set at all
	hasCookies: function()
	{
	},
	
	// Get the specified cookie -- returns null if not found
	getCookie: function(name)
	{
		var arg = name + "=";
		var alen = arg.length;
		var cookies = document.cookie;
		var clen = cookies.length;
		var i = 0;
		while (i < clen)
		{
			var j = i + alen;
			if (cookies.substring(i, j) == arg)
			{
				return Cookies._getValue(j);
			}
			i = cookies.indexOf(" ", i) + 1;
			if (i == 0)
			{
				break;
			}
		}
		return null;
	},
	
	// Create/Update the specified cookie
	setCookie: function(value,name,expires,path,domain,secure)
	{
		document.cookie = name + "=" + escape(value)
				+ ((expires) ? "; expires=" + expires.toGMTString() : "")
				+ ((path) ? "; path=" + path : "")
				+ ((domain) ? "; domain=" + domain : "")
				+ ((secure) ? "; secure" : "");
	},
	
	// Delete the specified cookie.
	deleteCookie: function(name,path,domain)
	{
		if (this.getCookie(name))
		{
    	document.cookie = name + "="
					+ ((path) ? "; path=" + path : "")
					+ ((domain) ? "; domain=" + domain : "")
					+ "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
		}
	},
	
	// Get the actually cookie value from the "offset"
	_getValue: function(offset)
	{
		var endstr = document.cookie.indexOf (";", offset);
		if (endstr == -1)
		{
			endstr = document.cookie.length;
		}
		return unescape(document.cookie.substring(offset, endstr));
	}
}
