
red.prototype.cookie = {
	
	getval : function(offset){
		var endstr = document.cookie.indexOf (";", offset);
		if (endstr == -1){
			endstr = document.cookie.length;
		}
		return unescape(document.cookie.substring(offset, endstr));
	},
	
	get : function(name){
		var arg = name + "=";
		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 red.prototype.cookie.getval (j);
			}
			i = document.cookie.indexOf(" ", i) + 1;
			if (i == 0){
				break;
			}
		}
		return false;
	},
	
	fullset : function(name, value){
		var argv = red.prototype.cookie.fullset.arguments;
		var argc = red.prototype.cookie.fullset.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 = name + "=" + escape (value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
		((path == null) ? "" : ("; path=" + path)) +
		((domain == null) ? "" : ("; domain=" + domain)) +
		((secure == true) ? "; secure" : "");
	},
	
	set : function(name, value, hours){
		if(hours == null){hours = 24;}
		var expdate = new Date ();
		expdate.setTime(expdate.getTime() + (hours * 3600 * 1000));
		red.prototype.cookie.fullset(name, value, expdate, "/");
	},
	
	remove : function(name){
		var expdate = new Date();
		expdate.setTime (expdate.getTime() - 1);
		var cval = red.prototype.cookie.get(name);
		red.prototype.cookie.fullset(name, cval, expdate, "/");
	}

};