// 自作クッキーオブジェクト

// Last edited 02/09/01



function Cookie(name) {

	this._name = name;

}



function Cookie_allfetch() {

	var pair, cname, value;

	var result = new Object();

	var ary = document.cookie.split("; ");

	for (i = 0; i < ary.length; i++) {

		pair = ary[i].split("=");

		name = unescape(pair[0]);

		value = unescape(pair[1]);

		if (typeof result[name] != "object" || result[name].constructor != Cookie) {

			result[name] = new Cookie(name);

			result[name]._value = value;

		}

	}

	return result;

}



function Cookie_fetch(val) {

	if (typeof val == "undefined") {

		var ob = Cookie_allfetch();

		return ob;

	} else {

		var pair, cname, value;

		var result = new Object();

		var ary = document.cookie.split("; ");

		var f = 0;

		for (i = 0; i < ary.length; i++) {

			pair = ary[i].split("=");

			name = unescape(pair[0]);

			value = unescape(pair[1]);

			if(name == val){

				f = 1;

				result[name] = new Cookie(name);

				result[name]._value = value;

				break;

			}

		}

		if (f == 0){

			result[val] = new Cookie(val);

			result[val]._value = "undefined";

		}

	}

	return result[val];

}



function Cookie_toString() {

	var str = "";

	str += escape(this._name) + "=" + escape(this._value);

	if (this._expires) {

		str += "; expires=" + this._expires.toGMTString();

	}

	if (this._domain) {

		str += "; domain=" + this._domain;

	}

	if (this._path) {

		str += "; path=" + this._path;

	}

	if (this._secure) {

		str += "; secure";

	}

	return str;

}



function Cookie_name(val) {

	if (typeof val != "undefined") {

		this._name = val;

	}

	return this._name;

}



function Cookie_value(val) {

	if (typeof val != "undefined") {

		this._value = val;

	}

	return this._value;

}



function Cookie_expires(val) {

	if (typeof val != "undefined") {

		this._expires = val;

	}

	return this._expires;

}



function Cookie_expire(val) {

	var t = new Date().getTime();

	if (typeof val != "undefined") {

		this.expires(new Date(t + 60 * eval(val) * 60 * 1000));

	} else {

		this.expires(new Date(t + 60 * 60 * 1000));

	}

}



function Cookie_domain(val) {

	if (typeof val != "undefined") {

		this._domain = val;

	}

	return this._domain;

}



function Cookie_path(val) {

	if (typeof val != "undefined") {

		this._path = val;

	}

	return this._path;

}



function Cookie_secure(val) {

	if (typeof val != "undefined") {

		this._secure = val;

	}

	return this._secure;

}



function Cookie_set() {

	document.cookie = this.toString();

}



Cookie.allfetch = Cookie_allfetch;

Cookie.fetch = Cookie_fetch;

Cookie.prototype.toString = Cookie_toString;

Cookie.prototype.name = Cookie_name;

Cookie.prototype.value = Cookie_value;

Cookie.prototype.expire = Cookie_expire;

Cookie.prototype.expires = Cookie_expires;

Cookie.prototype.domain = Cookie_domain;

Cookie.prototype.path = Cookie_path;

Cookie.prototype.secure = Cookie_secure;

Cookie.prototype.set = Cookie_set;

