function JLJS_CookieManager() { this.DELIMITER = "|"; this.PATH = "/"; this.C_PATH = "cpath"; this.pathname = window.location.pathname; } JLJS_CookieManager.prototype = { setCookie : function(name, value, options) { var mValue = {}; mValue[name] = value; mValue[JLJS_CookieMgr.C_PATH] = JLJS_CookieMgr.pathname; JLJS_CookieMgr.setMulti(name, mValue, options); }, getCookie : function(name) { var mValue = JLJS_CookieMgr.getMulti(name); var value; if(mValue) { if(!mValue[JLJS_CookieMgr.C_PATH]) { value = mValue[""]; } else if(mValue[JLJS_CookieMgr.C_PATH] == JLJS_CookieMgr.pathname) { value = mValue[name]; } } return value; }, removeCookie : function(name) { var mValue = JLJS_CookieMgr.getCookie(name); if(mValue) { JLJS_CookieMgr.remove(name); } }, setMultiCookie : function(mName, valueHash, options) { var mValue = {}; for(var key in valueHash) { mValue[key] = valueHash[key]; } mValue[JLJS_CookieMgr.C_PATH] = JLJS_CookieMgr.pathname; JLJS_CookieMgr.setMulti(mName, mValue, options); }, addMultiCookie : function(mName, name, value, options) { var mValue = JLJS_CookieMgr.getMultiCookie(mName); if(!mValue) { mValue = {}; } mValue[name] = value; JLJS_CookieMgr.setMultiCookie(mName, mValue, options); }, getMultiCookie : function(mName) { var mValue = JLJS_CookieMgr.getMulti(mName); var valueHash; if(mValue) { if(!mValue[JLJS_CookieMgr.C_PATH]) { valueHash = mValue; } else if(mValue[JLJS_CookieMgr.C_PATH] == JLJS_CookieMgr.pathname) { delete mValue[JLJS_CookieMgr.C_PATH]; valueHash = mValue; } } return valueHash; }, removeMultiCookie : function(mName, name, options) { var mValue = JLJS_CookieMgr.getMultiCookie(mName); if(mValue) { JLJS_CookieMgr.removeMulti(mName, name, options); } }, // private function trim : function(str) { return ("" + str).replace(/^\s+|\s+$/g, ""); }, set : function(name, value, options) { name = JLJS_CookieMgr.trim(name); value = JLJS_CookieMgr.trim(value); var pathFlg = false; var option = "" for(var optKey in options) { option = option + optKey + "=" + options[optKey] + ";"; if(optKey.toLowerCase() == "path") { pathFlg = true; } } if(!pathFlg) { option = option + "path=" + JLJS_CookieMgr.PATH + ";"; } document.cookie = escape(name) + "=" + escape(value) + ";" + option; }, get : function(name) { name = JLJS_CookieMgr.trim(name); var value; if(document.cookie) { var array = document.cookie.split(";"); for(var i=0; i