function isIE(){return window.ActiveXObject}var GlobalClientStorage=function(a){this.store=window.globalStorage[a]};GlobalClientStorage.prototype={get:function(a){var b=this.store.getItem(a);if(b){return nk.JSON.decode(b.value)}return null},set:function(a,b){this.store.setItem(a,nk.JSON.encode(b))},remove:function(a){this.store.removeItem(a)}};var LocalClientStorage=function(a){this.store=window.localStorage};LocalClientStorage.prototype={get:function(a){var b=this.store.getItem(a);if(b){return nk.JSON.decode(b)}return null},set:function(a,b){this.store.setItem(a,nk.JSON.encode(b))},remove:function(a){this.store.removeItem(a)}};var UserDataStorage=function(){if(this.storage=nk.DOM.$("userDataStorage")){return}this.storage=nk.Element.create("div",{id:"userDataStorage",styles:{behavior:"url(#default#userdata)",display:"none"},parent:document.body})};UserDataStorage.prototype={get:function(b){this.storage.load("nk_cache_2");var a=this.storage.getAttribute(b);return a?nk.JSON.decode(a):null},set:function(a,b){this.storage.setAttribute(a,nk.JSON.encode(b));this.storage.save("nk_cache_2")},remove:function(a){this.storage.load("nk_cache_2");this.storage.removeAttribute(a);this.storage.save("nk_cache_2")}};var FlashStorage=function(){this.storage=nk.DOM.$("flash_storage")};FlashStorage.prototype={get:function(a){return this.storage.get(a)},set:function(a,c){try{if(!this.storage.set(a,c)){throw new Error("flash storage is full")}}catch(b){report_js_error(b,"flash_storage_set_failed")}},remove:function(a){this.storage.remove(a)},test:function(){if(!this.storage.test||!this.storage.test()||!this.storage.set||!this.storage.remove||!this.storage.get){return false}try{this.storage.set("nk_cache","nk_cache_test");val=this.storage.get("nk_cache");this.storage.remove("nk_cache");return val=="nk_cache_test"}catch(a){return false}}};function embed_flash_storage(){var a=nk.DOM.$("flash_storage_container");if(isIE()){a.innerHTML='<object height="1" width="1" id="flash_storage" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"><param name="movie" value="'+getStaticUri("/flash/flash_storage.swf")+'"><param name="quality" value="high"><param name="AllowScriptAccess" value="always"><param name="wmode" value="transparent"></object>'}else{a.innerHTML='<object height="1" width="1" id="flash_storage"  type="application/x-shockwave-flash" data="'+nk.get_static_uri("/flash/flash_storage.swf")+'"><param name="quality" value="high"><param name="AllowScriptAccess" value="always"><param name="wmode" value="transparent"></object>'}window.flash_storage_interface=new FlashStorage()}var CookieStorage=function(){};CookieStorage.prototype={get:function(a){return nk.JSON.decode(nk.Cookie.get(a,{path:"/"}))},set:function(b,c,a){if(a){nk.Cookie.set(b,nk.JSON.encode(c),{path:"/"})}},remove:function(a){nk.Cookie.remove(a,{path:"/"})}};var ClientStorage={storage:null,callbacks:new Array(),can_use_flash:false,was_dom_ready:false,was_flash_embedded:false,gc_active:false,gc_bucket:"GC_bucket_",gc_last_time:"GC_last_time",get_storage:function(){return this.storage?this:null},wait_storage:function(a){if(this.storage!=null){a()}else{this.callbacks.push(a)}},domready:function(){this.was_dom_ready=true;this.decide_storage(false,false);nk.Function.delay(nk.Function.bind(this.decide_storage,this,[false,false]),1000);nk.Function.delay(nk.Function.bind(this.decide_storage,this,[true,false]),7000)},decide_storage:function(d,a){this.can_use_flash|=a;if(this.storage===null){if(window.localStorage){this.storage=new LocalClientStorage();this.gc_active=true}else{if(window.globalStorage){this.storage=new GlobalClientStorage(window.location.host);this.gc_active=true}else{if(isIE()){this.storage=new UserDataStorage();this.gc_active=true}else{if(this.can_use_flash&&window.flash_storage_interface&&window.flash_storage_interface.test()){this.storage=window.flash_storage_interface;this.gc_active=true}else{if(!this.was_flash_embedded){embed_flash_storage();this.was_flash_embedded=true}else{if(d&&this.was_dom_ready){this.storage=new CookieStorage()}}}}}}if(this.storage!=null){while(this.callbacks.length>0){try{var b=this.callbacks.pop();nk.Function.delay(b,10)}catch(c){nk.Errors.report(c,"Error while running storage callbacks")}}if(this.gc_active){if(this.storage.get(this.gc_last_time)==null){this.storage.set(this.gc_last_time,Math.floor((new Date().getTime())/1000/60/60/24),false)}nk.Function.period(nk.Function.bind(ClientStorage.run_gc,this),60*1000)}}}return null},get:function(b){var a=this.storage.get(b);if(a==null){return null}if(this.is_expired(a.expire)){this.storage.remove(b);return null}else{return a.data}},set:function(f,h,c,b){try{var d=typeof(c)=="number"?new Date().getTime()+c*1000:null;this.storage.set(f,{data:h,expire:d},b?true:false);if(d&&this.gc_active){var g=this.gc_bucket+Math.floor(d/1000/60/60/24);var a=this.storage.get(g)||[];a.push(f);this.storage.set(g,a,false)}}catch(i){nk.Errors.report(i,"storage_set_failed")}},remove:function(a){this.storage.remove(a)},run_gc:function(){var e=this.storage.get(this.gc_last_time);var c=Math.floor((new Date().getTime())/1000/60/60/24);for(var b=e;b<c;b++){var a=this.storage.get(this.gc_bucket+b);if(a!=null){while(a.length>0){var d=a.pop();this.get(d)}}this.storage.remove(this.gc_bucket+b)}this.storage.set(this.gc_last_time,c,false)},is_expired:function(a){return a!=null&&a<new Date().getTime()}};
