/* Copyright (c) 2008 by FUNIX.NL. All rights reserved.
 * $Id: cookies.js,v 1.1 2009/10/27 07:58:44 raymond Exp $
 */

// create a cookie with the given name and value and the expire time in days
function createCookie(aName, aValue, aDays)
{
	var lExpires = '';
	if (aDays) {
		var lDate = new Date();
		lDate.setTime(lDate.getTime() + (aDays * 24 * 60 * 60 * 1000));
		var lExpires = "; expires=" + lDate.toGMTString();
	}
	document.cookie = aName + "=" + aValue + lExpires + "; path=/";
}


// read a cookie with the given name
function readCookie(aName)
{
	var aNameEQ = aName + '=';
	var aCookieData = document.cookie.split(';');
	for (var i = 0; i < aCookieData.length; i++) {
		var lData = aCookieData[i];
		while (lData.charAt(0) == ' ') lData = lData.substring(1, lData.length);
		if (lData.indexOf(aNameEQ) == 0) return lData.substring(aNameEQ.length, lData.length);
	}
	return null;
}


// erase a cookie with the given name
function eraseCookie(aName)
{
	createCookie(aName, '', -1);
}


