1// Cookie API  v1.0.1
2// documentation: http://www.dithered.com/javascript/cookies/index.html
3// license: http://creativecommons.org/licenses/by/1.0/
4// code (mostly) by Chris Nott (chris[at]dithered[dot]com)
5
6
7// Write a cookie value
8function setCookie(name, value, expires, path, domain, secure) {
9	var curCookie = name + '=' + escape(value) + ((expires) ? '; expires=' + expires.toGMTString() : '') + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + ((secure) ? '; secure' : '');
10	document.cookie = curCookie;
11}
12
13
14// Retrieve a named cookie value
15function getCookie(name) {
16	var dc = document.cookie;
17
18	// find beginning of cookie value in document.cookie
19	var prefix = name + "=";
20	var begin = dc.indexOf("; " + prefix);
21	if (begin == -1) {
22		begin = dc.indexOf(prefix);
23		if (begin != 0) return null;
24	}
25	else begin += 2;
26
27	// find end of cookie value
28	var end = document.cookie.indexOf(";", begin);
29	if (end == -1) end = dc.length;
30
31	// return cookie value
32	return unescape(dc.substring(begin + prefix.length, end));
33}
34
35
36// Delete a named cookie value
37function deleteCookie(name, path, domain) {
38	var value = getCookie(name);
39	if (value != null) document.cookie = name + '=' + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + '; expires=Thu, 01-Jan-70 00:00:01 GMT';
40	return value;
41}
42
43
44// Fix Netscape 2.x Date bug
45function fixDate(date) {
46	var workingDate = date;
47	var base = new Date(0);
48	var skew = base.getTime();
49	if (skew > 0) workingDate.setTime(workingDate.getTime() - skew);
50	return workingDate;
51}
52
53
54// Test for cookie support
55function supportsCookies(rootPath) {
56	setCookie('checking_for_cookie_support', 'testing123', '', (rootPath != null ? rootPath : ''));
57	if (getCookie('checking_for_cookie_support')) return true;
58	else return false;
59}