// <!--/*--><![CDATA[//><!--
// ------------------------------------------------------------------------------
// aba_tools aba_cookie.js v1.2.0, Wed May 31 23:27:19 CET 2006
// Copyright (c) 2006 Aurelien Barbier-Accary
// http://aurelien.barbier-accary.info
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// For details, see my web site: http://aurelien.barbier-accary.info
// ------------------------------------------------------------------------------

if ((window.Cookie)
 && ((! window.Cookie.Signature)
	|| (window.Cookie.Signature != 'ABA tools - cookie module')
	|| (parseFloat(window.Cookie.Version.split(".")[0] + "." +
					window.Cookie.Version.split(".")[1]) >= 1.2)))
{
	if (true)
		throw("'ABA cookie 1.2.0' not loaded");
}
else window.Cookie =
{
	Signature: 'ABA tools - cookie module',
	Version: '1.2.0',
	LogStream: 'console',  // '' for no log or null, 'console' (firebug) and 'alert' otherwise
	Verbose: 2, // 0 (only errors), 1 (main actions), 2 (waiting), 3 (for each script)

	// ----- Public methods -----------------------------------------------------

	load: function (nom)
	// recherche un cookie et renvoie un tableau des valeurs si le cookie existe, null sinon
	{
	  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 this._getVal(j).split(/,/);
	    i = document.cookie.indexOf(" ", i) + 1;
	    if (i == 0)
	      break;
	  }
	  return null;
	},

	save: function (nom, valeurs)
	// Cree (ou modifie) un cookie
	// nom doit etre distinctif
	// valeurs est une chaine de valeurs separees par des virgules
	// d'autres parametres sont optionnels :
	//  * expires : duree de vie sous forme d'objet date
	//  * path : chemin du cookie
	//  * domain : domaine du site
	//  * secure : securise ou pas
	// La commande d'utilisation complete est donc :
	//   window.Cookie.save(monCookie, valeurs, null, "/monChemin", null, true);
	{
	  var argv = this.save.arguments;
	  var argc = this.save.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 = nom + "=" + escape(valeurs) +
	    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
	    ((path == null) ? "" : ("; path=" + path)) +
	    ((domain == null) ? "" : ("; domain=" + domain)) +
	    ((secure == true) ? "; secure" : "");
	},

	expiresInDays: function (jours)
	{
	  var date = new Date();
	  date.setTime(date.getTime() + (jours * 24 * 3600 * 1000));
	  return date;
	},

	remove: function (nom)
	// pour detruire un cookie, on met sa date d'expiration a la date courante
	{
	  var exp = new Date();
	  exp.setTime (exp.getTime() - 1);
	  var cval = this.load(nom);
	  if (cval != null)
	    document.cookie = nom + "=" + cval + "; expires=" + exp.toGMTString();
	},

	// ----- Private methods ----------------------------------------------------

	_getVal: function (offset)
	// fonction utilisee par getCookie()
	{
	  var endstr = document.cookie.indexOf (";", offset);
	  if (endstr == -1)
	    endstr = document.cookie.length;
	  return unescape(document.cookie.substring(offset, endstr));
	},

	_log: function(msg, msgVerbose) {
		if (! msgVerbose)
			msgVerbose = window.Cookie.Verbose;
		if (window.Cookie.LogStream)
			if ((window.Cookie.LogStream == 'console') && console && console.log)
			{
				if (msgVerbose <= window.Cookie.Verbose)
					console.log('Cookie: '+msg);
			}
			else
			{
				if (msgVerbose <= window.Cookie.Verbose)
					alert('Cookie: '+msg);
			}
	}
};



