﻿Mortenson.Cookie = function()
{
    var _expiredays;
    var _industryCookieName;
    var _topicCookieName;
    Ext.onReady(this.Initialize.createDelegate(this));
}

Ext.extend(Mortenson.Cookie, Ext.util.Observable,
{
    Initialize : function()
    {
        this._expiredays = 1;
        this._industryCookieName = "IndustryDDL";
        this._topicCookieName = "TopicDDL";
    },
    
    Set : function(name, value)
    {
        var date = new Date();
	    date.setTime(date.getTime() + (this._expiredays * 24 * 60 * 60 * 1000));
	    expires = "; expires=" + date.toGMTString();
        document.cookie = name + "=" + escape(value) + expires + "; path=/"; 
    },
    
    Read : function(name)
    {
        var value = document.cookie.match ( '(^|;) ?' + name + '=([^;]*)(;|$)' );

        if (value)
        {
            return unescape(value[2]);
        }
        else
        {
            return null;
        }
    },
    
    Delete : function(cookiename)
    {
        var expiredate = new Date();
        expiredate.setTime(expiredate.getTime() - 1);
        cookiename += "=; expires=" + expiredate.toUTCString() + "; path=/;";
        document.cookie = cookiename;
    },
    
    SetIndustryCookie : function(val)
    {
        this.Set(this._industryCookieName, val);
    },
    GetIndustryCookie : function()
    {
        return this.Read(this._industryCookieName);
    },
    
    SetTopicCookie : function(val)
    {
        this.Set(this._topicCookieName, val);
    },
    GetTopicCookie : function()
    {
        return this.Read(this._topicCookieName);
    }
});    
