/************************************************
 * 
 * クッキー処理クラス(通常スキン用)
 * 
 * Author        : $Author: ohira $
 * Last Modified : $Date: 2006/05/29 19:01:21 $
 * Version       : $Revision: 1.1 $
 * 
 * (c) CYBER AGENT.LTD
 * 
 ************************************************/
function Cookie() {
    this.cookieName = '';
    this.cookieValue = '';
    this.days;
    this.date = new Date();
    this.expires = '';
    this.cookieName = '';

    /**
     * クッキー名・保存期間(日)を取得
     * 
     * @param String name  クッキー名
     * @param int    days  保存日数
     */
    this.setData = function(name, days) {
        this.cookieName = name;
        this.days = days;
    }
    Cookie.prototype.setData = this.setData;


    /**
     * 値をクッキー保存
     * 
     * @param String value 値
     */
    this.create = function(value) {
        this.cookieValue = value;
        if (this.days) {
            this.date.setTime(this.date.getTime()+(this.days*24*60*60*1000));
            this.expires = "; expires="+this.date.toGMTString();
        } else {
            this.expires = "";
        }
        document.cookie = this.cookieName + "=" + this.cookieValue + this.expires + "; path=/";
    }
    Cookie.prototype.create = this.create;

    /**
     * 指定されたクッキー名の値を読込
     */
    this.read = function() {
        var nameEQ = this.cookieName + "=";
        var ca = document.cookie.split(';');
        for (var i=0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    }
    Cookie.prototype.read = this.read;

    /**
     * クッキーを取り除く
     */
    this.remove = function() {
        document.cookie = this.cookieName + "=;expires=Thu, 01-Jan-70 00:00:01 GMT; path=/";
    }

    Cookie.prototype.create = this.create;
}
