/******************************************************************************
 * クッキー
 */

function Cookie() {
	this.initialize.apply(this, arguments);
}

Cookie.prototype = {
	initialize: function() {
		this.expires = null;
		this.domain = null;
		this.path = null;
		
		this.read();
	}, 
	
	read: function() {
		var cookie = null;
		var values = null;
		
		this.cookie = document.cookie;
		
		var cookies = this.cookie.split(';');
		
		if (cookies.length > 0 && cookies[0].length > 0) {
			for (var i = 0; i < cookies.length; i++) {
				cookie = cookies[i].replace(/^\s+|\s+$/g, '');
				
				values = cookie.split('=');
				
				if (values.length > 0 && values[0] != null) {
					if (values[0] == 'expires') {
						var expiresDate = new Date(values[1]);
						this.expires = expiresDate;
					}
					else {
						try {
							eval("this." + values[0] + ' = ' + unescape(values[1]) + ";");
						}
						catch (exception) {
						}
					}
				}
			}
		}
	}, 
	
	write: function(name, value) {
		var cookies = '';
		
		if (this.expires == null) {
			alert('有効日を設定しなければクッキーは食べられません');
		}
		
		if (name != null) {
			cookies += name + '=' + escape(value) +  '; ';
		}
		
		if (this.expires != null) {
			cookies += 'expires=' + this.expires.toGMTString() + '; ';
		}
		if (this.domain != null) {
			cookies += 'domain=' + this.domain + '; ';
		}
		if (this.path != null) {
			cookies += 'path=' + this.path + '; ';
		}
		
		document.cookie = cookies;
		
		this.read();
	}, 
	
	clear: function(name) {
		eval("this." + name + ' = undefined');
		
		this.expires = new Date(1999, 12, 31, 23, 59, 0);
		this.write(name, '');
	}
}
