window.Horde=window.Horde||{};Horde.dhtmlHistory={WAIT_TIME:200,currentWaitTime:0,initialize:function(){if(Prototype.Browser.Webkit){return false}Horde.historyStorage.init();if(Prototype.Browser.WebKit){this.createSafari()}this.currentLocation=this.getCurrentLocation();if(Prototype.Browser.IE){this.iframe=new Element("IFRAME",{name:"DhtmlHistoryFrame",id:"DhtmlHistoryFrame"}).hide();this.iframe.setAttribute("src","javascript:false;");$(document.body).insert(this.iframe);this.writeIframe(this.currentLocation);this.WAIT_TIME=400;this.ignoreLocationChange=true}Event.observe(window,"unload",function(){this.firstLoad=false}.bind(this));this.isFirstLoad();new PeriodicalExecuter(this.checkLocation.bind(this),0.3);return true},addListener:function(a){this.listener=a;if(this.fireOnNewListener){if(this.currentLocation){this.fireHistoryEvent(this.currentLocation)}this.fireOnNewListener=false}},add:function(b,c){if(Prototype.Browser.WebKit){return false;b=this.removeHash(b);Horde.historyStorage.put(b,c);var a=this.currentLocation;this.currentLocation=b;this.ignoreLocationChange=true;this.setLocation(b);this.putSafariState(b)}else{setTimeout(this.addImpl.bind(this,b,c),this.currentWaitTime)}this.currentWaitTime+=this.WAIT_TIME},setLocation:function(a){location.hash=a},getCurrentLocation:function(){if(Prototype.Browser.WebKit){return false;return this.getSafariState()}else{return this.removeHash(unescape(location.hash))}},addImpl:function(a,b){if(this.currentWaitTime){this.currentWaitTime-=this.WAIT_TIME}if($("newLoc")){return}a=this.removeHash(a);Horde.historyStorage.put(a,b);this.ignoreLocationChange=this.ieAtomicLocationChange=true;this.currentLocation=a;this.setLocation(escape(a));if(Prototype.Browser.IE){this.writeIframe(a)}this.ieAtomicLocationChange=false},isFirstLoad:function(){if(Horde.historyStorage.hasKey("DhtmlHistory_pageLoaded")==false){if(Prototype.Browser.IE){this.fireOnNewListener=false}else{this.ignoreLocationChange=true}this.firstLoad=true;Horde.historyStorage.put("DhtmlHistory_pageLoaded",true)}else{if(Prototype.Browser.IE){this.firstLoad=false}else{this.ignoreLocationChange=false}this.fireOnNewListener=true}},fireHistoryEvent:function(a){if(this.listener){this.listener.call(null,a,Horde.historyStorage.get(a))}},checkLocation:function(){if(!Prototype.Browser.IE){if(this.ignoreLocationChange){this.ignoreLocationChange=false;return}}else{if(this.ieAtomicLocationChange){return}}var a=this.getCurrentLocation();if(a==this.currentLocation||Object.isUndefined(a)){return}this.ieAtomicLocationChange=true;if(Prototype.Browser.IE){if(this.iframe.contentWindow.l==a){return}this.writeIframe(a)}this.currentLocation=a;this.ieAtomicLocationChange=false;this.fireHistoryEvent(a)},removeHash:function(a){if(a===null||Object.isUndefined(a)){return null}else{if(a.startsWith("#")){if(a.length==1){return""}else{return a.substring(1)}}}return a},iframeLoaded:function(a){if(this.ignoreLocationChange){this.ignoreLocationChange=false;return}this.setLocation(escape(a));this.fireHistoryEvent(a)},writeIframe:function(a){var b=this.iframe.contentWindow.document;b.open();b.write('<html><script type="text/javascript">var l="'+a+'";function pageLoaded(){window.parent.Horde.dhtmlHistory.iframeLoaded(l);}<\/script><body onload="pageLoaded()"></body></html>');b.close()},createSafari:function(){this.WAIT_TIME=400;this.safariHistoryStartPoint=history.length;this.safariStack=new Element("INPUT",{id:"DhtmlSafariHistory",type:"text",value:"[]"}).hide();$(document.body).insert(this.safariStack)},getSafariStack:function(){return $F(this.safariStack).evalJSON()},getSafariState:function(){var a=this.getSafariStack();return a[history.length-this.safariHistoryStartPoint-1]},putSafariState:function(b){var a=this.getSafariStack();a[history.length-this.safariHistoryStartPoint]=b;this.safariStack.setValue(a.toJSON())}};Horde.historyStorage={put:function(a,b){this.loadHashTable();this.storageHash.set(a,b);this.saveHashTable()},get:function(a){this.loadHashTable();var b=this.storageHash.get(a);return Object.isUndefined(b)?null:b},remove:function(a){this.loadHashTable();this.storageHash.unset(a);this.saveHashTable()},reset:function(){this.storageField.value="";this.storageHash=$H()},hasKey:function(a){this.loadHashTable();return!(typeof this.storageHash.get(a)==undefined)},init:function(){var a=new Element("FORM").hide();$(document.body).insert(a);this.storageField=new Element("TEXTAREA",{id:"historyStorageField"});a.insert(this.storageField)},loadHashTable:function(){if(!this.storageHash){this.storageHash=(this.storageField.value)?this.storageField.value.evalJSON():$H()}},saveHashTable:function(){this.loadHashTable();this.storageField.value=this.storageHash.toJSON()}};