
PDQ.popup=function(o){this.id=o.id;this.docId=o.docId;this.dForm=o.form;this.window=null;this.title=o.title;this.basicDialog=null;this.iFrame=null;this.iFrameRef=null;this.form=null;this.contentWindow=null;this.body=null;this.resized=false;this.centeredAfterResize=false;this.moved=false;this.url=o.url||'';this.openTask=null;this.displayTask=null;this.closeTask=null;this.resizeTask=null;this.initialCE=false;this.formLoaded=false;this.currentUrl='';this.isDominoForm=null;this.prevFormHeight=0;this.resizeLoopCount=0;this.extFieldsDone=false;this.mainScroll=null;this.onClose=o.onClose;this.position=o.position||'';}
PDQ.popup.prototype.init=function(o){function openHTML(o,b){if(typeof o.renderTo=='undefined')o.renderTo=document.body;o.shadow='sides';if(Ext.isIE){o.shadowOffset=14;}else{o.shadowOffset=6;}
PDQ.log('Opening embedded HTML or Page URL window');b.window=new Ext.Window(o);var hFR=b.window.getFrameHeight();var wFR=b.window.getFrameWidth();var hN=o.height+hFR;var wN=o.width+wFR;b.window.setSize(wN,hN);b.window.addListener('beforeclose',b.beforeclose,b,true);b.window.addListener('close',b.afterclose,b,true);b.center();PDQ.resetPopupShadows();b.window.show(o.animateTarget);b.basicDialog=b.window;b.window.body.update(o.html,true);}
if(!Ext.isEmpty(o.html)){o.resizable=false;openHTML(o,this);PDQ.resetPopupShadows();return;}
if(!Ext.isEmpty(o.swf)){o.html='<div id="flashObject"></div>';o.resizable=true;openHTML(o,this);var params={src:o.swf};o.param=o.param||{};var flashvars={};for(var i in o.param){if(typeof o.param[i]=='string'){if(i!='flashvars'){params[i]=o.param[i];}else{if(typeof o.param['flashvars']=='string'){o.param['flashvars']=Ext.urlDecode(o.param['flashvars']);}}}
if(i=='flashvars'){for(var k in o.param['flashvars']){flashvars[k]=o.param['flashvars'][k];}}}
delete o.param['flashvars'];var nd=Ext.DomQuery.selectNode('div:first',this.window.body.dom);var expressInstallURL=PDQ.pathNSF+'/expressInstall.swf?OpenFileResource';swfobject.embedSWF(o.swf,'flashObject',o.width,o.height,'9.0.115',expressInstallURL,flashvars,params);PDQ.resetPopupShadows();return;}
if(!Ext.isEmpty(o.p2f)){o.html='<div id="flashObject"></div>';o.resizable=true;openHTML(o,this);var params={src:o.p2f,name:o.id,play:'true',quality:'best',allowScriptAccess:'sameDomain'};var nd=Ext.DomQuery.selectNode('div:first',this.window.body.dom);var expressInstallURL=PDQ.pathNSF+'/expressInstall.swf?OpenFileResource';swfobject.embedSWF(o.p2f,'flashObject',o.width,o.height,'9.0.115',expressInstallURL,{extName:o.id},params);PDQ.resetPopupShadows();return;}
if(!Ext.isEmpty(o.pageURL)){o.url=o.pageURL;delete o.pageURL;}
this.url=o.url;var url=PDQ.portalDir+'/ajax-loader70.gif?OpenImageResource';if(!this.sameDomain()&&(typeof o.autoScroll=='undefined')){o.autoScroll=true;if(typeof o.resizeable=='undefined'){o.resizeable=true;}}
var s='background-color:white;';this.isDominoForm=false;if(o.url){if(o.url.match(/(\?opendocument)|(\?editdocument)|(\?openform)/i)){this.isDominoForm=true;}}
if(this.isDominoForm){o.autoScroll=true;o.autoHeight=false;o.bodyStyle='overflow-x:hidden;overflow-y:auto;';}else if(this.sameDomain()){if(o.autoScroll===false&&o.resizable===false){o.bodyStyle='overflow-x:hidden;overflow-y:auto;';}
o.bodyStyle='overflow-x:hidden;overflow-y:hidden;';s+='overflow:hidden;';}
var iframeScroll='no';if(o.autoScroll&&!this.isDominoForm){var iframeScroll='yes';}
var nHtml='<IFRAME id='+this.id+'-dlg-iFrame name='+this.id+'-dlg-iFrame'+' src="'+url+'" '+' scrolling="'+iframeScroll+'" '+' frameborder="no" height="100%" width="100%" style="'+s+'"'+' onload="parent.PDQ.closePopupOnBack({fId: this.id});" '+'></IFRAME>';o.html=nHtml;if(typeof o.autoHeight=='undefined')o.autoHeight=false;if(typeof o.autoScroll=='undefined')o.autoScroll=true;o.id=this.id+'-dlg';if(typeof o.renderTo=='undefined')o.renderTo=document.body;o.title='Loading...';if(Ext.isEmpty(o.width))o.width=300;if(Ext.isEmpty(o.height))o.height=192;o.shadow='sides';if(Ext.isIE){o.shadowOffset=14;}else{o.shadowOffset=6;}
if(typeof o.resizable=='undefined')o.resizable=true;if(!Ext.isIE)o.animCollapse=false;o.border=false;if(typeof o.resizable=='undefined'){o.resizable=false;}
this.window=new Ext.Window(o);this.window.on('show',function(){PDQ.windowMarginsAdjust(this.window);PDQ.resetPopupShadows();},this,{single:true,delay:500});this.window.on('show',function(){PDQ.resetPopupShadows();},this);if(this.sameDomain()){this.window.body.dom.style.overflowX='hidden';}
if(!this.isDominoForm){this.window.body.dom.style.overflowY='hidden';}else{this.window.body.dom.style.overflowY='auto';}
this.window.addListener('move',this.move,this,true);this.window.addListener('beforeclose',this.beforeclose,this,true);this.window.addListener('close',this.afterclose,this,true);if(this.sameDomain()){this.window.addListener('resize',this.setIframeHeight,this,true);}else{this.window.addListener('resize',PDQ.resetPopupShadows,this,true);}
this.window.setHeight(o.height);this.window.setWidth(o.width);this.center();this.moveTBC=true;this.window.show(o.animateTarget);if(!Ext.isIE&&this.topFix>=0){this.window.getEl().dom.style.position='fixed';this.window.getEl().dom.style.top=this.topFix+'px';}
this.iFrame=document.getElementById(this.id+'-dlg-iFrame');if(Ext.isGecko){this.iFrameRef=window.frames[this.id+'-dlg-iFrame'].content;}else if(Ext.isOpera||Ext.isIE){this.iFrameRef=document.frames[this.id+'-dlg-iFrame'];}else{this.iFrameRef=window.frames[this.id+'-dlg-iFrame'];}
this.basicDialog=this.window;var fn=function(){var t='';var t='';var t='';var t='';this.iFrame.src=this.url;if(this.title){this.window.setTitle(this.title);}else{this.window.setTitle(' ');}
PDQ.resetPopupShadows();}
this.displayTask=new Ext.util.DelayedTask();this.displayTask.delay(10,fn,this);if(Ext.isIE)this.docScrollTop=document.body.scrollTop;PDQ.resetPopupShadows();}
PDQ.popup.prototype.getContentHeight=function(){var t='';var t='';var t='';var t='';if(!this.sameDomain()){var h=this.window.body.getHeight();return h;}
if(Ext.isGecko){var fd=this.iFrame.contentDocument;if(this.iFrame.contentDocument===undefined)return null;if(Ext.isEmpty(this.iFrame.contentDocument))return null;if(this.iFrame.contentDocument.body===null)return null;this.contentWindow=this.iFrame;this.body=this.iFrame.contentDocument.body;}else if(Ext.isIE){var fd=window.frames[this.id+'-dlg-iFrame'].document;this.contentWindow=this.iFrame.contentWindow;if(Ext.isEmpty(this.iFrame.contentWindow.document.body)){PDQ.messageBox.alert('ERROR - IE Cannot handle text in front of form in popup windows');return 500;}else{this.body=this.iFrame.contentWindow.document.body;}}else{var fd=window.frames[this.id+'-dlg-iFrame'].document;this.contentWindow=this.iFrame.contentWindow;this.body=this.iFrame.contentWindow.document.body;}
this.form=fd.forms[0];var h=null;var hS=this.body.scrollHeight;var hO=this.body.offsetHeight;if(this.form){var hF=this.form.scrollHeight
var hFP=this.form.parentNode.scrollHeight;if(h===null)h=hF;h=(hF>h)?hF:h;if(typeof this.form.Query_String_Decoded!='undefined'){h+=12;}}
if(Ext.isIE&&hO!=150&&Ext.DomQuery.select('form',fd.forms[0]).length>0){if(hS>hF){h=hS;}}
if(Ext.isGecko){}else if(Ext.isOpera){}else if(Ext.isIE){}else{}
if(!Ext.isEmpty(this.form)){h+=this.form.offsetTop;}
return h;}
PDQ.popup.prototype.setIframeHeight=function(){if(this.iFrame===null)return;var hCn=this.getContentHeight();if(hCn===null)return;if(typeof this.dForm=='undefined'){this.iFrame.height=hCn+10;}else if(this.dForm==''){this.iFrame.height=hCn+10;}else if(this.dForm.indexOf('_')>=0){this.iFrame.height=hCn;}else{this.iFrame.height=hCn+10;}
var sz=this.window.getSize();var h=this.window.getInnerHeight();if(h!=hCn){var hFR=this.window.getFrameHeight();var hN=hCn+hFR;}
var wH=parseInt(this.iFrame.height)+this.window.getFrameHeight();if(wH<this.window.getSize().height){this.window.setSize(sz.width,hN);}
PDQ.resetPopupShadows();}
PDQ.popup.prototype.beforeclose=function(o){var p=this.window.getPosition();this.initX=p[0];this.initY=p[1];return true;}
PDQ.popup.prototype.close=function(o){if(Ext.isIE)delete this.docScrollTop;this.window.close();this.resizeLoopCount=0;}
PDQ.popup.prototype.afterclose=function(o){PDQ.messageBox.hide();PDQ.closePopTask=new Ext.util.DelayedTask();PDQ.closePopTask.delay(50,PDQ.closePopup,PDQ,[{id:this.id}]);PDQ.doMarkedRefreshes();if(this.onClose){this.onClose();}}
PDQ.popup.prototype.addScroll=function(o){PDQ.log('DEBUG - starting addScroll');if(this.isDominoForm)return;if(typeof this.form=='undefined')return;if(Ext.isEmpty(this.form)){PDQ.log('AddScroll - form not ready yet');this.addScroll.defer(250,this);return;}
if(!Ext.isEmpty(this.mainScroll))return;try{var t=this.form.id;}catch(e){PDQ.log('AddScroll - form not ready yet - permission error');this.addScroll.defer(250,this);return;}
var mainScroll=Ext.DomQuery.select('div[id=mainScroll]',this.form)[0];if(typeof mainScroll=='undefined')return;if(mainScroll.scrollHeight==0){PDQ.log('AddScroll - form not ready yet - mainScroll.scrollHeight = 0');this.addScroll.defer(250,this);return;}
buttonArea=Ext.DomQuery.select('div[id=buttonArea]',this.form)[0];var sz=this.window.getSize();var hFR=this.window.getFrameHeight();var h=sz.height-hFR;var hMax=Ext.lib.Dom.getViewportHeight()-70;PDQ.log('addScroll: window h='+h+' mainScroll h='+mainScroll.scrollHeight);if((mainScroll.scrollHeight+buttonArea.scrollHeight)>h&&sz.height>=hMax){PDQ.log('addScroll: setting scroll area to '+(h-35));this.mainScroll=Ext.DomQuery.select('div[id=mainScroll]',this.form)[0];this.iFrame.height=h;this.iFrame.parentNode.style.height=h;this.mainScroll.style.height=(h-buttonArea.scrollHeight)+'px';this.mainScroll.style.overflowY='scroll';this.mainScroll.style.overflowX='hidden';this.mainScroll.style.width='100%';this.mainScroll.parentNode.style.width='100%';this.iFrame.style.overflow='hidden';}
var ms=Ext.get(this.mainScroll);if(ms){ms.on('mousewheel',function(e,div){var sNode=div
while(sNode.id!='mainScroll'){sNode=sNode.parentNode}
if(sNode.scrollHeight==sNode.clientHeight){return;}
var delta=e.getWheelDelta();if(delta<0){if((sNode.scrollTop+sNode.clientHeight)>=sNode.scrollHeight){e.stopEvent();}}else{if(sNode.scrollTop==0){e.stopEvent();}}},this);}}
PDQ.popup.prototype.resize=function(o){PDQ.log('Resizing popup');this.resizeLoopCount+=1;if(typeof o=='undefined'){var o={};}
if(typeof o.count=='undefined'){this.prevFormHeight=0;}
if(!this.isDominoForm&&!this.extFieldsDone){PDQ.log('resize cancelled - Ext fields not created yet');if(this.resize){setTimeout(this.resize.createDelegate(this),100);}
return;}
if(!Ext.isEmpty(this.mainScroll)){if(typeof this.mainScroll.style!='undefined'){var fn=function(){this.mainScroll.style.width='99.9%'};fn.defer(100,this);if(typeof this.mainScroll.style.height!='undefined'){PDQ.log('resize cancelled - mainScroll already set');return;}}}
var sz=this.window.getSize();var hP=sz.height;var wP=sz.width;var hFR=this.window.getFrameHeight();var wFR=this.window.getFrameWidth();var hScroll=this.getContentHeight();hScroll=(typeof hScroll=='undefined')?null:hScroll;if(hScroll===null){setTimeout(this.resize.createDelegate(this),100);return;}
if(this.isDominoForm){this.iFrame.style.height=hScroll;}
PDQ.log('(resize) iFrame height set to '+hScroll);if(typeof this.form._field=='undefined'){}
if(this.form._editMode===undefined){var edit='';}else{var edit=this.form._editMode.value;}
if(edit=='1'&&this.form._WidthEdit){var wS=this.form._WidthEdit.value;if(wS==''){var wS=this.form._Width.value;}}else{if(this.form._Width){var wS=this.form._Width.value;}else{var wS=800;}}
wS=(wS=='')?600:eval(wS)+wFR;if(edit=='1'&&this.form._HeightEdit){var hS=this.form._HeightEdit.value;if(hS==''){var hS=this.form._Height.value;}}else{if(this.form._Height){var hS=this.form._Height.value;}else{var hS='';}}
if((this.id=='login'||this.name=='login')&&hS=='270')hS='200';var wC=wP;var hC=hScroll+hFR;if(hS!='')hC=eval(hS)+hFR;var x=this.window.getPosition()[0];var y=this.window.getPosition()[1];var hMax=Ext.lib.Dom.getViewportHeight()-50;var h=(hMax<hC)?hMax:hC;if(hScroll<=(h-hFR)){this.body.style.overflowY='hidden';this.window.body.dom.style.overflowY='hidden';this.body.style.overflowX='hidden';this.window.body.dom.style.overflowX='hidden';}else{this.body.style.overflowY='auto';this.window.body.dom.style.overflowY='auto';}
if(!this.centeredAfterResize){var pW=Ext.lib.Dom.getViewportWidth();var pH=Ext.lib.Dom.getViewportHeight();var xN=(pW-wS)/2;var yN=(pH-h)/2*.8+document.body.scrollTop;yN=(Math.abs(y-yN)<10)?y:yN;this.window.setPosition(xN,yN);x=xN;y=yN;}
this.window.setSize(wS,h);if(this.form){var sT=this.form.scrollTop;var hW=this.form.scrollHeight;}else{var sT=this.iFrame.document.body.scrollTop;var hW=this.iFrame.document.body.clientHeight;}
if((hC-sT)<hW){sT=hC-hW;sT=(sT<0)?0:sT;if(this.form){this.body.scrollTop=sT;}else{this.iFrame.document.body.scrollTop=sT;}}
var sz=this.window.getSize();var hC=sz.height;var wC=sz.width;if(hW==0||wC==0){setTimeout(this.resize.createDelegate(this),5);return;}
this.setIframeHeight();if(this.resized){var xN=x-(wC-wP)/2;}else{var xN=x;this.resized=true;}
if(Math.abs((y-document.body.scrollTop)-(Ext.lib.Dom.getViewportHeight()-hP)/2)<20){yN=(Ext.lib.Dom.getViewportHeight()-hC)/2;yN=(Math.abs(y-yN)<10)?y:yN;}else{yN=y-document.body.scrollTop;}
if(this.initY){yN=this.initY-document.body.scrollTop;}
var pW=Ext.lib.Dom.getViewportWidth();var pH=Ext.lib.Dom.getViewportHeight();var pastRight=xN+wC-pW;if(pastRight>0){xN=xN-pastRight-2;}
var pastBottom=yN+hC-pH;if(PDQ.showLog&&(pastBottom+30)>0){yN=yN-pastBottom-30;}
if(PDQ.showLog&&(pastBottom+4)>0){yN=yN-pastBottom-4;}
xN=(xN<4)?4:xN;yN=(yN<4)?4:yN;yN=yN+document.body.scrollTop;if(!this.centeredAfterResize){this.center();this.centeredAfterResize=true;}else if(yN!=y){this.window.setPagePosition(xN,yN)}
if(typeof o.count=='undefined'){this.resizeTask=new Ext.util.DelayedTask();this.resizeTask.delay(700,this.resize,this,[{count:1}]);}
PDQ.resetPopupShadows();}
PDQ.popup.prototype.move=function(){var t='';var t='';var t='';var t='';if(!Ext.isIE){if(this.window.getEl().dom.style.position!='fixed'){if(this.topFix){var top=this.topFix;}else{var top=document.body.scrollTop;var topW=this.window.getEl().dom.offsetTop;top=topW-top;}
this.window.getEl().dom.style.position='fixed';this.window.getEl().dom.style.top=top+'px';this.topFix=top;this.topSave=document.body.scrollTop;}else{var top=document.body.scrollTop;var topW=this.window.getEl().dom.offsetTop;top=topW-top;if(top<0)return;this.topFix=top;this.topSave=document.body.scrollTop;this.window.getEl().dom.style.top=top+'px';}
var sDiv=this.window.getEl().dom.previousSibling;if(sDiv.className.match(/x-shadow/i)){if(this.topFix){var top=this.topFix+5;}else{var top=document.body.scrollTop;var topW=sDiv.offsetTop;top=topW-top;}
sDiv.style.display='block';sDiv.style.position='fixed';sDiv.style.top=top+'px';}}
if(this.moved===null){this.moved=false;}else{this.moved=true;}}
PDQ.popup.prototype.center=function(){var left=null;var top=null;var vH=Ext.lib.Dom.getViewportHeight();var vW=Ext.lib.Dom.getViewportWidth();var wH=this.window.getSize().height;var wW=this.window.getSize().width;if(this.position=='TL'||this.position==''){var mP=PDQ.mainPanel.getPosition();left=mP[0]-30;top=mP[1]+12;var nPops=0;for(var i in PDQ.popups){if(PDQ.popups[i].window){if(!PDQ.popups[i].window.hidden&&(PDQ.popups[i].position=='TL'||PDQ.popups[i].position=='')){nPops++}}}
if(this.window.hidden){nPops++}
nPops--
left+=30*nPops;top+=30*nPops;}else if(this.position=='TR'){top=20;left=vW-20-wW;}else if(this.position=='BL'){top=vH-20-wH;left=20;}else if(this.position=='BR'){top=vH-20-wH;left=vW-20-wW;}else{top=(vH-wH)/2*.9
left=(vW-wW)/2;var nPops=0;for(var i in PDQ.popups){if(PDQ.popups[i].window){if(!PDQ.popups[i].window.hidden&&PDQ.popups[i].position=='C'){nPops++}}}
if(this.window.hidden){nPops++}
nPops--
left-=30*nPops;top-=30*nPops;}
var topS=document.body.scrollTop;if(top<20)top=20;if(left<20)left=20;if((top+wH)>vH){top=vH-30-wH;}
if(top<0)top=20;if(left<0)left=20;if(Ext.isIE){top+=topS;}
this.window.setPosition([left,top]);}
PDQ.popup.prototype.sameDomain=function(){var sameDom=false;var domM=document.location.href
var domF=this.url;if(domF.slice(0,1)=='/')sameDom=true;if(!sameDom){var mA=domM.match(/(https:\/\/|http:\/\/)([^\/]*)/i)[0];var mF=domF.match(/(https:\/\/|http:\/\/)([^\/]*)/i)[0];if(mA==mF)sameDom=true;}
return sameDom;}
