/***** Gestion des cookies ********************************/

// Taille Maximum d'un cookie
var COOKIE_MAX_SIZE = 3500;

var d = new Date();
var COOKIE_UNLIMITED_MEMO = new Date(d.getTime() + 3E11);


function Cookie_Ajouter(nom, valeur, expiration) {
    if (isDiffusion) {
	document.cookie = nom + "=" + escape (valeur) + ((expiration) ? "; expires=" + expiration.toGMTString() : ";") + "; path=/";
    }
    else {
	context.cookies.set(nom,valeur);
    }
}

function Cookie_Supprimer(nom) {
    if (isDiffusion) {
	if (Cookie_Existe(nom)) {
	    document.cookie = nom + "=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/";
	}
    }
    else {
	context.cookies.set(nom,"");
    }
}

function Cookie_Valeur(nom) {
    if (isDiffusion) {
	var arg = nom + "=";
	var result = "";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)  {
	    var j = i + alen;
	    if (document.cookie.substring(i, j) == arg) {
		var endstr = document.cookie.indexOf (";", j);
		if (endstr == -1)
		    endstr = document.cookie.length;
		result = unescape(document.cookie.substring(j, endstr));
	    }
	    i = document.cookie.indexOf(" ", i) + 1;
	    if (i == 0) break;
	}
	return result;
    }
    else {
	return context.cookies.get(nom);
    }
}


function Cookie_Existe(nom) {
    if (isDiffusion) {
	var arg = nom + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
	    var j = i + alen;
	    if (document.cookie.substring(i, j) == arg)
		return true;
	    i = document.cookie.indexOf(" ", i) + 1;
	    if (i == 0) break;
	}
	return false;
    }
    else {
	return context.cookies.get(nom) != "";
    }
}

function AreCookiesEnabled() {
    if (!isDiffusion) {
	return true;
    }
    else {
	if (document.all) {
	    if (window.navigator.cookieEnabled)
		return true;
	}
	else {
	    var strTest = "#this is a test to know if cookie are enabled#";
	    exp = new Date();
	    exp.setTime(exp.getTime() + (86400 * 1000 * 30));
	    setCookie("testCookieEnabled",strTest,exp);
	    var cookieTest = getCookie("testCookieEnabled");
	    if (strTest == cookieTest)
		return true;
	}
	return false;
    }
}
