// returns the value of the cookie, or null if the cookie does not exist
function readCookie( name )
{
	var start=document.cookie.indexOf(name+"=");
	var len=start + name.length + 1;
	if(!start && (name!=document.cookie.substring(0,name.length)))
	{
		return null;
	}
	if(start==-1)
	{
		return null;
	}
	var end=document.cookie.indexOf(";",len);
	if(end==-1)
	{
		end=document.cookie.length;
	}
	return unescape(document.cookie.substring(len,end));
}

//return true if successful, false otherwise
function createCookie( name, value, expires, path, domain, secure )
{
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date=new Date(today.getTime()+(expires));
	document.cookie=name+"="+escape( value ) +
		( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
return (null!==readCookie(name));
}

//return true if successful, false otherwise
function deleteCookie( name, path, domain )
{
	if(readCookie(name))
	{
		document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
return (null===readCookie(name));
}

/* why not use navigator.cookieEnabled?
 because firefox allows you to disable cookies globally and then create
 an "exceptions" list. Technically if your site is in your client's
 exception list, cookies are enabled. However, the navigator.cookieEnabled
 reports the global state only. Thus, a client's browser could be 
 accepting cookies from your site and yet the property above would
 indicate otherwise. Thus, the best cross-browser approach to detect
 cookies is to:
 	1. create a test cookie
	2. does the newly created test cookie exist?
		Yes: 
			delete the test cookie
			return true
		No:
			return false
*/
function cookieEnabled()
{
	if(createCookie("CookieTest","test",1,"/"))
	{
		deleteCookie("CookieTest","/");
		return true;
	}
return false;
}
