/**
 * Modification of Riki's Cookie Manager to work with prototype.
 * Original script can be found at http://www.fczbkk.com/js/cookie_manager/cookie_manager.js
 * 
 * @author	Gregor "hrax" Magdolen
 * @author	Riki "fczbkk" Fridrich
 * @uses	Prototype 1.5.0_rc0 (hrax modification)
 * @charset	utf-8
 * @package	util
 */

if(typeof MA == "undefined") var MA = {};
if(typeof MA.util == "undefined") MA.util = {};

MA.util.CookieManager = Class.create();

MA.util.CookieManager.prototype = {
	cookieValue: null,
	
	initialize: function(){},
	
	save: function(name, value, days){
		days = (days*24*60*60*1000);
		var date = new Date()
		date.setTime(date.getTime()+days);
		d.cookie = name+"="+value+"; expires="+date.toGMTString()+"; path=/";
	},
	
	read: function(name){
		var cookies = d.cookie.split(";");
		name = name+"=";
		cookies.each(
			function(item){
				while(item.charAt(0) == ' ') item = item.substring(1, item.length);
				if(item.indexOf(name) == 0) CookieManager.cookieValue = item.substring(name.length, item.length);
			}
		);
		
		return this.cookieValue;
	},
	
	remove: function(name){
		this.save(name, null, 0.0001);
	}
}

var CookieManager = new MA.util.CookieManager();
