var exp = new Date(); 
exp.setTime(exp.getTime() + (365*10*24*60*60*1000));

function SetCookie(name, value) {
   	document.cookie = name + "=" + escape(value) +";expires=" +exp.toGMTString()+";path=/"
}

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 DeleteCookie (name) {  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	// This cookie is history  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
function getCookieVal(offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}

function CheckCookieInfo(){
	var count = GetCookie('Count')
	var cgiStats = GetCookie('CGIStats')
	
	//si le cookie n'est pas creer
	if(cgiStats == null){
		var curDate = new Date()

		var curDay = curDate.getDay()
		if (curDay <10){
			curDay = "0" + curDay.toString()
		}

		var curMonth = curDate.getMonth()
		if (curMonth <10){
			curMonth = "0" + curMonth.toString()
		}

		var curYear = curDate.getYear()

		var curHours = curDate.getHours()
		if (curHours <10){
			curHours = "0" + curHours.toString()
		}

		var curMins = curDate.getMinutes()
		if (curMins <10){
			curMins = "0" + curMins.toString()
		}

		var curSec = curDate.getSeconds()
		if (curSec <10){
			curSec = "0" + curSec.toString()
		}

		var curMs = curDate.getMilliseconds()
		if (curMs <10){
			curMs = "0" + curMs.toString()
		}

		var key = curDay.toString() + curMonth.toString() + curYear.toString() + curHours.toString() + curMins.toString() + curSec.toString() + curMs.toString()

		SetCookie("CGIStats", key);
		SetCookie("Ver","1.0");
		SetCookie("Count","1");
	}
	
	if(count == null) {
		SetCookie('Count','1')
		return 1
	} else {
		var newcount = parseInt(count) + 1;
		DeleteCookie('Count')
		SetCookie('Count',newcount,exp)
		return count
	}
}
