Ext.ux.ManagedIFrame=function(){var C=Array.prototype.slice.call(arguments,0),D=Ext.get(C[0]),B=C[0];if(D&&D.dom&&D.dom.tagName=="IFRAME"){B=C[1]||{};}else{B=C[0]||C[1]||{};D=B.autoCreate?Ext.get(Ext.DomHelper.append(B.autoCreate.parent||document.body,Ext.apply({tag:"iframe",src:(Ext.isIE&&Ext.isSecure)?Ext.SSL_SECURE_URL:""},B.autoCreate))):null;}if(!D||D.dom.tagName!="IFRAME"){return D;}!!D.dom.name.length||(D.dom.name=D.dom.id);this.addEvents({"domready":true,"documentloaded":true,"exception":true,"message":true});if(B.listeners){this.listeners=B.listeners;Ext.ux.ManagedIFrame.superclass.constructor.call(this);}Ext.apply(D,this);D.addClass("x-managed-iframe");if(B.style){D.applyStyles(B.style);}if(!Ext.util.CSS.getRule(".x-managed-iframe")){var F=[".x-frame-shim"," {z-index:18000!important;position:absolute;top:0;left:0;background-color:transparent;width:100%;height:100%;zoom:1;}",".x-managed-iframe-mask"," {width:100%;height:100%;position:relative;}",".x-managed-iframe"," {overflow:auto;}"];Ext.util.CSS.createStyleSheet(F.join(""));}D.disableMessaging=B.disableMessaging===true;D._maskEl=D.parent(".x-managed-iframe-mask")||D.parent().addClass("x-managed-iframe-mask");Ext.apply(D._maskEl,{applyShim:function(G){if(this._mask){this._mask.remove();}this._mask=Ext.DomHelper.append(this.dom,{cls:G||"x-frame-shim"},true);this.addClass("x-masked");this._mask.setDisplayed(true);},removeShim:function(){this.unmask();}});D.applyShim=D._maskEl.applyShim.createDelegate(D._maskEl);D.removeShim=D._maskEl.removeShim.createDelegate(D._maskEl);D.loadMask=Ext.apply({msg:"Loading..",msgCls:"x-mask-loading",maskEl:D._maskEl,hideOnReady:true,disabled:!B.loadMask},B.loadMask);D._eventName=Ext.isIE?"onreadystatechange":"onload";D._windowContext=null;D.dom[D._eventName]=D.loadHandler.createDelegate(D);if(document.addEventListener){Ext.EventManager.on(window,"DOMFrameContentLoaded",D.dom[D._eventName]);}var A=D.updateManager=new Ext.UpdateManager(D,true);A.showLoadIndicator=B.showLoadIndicator||false;D.eventsFollowFrameLinks=typeof B.eventsFollowFrameLinks=="undefined"?true:B.eventsFollowFrameLinks;if(B.src){D.setSrc(B.src);}else{D.src=D.dom.src||null;var E=B.html||B.content||false;if(E){D.update.defer(10,D,[E]);}}return D;};Ext.extend(Ext.ux.ManagedIFrame,Ext.util.Observable,{setSrc:function(A,C,E){var B=Ext.isIE&&Ext.isSecure?Ext.SSL_SECURE_URL:"";var D=A||this.src||B;if(Ext.isOpera){this.dom.src=B;}this._windowContext=null;this._hooked=this._domReady=this._domFired=false;this._callBack=E||false;this.showMask();(function(){var G=typeof D=="function"?D()||"":D;try{this._frameAction=true;this.dom.src=G;this.frameInit=true;this.checkDOM();}catch(F){this.fireEvent("exception",this,F);}}).defer(10,this);if(C!==true){this.src=D;}return this;},reset:function(A,B){this.setSrc(A||(Ext.isIE&&Ext.isSecure?Ext.SSL_SECURE_URL:""),true,B);},scriptRE:/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/gi,update:function(B,A,D){A=A||this.getUpdateManager().loadScripts||false;B=Ext.DomHelper.markup(B||"");B=A===true?B:B.replace(this.scriptRE,"");var C;if(C=this.getDocument()){this._frameAction=!!B.length;this._windowContext=null;this._callBack=D||false;this._hooked=this._domReady=this._domFired=false;this.showMask();C.open();C.write(B);C.close();this.frameInit=true;if(this._frameAction){this.checkDOM();}else{this.hideMask(true);if(this._callBack){this._callBack();}}}else{this.hideMask(true);if(this._callBack){this._callBack();}}return this;},disableMessaging:true,_XFrameMessaging:function(){var A={"$":[]};var B=function(D,C){return D===null||D===undefined||(!C?D==="":false);};window.sendMessage=function(K,L,J){var F;if(F=arguments.callee.manager){if(K._fromHost){var I,M;var C=K.tag||L||null;var D=!B(C)?A[C.toLowerCase()]||[]:A["$"];for(var G=0,E=D.length;G<E;G++){if(I=D[G]){M=I.apply(I.__scope,arguments)===false?false:M;if(I.__single){D[G]=null;}if(M===false){break;}}}return M;}else{K={type:B(L)?"message":"message:"+L.toLowerCase().replace(/^\s+|\s+$/g,""),data:K,domain:J||document.domain,uri:document.documentURI,source:window,tag:B(L)?null:L.toLowerCase()};try{return F.disableMessaging!==true?F.fireEvent.call(F,K.type,F,K):null;}catch(H){}return null;}}};window.onhostmessage=function(F,E,G,C){if(typeof F=="function"){if(!B(F.__index)){throw"onhostmessage: duplicate handler definition"+(C?" for tag:"+C:"");}F.__single=G||false;F.__scope=E||window;var D=F.__tag=B(C)?"$":C.toLowerCase();A[D]||(A[D]=[]);F.__index=A[D].length;A[D].push(F);}};window.unhostmessage=function(D){if(typeof D=="function"&&typeof D.__index!="undefined"){var C=D.__tag||"$";A[C][D.__index]=null;}};},_renderHook:function(){this._windowContext=null;this._hooked=false;try{if(this.writeScript('(function(){parent.Ext.get("'+this.dom.id+'")._windowContext='+(Ext.isIE?"window":"{eval:function(s){return eval(s);}}")+";})();")){if(this.disableMessaging!==true){this.loadFunction({name:"XMessage",fn:this._XFrameMessaging},false,true);var B;if(B=this.getWindow().sendMessage){B.manager=this;}}}return this.domWritable();}catch(A){}return false;},sendMessage:function(C,A,B){var D;if(this.disableMessaging!==true&&(D=this.getWindow())){A||(A=C.tag||"");A=A.toLowerCase();C=Ext.applyIf(C.data?C:{data:C},{type:Ext.isEmpty(A)?"message":"message:"+A,domain:B||document.domain,uri:document.documentURI,source:window,tag:A||null,_fromHost:this});return D.sendMessage?D.sendMessage.call(null,C,A,B):null;}return null;},_windowContext:null,getDocument:function(){return this.getWindow()?this.getWindow().document:null;},getWindow:function(){var A=this.dom;return A?A.contentWindow||window.frames[A.name]:null;},print:function(){try{var B=this.getWindow();if(Ext.isIE){B.focus();}B.print();}catch(A){throw"print exception: "+(A.description||A.message||A);}},destroy:function(){this.removeAllListeners();if(this.dom){if(document.addEventListener){Ext.EventManager.un(window,"DOMFrameContentLoaded",this.dom[this._eventName]);}this.dom[this._eventName]=null;this._windowContext=null;if(Ext.isIE&&this.dom.src){this.dom.src="javascript:false";}this._maskEl=null;Ext.removeNode(this.dom);}Ext.apply(this.loadMask,{masker:null,maskEl:null});},domWritable:function(){return !!this._windowContext;},execScript:function(block,useDOM){try{if(this.domWritable()){if(useDOM){this.writeScript(block);}else{return this._windowContext.eval(block);}}else{throw"execScript:non-secure context";}}catch(ex){this.fireEvent("exception",this,ex);return false;}return true;},writeScript:function(G,B){B=Ext.apply({},B||{},{type:"text/javascript",text:G});try{var D,A,F=this.getDocument();if(F&&F.getElementsByTagName){if((D=F.getElementsByTagName("head")[0])&&(A=F.createElement("script"))){D.appendChild(A);for(var E in B){if(B.hasOwnProperty(E)){A[E]=B[E];}}return true;}}}catch(C){this.fireEvent("exception",this,C);}return false;},loadFunction:function(D,B,C){var A=D.name||D;var D=D.fn||window[D];this.execScript(A+"="+D,B);if(C){this.execScript(A+"()");}},showMask:function(D,C,B){var A;if((A=this.loadMask)&&(!A.disabled||B)){if(A._vis){return ;}A.masker||(A.masker=Ext.get(A.maskEl||this.dom.parentNode||this.wrap({tag:"div",style:{position:"relative"}})));A._vis=true;A.masker.mask.defer(A.delay||5,A.masker,[D||A.msg,C||A.msgCls]);}},hideMask:function(B){var A;if((A=this.loadMask)&&!A.disabled&&A.masker){if(!B&&(A.hideOnReady!==true&&this._domReady)){return ;}A._vis=false;A.masker.unmask.defer(A.delay||5,A.masker);}},loadHandler:function(B){if(!this.frameInit||(!this._frameAction&&!this.eventsFollowFrameLinks)){return ;}var A=(B&&typeof B.type!=="undefined"?B.type:this.dom.readyState);switch(A){case"loading":case"interactive":break;case"DOMFrameContentLoaded":if(this._domFired||(B&&B.target!==this.dom)){return ;}case"domready":if(this._domFired){return ;}if(this._domFired=this._hooked=this._renderHook()){this._frameAction=(this.fireEvent("domready",this)===false?false:this._frameAction);}case"domfail":this._domReady=true;this.hideMask();break;case"load":case"complete":if(!this._domFired){this.loadHandler({type:"domready"});}this.hideMask(true);if(this._frameAction||this.eventsFollowFrameLinks){this.fireEvent("documentloaded",this);}this._frameAction=false;if(this.eventsFollowFrameLinks){this._domFired=this._domReady=false;}if(this._callBack){this._callBack(this);}break;default:}},checkDOM:function(D){if(Ext.isOpera){return ;}var F=0,D=D||this.getWindow(),C=this,B=false,A=100;var E=function(){try{B=false;var I=D.document,G;if(!C._domReady){B=(I&&I.getElementsByTagName);B=B&&(G=I.getElementsByTagName("body")[0])&&!!G.innerHTML.length;}}catch(H){F=A;}if(!C._frameAction||C._domReady){return ;}if(F++<A&&!B){setTimeout(arguments.callee,10);return ;}C.loadHandler({type:B?"domready":"domfail"});};setTimeout(E,50);}});Ext.ux.ManagedIframePanel=Ext.extend(Ext.Panel,{defaultSrc:null,bodyStyle:{height:"100%",width:"100%"},frameStyle:false,loadMask:false,animCollapse:false,autoScroll:false,closable:true,ctype:"Ext.ux.ManagedIframePanel",showLoadIndicator:false,unsupportedText:{tag:"span",cls:"x-error-noframes",html:"Inline frames are NOT enabled/supported by your browser."},initComponent:function(){var A=this.unsupportedText?{cn:this.unsupportedText}:false;this.frameConfig||(this.frameConfig={autoCreate:{}});this.bodyCfg||(this.bodyCfg={tag:"div",cls:"x-panel-body",children:[{cls:"x-managed-iframe-mask",children:[Ext.apply(Ext.apply({tag:"iframe",frameborder:0,cls:"x-managed-iframe",style:Ext.apply({height:"100%",width:"100%",overflow:"auto"},this.frameStyle||this.iframeStyle||{})},this.frameConfig.autoCreate),A,Ext.isIE&&Ext.isSecure?{src:Ext.SSL_SECURE_URL}:false)]}]});Ext.ux.ManagedIframePanel.superclass.initComponent.call(this);this.monitorResize||(this.monitorResize=this.fitToParent);this.addEvents({documentloaded:true,domready:true,message:true,exception:true});this.addListener=this.on;if(this.defaultSrc){this.on("render",this.setSrc.createDelegate(this,[this.defaultSrc],0),this,{single:true});}},doLayout:function(){if(this.fitToParent&&!this.ownerCt){var B=this.getPosition(),A=this.getEl().parent().getViewSize();this.setSize(A.width-B[0],A.height-B[1]);}Ext.ux.ManagedIframePanel.superclass.doLayout.apply(this,arguments);},beforeDestroy:function(){if(this.rendered){if(this.tools){for(var A in this.tools){Ext.destroy(this.tools[A]);}}if(this.header&&this.headerAsText){var B;if(B=this.header.child("span")){B.remove();}this.header.update("");}Ext.each(["iframe","header","topToolbar","bottomToolbar","footer","loadMask","body","bwrap"],function(C){if(this[C]){if(typeof this[C].destroy=="function"){this[C].destroy();}else{Ext.destroy(this[C]);}this[C]=null;delete this[C];}},this);}Ext.ux.ManagedIframePanel.superclass.beforeDestroy.call(this);},onDestroy:function(){Ext.Panel.superclass.onDestroy.call(this);},onRender:function(B,A){Ext.ux.ManagedIframePanel.superclass.onRender.call(this,B,A);if(this.iframe=this.body.child("iframe.x-managed-iframe")){Ext.each([this[this.collapseEl],this.el,this.iframe],function(C){C.setVisibilityMode(Ext.Element[(this.hideMode||"display").toUpperCase()]||1).originalDisplay=(this.hideMode!="display"?"visible":"block");},this);if(this.loadMask){this.loadMask=Ext.apply({disabled:false,maskEl:this.body,hideOnReady:true},this.loadMask);}if(this.iframe=new Ext.ux.ManagedIFrame(this.iframe,Ext.apply({loadMask:this.loadMask,showLoadIndicator:this.showLoadIndicator,disableMessaging:this.disableMessaging},this.frameConfig))){this.loadMask=this.iframe.loadMask;this.iframe.ownerCt=this;this.relayEvents(this.iframe,["documentloaded","domready","exception","message"].concat(this._msgTagHandlers||[]));delete this._msgTagHandlers;}this.getUpdater().showLoadIndicator=this.showLoadIndicator||false;if(this.ownerCt){this.ownerCt.on("afterlayout",function(C,E){var D,F=false;Ext.each(["north","south","east","west"],function(G){if((D=E[G])&&D.splitEl){F=true;D.split.on("beforeresize",this.showDragMask,this);}},this);if(F){this.on("resize",this.hideDragMask,this);}},this,{single:true});}}},afterRender:function(A){var B=this.html;delete this.html;Ext.ux.ManagedIframePanel.superclass.afterRender.call(this);if(B&&this.iframe){this.iframe.update(typeof B=="object"?Ext.DomHelper.markup(B):B);}},sendMessage:function(){if(this.iframe){this.iframe.sendMessage.apply(this.iframe,arguments);}},on:function(B){var D=/^message\:/i,C=null;if(typeof B=="object"){for(var A in B){if(!this.filterOptRe.test(A)&&D.test(A)){C||(C=[]);C.push(A.toLowerCase());}}}else{if(D.test(B)){C=[B.toLowerCase()];}}if(this.getFrame()&&C){this.relayEvents(this.iframe,C);}else{this._msgTagHandlers||(this._msgTagHandlers=[]);if(C){this._msgTagHandlers=this._msgTagHandlers.concat(C);}}Ext.ux.ManagedIframePanel.superclass.on.apply(this,arguments);},hideDragMask:function(){Ext.select(".x-managed-iframe-mask",true).each(function(A){A.removeShim();});},showDragMask:function(){Ext.select(".x-managed-iframe-mask",true).each(function(A){A.applyShim();});},setSrc:function(B,C,E){var A=B||this.defaultSrc||null;if(!A){return this;}if(typeof A=="object"){B=A.url||false;E=A.callback||false;}var D=B||(Ext.isIE&&Ext.isSecure?Ext.SSL_SECURE_URL:"");if(this.rendered&&this.iframe){this.iframe.setSrc(D,C,E);}if(C!==true){this.defaultSrc={url:D,callback:E};}this.saveState();return this;},getState:function(){var A=(this.defaultSrc?this.defaultSrc.url||this.defaultSrc:null);return Ext.apply(Ext.ux.ManagedIframePanel.superclass.getState.call(this)||{},{defaultSrc:typeof A=="function"?A():A});},getUpdater:function(){return this.rendered?(this.iframe||this.body).getUpdater():null;},getFrame:function(){return this.rendered?this.iframe:null;},getFrameWindow:function(){return this.rendered&&this.iframe?this.iframe.getWindow():null;},getFrameDocument:function(){return this.rendered&&this.iframe?this.iframe.getDocument():null;},load:function(B){var A;if(A=this.getUpdater()){if(B&&B.renderer){A.setRenderer(B.renderer);delete B.renderer;}A.update.apply(A,arguments);}return this;},doAutoLoad:function(){this.load(typeof this.autoLoad=="object"?this.autoLoad:{url:this.autoLoad});},onShow:function(){if(this.iframe){this.iframe.setVisible(true);}Ext.ux.ManagedIframePanel.superclass.onShow.call(this);},onHide:function(){if(this.iframe){this.iframe.setVisible(false);}Ext.ux.ManagedIframePanel.superclass.onHide.call(this);}});Ext.reg("iframepanel",Ext.ux.ManagedIframePanel);Ext.ux.ManagedIframePortlet=Ext.extend(Ext.ux.ManagedIframePanel,{anchor:"100%",frame:true,collapseEl:"bwrap",collapsible:true,draggable:true,cls:"x-portlet"});Ext.reg("iframeportlet",Ext.ux.ManagedIframePortlet);
