/*
 * cookie object written by Seung Chan Lim (dev@djslim.com) May 1999
 * you may use it freely at your own risk after you get permission
 * from the author by e-mailing at dev@djslim.com. You must also
 * leave this whole segment of this comment as it is.
 *
 * Usage:
 * 	c=new Cookie()
 *	c.set('test','hello');
 *	document.write(c.get('test')+"<br>");
 *	c.remove('test');
 *	document.write(c.get('test'));
 *
 *	a non-existent cookie will return 'undefined'
 *
 * dependency: setup.java
 */

function Cookie(){
	var keyval,tuple;
	this._keys={};
	keyval=doc.cookie.split(";");
	for (var i=0;i<keyval.length;i++){
		tuple=keyval[i].split("=");
		this._keys[tuple[0].replace(/^\s*/,"")]=tuple[1];
	}
	this.get=_get;
	this.set=_set;
	this.remove=_del;
}

function _get(key){ return unescape(this._keys[key]); }

function _set(key,val,expire,path,domain,secure){
if (escape(key)!=key) { alert('error: cookie with a non alpha numeric key is illegal!'); return; }
	var newck=key+"="+escape(val)+"; ";
	if (path) { newck+="path="+path+"; "; }
	if (domain) { newck+="domain="+domain+"; "; }
	if (expire) { newck+="expires="+expire.toGMTString()+"; "}
	if (secure) { newck+"secure;"}
	doc.cookie=newck;
}

function _del(key,path,domain){
	if (this._keys[key]){
		var newck=key+"=;expires=Thu, 01-Jan-70 00:00:01 GMT;";
		if (path) { newck+="path="+path+";"; }
		if (domain) { newck+="domain="+domain+";"; }
		doc.cookie=newck;
	}
}

