/**
 * @alias Cookie.class
 * @author Arweb <systems@arweb.com>
 * @since 2007.
 */

function Cookie(name) {
	
	this.name = name;
	this.value = "";
	this.deathdate = null;
	this.path = null;
	this.domain = null;
	this.secure = false;
	
	this.load = function () {
		var data = " " + document.cookie;
		var offset = data.indexOf(" " + this.name + "=");
		if (offset == -1) {
			return false;
		}
		offset += this.name.length + 2;
		var end = data.indexOf("; ", offset);
		if (end == -1) {
			end = data.length;
		}
		this.value = unescape(data.substring(offset, end));
		return true;
	};
	
	this.save = function () {
		var data = this.name + "=" + escape(this.value);
		if (this.deathdate != null)  {
			data += "; expires=" + this.deathdate.toGMTString();
		}
		if (this.path != null)  {
			data += "; path=" + this.path;
		}
		if (this.domain != null)  {
			data += "; domain=" + this.domain;
		}
		if (this.secure)  {
			data += "; secure";
		}
		document.cookie = data;
	};
	
	this.unlink = function () {
		if (this.load()) {
			this.value = "";
			this.deathdate = new Date();
			this.save();
	  }
	};
	
}
