/*   ecriture d'une cookie               */
function setCookie (name, value) {  
   argv = setCookie.arguments;   // array with the arguments in the call  
   argc = setCookie.arguments.length; // length of array argv
   expires = (argc > 2) ? argv[2] : null;  
   path    = (argc > 3) ? argv[3] : null;  
   domain  = (argc > 4) ? argv[4] : null;  
   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" : "");
}

/*   lecture d'une cookie */
function getCookie(name) {
   name = "visiteur";

   search = name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search)
      if (offset != -1) { // if cookie exists
         offset += search.length
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset)
         // set index of end of cookie value
         if (end == -1)
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      }
   }
}

/*   destruction d'une cookie */
function deleteCookie (name) {
   end_time = new Date();                      // object Date with current date 
   end_time.setTime (end_time.getTime() - 1);  // set time of this object in the past!
   value = getCookie(name);                    // get cookie value
   document.cookie = name + "=" + value + "; expires=" + end_time.toGMTString();
}

