foswiki.Pref={FOSWIKI_PREF_COOKIE_NAME:"FOSWIKIPREF",COOKIE_PREF_SEPARATOR:"|",COOKIE_PREF_VALUE_SEPARATOR:"=",COOKIE_EXPIRY_TIME:31536e6,setPref:function(e,i){var r=foswiki.Pref._getPrefCookie().split(foswiki.Pref.COOKIE_PREF_SEPARATOR),f=foswiki.Pref._getSafeString(e),o=foswiki.Pref._getKeyValueLoc(r,f);-1!=o&&r.splice(o,1);var t=isNaN(i)?foswiki.Pref._getSafeString(i):i,n=f+foswiki.Pref.COOKIE_PREF_VALUE_SEPARATOR+t;r.push(n),foswiki.Pref._writePrefValues(r)},clearPref:function(e){var i=foswiki.Pref._getPrefCookie().split(foswiki.Pref.COOKIE_PREF_SEPARATOR),r=foswiki.Pref._getSafeString(e),f=foswiki.Pref._getKeyValueLoc(i,r);-1!=f&&i.splice(f,1),foswiki.Pref._writePrefValues(i)},getPref:function(e){var i=foswiki.Pref._getSafeString(e);return foswiki.Pref.getPrefValueFromPrefList(i,foswiki.Pref.getPrefList())},getPrefValueFromPrefList:function(e,i){var r=foswiki.Pref._getKeyValue(i,e);return null!=r?r[1]:""},getPrefList:function(){var e=foswiki.Pref._getPrefCookie();return e?e.split(foswiki.Pref.COOKIE_PREF_SEPARATOR):null},getCookie:function(e){for(var i=e+"=",r=i.length,f=document.cookie.length,o=0;o<f;){var t=o+r;if(document.cookie.substring(o,t)==i)return foswiki.Pref._getCookieVal(t);if(0==(o=document.cookie.indexOf(" ",o)+1))break}return null},setCookie:function(e,i,r,f,o,t){var n=e+"="+escape(i)+(r?"; expires="+r.toGMTString():"")+(f?"; path="+f:"")+(o?"; domain="+o:"")+(t?"; secure":"");document.cookie=n},deleteCookie:function(e,i,r){foswiki.Pref.getCookie(e)&&(document.cookie=e+"="+(i?";path="+i:"")+(r?"; domain="+r:"")+"; expires=Thu, 01-Jan-70 00:00:01 GMT")},_getKeyValue:function(e,i){if(!e)return null;for(var r=e.length;r--;){var f=e[r].split(foswiki.Pref.COOKIE_PREF_VALUE_SEPARATOR);if(f[0]==i)return f}return null},_getKeyValueLoc:function(e,i){if(!e)return null;for(var r=e.length;r--;){if(e[r].split(foswiki.Pref.COOKIE_PREF_VALUE_SEPARATOR)[0]==i)return r}return-1},_writePrefValues:function(e){var i=null!=e?e.join(foswiki.Pref.COOKIE_PREF_SEPARATOR):"",r=new Date,f=foswiki.getPreference("COOKIEREALM"),o=foswiki.getPreference("URLHOST").startsWith("https://");foswiki.Pref._fixCookieDate(r),r.setTime(r.getTime()+foswiki.Pref.COOKIE_EXPIRY_TIME),foswiki.Pref.setCookie(foswiki.Pref.FOSWIKI_PREF_COOKIE_NAME,i,r,"/",f,o)},_getPrefCookie:function(){var e=foswiki.Pref.getCookie(foswiki.Pref.FOSWIKI_PREF_COOKIE_NAME);return null==e&&(e=""),e},_getSafeString:function(e){var i=new RegExp(/[|=]/);return e.replace(i,"")},_getCookieVal:function(e){var i=document.cookie.indexOf(";",e);return-1==i&&(i=document.cookie.length),unescape(document.cookie.substring(e,i))},_fixCookieDate:function(e){var i=new Date(0).getTime();i>0&&e.setTime(e.getTime()-i)}};
