// Last modification : 05/12/2005.

/* Functions in this file :

	 f_checkCookie(name)
	 f_getCookie(name)
	 f_setCookie(name, value, expires)
	 f_deleteCookie(name)
	 f_isCookieEnabled()
*/

// --------------------------------------------------------------------------------
// CONSTANTS
// --------------------------------------------------------------------------------

var expDays = 365;
var expDate = new Date();
expDate.setTime(expDate.getTime() + (expDays*24*60*60*1000));


// --------------------------------------------------------------------------------
// f_checkCookie(name)
// --------------------------------------------------------------------------------
// Returns -1 when the cookie does not exist.

function f_checkCookie(cookieName) {
	var search = cookieName + "=";

	if (document.cookie.length > 0) {                   // at least 1 cookie exists
		offset = document.cookie.indexOf(search);

		if (offset != -1) {                               // the cookie exists
			return offset;
		} else {                                          // the cookie does not exist
			return -1;
		}
	}
}


// --------------------------------------------------------------------------------
// f_getCookie(name)
// --------------------------------------------------------------------------------
// Returns the value of the cookie.

function f_getCookie(cookieName) {
	var search = cookieName + "=";

	if (document.cookie.length > 0) {                   // at least 1 cookie exists
		offset = document.cookie.indexOf(search);

		if (offset != -1) {                               // the cookie exists
			offset += search.length;                        // start position of cookie value
			end = document.cookie.indexOf(";", offset);     // end position of cookie value

			if (end == -1) end = document.cookie.length;

			return unescape(document.cookie.substring(offset, end));
		}
	}
}


// --------------------------------------------------------------------------------
// f_setCookie(name, value, expires)
// --------------------------------------------------------------------------------
// Sets the cookie.

function f_setCookie(cookieName, cookieValue, cookieExpires) {
	if (cookieExpires != null) {
		var today = new Date();
		var expires = new Date();

		expires.setTime(today.getTime() + (60*60*24*1000*cookieExpires));
	}
	document.cookie = cookieName + "=" + escape(cookieValue) + ((cookieExpires == null) ? "" : ("; expires=" + expires.toGMTString()));
}


// --------------------------------------------------------------------------------
// f_deleteCookie(name)
// --------------------------------------------------------------------------------
// Delete the cookie.

function f_deleteCookie(name) {
	var expDate = new Date();
	expDate.setTime(expDate.getTime()-1);
	var cval = f_getCookie(name);
	document.cookie = name + "=" + cval + "; expires=" + expDate.toGMTString();
}


// --------------------------------------------------------------------------------
// f_isCookieEnabled()
// --------------------------------------------------------------------------------
// Returns true when cookies are enabled.
// Returns false when cookies are disabled.

function f_isCookieEnabled() {
	if (document.all) {
		if (!navigator.cookieEnabled) {
			// alert('Cookies disabled');
			return false;
		}
		else return true;
	}
	else {
		f_setCookie('temp', 'temp');
		var temp = f_getCookie('temp');
		if (!temp) {
			// alert('Cookies disabled');
			return false;
		}
		else return true;
	}
}
