
function recordCookie(name) {
	// Vérifie que le cookie "name" n'est pas présent
	if (GetCookie(name)==null) {
		var pathname=location.pathname;
		var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
		var date_exp = new Date();
		date_exp.setTime(date_exp.getTime()+(1*3600*1000)); // 1 heure
		SetCookie(name,"ok",date_exp,myDomain);
		return true
	}else{
		return false;
	}
}

function ViderCookie(command,name) {
		var pathname=location.pathname;
		var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
		var date_exp = new Date();
		date_exp.setTime(date_exp.getTime()-(1000)); // Heure déjà expirée
		SetCookie(name,"",date_exp,myDomain);
		if(command){
			alert("Vous avez effacé le cookie.\n Vous pouvez recharger la page pour accéder à nouveau au service...");
		}
}

function SetCookie (name, value) {
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	var path=(argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=name+"="+escape(value)+
		((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
}

function getCookieVal(offset) {
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1)
      		endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
	var arg=name+"=";
	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 getCookieVal (j);
			i=document.cookie.indexOf(" ",i)+1;
			if (i==0) break;
		}
	return null;
	}
}
function addpopVisite(){ //incrémente le cookie à chaque click sur le pop
	var nb=0;
	if(GetCookie("pop_visite")==null){
		nb++;
	}else{
		nb=parseInt(GetCookie("pop_visite"));
		nb++;
	}
	var pathname=location.pathname;
	var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
	var date_exp = new Date();
	date_exp.setTime(date_exp.getTime()+((24*3600*1000)*36)); // 3 ans
	SetCookie("pop_visite",nb,date_exp,myDomain);
}
