/*  cookie.js  -  contains some very basic cookie-handling functions.
 *  (C) Copyright 2003  Kars Meyboom <kars@kde.nl>
 *
 *  LICENSE:
 *
 *  This code is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This code 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 General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

// -- Returns the value of the cookie named 'name', or null
// -- if the cookie was not found.
function getCookie (name) {
	var cookieStr = document.cookie;
	var cookies = cookieStr.split(/;\s*/);

	for (var i = 0; i < cookies.length; i++) {
		if (cookies[i].indexOf(name+'=') != 0) {
			continue;
		}
		var start = name.length+1;
		var end = cookies[i].length;
		return cookies[i].substring(start, end);
	}

	return null;
}

// -- Sets the cookie named 'name' to 'value', with an expiration
// -- of 28 days, for the entire document root.
function setCookie (name, value) {
	// expire in 28 days
	var expiration = new Date((new Date()).getTime() + 28*24*3600000);

	var cookie = name+'='+value+'; expires='+expiration + '; path=/';
	document.cookie = cookie;
}


