!function(e){var t=!1,r="Storage",o=e.Core.newType("hafasModule"),n={};function a(){}a.prototype=n,e.Core.registerType(r,"hafasStorage",a);var s={testOrder:["testLocalStorage","testIndexedDB","testCookies","testSessionStorage"]},i={testCookies:function(){try{var e=!1,t="HafasStorageCTest",r="cookie123";return l.set(t,r),l.get(t)===r&&(e=!0),l.remove(t),e}catch(e){return!1}},testLocalStorage:function(){var e="HafasStorageLSTest";try{localStorage.setItem(e,"localstorage123");var t=!!localStorage.getItem(e);return localStorage.removeItem(e),t}catch(e){return!1}},testSessionStorage:function(){var e="HafasStorageSSTest";try{return sessionStorage.setItem(e,"sessionstorage123"),!!sessionStorage.getItem(e)}catch(e){return!1}},testIndexedDB:function(){try{return f.indexedDB&&f.openDB()}catch(e){return!1}}},c={internalStorage:{},get:function(e){return c.internalStorage[e]},getAll:function(){var t={};return e.Core.extend(t,c.internalStorage),t},set:function(e,t){c.internalStorage[e]=t},remove:function(e){delete c.internalStorage[e]},removeAll:function(){c.internalStorage={}}},l={getAll:function(){var e=document.cookie.split("; "),t={};for(var r in e){var o=e[r].indexOf("=");if(o>=0){var n=e[r].substring(0,o),a=e[r].substring(o+1);t[n]=a}}return t},get:function(e){var t=l.getAll();return e&&e in t?unescape(t[e]):null},set:function(e,t){document.cookie=e+"="+escape(t)},remove:function(e){document.cookie=e+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT;"},removeAll:function(){var e=l.getAll();for(var t in e)l.remove(t)}},u={get:function(e){return localStorage.getItem(e)},getAll:function(){var e={};for(var t in localStorage)e[t]=localStorage[t];return e},set:function(e,t){localStorage.setItem(e,t)},remove:function(e){localStorage.removeItem(e)},removeAll:function(){localStorage.clear()}},g={get:function(e){return sessionStorage.getItem(e)},getAll:function(){var e={};for(var t in sessionStorage)e[t]=sessionStorage[t];return e},set:function(e,t){sessionStorage.setItem(e,t)},remove:function(e){sessionStorage.removeItem(e)},removeAll:function(){sessionStorage.clear()}},f={};try{f.indexedDB=indexedDB||window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB}catch(e){}try{f.RW=IDBTransaction.READ_WRITE||IDBTransaction.readwrite||"readwrite"}catch(e){}function d(){var t=function(){var t,r,o,n=(e.Config.Storage||s).testOrder;for(var a in n)if(o=n[a],!0===(r=i[o]()))break;if(!0===r)switch(o){case"testCookies":(t=l).desc="Using Cookies";break;case"testLocalStorage":(t=u).desc="Using LocalStorage";break;case"testSessionStorage":(t=g).desc="Using SessionStorage";break;case"testIndexedDB":t=f,v=!0}else(t=c).set("hfsYes","1"),t.desc="Using internal object (no browser capabilities/permissions)";return t}();!1===v&&S(t)}function S(e){m(e)}f.db=null,f.cursorResult={},f.openDB=function(){try{if(f.indexedDB){var e=f.indexedDB.open("hafasdb",1);if(e.onupgradeneeded=function(e){f.db=e.target.result,f.db.createObjectStore("hfsKeyValue")},e.onsuccess=function(e){f.db=e.target.result,f.loadAll()},e)return!e.error}}catch(e){return!1}},f.getObjectStore=function(){return f.db.transaction("hfsKeyValue",f.RW).objectStore("hfsKeyValue")},f.loadAll=function(){f.cursorResult={},f.getObjectStore().openCursor().onsuccess=function(e){var t=e.target.result;if(t)f.cursorResult[t.key]=t.value,t.continue();else{c.internalStorage=f.cursorResult;var r=f;r.desc="Using IndexedDB backed by sync access object",S(r)}}},f.get=function(e){return c.get(e)},f.getAll=function(){return c.getAll()},f.set=function(e,t){f.getObjectStore().put(t,e),c.set(e,t)},f.remove=function(e){f.getObjectStore().delete(e),c.remove(e)},f.removeAll=function(){f.getObjectStore().clear(),c.removeAll()};var v=!1;function m(a){var s;o.log(r,a.desc),e.Core.extend(n,{get:(s=a).get,getAll:s.getAll,set:s.set,remove:s.remove,removeAll:s.removeAll}),!0===t&&(o.Interface=n),moduleState="ready"}o.init=function(e,r){t===e.debug&&(o.Tests=i),d()},e.Core.registerModule(r,o)}(window.Hafas=window.Hafas||{});