// ** Functions for cookies!
// ** by Jim Reijers
// **
// ** Last update: 16 Sep 2004

function getExpiryDate(nrOfDays) {
	if (typeof nrOfDays == "undefined") nrOfDays = 365;
	var Today = new Date();
	Today.setTime(Date.parse(Today) + nrOfDays * 24 * 60 * 60 * 1000);
	return Today.toGMTString();
}

function getCookie(cookieName) {
	var allCookies = document.cookie;
	var indexStr = allCookies.indexOf(cookieName + "=");
	if (indexStr == -1) return null;
	indexStr = allCookies.indexOf("=", indexStr) + 1;
	var endStr = allCookies.indexOf(";", indexStr);
	if (endStr == -1) endStr = allCookies.length;
	return unescape(allCookies.substring(indexStr, endStr));
}

function setCookie(cookieName, cookieValue, nrOfDays) {
	var isSessionCookie = (typeof nrOfDays == "undefined" || nrOfDays == 0);
	if (typeof cookieValue != "undefined" && cookieValue != "") {
		var cookieString = cookieName + "=" + escape(cookieValue) + ";";
		if (!isSessionCookie) cookieString += "expires=" + getExpiryDate(nrOfDays);
		document.cookie = cookieString;
	}
}

function delCookie(cookieName) {
	document.cookie = cookieName + "=; expires=" + getExpiryDate(-1);
}