/*
	Copyright (C) 2008 - Juan Ferrer Toribio

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with this program; if not, write to the Free
	Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
	02111-1307 USA.
*/

var Cookie =
{
	add: function (days, key, value)
	{
		var strCookie = key + '=' + value + ';';
	
		if (days != undefined)
		{
			var date = new Date ();
			date.setTime (date.getTime () + days * 86400000);
			strCookie += 'expires=' + date.toGMTString ();
		}
	
		document.cookie = strCookie;
	}

	,del: function (key)
	{
		this.add (-1, key, '');
	}

	,get: function (key)
	{
		var start;
		var cookie = new String (document.cookie);

		start = cookie.indexOf (key + '=');
	
		if (start != -1)
		{
			var end;

			start += key.length + 1;
			end = cookie.indexOf (';', start);

			if (end > 0)
				return cookie.substring (start, end);
			else
				return cookie.substring (start);
			
		}
		
		return null;
	}
	
	,getFloat: function (key)
	{
		var value = Cookie.get (key);
		
		if (value != null)
			return parseFloat (value);
		
		return null;
	}

	,check: function (key)
	{
		return this.get (key) != null;
	}
};


