Request.PartialPageLoad=new Class({Extends:Request.HTML,options:{timeout:5000,noSpinner:false},send:function(a){this.sendOptions=new Hash(a);var c=a.data;switch($type(c)){case"element":a.method=c.get("method")||"get";a.url=c.get("action");if(!a.url&&c.getAttributeNode&&c.getAttributeNode("action")){a.url=c.getAttributeNode("action").nodeValue}a.data=document.id(c).toQueryString();break;case"object":case"hash":a.data=Hash.toQueryString(c);break;default:break}a.data=(a.data?a.data+"&":"")+"doPartialPageLoad=1&checkTemplate="+mainTemplate;if(!this.options.noSpinner){this.showProgressCursor()}window.fireEvent("beforePartialPageLoad");this.timeoutID=null;var b=(a.timeout||this.options.timeout);if(b){this.timeoutID=this.onTimeout.delay(b,this)}return this.parent(a)},onStateChange:function(){if(this.xhr.readyState!=4||!this.running){return}this.running=false;this.status=0;$try(function(){this.status=this.xhr.status}.bind(this));if(this.timeoutID){$clear(this.timeoutID)}this.timeoutID=null;this.xhr.onreadystatechange=$empty;if(this.options.isSuccess.call(this,this.status)){if(!this.options.noSpinner){this.hideProgressCursor()}this.response={text:this.xhr.responseText,xml:null};this.success(this.response.text)}else{this.response={text:null,xml:null};this.failure(1)}},onTimeout:function(){if(!this.running){return}this.running=false;this.status=0;this.timeoutID=null;this.xhr.abort();this.xhr.onreadystatechange=$empty;this.response={text:null,xml:null};this.failure(2)},isSuccess:function(a){if(a<200){return false}if(a>=300){return false}if(this.getHeader("X-Avenue-Reload")){return false}if(!this.getHeader("Content-Type").match(/text\/html/)){return false}if(this.getHeader("X-Avenue-Partial")!="1"){return false}if(!this.xhr.responseText){return false}return true},success:function(l){var m=this.options,f=this.response;if(!this.sendOptions.noHistoryUpdate){window.historyManager.resetState()}var n=new Element("div");var g=l.match(/<body[^>]*>([\s\S]*?)<\/body>/i);var c=(g)?g[1]:l;if(Browser.Engine.trident){c=c.replace(/< *(param.*?)>/ig,"<!-- wrap $1 -->")}n.set("html",c);if(m.update){try{window.fireEvent("partialPageLoad")}catch(h){}var j=new Hash();var d=new Array();switch($type(m.update)){case"element":case"function":j[m.update.id]=m.update;break;case"object":case"hash":j=new Hash(m.update);break;default:break}var k=true;var i=false;var b=[];j.each(function(p,o){var e=(o=="pagecontents"?n:n.getElement("[id="+o+"]"));if(!e){k=false;return}if(e.tagName.match(/script/i)){d.push(e);return}e.getElements("script").each(function(r){if(!r.src&&(Browser.Engine.webkit&&Browser.Engine.version<420?r.innerText:r.text).match(/register(DHTMLSelectable|MouseoverAttributes)/)){i=true}d.push(r.dispose())});switch($type(p)){case"element":var q=e.get("html");if(Browser.Engine.trident){q=q.replace(/< *(param.*?)>/ig,"").replace(/<!-- wrap (param.*?) -->/ig,"<$1>")}$(p).set("html",q);b.push($(p));break;case"function":p.attempt(e);if($(o)){b.push($(o))}break;default:break}});if(!k){f={text:null,xml:null};this.failure(3);return}if(m.evalScripts){if(!i&&b){restrictRegistrationContainers=b;n.getElements("script").each(function(e){if(!e.src&&(Browser.Engine.webkit&&Browser.Engine.version<420?e.innerText:e.text).match(/register(DHTMLSelectable|MouseoverAttributes)/)){d.unshift(e.dispose())}})}else{restrictRegistrationContainers=null}d.each(function(e){var o=document.createElement("script");o.setAttribute("type","text/javascript");if(e.src){o.src=e.src}else{if(Browser.Engine.webkit&&Browser.Engine.version<420){o.innerText=e.innerText}else{o.text=e.text}}o.onload=function(){o.onload=null;document.head.removeChild(o)};document.head.appendChild(o)})}window.fireEvent("afterPartialPageLoad")}f.html=l;this.onSuccess(f.html);if(!m.noScroll){if(this.options.url.match(/#(.*)/)){window.location.hash=RegExp.$1}else{window.scrollTo(0,0)}}var a=this.getHeader("X-Avenue-Location");if(!a){a=this.sendOptions.url}if(!a){a=window.fullPageRelUrlLongId}if(!a){a=window.fullPageRelUrl}if(!this.sendOptions.noHistoryUpdate){window.historyManager.update(a)}},failure:function(a){this.onFailure();this.retryPartialAsFullPageLoad()},retryPartialAsFullPageLoad:function(){if(this.getHeader("X-Avenue-Reload")){window.location=this.getHeader("X-Avenue-Reload")}else{if(this.sendOptions.url){window.location=this.sendOptions.url}else{if(this.sendOptions.data){this.sendOptions.data.submit()}}}},handleHistoryChange:function(a){$("pagecontents").partialPageLoad(a,true)},showProgressCursor:function(){if(this.options.noSpinner){return}var a=$(document.body);a.setStyle("cursor","progress");if(Request.PartialPageLoad.spinOpacity>0){a.spin({style:{opacity:Request.PartialPageLoad.spinOpacity}});a.get("spinner").element.setStyle("position","fixed")}},hideProgressCursor:function(){if(this.options.noSpinner){return}var a=$(document.body);a.setStyle("cursor","auto");if(Request.PartialPageLoad.spinOpacity>0){a.get("spinner").hide(true)}}});Request.PartialPageLoad.spinOpacity=0.5;Request.PartialPageLoad.requestDirs=["Admin"];Element.Properties.partialPageLoad={set:function(b){var a=this.retrieve("partialPageLoad");if(a){a.cancel()}return this.eliminate("partialPageLoad").store("partialPageLoad:options",$extend({link:"cancel",update:this,method:"get",noScroll:(this.id!="pagecontents")},b))},get:function(a){if(a||!this.retrieve("partialPageLoad")){if(a||!this.retrieve("partialPageLoad:options")){this.set("partialPageLoad",a)}this.store("partialPageLoad",new Request.PartialPageLoad(this.retrieve("partialPageLoad:options")))}return this.retrieve("partialPageLoad")}};Element.implement({partialPageLoad:function(){this.get("partialPageLoad").send(Array.link(arguments,{url:String.type,noHistoryUpdate:Boolean.type,data:$defined}));return this}});var HistoryManager=new Class({Implements:[Events],initialize:function(){this.hashTrackedInHistory=!Browser.Engine.trident||(document.documentMode&&document.documentMode>=8);this.initialState=this.getURIRelativeToRoot(window.location.href);this.state=this.initialState;if(this.getHash().match(/\/(.*)/)&&RegExp.$1!=this.initialState){this.state=null}this.observationPaused=false;this.observe.periodical(400,this)},getHash:function(){return window.location.href.match(/#(.*)/)?RegExp.$1:""},setHash:function(b,a){if(a&&!Browser.Engine.presto){window.location.replace(window.location.href.replace(/#.*/,"")+"#"+b)}else{window.location.hash=b}},assertIFrame:function(){if(!this.iframe){this.iframe=$("historyIframe")}if(!this.iframe){this.iframe=new Element("iframe",{id:"historyIframe",src:wwwroot+"/blank.html",styles:{display:"none"}}).injectInside($(document.body))}},getIFrameContents:function(){var a=this.initialState;if(this.iframe){var b=this.iframe.contentWindow.document;if(b&&b.body.id=="state"){if(b.body.innerText){a=decodeURIComponent(b.body.innerText)}}}return a},setIFrameContents:function(a){this.assertIFrame();try{var c=this.iframe.contentWindow.document;c.open();c.write('<html><body id="state">'+encodeURIComponent(a)+"</body></html>");c.close()}catch(b){}},getState:function(){var a=this.getHash().match(/\/(.*)/)?RegExp.$1:null;if(!this.hashTrackedInHistory){if(a===null||a==this.state){return this.getIFrameContents()}}return a},setState:function(b,a){this.observationPaused=true;var c=b===null?"":"/"+b;if(this.getHash()!=c){this.setHash(c,a)}if(!this.hashTrackedInHistory){if(this.getIFrameContents()!=b){this.setIFrameContents(b)}}this.state=b;this.observationPaused=false},resetState:function(){if(this.state!==null){this.setState(this.state,true)}},update:function(a){this.setState(this.getURIRelativeToRoot(a))},observe:function(){if(!Browser.loaded){return}if(this.observationPaused){return}var b=this.getState();if(b===null||b==this.state){return}this.setState(b);var a=this.getURIAbsoluteFromRootBase(b);this.fireEvent("historyChange",[a])},getURIRelativeToRoot:function(b){b=b.replace(/#.*/,"");if(b.match(/^\w+:\/\//)){var a=location.protocol+"//"+location.host;if(b.substr(0,a.length+1)!=a+"/"){return null}b=b.substr(a.length)}if(!b.match(/^\//)){b=window.location.pathname.replace(/[^\/]*$/,"")+b}if(b.substr(0,wwwroot.length+1)!=wwwroot+"/"){return null}b=b.substr(wwwroot.length+1);if(b===""){return"."}if(b.match(/^([^?]+\/)?\w+.php(\?.*)/)){return RegExp.$2}if(b.match(/^([^?]+\/)?\w+.php$/)){return"?"}if(b.match(/^([^\x00-\x1F.\s+?%:;!#&<>''""\\]|:\w+:)*(\?|$)/)){return b}return null},getURIAbsoluteFromRootBase:function(a){if(a.match(/^\?/)&&window.location.pathname.match(".php$|("+Request.PartialPageLoad.requestDirs.join("|")+")/$")){return window.location.pathname.replace(/[?#].*$/,"")+a}else{return wwwroot+"/"+(a=="."?"":a)}}});function tryPartialPageLoad(d,b){if(!d){return true}b=$(b)||$("pagecontents");if(!b){return true}switch($type(d)){case"object":case"element":if(d.getAttributeNode&&d.getAttributeNode("target")&&d.getAttributeNode("target")!="self"){return true}if($(d).getElements("input").some(function(f){return f.type=="file"&&f.value!==""})){return true}if(!d.href){break}d=d.href;case"string":var c=window.historyManager.getURIRelativeToRoot(d);if(!c){return true}var a=(window.historyManager?window.historyManager.state:window.historyManager.getURIRelativeToRoot(window.location.href));var e=d.indexOf("#")+1;if(c==a&&e){window.location.hash=d.substr(e);return false}break;default:break}b.partialPageLoad(d);return false}window.historyManager=new HistoryManager();window.historyManager.addEvent("historyChange",function(a){$("pagecontents").get("partialPageLoad").handleHistoryChange(a)});window.addEvent("domready",function(){window.historyManager.observe()});window.hidePageContents=(window.historyManager.state!==window.historyManager.initialState);if(window.hidePageContents){window.addEvent("partialPageLoad",function(){window.hidePageContents=false})}function replaceContainer(a,b){var c=$(a);var d=$(b);if(c&&d){d.replaces(c);d.setStyle("display","");d.set("id",c.id)}};
