// (c)2009 Alan Lawson

PDQ.block=function(config){this.init(config);};PDQ.block.prototype.init=function(config){this.id=config.id;this.pageSet=null;this.blockPC=null;this.title=config.title;this.copyVer=config.copyVer;this.srcBlockPC=config.srcBlockPC;this.blockCode=config.blockCode;this.docId=config.docId;this.portletDocId=config.portletDocId||null;this.sort=eval(config.sort);this.isDisplay=config.isDisplay;this.sameSpaceCode=config.sameSpaceCode;this.displayMode=config.displayMode;this.progressIcon=config.progressIcon;this.debug=config.debug;this.blockType=config.blockType;this.alignH=config.alignH;this.isColumn=config.isColumn;this.parentId=config.parentId||null;this.parentPanel=null;this.width=config.width||null;this.heightMin=config.heightMin||null;this.heightMax=config.heightMax||null;this.clip=config.clip;this.forceAbsolute=config.forceAbsolute;this.prevColumn=config.prevColumn||null;this.blockStyles=config.blockStyles||'';this.transparent=false;this.db=config.db||null;this.cacheForms=config.cacheForms;this.formName=config.formName||'';this.URLOpts=config.URLOpts||'';this.gAnalytics=[];this.gAnalyticsLast=[];this.fromServerCache=null;this.reasonNotServerCache=null;this.execMsSrv=null;if(typeof this.param=='undefined')this.param={};this.paramMon=config.paramMon;this.paramUsed=config.paramUsed;this.paramRef=config.paramRef;this.paramUpdates=config.paramUpdates;this.refreshSelf=config.refreshSelf;this.paramNoRefreshOnBank=config.paramNoRefreshOnBank||null;this.paramsClearOnExit=config.paramsClearOnExit;this.typeParams=config.typeParams;this.debugInfo=config.debugInfo||null;this.initialized=false;this.toDelete=false;this.parent=null;this.childIndex=null;this.previous=null;this.next=null;this.firstChild=null;this.lastChild=null;this.childBlocks=[];this.refreshMark=false;this.refreshDoc=[];this.lastSingleClickRowIndex=null;this.deleteRefreshBlocks=[];this.deleteRow=null;this.deleteTrans=null;this.deleteIndex=null;this.deleteCount=null;this.deleteMsg=null;if(typeof this.panel=='undefined')this.panel=null;if(typeof this.toolBar=='undefined')this.toolBar=null;if(typeof this.data=='undefined')this.data=null;if(typeof this.recordCfg=='undefined')this.recordCfg=null;if(typeof this.record=='undefined')this.record=null;if(typeof this.store=='undefined')this.store=null;if(typeof this.colModel=='undefined')this.colModel=null;if(typeof this.grid=='undefined')this.grid=null;if(typeof this.dataview=='undefined')this.dataview=null;if(typeof this.map=='undefined')this.map=null;this.heightChange=false;this.widthChange=false;this.isPaged=null;this.calcInProcess=false;this.calcTotalRows=null;this.calcO={};this.calcLastRowDone=null;this.dragZone=null;this.dragEnabled=false;this.dragInProcess=false;this.currentPressed;this.lastPressed;if(this.parentId){this.parent=PDQ.getActiveBlock(this.parentId);var pObj=this.parent;}else{var pObj=PDQ;}
var blockExists=false;for(var i=0;i<pObj.childBlocks.length;i++){if(pObj.childBlocks[i].id==this.id){blockExists=true;}
if(pObj.childBlocks[i].sort>this.sort){break;}}
if(!blockExists){if(i<pObj.childBlocks.length){pObj.childBlocks.splice(i,0,this);}else{pObj.childBlocks[i]=this;}}
for(var i=0;i<pObj.childBlocks.length;i++){pObj.childBlocks[i].childIndex=i;if(i==0){pObj.childBlocks[i].previous=null;if(pObj.childBlocks.length>=2){pObj.childBlocks[i].next=pObj.childBlocks[i+1];}else{pObj.childBlocks[i].next=null;}}else if(i<(pObj.childBlocks.length-1)){pObj.childBlocks[i].previous=pObj.childBlocks[i-1];pObj.childBlocks[i].next=pObj.childBlocks[i+1];}else{pObj.childBlocks[i].previous=pObj.childBlocks[i-1];pObj.childBlocks[i].next=null;}}
pObj.firstChild=pObj.childBlocks[0];pObj.lastChild=pObj.childBlocks[pObj.childBlocks.length-1];var t=this.id.split('__');this.pageSet=t[0]
this.blockPC=PDQ.pageCode+"-"+t[1];if(t.length>=3){this.blockPC+="-"+t[2];}
PDQ.Block[this.blockCode]=this;}
PDQ.block.prototype.createBlankPanel=function(){if(document.body){PDQ.log('New block '+this.id);}
var hidden=!this.isDisplay;var hideMode='offsets';if(this.blockType=='PC'){var bs='';if(!this.blockStyles.match(/background-color:/i)){bs='background-color:transparent;';}
var np={id:this.id,style:bs+this.blockStyles,bodyStyle:bs,hidden:hidden,hideMode:hideMode,border:false,autoScroll:false};np.layout='column';this.panel=new Ext.Panel(np);}else if(this.blockType=='P'){if(this.heightMax===null){var sc=false;}else{var sc=!this.clip;}
var bs='';if(!this.blockStyles.match(/background-color:/i)){bs='background-color:transparent;';}
var np={id:this.id,style:bs+this.blockStyles,bodyStyle:bs,border:false,hidden:hidden,hideMode:hideMode,autoScroll:sc};if(this.width){np.width=this.width;}
this.panel=new Ext.Panel(np);}else if(this.blockType==''){var bs='';if(!this.blockStyles.match(/background-color:/i)){bs='background-color:transparent;';}
if(this.heightMax===null){var sc=false;}else{var sc=!this.clip;bs+='overflow-x:hidden;';}
var np={id:this.id,style:bs+this.blockStyles,bodyStyle:bs,cls:'HTMLtext',border:false,hidden:hidden,autoScroll:sc};if(this.width){np.width=this.width;}
this.panel=new Ext.Panel(np);}else if(this.blockType=='T1'){var np={id:this.id,style:this.blockStyles,hidden:hidden,border:false};if(this.width){np.width=this.width;}
this.panel=new Ext.Panel(np);}else if(this.blockType=='M'){if(Ext.isEmpty(this.parent.width)){}
var np={id:this.id,style:this.blockStyles,border:false,autoScroll:!this.clip};if(this.width){np.width=this.width;}
this.panel=new Ext.Panel(np);}else{var np={id:this.id,style:this.blockStyles,border:false,autoScroll:!this.clip};if(this.width){np.width=this.width;}
this.panel=new Ext.Panel(np);}
this.panel.PDQblock=this;this.transparent=false;this.panel.addListener('render',this.setBlockColor,this,true);if(Ext.isSafari){this.panel.on('render',this.adjustHeight,this,{delay:500,buffer:500});this.panel.on('render',this.adjustHeight,this,{delay:2000,buffer:2000});}
this.placeBlankPanel();};PDQ.block.prototype.setBlockColor=function(){var div=this.panel.getEl().dom;if(div.currentStyle){var bgc=div.currentStyle.backgroundColor;}else{var bgc=div.style.backgroundColor;}
if(bgc==''){bgc='transparent';}
var div=this.panel.body.dom;if(div.firstChild){if(div.firstChild.tagName=='DIV'){div=div.firstChild;}}
if(div.firstChild){if(div.firstChild.tagName=='DIV'){div=div.firstChild;}}
while(div&&div.id.slice(0,4)!='CM__'&&div.id!='MainPage'){div.style.backgroundColor=bgc;div.style.background=bgc;div=div.parentNode;}}
PDQ.block.prototype.setVisibility=function(){if(this.panel===null)return;var h=this.panel.hidden;var r=this.panel.rendered;var changed=false;if(this.getVisibility()){if(!this.panel.isVisible()){this.panel.show();changed=true;}
for(var i=0;i<this.childBlocks.length;i++){var childChanged=this.childBlocks[i].setVisibility();if(!changed&&childChanged){changed=true;}}}else{if(this.panel.isVisible()){this.panel.hide();changed=true;}
for(var i=0;i<this.childBlocks.length;i++){var childChanged=this.childBlocks[i].setVisibility();if(!changed&&childChanged){changed=true;}}}
PDQ.recalcWidths(this.id);this.adjustHeight();return changed;}
PDQ.block.prototype.placeBlankPanel=function(pn){if(typeof pn=='undefined'){var pn=this.panel;}
if(this.parent){var pp=this.parent.panel;}else{var pp=PDQ.mainPanel;}
this.parentPanel=pp;if(typeof this.parentPanel.items=='undefined'){this.parentPanel.add(pn);}else{if(this.childIndex<this.parentPanel.items.length){this.parentPanel.remove(this.parentPanel.items[this.childIndex]);}
this.parentPanel.insert(this.childIndex,pn);}
this.panel=pn;if(this.parentPanel.doLayout){this.parentPanel.doLayout();}
if(this.heightMin){this.panel.setHeight(this.heightMin);}
this.adjustRightColumn();}
PDQ.block.prototype.adjustRightColumn=function(){if(this.parent===null){return;}
if(this.width!==null){return;}
if(this.parent.blockType!='PC'){return;}
var pb=this.parent;if(pb.childBlocks.length>1){var totW=0;var lastC=null;for(var i=0;i<pb.childBlocks.length;i++){if(pb.childBlocks[i].isDisplay){if(pb.childBlocks[i].width!==null&&lastC===null){totW+=pb.childBlocks[i].width;}
if(pb.childBlocks[i].width!==null&&lastC!==null){if(pb.childBlocks[i].panel){var m='ERROR - not enough room for block '+pb.childBlocks[i].id+' as a column in parent block.';PDQ.messageBox.alert(m);pb.childBlocks[i].panel.hide();}}
if(pb.childBlocks[i].width===null&&lastC===null){lastC=pb.childBlocks[i];}
if(pb.childBlocks[i].width===null&&lastC!==null&&lastC!=pb.childBlocks[i]){var m='ERROR - Column '+lastC.blockCode+' has a blank width and it is not the last column.';PDQ.messageBox.alert(m);}}}
if(lastC===null){return;}
if(pb.panel){var lastW=pb.panel.getInnerWidth()-totW;if(typeof lastC.panel!='undefined'){if(lastC.panel){lastC.panel.setWidth(lastW);}}}}}
PDQ.block.prototype.addDataRequestToQ=function(o,reason,LatLng,isPointsReq,worldPoints){if(typeof isPointsReq=='undefined'){var isPointsReq=false;}
if(typeof worldPoints=='undefined'){var worldPoints=false;}
if(typeof o=='undefined')o={};if(o===null)o={};if(typeof reason=='undefined')reason='';if(this.blockType=='P'||this.blockType=='PC'){if(this.paramUsed.length==0){return;}}
var docsDeleted=false;var hasStore=false;if(typeof this.store!='undefined'){if(this.store)hasStore=true;}
if(this.refreshDoc.length>0&&hasStore){for(var k=this.refreshDoc.length-1;k>=0;k--){if(this.refreshDoc[k].mode=='Delete'){var delRecIndex=this.store.find('docId',this.refreshDoc[k].docId);if(delRecIndex>=0){var delRec=this.store.getAt(delRecIndex);if(typeof delRec!='undefined'){this.store.remove(delRec);}}
this.refreshDoc.splice(k,1);docsDeleted=true;}}}
if(docsDeleted&&this.refreshDoc.length==0){return}
var p={};p.type='Block';p.db=PDQ.db;p.cmPageId=PDQ.cmPageId;p.pageSet=this.pageSet;p.pageCode=PDQ.pageCode;p.blockPC=this.blockPC;p.blockDocId=this.docId;p.block=this;p.requestFn=this.request;if(o.ignoreCache){p.ignoreCache=true;delete o.ignoreCache;}
if(this.portletDocId)p.portletDocId=this.portletDocId;if(reason)p.reason=reason;if(this.refreshDoc.length>0&&(this.blockType=='G'||this.blockType=='DV')){var i=0;var d=[];for(var k=this.refreshDoc.length-1;k>=0;k--){if(this.refreshDoc[k].mode=='Update'||this.refreshDoc[k].mode=='Create'){if(this.refreshDoc[k].db){var dcp=this.refreshDoc[k].db.replace(/\\/g,'/');dcp=this.refreshDoc[k].docId+'^'+dcp;d.push(dcp);}else{d.push(this.refreshDoc[k].docId);}
this.refreshDoc.splice(k,1);}}
p.GetDocID=d.join('|');}
p.params={};for(var i in o){p.params[i]=o[i];}
if(this.blockType=='M'){var zoomCenter=PDQ.getMapCenterZoom(this);if(zoomCenter.zoom){if(this.map){p.params['SM_zoom']=this.map.getZoom();}else{p.params['SM_zoom']=zoomCenter.zoom;}}
if(this.mapWorldLoaded){p.params['SM_zoom']=PDQ.map.ajaxZoom;worldPoints=false;}
if(typeof LatLng=='undefined'){var LL=zoomCenter.centerPoint;}else{var LL=LatLng;}
if(LL){p.params['SM_lat']=LL.lat();p.params['SM_lng']=LL.lng();}
if(worldPoints){if(PDQ.map.worldMapAge>0){p.params['UseCacheMin']=PDQ.map.worldMapAge;}}
if(zoomCenter.zoom<PDQ.map.ajaxZoom){p.params['UseCacheMin']=PDQ.map.worldMapAge;}}
var inQueue=false;if(typeof p.GetDocID=='undefined'){CheckStackEntry:for(var i=PDQ.q.stack.low;i<=PDQ.q.stack.high&&!inQueue;i++){if(PDQ.q.stack[i].type!='Block')continue CheckStackEntry;if(typeof PDQ.q.stack[i].transaction=='undefined'||PDQ.q.stack[i].status===null){if(p.db!=PDQ.q.stack[i].db)continue CheckStackEntry;if(p.cmPageId!=PDQ.q.stack[i].cmPageId)continue CheckStackEntry;if(p.pageSet!=PDQ.q.stack[i].pageSet)continue CheckStackEntry;if(p.pageCode!=PDQ.q.stack[i].pageCode)continue CheckStackEntry;if(p.blockPC!=PDQ.q.stack[i].blockPC)continue CheckStackEntry;inQueue=true;break;}}}
if(!inQueue||isPointsReq){p.isPointsReq=isPointsReq;p.worldPoints=worldPoints;var si=PDQ.q.add(p);PDQ.q.exec();}
this.refreshMark=false;};PDQ.block.prototype.request=function(o){var stackEntry=this;var delayMsec=null;if(!stackEntry.params)stackEntry.params={};stackEntry.paramsSent={};stackEntry.paramsSentURL={PDQsession:PDQ.session};var b=stackEntry.block;if(this.type=='Block'){if(b.blockType=='T1'){if(b.toolBar){b.panel.remove(b.toolBar,true);b.parentPanel.doLayout();}
b.toolBar=new Ext.Toolbar({height:b.panel.getBox()['height']});b.panel.add(b.toolBar);b.parentPanel.doLayout();}else if((b.blockType==''||b.blockType=='DV')&&b.progressIcon=='D'){b.panel.body.update('');var yOff=b.panel.getBox()['height']/2-16;var progress=dh.insertFirst(b.panel.body,{tag:'div',align:'center',style:'margin-top:'+yOff+'px;',children:{tag:'img',src:PDQ.portalDir+'/ajax-loader.gif?OpenImageResource'}});b.panel.doLayout();}
var p=b.paramUsed.concat(b.paramRef);p=PDQ.getParams(p,stackEntry.block);for(var i in p){if(i!==''){stackEntry.paramsSent[i]=p[i];stackEntry.paramsSentURL['V_'+i]=p[i];}}
stackEntry.paramsSentURL['Mode']='BlockJS';if(this.db){if(stackEntry.cmdb){stackEntry.paramsSentURL['DB']=this.db;stackEntry.paramsSentURL['CMDB']=stackEntry.cmdb;}else{stackEntry.paramsSentURL['DB']=this.db;}}else{stackEntry.paramsSentURL['DB']=stackEntry.db||PDQ.db;}
stackEntry.paramsSentURL['CMPageID']=stackEntry.cmPageId;stackEntry.paramsSentURL['PageSet']=stackEntry.pageSet;stackEntry.paramsSentURL['PageCode']=stackEntry.pageCode;stackEntry.paramsSentURL['Block']=stackEntry.blockPC;stackEntry.paramsSentURL['BlockDocID']=b.docId;if(b.portletDocId){stackEntry.paramsSentURL['PortletDocID']=b.portletDocId;}
if(typeof stackEntry.GetDocID!='undefined'){stackEntry.paramsSentURL['GetDocID']=stackEntry.GetDocID;}
if(stackEntry.ignoreCache){stackEntry.paramsSentURL['IgnoreCache']='yes';}
stackEntry.paramsSentURL['Build']=PDQ.buildNumber;var fullUrl=PDQ.host+PDQ.path;var callBack=this.block.callback;}else if(this.type=='Recalc'){stackEntry.paramsSentURL['PP']=PDQ.portalCode;stackEntry.paramsSentURL['PORG']=PDQ.orgCode;stackEntry.paramsSentURL['DB']=PDQ.db;if(this.db){if(stackEntry.cmdb){stackEntry.paramsSentURL['DB']=this.db;stackEntry.paramsSentURL['CMDB']=stackEntry.cmdb;}else{stackEntry.paramsSentURL['DB']=this.db;}}else{stackEntry.paramsSentURL['DB']=stackEntry.db||PDQ.db;}
stackEntry.paramsSentURL['DocID']=stackEntry.docId;stackEntry.paramsSentURL['ReCalc']='current';if(stackEntry.reconvert){stackEntry.paramsSentURL['Reconvert']='Yes';}
stackEntry.paramsSentURL['ProcID']=stackEntry.index;stackEntry.paramsSentURL['ExtVer']=PDQ.extVer;if(PDQ.cssTheme!='')stackEntry.paramsSentURL['CSSTheme']=PDQ.cssTheme;for(var i in PDQ.param){if(PDQ.param[i]!==null){if(PDQ.param[i]!=''){var ipv=PDQ.getParams([i],stackEntry.block,true);stackEntry.paramsSent[i]=ipv;stackEntry.paramsSentURL[i]=ipv;}}}
var fullUrl=PDQ.host+PDQ.pathNSF+'/GenForm?OpenAgent';var callBack=this.block.callbackMacroExec;delayMsec=0;}else if(this.type=='Macro'){stackEntry.paramsSentURL['PP']=PDQ.portalCode;stackEntry.paramsSentURL['PORG']=PDQ.orgCode;stackEntry.paramsSentURL['DB']=PDQ.db;if(this.db){if(stackEntry.cmdb){stackEntry.paramsSentURL['DB']=this.db;stackEntry.paramsSentURL['CMDB']=stackEntry.cmdb;}else{stackEntry.paramsSentURL['DB']=this.db;}}else{stackEntry.paramsSentURL['DB']=stackEntry.db||PDQ.db;}
stackEntry.paramsSentURL['FormCode']=stackEntry.block.formName;stackEntry.paramsSentURL['RunMacro']=stackEntry.macro;stackEntry.paramsSentURL['Mode']='Open';stackEntry.paramsSentURL['BlockDocID']=b.docId;stackEntry.paramsSentURL['DocID']=stackEntry.docId;stackEntry.paramsSentURL['ProcID']=stackEntry.index;stackEntry.paramsSentURL['ExtVer']=PDQ.extVer;if(PDQ.cssTheme!='')stackEntry.paramsSentURL['CSSTheme']=PDQ.cssTheme;if(stackEntry.reconvert)stackEntry.paramsSentURL['Reconvert']=stackEntry.reconvert;for(var i in PDQ.param){var ipv=PDQ.getParams([i],stackEntry.block,true);if(ipv!==null){if(ipv!=''){stackEntry.paramsSent[i]=ipv;stackEntry.paramsSentURL[i]=ipv;}}}
var fullUrl=PDQ.host+PDQ.pathNSF+'/GenForm?OpenAgent';var callBack=this.block.callbackMacroExec;delayMsec=0;}
for(var i in stackEntry.params){stackEntry.paramsSent[i]=stackEntry.params[i];stackEntry.paramsSentURL['V_'+i]=stackEntry.params[i];}
if(Ext.isSecure){fullUrl='https://'+fullUrl;}else{fullUrl='http://'+fullUrl;}
var trans=Ext.Ajax.request({url:fullUrl,params:stackEntry.paramsSentURL,method:'GET',callback:callBack,scope:stackEntry});stackEntry.transaction=trans;if(stackEntry.type=='Recalc'||stackEntry.type=='Macro'){if(PDQ.messageBox.type=='P'){PDQ.messageBox.progressUpdate(stackEntry.progressPercent,'',stackEntry.progressMsg,0,stackEntry.rowIndex)}}else if(b.progressIcon==''){}};PDQ.block.prototype.callback=function(o,s,r){if(!s){var m='ERROR in block '+this.block.id+' callback (probably ajax request timeout).';if(PDQ.showLog){PDQ.messageBox.alert(m);}
PDQ.log(m);return;}
var b=this.block;o.scope.status=r.status;o.scope.returnText=r.responseText;o.scope.tId=r.tId;o.scope.evalErrorMessage=null;if(b.debug){PDQ.log('*** HTTP Response from '+b.id+' ***\n'+o.scope.returnText);PDQ.callDebugger();}
if(r.responseText.slice(0,6)=='<html>'){var m='ERROR in block '+o.scope.block.blockCode+' callback (probably formula error).\n';m+='See console for details.\n'
var em=r.responseText.match(/<body.*>\n(.*)\n<\/body>/mi);if(em){m+=r.responseText.match(/<body.*>\n(.*)\n<\/body>/mi)[1];}
PDQ.messageBox.alert(m);PDQ.showLog=true;PDQ.log(m);PDQ.log(r.responseText);return;}
if(r.responseText.slice(0,1)!='('){var m='ERROR in block '+o.scope.block.blockCode+' callback (probably formula error).\n';m+='See console for details.\n'
m+=r.responseText.slice(0,1024);PDQ.messageBox.alert(m);PDQ.showLog=true;PDQ.log(m);PDQ.log(r.responseText);return;}
try{o.scope.returnObj=eval(r.responseText);}
catch(exception){if(PDQ.haltOnEval){var m='Block '+o.scope.block.id+' stack index:'+o.scope.index+'. Callback return code eval error: ';m+='See console for details.\n'
m+=+exception.message+'\n'+r.responseText;PDQ.messageBox.alert(m);}
var m='Block '+o.scope.block.id+' stack index:'+o.scope.index+'. Callback return code eval error: ';PDQ.showLog=true;PDQ.log(m);PDQ.log(r.responseText);o.scope.evalErrorMessage=exception.message;b.panel.body.update('ERROR - '+exception.message);return;}
if(o.scope.returnObj){var rObj=o.scope.returnObj;if(rObj.debugInfo){if(rObj.debugInfo!=''){var m='Block '+o.scope.block.id+' debug results: '+rObj.debugInfo;PDQ.messageBox.alert(m);PDQ.showLog=true;PDQ.log(m);PDQ.log(rObj.debugInfo);}}}
var m='Block callback - '+this.block.id;if(typeof rObj.fromServerCache!='undefined'){if(rObj.fromServerCache){m+=' (from cache)';}else{if(rObj.reasonNotServerCache){m+='(not from cache - '+rObj.reasonNotServerCache+')';}}}
if(b.blockType=='M'){m+=' Grid:'+rObj.typeParams.mapGrid;}
PDQ.log(m);if(rObj.updateOnly&&(b.blockType=='G'||b.blockType=='DV')){if(b.store){for(var recN=0;recN<rObj.records.length;recN++){var rowData={};for(var i=0;i<b.recordCfg.length;i++){var cn=b.recordCfg[i].mapping;var nm=b.recordCfg[i].name;rowData[nm]=rObj.records[recN][cn];}
var targetRecIndex=b.store.find('docId',rowData['docId']);var wasUpdated=false;if(targetRecIndex>=0){var targetRec=b.store.getAt(targetRecIndex);if(typeof targetRec!='undefined'){for(var i in rowData){if(targetRec.get(i)!=rowData[i]){targetRec.set(i,rowData[i]);}}
wasUpdated=true;}}
if(!wasUpdated){var recConstructor=b.store.recordType;var newRec=new recConstructor(rowData);b.store.addSorted(newRec);}}}
PDQ.progressOffCheck();return;}
if(b.blockType=='M'&&this.isPointsReq){if(b.map){b.addData(rObj.data,rObj.typeParams.mapGrid);return;}}
if(rObj.data){b.data=rObj.data;}else{b.data=null;}
if(b.blockType=='G'&&b.heightMin!=rObj.heightMin){b.heightChange=true;b.heightMin=rObj.heightMin;}
if(b.blockType=='G'&&b.heightMax!=rObj.heightMax){b.heightChange=true;b.heightMax=rObj.heightMax;}
if(b.width!==rObj.width){b.widthChange=true;b.width=rObj.width;PDQ.recalcWidths(b.id);}
if(b.blockType=='G'&&b.width!==rObj.width){b.heightChange=true;b.width=rObj.width;}
if(b.width!==rObj.width){b.width=rObj.width;}
if(typeof rObj.db!='undefined'){b.db=rObj.db;}
if(rObj.formName)b.formName=rObj.formName;if(rObj.URLOpts)b.URLOpts=rObj.URLOpts;if(rObj.colModelP)b.colModelP=rObj.colModelP;if(rObj.gAnalytics)b.gAnalytics=rObj.gAnalytics;if(typeof rObj.fromServerCache!='undefined')b.fromServerCache=rObj.fromServerCache;if(rObj.reasonNotServerCache)b.reasonNotServerCache=rObj.reasonNotServerCache;if(rObj.execMsSrv)b.execMsSrv=rObj.execMsSrv;if(b.blockType=='G'){b.typeParams.colModelP=rObj.colModelP;b.typeParams.defaultSort=rObj.defaultSort;b.typeParams.gridOptions=rObj.gridOptions;b.typeParams.record=rObj.record;b.typeParams.selectFirst=rObj.selectFirst;b.typeParams.paramsClearOnNoRows=rObj.paramsClearOnNoRows;b.typeParams.pageRows=rObj.pageRows;if(b.typeParams.pageRows){b.isPaged=true;}else{b.isPaged=false;}}else if(b.blockType=='DV'){b.typeParams.defaultSort=rObj.defaultSort;b.typeParams.record=rObj.record;b.typeParams.template=rObj.template;b.typeParams.dataViewOptions=rObj.dataViewOptions;}else if(b.blockType=='S'){b.typeParams.generate=rObj.generate;}else if(b.blockType=='M'){for(var i in rObj.typeParams){b.typeParams[i]=rObj.typeParams[i]}}
if(rObj.dragEnabled){b.dragEnabled=true;b.typeParams.targetBlocks=rObj.targetBlocks;b.dragInProcess=rObj.dragInProcess;}
b.updateParams(rObj.param,this);b.isDisplay=rObj.isDisplay;if(b.isDisplay){var sbs=b.GetSameSpaceBlocks();for(var i in sbs){if(sbs[i].toDelete){PDQ.deleteBlock(i,true);}else if(sbs[i].isDisplay){PDQ.log('Hiding '+sbs[i].id+' dues to same space with '+b.id);sbs[i].isDisplay=false;sbs[i].setVisibility();}}
b.setVisibility();b.display();}else{b.setVisibility();}
PDQ.checkBlocks(b.id);PDQ.q.exec();PDQ.progressOffCheck({skipPageCheck:true});setTimeout(function(){PDQ.progressOffCheck({skipPageCheck:true});},2000);};PDQ.block.prototype.updateParams=function(o,stackEntry){if(typeof stackEntry=='undefined'){stackEntry={};}
if(stackEntry.block){PDQ.updateParams(o,stackEntry.block)}else{PDQ.updateParams(o.param)}
if(typeof stackEntry.paramsSent=='undefined'){stackEntry.paramsSent={};}
for(var i=0;i<this.paramUsed.length;i++){var p=this.paramUsed[i];if(typeof stackEntry.paramsSent[p]!='undefined'){this.param[p]=stackEntry.paramsSent[p];}else if(typeof PDQ.param[p]!='undefined'){this.param[p]=PDQ.param[p];}}
for(var i in o){if(this.paramUsed.indexOf(i)<0&&this.paramRef.indexOf(i)<0){continue;}
this.param[i]=o[i];}}
PDQ.block.prototype.initUI=function(o){if(typeof o=='undefined')o={};if(typeof o.forceLoad=='undefined')o.forceLoad=false;if(typeof o.ignoreCache=='undefined')o.ignoreCache=false;if(o.forceLoad||o.ignoreCache){if(o.ignoreCache){this.addDataRequestToQ({ignoreCache:'yes'},'New block');}else{this.addDataRequestToQ(null,'New block');}}else{this.display(o);}}
PDQ.block.prototype.display=function(){if(typeof PDQ.blocks[this.id]=='undefined'){return;}
if(this.blockType==''){if(this.data===null){if(this.panel){this.panel.body.update('');}
this.panel.doLayout();}else{if(this.panel){if(Ext.isArray(this.data)){var d=this.data.join('');this.panel.body.update(d,true);}else{this.panel.body.update(this.data,true);}
this.panel.body.dom.style.overflowX='hidden';this.panel.doLayout();var w=this.panel.getSize().width;var wP=this.panel.getEl().dom.parentNode.parentNode.scrollWidth
if(w>wP){this.panel.setWidth(wP);}}}
PDQ.initGoogleMap(this.panel);PDQ.initPopZoom(this.panel);this.adjustHeight();}else if(this.blockType=='T1'){this.displayT1();}else if(this.blockType=='G'&&typeof this.typeParams.colModelP=='undefined'){if(this.panel){this.panel.body.update('');}}else if(this.blockType=='G'){this.displayG();}else if(this.blockType=='S'){if(this.panel){this.displayS();}}else if(this.blockType=='P'||this.blockType=='PC'){this.panel.doLayout();}else if(this.blockType=='DV'){this.displayDV();}else if(this.blockType=='M'){this.displayM();}else{if(this.panel){this.panel.body.update('UPDATE CODE NOT CREATED YET FOR BLOCK TYPE '+this.blockType);}}
if(this.panel){if(this.blockStyles){var el=this.panel.body;el.applyStyles('background-color: transparent;');var el=this.panel.getEl();el.applyStyles(this.blockStyles);}
this.adjustHeight();}
PDQ.progressOffCheck();PDQ.logSetPosition();if(this.getVisibility()){this.trackingUpdate();}};PDQ.block.prototype.displayM=function(o){PDQ.log('Creating map for '+this.id);if(Ext.isEmpty(PDQ.googleMapKey)){m='ERROR - Google Map Key has not been defined for this site. ';m+=' Please get key from http://code.google.com/apis/maps/signup.html and enter it ';m+='in the appropriate site configuration document.';PDQ.messageBox.alert(m);return;}
var sz=this.panel.getSize();this.map=new GMap2(this.panel.body.dom);if(this.typeParams.mapOptions.indexOf('SM')>=0){PDQ.map.map=this.map;PDQ.map.block=this;}
this.mapGrids=[];this.mapWorldLoaded=false;this.map.enableScrollWheelZoom();if(this.typeParams.typeControl=='B'){this.map.addControl(new GMapTypeControl());}else if(this.typeParams.typeControl=='D'){this.map.addControl(new GMenuMapTypeControl())}else if(this.typeParams.typeControl=='N'){this.map.addControl(new GHierarchicalMapTypeControl())}
if(this.typeParams.panZoomControl=='L'){this.map.addControl(new GLargeMapControl())}else if(this.typeParams.panZoomControl=='S'){this.map.addControl(new GSmallMapControl());}else if(this.typeParams.panZoomControl=='Z'){this.map.addControl(new GSmallZoomControl())}
if(this.typeParams.mapOptions.indexOf('SC')>=0){this.map.addControl(new GScaleControl())}
this.mapKB=new GKeyboardHandler(this.map);var zoomCenter=PDQ.getMapCenterZoom(this);if(zoomCenter.zoom===null){zoomCenter.zoom=13;}
if(zoomCenter.centerPoint===null){zoomCenterPoint=new GLatLng(19.22264548836949,-9.31640625);zoomCenter.zoom=2;}
var zoom=zoomCenter.zoom;var centerPoint=zoomCenter.centerPoint;if(this.typeParams.mapOptions.indexOf('SV')>=0){PDQ.map.zoom=zoom;PDQ.map.centerPoint=centerPoint;}
this.map.setCenter(centerPoint,zoom);if(typeof this.data=='undefined'||this.data===null){PDQ.messageBox.alert('SYSTEM ERROR - data missing from block '+this.id);return;}
this.markers=[];this.clickPoint=function(){PDQ.map.openPoint={};PDQ.map.openPoint.docId=this.PDQdata.docId;PDQ.map.openPoint.lat=this.PDQdata.latitude;PDQ.map.openPoint.lng=this.PDQdata.longitude;if(this.PDQtabsHTML.length>0){this.openInfoWindowTabsHtml(this.PDQtabsHTML);}
if(!Ext.isEmpty(this.PDQdata.update)){try{eval('var oP = {'+this.PDQdata.update+'}');}catch(exception){var m='Error in update item for marker:'+this.PDQdata.update;if(PDQ.haltOnEval){PDQ.messageBox.alert(m);}
PDQ.showLog=true;PDQ.log(m);return;}
PDQ.updateCheck(this.PDQblock,oP);}
if(!Ext.isEmpty(this.PDQdata.JS)){try{eval(this.PDQdata.JS);}catch(exception){var m='Error in JS code for marker:'+this.PDQdata.JS;if(PDQ.haltOnEval){PDQ.messageBox.alert(m);}
PDQ.showLog=true;PDQ.log(m);}}}
this.onCloseInfoWindow=function(){PDQ.map.openPoint={};if(!Ext.isEmpty(this.PDQdata.updateOff)){try{eval('var oP = {'+this.PDQdata.updateOff+'}');}catch(exception){var m='Error in updateOff item for marker:'+this.PDQdata.updateOff;if(PDQ.haltOnEval){PDQ.messageBox.alert(m);}
PDQ.showLog=true;PDQ.log(m);return;}
PDQ.updateCheck(this.PDQblock,oP);}}
this.createMarker=function(pCount){var LatLon=new GLatLng(this.data[pCount].latitude,this.data[pCount].longitude)
if(isNaN(LatLon.lat())){return;}
if(typeof this.data[pCount].marker!='undefined'){return;}
var marker=new GMarker(LatLon);var mOpts={};if(!Ext.isEmpty(this.data[pCount].icon)){var newIcon=new GIcon(G_DEFAULT_ICON);var icon=this.data[pCount].icon;icon=icon.toLowerCase();if(icon.search(/^blue\d+s|^red\d+s|^green\d+s|^yellow\d+s|^greenred\d+s|bluered\d+s/i)>=0){var dd=icon.match(/^(\D+)(\d+)/i);var clr=dd[1];var num=dd[2];if(clr=='bluered'){clr='BlueRed';}else if(clr=='greenred'){clr='GreenRed';}else{clr=clr.slice(0,1).toUpperCase()+clr.slice(1);}
icon=PDQ.cdnHost+'/PDQ/etc/icons/numberMarkers/smallSQ'+clr+'Icons/marker'+num+'.png';newIcon.image=icon;}else if(icon.search(/^blue\d+|^red\d+|^green\d+|^yellow\d+|^greenred\d+|bluered\d+/i)>=0){var dd=icon.match(/^(\D+)(\d+)/i);var clr=dd[1];var num=dd[2];if(clr=='bluered'){clr='BlueRed';}else if(clr=='greenred'){clr='GreenRed';}else{clr=clr.slice(0,1).toUpperCase()+clr.slice(1);}
icon=PDQ.cdnHost+'/PDQ/etc/icons/numberMarkers/largeTD'+clr+'Icons/marker'+num+'.png';newIcon.image=icon;}else if(icon.search(/^blue\D|^brown\D|^darkgreen\D|^green\D|^orange\D|^paleblue\D|^pink\D|^purple\D|^red\D|^yellow\D/i)>=0){var lt=icon.slice(icon.length-1).toUpperCase();var clr=icon.slice(0,icon.length-1);icon=PDQ.cdnHost+'/PDQ/etc/icons/letterMarkers/'+clr+'_Marker'+lt+'.png';newIcon.image=icon;}else if(icon.search(/^blue|^brown|^darkgreen|^green|^orange|^paleblue|^pink|^purple|^red|^yellow/i)>=0){icon=PDQ.cdnHost+'/PDQ/etc/icons/letterMarkers/'+icon+'_Marker.png';newIcon.image=icon;}
mOpts.icon=newIcon;}
if(this.data[pCount].title){mOpts.title=this.data[pCount].title;}
if(this.typeParams.mapOptions.indexOf('DM')>=0){mOpts.draggable=true;}
var marker=new GMarker(LatLon,mOpts);if(this.typeParams.mapOptions.indexOf('DM')>=0){marker.enableDragging();}
marker.PDQblock=this;marker.PDQdata=this.data[pCount];marker.PDQshow=false;var cTab=0;marker.PDQtabsHTML=[];for(var tab=0;tab<=9;tab++){var sfx=(tab==0)?'':tab.toString();if(!(Ext.isEmpty(this.data[pCount]['infoWindow'+sfx]))){if(!(Ext.isEmpty(this.data[pCount]['label'+sfx]))){var label=this.data[pCount]['label'+sfx];}else{var label='';}
marker.PDQtabsHTML[cTab]=new GInfoWindowTab(label,this.data[pCount]['infoWindow'+sfx]);cTab+=1;}}
GEvent.addListener(marker,'click',this.clickPoint);GEvent.addListener(marker,'infowindowclose',this.onCloseInfoWindow);this.data[pCount].marker=marker;this.markers.push(marker);};this.adjustMarkers=function(){for(var pCount=0;pCount<this.data.length;pCount++){var LatLon=new GLatLng(this.data[pCount].latitude,this.data[pCount].longitude)
if(this.map.getBounds().containsLatLng(LatLon)&&Ext.isEmpty(this.data[pCount].marker)){this.createMarker(pCount);}
if(this.map.getBounds().containsLatLng(LatLon)&&!this.data[pCount].marker.PDQshow){this.map.addOverlay(this.data[pCount].marker);this.data[pCount].marker.PDQshow=true;}}
if(PDQ.map.openPoint){PDQ.mapPointOpen(PDQ.map.openPoint);}};this.addData=function(data,mapGrid){if(typeof mapGrid=='undefined'){this.mapGrids.push(this.typeParams.mapGrid);}
if(typeof data!='undefined'){NEXTINROW:for(var i=0;i<data.length;i++){for(var j=0;j<this.data.length;j++){if(this.data[j].docId==data[i].docId)continue NEXTINROW}
this.data.push(data[i]);if(PDQ.map.openPoint){if(PDQ.map.openPoint.docId){if(data[i].docId==PDQ.map.openPoint.docId){PDQ.mapPointOpen();}}}}}
this.adjustMarkers();};this.getGridKey=function(lat,lng){var d=this.typeParams.mapGridSize;var nLat=lat+90;nLat=Math.floor((nLat+d/2)/d)*d*2;var kLat='000000'+nLat;kLat=kLat.slice(kLat.length-6);var nLng=lng+180;nLng=Math.floor((nLng+d/2)/d)*d;var kLng='000000'+nLng;kLng=kLng.slice(kLng.length-6);return{key:kLat+'-'+kLng,nLat:nLat,nLng:nLng}}
this.moreGridsCheck=function(){if(this.map.getZoom()<PDQ.map.ajaxZoom){if(this.mapWorldLoaded)return;var reason='World map points';this.addDataRequestToQ(null,reason,null,true,true);this.mapWorldLoaded=true;return;}
var d=this.typeParams.mapGridSize;var b=this.map.getBounds();var sw=b.getSouthWest();var ne=b.getNorthEast();var swG=this.getGridKey(sw.lat(),sw.lng());var neG=this.getGridKey(ne.lat(),ne.lng());for(var i=swG.nLat;i<=neG.nLat;i++){for(var j=swG.nLng;j<=neG.nLng;j++){var lat=i/d/2-90;var lng=j/d-180;var ky=this.getGridKey(lat,lng);if(this.mapGrids.indexOf(ky.key)<0){this.mapGrids.push(ky.key);var reason='Additional map points '+ky.key;var LatLng=new GLatLng(lat,lng)
this.addDataRequestToQ(null,reason,LatLng,true);}}}}
this.addData();this.moreGridsCheck();GEvent.addListener(this.map,'moveend',function(){if(this.typeParams.mapOptions.indexOf('SV')>=0){this.moreGridsCheck();PDQ.map.centerPoint=this.map.getCenter();PDQ.map.zoom=this.map.getZoom();var pos=PDQ.map.centerPoint.lat()+' '+PDQ.map.centerPoint.lng()+' '+PDQ.map.zoom;PDQ.setRawCookie('map',pos);PDQ.updateCheck();}
this.adjustMarkers();}.createDelegate(this));GEvent.addListener(this.map,'infowindowclose',function(){delete PDQ.map.openPoint;});}
PDQ.block.prototype.displayDV=function(o){if(this.dataview){this.dataview.destroy();}
if(this.progressIcon!=''){this.panel.body.update('');}
var recordCfg=this.typeParams.record;this.recordCfg=recordCfg;this.record=Ext.data.Record.create(recordCfg);for(var keyIndex=0;keyIndex<recordCfg.length;keyIndex++){if(recordCfg[keyIndex].name=='docId')break;}
if(keyIndex<recordCfg.length){var readerObj=new Ext.data.ArrayReader({id:keyIndex},recordCfg);}else{var readerObj=new Ext.data.ArrayReader(recordCfg);}
var storeObj={};storeObj.data=this.data;storeObj.reader=readerObj;storeObj.storeId=this.id;if(typeof this.typeParams.defaultSort!='undefined'){var sv=this.typeParams.defaultSort.split(' ');storeObj.sortInfo={field:sv[0],direction:sv[1]};}
this.store=new Ext.data.Store(storeObj);this.store.sort('title');PDQ.log('Initial generating data view '+this.id);var dViewObj={};dViewObj.itemSelector='div.DV-'+this.id+'-wrap';dViewObj.style='overflow:auto';dViewObj.singleSelect=true;if(this.dragEnabled){dViewObj.plugins=new Ext.DataView.DragSelector({dragSafe:true});}
dViewObj.store=this.store;if(this.typeParams.template.match(/"div.DV-/i)){dViewObj.tpl=new Ext.XTemplate('<tpl for=".">',this.typeParams.template,'</tpl>')}else{dViewObj.tpl=new Ext.XTemplate('<tpl for=".">','<div class="DV-'+this.id+'-wrap" id="{docId}" >',this.typeParams.template,'</div>','</tpl>')}
this.dataview=new Ext.DataView(dViewObj);this.dataview.PDQblock=this;this.dataview.on('click',function(view,index,htmlNode,e){var task=new Ext.util.DelayedTask();task.delay(250,function(view,index,htmlNode,e){if(PDQ.dblClickExec){PDQ.dblClickExec=false;return;}
if(PDQ.dragStarted){PDQ.dragStarted=false;return;}
var rec=this.store.getById(htmlNode.id);if(this.typeParams.dataViewOptions.indexOf('popImage')>=0){var opts={};var tooltip=rec.get('tooltip')
if(tooltip){opts.tooltip=tooltip;}
if(this.typeParams.dataViewOptions.indexOf('largeImage')>=0){opts.prefSize=950;var popFile='size-950.jpg';}else{var popFile='size-605.jpg';}
opts.icon=false;PDQ.popImage(htmlNode,popFile,opts);}},this,[view,index,htmlNode,e]);},this);this.dataview.on('dblclick',function(view,index,htmlNode,e){PDQ.log('Data view dblclick '+index);PDQ.dblClickExec=true;if(!htmlNode.id){PDQ.messageBox.alert('SYSTEM ERROR','Cannot open document - docId field is missing from block data definition.');return;}
var dblClickOK=true;var dblClickMsg='';var recIndex=view.store.find('docId',htmlNode.id);if(recIndex>=0){var rec=view.store.getAt(recIndex);if(typeof rec!='undefined'){if(typeof rec.get('dblClickOK')!='undefined'){dblClickOK=rec.get('dblClickOK');}
if(dblClickOK===false){dblClickOK=false;}else if(typeof dblClickOK=='string'){if(dblClickOK!=''){dblClickMsg=dblClickOK;dblClickOK=false;}}}}
if(dblClickOK){var vers=htmlNode.id.slice(-6);PDQ.pop({id:this.id+vers,block:this,docId:htmlNode.id,constraintoviewport:true,animateTarget:htmlNode});}else{if(dblClickMsg!=''){PDQ.messageBox.alert(dblClickMsg);return;}}},this);this.dataview.render(this.panel.body);if(this.dragEnabled){var dvBox=this.dataview.getBox();var parentBox=this.parentPanel.getBox();if((dvBox.y+dvBox.height+12)<(parentBox.y+parentBox.height)){var newH=parentBox.height-(dvBox.y-parentBox.y)-12;this.dataview.setHeight(newH);}
this.dragZone=new PDQ.dragZone(this.dataview,{containerScroll:true});this.dragZone.PDQblock=this;this.dropTarget=new PDQ.dropZone(this.dataview,{});this.dropTarget.PDQblock=this;this.dragZone.onStartDrag=function(){PDQ.dragStarted=true;};}
this.dataview.hide();var task=new Ext.util.DelayedTask();task.delay(10,function(view){this.dataview.show();},this,[this.dataview]);}
PDQ.block.prototype.displayS=function(o){if(!this.typeParams.generate){var nHtml='<P style="font-size:0px;line-height:0;height:0px"></P>';this.panel.body.update(nHtml);return;}
if(this.typeParams.width){var w=this.typeParams.width;}else if(this.width){var w=this.width;}else{var w=this.parentPanel.getInnerWidth();}
if(this.typeParams.height){var h=this.typeParams.height}else if(this.heightMin){var h=this.heightMin;}else{var h=this.panel.getInnerHeight();}
if(typeof h!='number'){if(h.indexOf(':')>=0){var t=h.split(':');var h=Math.round(eval(w.toString()+'*'+t[1]+'/'+t[0]));}else{var h=eval(h);}}
w=w.toString();h=h.toString();var urlParams={};urlParams.DB=PDQ.db;urlParams.Mode='BlockJS';urlParams.Build=PDQ.buildNumber;urlParams.PageSet=this.pageSet;urlParams.PageCode=PDQ.pageCode;urlParams.Block=this.blockPC;urlParams.BlockDocID=this.docId;urlParams.CMPageID=PDQ.cmPageId;if(this.portletDocId){urlParams.PortletDocID=this.portletDocId;}
var p=this.paramUsed.concat(this.paramRef);p=PDQ.getParams(p,this);for(var i in p){if(i!==''){urlParams['V_'+i]=p[i];}}
urlParams.xmlContent='yes';urlParams=Ext.urlEncode(urlParams);urlParams+='&_dc='+(new Date().getTime());var xmlUrl=PDQ.host+PDQ.path+'&'+urlParams;if(Ext.isSecure){xmlUrl='https://'+xmlUrl;}else{xmlUrl='http://'+xmlUrl;}
var sd=PDQ.pathNSF+'/monoslideshow.swf?OpenFileResource';var xi=PDQ.pathNSF+'/expressInstall.swf?OpenFileResource';var soIdF=this.id+'_slide';var s='';var soId='divBL_'+this.id+'_slide';var nHtml='<DIV id='+soId+' style="'+s+'"></div>';this.panel.body.update(nHtml);var flashvars={};flashvars.dataFile=escape(xmlUrl);if(!this.typeParams.monoLogo){flashvars.showLogo='false';}
flashvars.showVersionInfo='false';var params={};params.bgcolor=PDQ.pageBGcolor;params.wmode='opaque';params.menu='false';var attributes={};swfobject.embedSWF(sd,soId,w,h,"7",xi,flashvars,params,attributes);}
PDQ.block.prototype.displayG=function(o){function toolTip(val,metadata,record,rowIndex,colIndex,store){var tt=record.get(this.id+'_toolTip');var ttt=record.get(this.id+'_toolTipTitle');if(typeof tt=='undefined')tt='';if(typeof ttt=='undefined')ttt='';if(tt==''){var tt=record.get('toolTip');var ttt=record.get('toolTipTitle');if(typeof tt=='undefined')tt='';if(typeof ttt=='undefined')ttt='';}
if(tt!=''){metadata.attr='ext:qtip="'+tt+'"';if(ttt!=''){metadata.attr+=' ext:qtitle="'+ttt+'"';}}
return val;}
function redNeg(val,metadata,record,rowIndex,colIndex,store){toolTip(val,metadata,record,rowIndex,colIndex,store);if(val<0){return'<span style="color:red;">'+val+'</span>';}
return val;}
function cellStyle(val,metadata,record,rowIndex,colIndex,store){toolTip(val,metadata,record,rowIndex,colIndex,store);var i=val.indexOf('~');if(i>=0){return'<span '+metadata.attr+' style="'+val.slice(i+1)+';">'+val.slice(0,i)+'</span>';}
return val;}
function italic(value,metadata,record,rowIndex,colIndex,store){toolTip(val,metadata,record,rowIndex,colIndex,store);return'<i>'+value+'</i>';}
function change(val,suffix){suffix=suffix||'';if(val>0){return'<span style="color:green;">'+val+suffix+'</span>';}else if(val<0){return'<span style="color:red;">'+val+suffix+'</span>';}
return val;}
function pctChange(val,metadata,record,rowIndex,colIndex,store){toolTip(val,metadata,record,rowIndex,colIndex,store);return change(val,'%');}
function money(val,metadata,record,rowIndex,colIndex,store){toolTip(val,metadata,record,rowIndex,colIndex,store);val-=0;val=(Math.round(val*100))/100;val=(val==Math.floor(val))?val+'.00':((val*10==Math.floor(val*10))?val+'0':val);return"$"+val;}
PDQ.log('Generating grid '+this.id);this.lastSingleClickRowIndex=null;if(this.typeParams.colModelP.length==0){this.panel.body.update('');if(this.grid){PDQ.log('No columns - destroying grid '+this.id);this.grid.destroy();this.grid=null;}else{PDQ.log('No columns - grid '+this.id+' not displayed.');}
return;}
var recordCfg=this.typeParams.record;var colModelCfg=this.typeParams.colModelP;if(typeof this.typeParams.defaultSort!='undefined'){var sv=this.typeParams.defaultSort.split(' ');if(sv[0].replace(/[0-9]*/,'')==''){var isName=false;}else{var isName=true;}}else{var isName=true;}
for(var i=0;i<colModelCfg.length;i++){for(var ri=0;ri<recordCfg.length;ri++){if(colModelCfg[i].dataIndex){colModelCfg[i].field=colModelCfg[i].dataIndex;}
if(recordCfg[ri].name==colModelCfg[i].field)break;}
if(ri==recordCfg.length){var t='ERROR - field "'+colModelCfg[i].field+'" does not exist in field names';PDQ.log(t);PDQ.messageBox.alert(t);return;}
colModelCfg[i].id=colModelCfg[i].field;delete colModelCfg[i].field;colModelCfg[i].dataIndex=colModelCfg[i].id;if(colModelCfg[i].sortType){recordCfg[ri].sortType=colModelCfg[i].sortType.replace(/sort./,'');}
if(colModelCfg[i].renderer){colModelCfg[i].renderer=eval(colModelCfg[i].renderer);}else{colModelCfg[i].renderer=eval('toolTip');}
if(!isName){if(parseInt(sv[0],10)==i){sv[0]=colModelCfg[i].id;}}}
this.recordCfg=recordCfg;this.record=Ext.data.Record.create(recordCfg);for(var keyIndex=0;keyIndex<recordCfg.length;keyIndex++){if(recordCfg[keyIndex].name=='docId')break;}
if(keyIndex<recordCfg.length){var readerObj=new Ext.data.ArrayReader({id:keyIndex},recordCfg);}else{var readerObj=new Ext.data.ArrayReader(recordCfg);}
var storeObj={};storeObj.data=this.data;storeObj.reader=readerObj;storeObj.storeId=this.id;if(typeof sv!='undefined'){storeObj.sortInfo={field:sv[0],direction:sv[1]};}
if(this.isPaged){var pUrl={};pUrl.Mode='BlockJS';pUrl.DB=PDQ.db;pUrl.CMPageID=PDQ.cmPageId;pUrl.PageSet=PDQ.pageSet;pUrl.PageCode=PDQ.pageCode;pUrl.Block=this.blockPC;pUrl.BlockDocID=this.docId;if(this.portletDocId){pUrl.PortletDocID=this.portletDocId;}
pUrl.PageData='yes';if(this.typeParams.gridOptions.indexOf('reuseRowCount')>=0){pUrl.numRows='';}
var p=this.paramUsed.concat(this.paramRef);p=PDQ.getParams(p);for(var i in p){if(i!==''){pUrl['V_'+i]=p[i];}}
var pUrlEnc=Ext.urlEncode(pUrl);var url=PDQ.host+PDQ.path+'&'+pUrlEnc;if(Ext.isSecure){url='https://'+url;}else{url='http://'+url;}
var storeObj={};storeObj.proxy=new Ext.data.ScriptTagProxy({url:url,timeout:120000});storeObj.remoteSort=true;var setNumRows=function(o){var c=this.store.getTotalCount();if(c==0){c='';}
var iS=this.store.proxy.url.indexOf('&numRows=');if(iS>=0){var iE=this.store.proxy.url.indexOf('&',iS+1);var url=this.store.proxy.url.slice(0,iS)+'&numRows='+c;if(iE>=0){url+=this.store.proxy.url.slice(iE);}
this.store.proxy.url=url;}}
storeObj.proxy.on('beforeload',setNumRows,this,[]);var readerObj={};readerObj.root='records';readerObj.id='docId';readerObj.totalProperty='totalCount';readerObj.autoLoad=true;readerObj.fields=[];for(var i=0;i<this.recordCfg.length;i++){readerObj.fields[i]=this.recordCfg[i].name;}
storeObj.reader=new Ext.data.JsonReader(readerObj);}
this.store=new Ext.data.Store(storeObj);this.colModel=new Ext.grid.ColumnModel(colModelCfg);var createGrid=false;var opts=this.typeParams.gridOptions;if(this.grid===null||opts.indexOf('autoFill')>=0||opts.indexOf('forceFit')>=0||this.isPaged){createGrid=true;}
if(this.heightChange){this.heightChange=false;createGrid=true;}
if(this.widthChange){this.widthChange=false;createGrid=true;}
if(this.grid!==null&&!this.isPaged&&this.grid.bbar){createGrid=true;}
if(this.typeParams.gridOptions.indexOf('forceRegen')>=0){createGrid=true;}
if(this.grid!==null){if(createGrid||(this.width-this.panel.getInnerWidth())!=(this.grid.getSize().width)){PDQ.log('Destroying grid '+this.id);this.grid.destroy();this.grid=null;}else{PDQ.log('Regenerating grid '+this.id);this.grid.reconfigure(this.store,this.colModel);this.grid.view.scrollToTop();}
this.refreshDoc=[];}
if(this.grid===null){PDQ.log('Initial generating grid '+this.id);var w=this.panel.getInnerWidth();var h=this.panel.getInnerHeight()-1;var gridObj={};gridObj.store=this.store;gridObj.colModel=this.colModel;gridObj.stripeRows=true;gridObj.loadMask=true;gridObj.height=h;gridObj.width=w;if(this.typeParams.gridOptions.indexOf('frame')>=0){gridObj.frame=true;}
if(this.typeParams.gridOptions.indexOf('noBorder')>=0){gridObj.border=false;}
if(this.dragEnabled){gridObj.enableDragDrop=true;gridObj.ddGroup=this.typeParams.targetBlocks[0];}
var hasBody=false;for(var i=0;i<this.recordCfg.length;i++){if(this.recordCfg[i].name=='body'){hasBody=true;}}
var vcObj={};if(this.typeParams.gridOptions.indexOf('autoFill')>=0){vcObj.autoFill=true;}
if(this.typeParams.gridOptions.indexOf('forceFit')>=0){vcObj.forceFit=true;}
if(hasBody){PDQ.log('BODY field found in grid '+this.id);vcObj.enableRowBody=true;vcObj.showPreview=true;vcObj.getRowClass=function(record,rowIndex,p,store){if(this.showPreview){p.body='<p>'+record.data.body+'</p>';return'x-grid3-row-expanded';}
return'x-grid3-row-collapsed';};}
gridObj.viewConfig=vcObj;if(this.isPaged){var bbar={};bbar.pageSize=this.typeParams.pageRows;bbar.store=this.store;bbar.displayInfo=true;bbar.displayMsg='Displaying records {0} - {1} of {2}';bbar.emptyMsg='No records to display';gridObj.bbar=new Ext.PagingToolbar(bbar);}
this.grid=new Ext.grid.GridPanel(gridObj);this.grid.PDQblock=this;};if(opts.indexOf('trackMouseOver')>=0)this.grid.trackMouseOver=true;if(opts.indexOf('enableDragDrop')>=0)this.grid.enableDragDrop=true;this.grid.render(this.panel.body);if(this.isPaged){this.store.load({params:{start:0,limit:this.typeParams.pageRows}});}
if(opts.indexOf('noSingleClick')==-1){if(Ext.isGecko){this.grid.addListener('rowclick',this.rowclick,this,{delay:400,buffer:200});}else{this.grid.addListener('rowclick',this.rowclick,this,{delay:300});}}
if(opts.indexOf('noDoubleClick')==-1){this.grid.addListener('rowdblclick',this.rowdblclick,this,true);}
this.grid.selModel.clearSelections();if(this.typeParams.selectFirst&&this.store.getCount()>0){if(this.typeParams.selectFirst===true){var rowNum=0;}else{var rowNum=0;for(var i=0;i<this.data.length;i++){if(this.store.data.items[i].data.docId==this.typeParams.selectFirst){rowNum=i;break;}}}
this.rowclick(this.grid,rowNum);}else if(this.store.getCount()==0){var clearParams={};for(var i=0;i<this.typeParams.paramsClearOnNoRows.length;i++){clearParams[this.typeParams.paramsClearOnNoRows[i]]='';}
PDQ.updateParams(clearParams);}
if(this.typeParams.selectFirst!==false){this.typeParams.selectFirst=true;}
if(!this.dragEnabled){return;}
var gridDropTargetEl=this.grid.getView().el.dom.childNodes[0].childNodes[1];this.gridDropTarget=new Ext.dd.DropTarget(gridDropTargetEl,{ddGroup:this.blockCode,copy:true,notifyDrop:function(ddSource,e,data){for(var i=0;i<ddSource.dragData.selections.length;i++){var record=ddSource.dragData.selections[i];if(typeof record.get('noDrag')!='undefined'){if(record.get('noDrag')){PDQ.messageBox.alert('That line cannot be dragged.')
return(false);}}
this.PDQblock.store.add(record);ddSource.grid.store.remove(record);var p={docId:record.id,sourceBlock:ddSource.grid.PDQblock,targetBlock:this.PDQblock};PDQ.runDragMacro(p);}
return(true);}});this.gridDropTarget.PDQblock=this;}
PDQ.block.prototype.rowclick=function(Grid,rowIndex,e){PDQ.log('rowClick - PDQ.dblClickExec = '+PDQ.dblClickExec);PDQ.log('rowclick '+rowIndex);if(PDQ.dblClickExec){setTimeout(function(){PDQ.dblClickExec=false;},500);return;}
if(e){if(e.shiftKey){return;}else if(e.ctrlKey){return;}else if(e.altKey){return;}}
var d=this.store.data.items[rowIndex].data;if(PDQ.tracking.indexOf('CL')>=0){var tkn;if(d.title){tkn=d.title;}else if(d.name){tkn=d.name;}else if(d.code){tkn=d.code;}else if(d.id){tkn=d.id;}else{tkn='row '+(rowIndex+1);}
tkn=tkn.match(/^[^~]*/i)[0];tkn='Grid | Single click | '+tkn;tkn=Ext.util.Format.stripTags(tkn);tkn=tkn.replace(/&nbsp;/ig,'');tkn=tkn.replace(/'/g,"\\\'");var tt=Ext.util.Format.stripTags(this.title);tt=tt.replace(/&nbsp;/ig,'');tt=tt.replace(/'/g,"\\\'");PDQ.traffic({TREvent:'C',AType:'GC',BlockCode:this.blockCode,Title:tt,Token:tkn});}
if(rowIndex==this.lastSingleClickRowIndex){this.lastSingleClickRowIndex=null;this.grid.getSelectionModel().deselectRow(rowIndex);if(d.updateOff&&d.updateOff!=''){var s='var o = {'+d.updateOff+'};';eval(s);PDQ.updateCheck(this.id,o);}
return;}
this.lastSingleClickRowIndex=rowIndex;var task=new Ext.util.DelayedTask();task.delay(10,function(blockId){PDQ.blocks[blockId].grid.getSelectionModel().selectRow(rowIndex);},null,[this.id]);if(d.url&&d.url!=''){return;}
if(d.JS&&d.JS!=''){PDQ.log('Execute JS '+d.JS);eval(d.JS);}
if(d.update&&d.update!=''){var s='var o = {'+d.update+'};';eval(s);PDQ.updateCheck(this.id,o);}}
PDQ.block.prototype.rowdblclick=function(Grid,rowIndex,e){if(e){if(e.shiftKey){return;}else if(e.ctrlKey){return;}else if(e.altKey){return;}}
PDQ.log('rowdblclick '+rowIndex);PDQ.dblClickExec=true;if(this.lastSingleClickRowIndex===null){this.grid.getSelectionModel().clearSelections();}else{if(this.lastSingleClickRowIndex<this.store.getCount()){var task=new Ext.util.DelayedTask();task.delay(10,function(blockId,rowIndex){PDQ.blocks[blockId].grid.getSelectionModel().selectRow(rowIndex);},null,[this.id,this.lastSingleClickRowIndex]);}else{this.grid.getSelectionModel().clearSelections();this.lastSingleClickRowIndex=null;}}
if(typeof this.store.data.items[rowIndex].data['dblClickOK']!='undefined'){var dbc=this.store.data.items[rowIndex].data['dblClickOK'];if(typeof dbc=='string'){if(dbc!=''){PDQ.messageBox.alert(dbc);return;}}else if(!dbc){PDQ.messageBox.alert('This row cannot be double clicked.');return;}}
if(this.store.data.items[rowIndex].data['JSdblClick']){eval(this.store.data.items[rowIndex].data['JSdblClick']);return;}else if(this.store.data.items[rowIndex].data['docId']){var docId=this.store.data.items[rowIndex].data['docId'];}else{PDQ.messageBox.alert('SYSTEM ERROR','Cannot open document - docId field is missing from block data definition.');return;}
var formCode='';if(typeof this.store.data.items[rowIndex].data['formCode']!='undefined'){formCode=this.store.data.items[rowIndex].data.formCode;}
var view=this.grid.getView();var cellDom=view.getCell(rowIndex,0);var fly=Ext.fly(cellDom.firstChild,'cell');var vers=docId.slice(-6);var cfg={id:this.id+vers,block:this,docId:docId,form:formCode,constraintoviewport:true,animateTarget:fly.id};if(formCode!=''){cfg.form=formCode;}
PDQ.pop(cfg);}
PDQ.block.prototype.displayT1=function(){var d=this.data;for(var i=0;i<d.length;i++){if(d[i].parentId!==null){if(d[i].parentId=='')d[i].parentId=null;}};for(var i=0;i<d.length;i++){if(typeof d[i].align=='undefined'){d[i].align='';};if(d[i].align===null){d[i].align='';};if(typeof d[i].parentId=='undefined'){d[i].parentId=null;};d[i].PDQblock=this;};var sortFn=function(a,b){if(a.parentId&&b.parentId===null)
return 1;if(a.parentId===null&&b.parentId)
return-1;if(a.sort<b.sort)
return-1;if(a.sort>b.sort)
return 1;return 0;W};if(this.toolBar){this.panel.remove(this.toolBar,true);this.parentPanel.doLayout();}
this.toolBar=new Ext.Toolbar({style:'padding-top:3px;',height:26});this.panel.add(this.toolBar);this.parentPanel.doLayout();d.sort(sortFn);for(var i=(d.length-1);i>=0;i--){if(d[i].parentId===null&&i>0){if(this.typeParams.fullWidth&&d[i].align==''){d[i].align='right';}
break;}};var nTop=0;for(var i=0;i<d.length;i++){if(d[i].align==''){d[i].align='left';}
if(d[i].id!=''&&d[i].parentId===null&&d[i].align=='left'){var tabObj=this.displayT1tabObj(i);if(nTop==1)this.toolBar.add('-');if(tabObj.menu){d[i].buttonObj=new Ext.Toolbar.MenuButton(tabObj);this.toolBar.add(d[i].buttonObj);}else{d[i].buttonObj=this.toolBar.addButton(tabObj);}
nTop++;if(nTop>1)this.toolBar.add('-');}}
if(this.typeParams.extraJS&&PDQ.userName!=''){toolBar=this.toolBar;eval(this.typeParams.extraJS);}
var rs=false;var nTop=0;for(var i=0;i<d.length;i++){if(d[i].parentId===null&&d[i].align=='right'){if(rs==false){this.toolBar.add('->');rs=true;}
if(nTop==1)this.toolBar.add('-');var tabObj=this.displayT1tabObj(i);if(tabObj.menu){d[i].buttonObj=new Ext.Toolbar.MenuButton(tabObj);this.toolBar.add(d[i].buttonObj);}else{d[i].buttonObj=this.toolBar.addButton(tabObj);}
nTop++;if(nTop>1)this.toolBar.add('-');}}};PDQ.block.prototype.displayT1tabObj=function(tabIndex){var d=this.data;var tabObj={id:'menu-'+this.id+'-'+d[tabIndex].id,text:d[tabIndex].text}
if(d[tabIndex].icon){if(d[tabIndex].icon.indexOf('/')<0&&d[tabIndex].icon.indexOf('\\')<0){var iconFP=PDQ.cdnHost+'/PDQ/etc/icons/fam/'+d[tabIndex].icon;d[tabIndex].icon=iconFP;}}
if(d[tabIndex].parentId===null){if(d[tabIndex].icon){var s='background-image:url('+d[tabIndex].icon+');';s+='background-position-y:0px;';s+='background-repeat:no-repeat;';s+='padding:1px 0px 2px 18px;';var ttp='';if(d[tabIndex].tooltip){var ttp=d[tabIndex].tooltip.replace(/"/g,'\"')
ttp=' ext:qtip="'+ttp+'"';}
var txt='<div style="'+s+'"'+ttp+'>'+d[tabIndex].text+'</div>';tabObj.text=txt;}}
var itemsObj=this.displayT1menuObj(tabIndex);if(itemsObj.items[0]){tabObj.menu=itemsObj;}
if(d[tabIndex].parentId){if(d[tabIndex].icon){tabObj.icon=d[tabIndex].icon;}else{tabObj.icon=PDQ.portalDir+'/orangeDotGREY.gif';}}
if(d[tabIndex].tooltip){tabObj.tooltip=d[tabIndex].tooltip;}
var js1='';if(d[tabIndex].JS){if(d[tabIndex].JS!=''){js1=d[tabIndex].JS;}}
var js2='';if(d[tabIndex].update){if(d[tabIndex].update!=''){if(d[tabIndex].update.search(/'home'/i)>=0){js2='{ id :\''+this.id+'\', update: {'+d[tabIndex].update+'}}';}else{js2='{id :\''+this.id+'\', update: {'+d[tabIndex].update+'}}';}}}
var url='';if(d[tabIndex].url){url=d[tabIndex].url;}else if(d[tabIndex].email){url='mailto:'+d[tabIndex].email;var hrP='';if(d[tabIndex].emailS)hrP='?subject='+encodeURIComponent(d[tabIndex].emailS);if(d[tabIndex].emailB){var hrS=d[tabIndex].emailB.replace(/'/g,"\'");hrS=encodeURIComponent(hrS);hrS=hrS.replace(/%0A/gi,'');hrS=hrS.replace(/%20/gi,' ');hrS=hrS.slice(0,172);if(hrP==''){hrP+='?body='+hrS;}else{hrP+='&body='+hrS;}}
url+=hrP;}
if((js1+js2)!=''){if(typeof d[tabIndex].pressed=='boolean'){var js="PDQ.blocks['"+this.id+"'].tabsOff("+tabIndex+");";}else{var js='';}
var js3="PDQ.pressButton({id: '"+d[tabIndex].id+"', block: PDQ.blocks['"+this.id+"']}); return changes";var jsAll='var changes = false;'+String.fromCharCode(13);if(js2!=''){jsAll+='var iu = '+js2+';'+String.fromCharCode(13);}
jsAll+=js+';'+String.fromCharCode(13);jsAll+='if (arguments.length == 1){'+String.fromCharCode(13)+'  for (var i in arguments[0]){'+String.fromCharCode(13)+"    if (typeof iu == 'undefined'){"+String.fromCharCode(13)+"      var iu = {};"+String.fromCharCode(13)+"      iu.update = {};"+String.fromCharCode(13)+"    }"+String.fromCharCode(13)+'    iu.update[i] = arguments[0][i];'+String.fromCharCode(13)+'  }'+String.fromCharCode(13)+'}'+String.fromCharCode(13);jsAll+='if (typeof iu != \'undefined\') {'+String.fromCharCode(13)+'changes = PDQ.updateCheck( iu.id, iu.update);'+String.fromCharCode(13)+'};'+String.fromCharCode(13);jsAll+=js1+';'+String.fromCharCode(13);jsAll+=js3+String.fromCharCode(13);tabObj.handler=new Function(jsAll);}else if(url!=''){if(url.slice(0,0)=='/'){var tg='_top';}else{var tg='_blank';}
tabObj.href=url;tabObj.hrefTarget=tg;}
if(d[tabIndex].pressed){if(typeof d[tabIndex].pressed!='boolean'){var m='SYSTEM ERROR: Button pressed field should be boolean: button:'+d[tabIndex].id+' value:"'+d[tabIndex].pressed+'"';PDQ.messageBox.alert(m);PDQ.log(m);}
tabObj.enableToggle=true;tabObj.pressed=true;this.currentPressed=d[tabIndex];}else if(d[tabIndex].pressed==false){tabObj.enableToggle=true;}
if((js1+js2)==''){tabObj.listeners={'click':{fn:function(o,e){PDQ.pressButton({id:this.id,block:this.PDQblock});},scope:d[tabIndex]}};}
return tabObj;}
PDQ.block.prototype.tabsOff=function(tabIndex){var d=this.data;for(var i=0;i<d.length;i++){if(i!=tabIndex){if(d[i].buttonObj){if(d[i].buttonObj.pressed){d[i].buttonObj.toggle(false);d[i].buttonObj.hideMenu();}}}}}
PDQ.block.prototype.tabRestore=function(){this.tabsOff();if(this.lastPressed===null){return;}
if(!this.lastPressed.buttonObj){return;}
if(!this.lastPressed.buttonObj.toggle){return;}
this.lastPressed.buttonObj.toggle();setTimeout(function(){this.lastPressed.toggle(true);this.currentPressed=this.lastPressed;}.createDelegate(this),10);}
PDQ.block.prototype.displayT1menuObj=function(optionIndex){var d=this.data;var ni=0;var items=[];for(var i=0;i<d.length;i++){if(d[i].parentId!==d[optionIndex].id)continue;items[items.length]=this.displayT1tabObj(i);d[i].parentItem=d[optionIndex];}
var itemsObj={items:items};return itemsObj;}
PDQ.block.prototype.adjustWidth=function(newW){}
PDQ.block.prototype.adjustHeight=function(){var func=function(b){var h=0;if(!b.panel.rendered||b.panel.hidden)return;if(b.blockType=='PC'){for(var i=0;i<b.panel.items.items.length;i++){var hi=0;if(b.panel.rendered&&!b.panel.hidden){var p=b.panel.items.items[i];hi=p.getInnerHeight()+p.getFrameHeight();var marginTop=p.getEl().dom.style.marginTop;if(!Ext.isEmpty(marginTop)){marginTop=parseInt(marginTop,10);}else{marginTop=0;}
var marginBottom=p.getEl().dom.style.marginBottom;if(!Ext.isEmpty(marginBottom)){marginBottom=parseInt(marginBottom,10);}else{marginBottom=0;}}
h=hi>h?hi:h;}}else if(b.blockType=='P'){for(var i=0;i<b.childBlocks.length;i++){var p=b.childBlocks[i].panel;if(p){if(p.rendered&&!p.hidden){h+=p.getInnerHeight()+p.getFrameHeight();var el=p.getEl();if(el.dom.style.borderTopWidth!=''){h+=parseFloat(el.dom.style.borderTopWidth);}
if(el.dom.style.borderBottomWidth!=''){h+=parseFloat(el.dom.style.borderBottomWidth);}
var marginTop=p.getEl().dom.style.marginTop;if(!Ext.isEmpty(marginTop)){marginTop=parseInt(marginTop,10);}else{marginTop=0;}
var marginBottom=p.getEl().dom.style.marginBottom;if(!Ext.isEmpty(marginBottom)){marginBottom=parseInt(marginBottom,10);}else{marginBottom=0;}
h+=marginTop+marginBottom;}}}
h=h==0?2:h;}else{var el=b.panel.body.dom;b.panel.lastSize.height=0;if(Ext.isGecko){if(b.heightMin===null||b.heightMax==null){PDQ.log('RESIZING: Gecko using style.height '+b.id+' '+b.heightMin+' '+b.heightMax);var th=el.style.height;for(var hG=el.scrollHeight;hG>0;hG=hG-50){el.style.height=hG+'px';h=el.scrollHeight;if(h>hG){break;}}
el.style.height=th;}}else{h=el.scrollHeight;}}
var frm=b.panel.getFrameHeight();if(b.heightMin&&(h+frm)<b.heightMin){b.panel.setHeight(b.heightMin);}else if(b.heightMax&&(h+frm)>b.heightMax){b.panel.setHeight(b.heightMax);}else{b.panel.setHeight(h+frm);}
b.parentPanel.doLayout();}
var b=this;while(b){if(b.panel){var h=b.panel.hidden;var r=b.panel.rendered;if(!h&&r)func(b);}
b=b.parent;}
var h=0;var b=PDQ.firstBlock;while(b){if(b.panel){if(b.panel.rendered&&!b.panel.hidden){h+=b.panel.getInnerHeight()+b.panel.getFrameHeight();var marginTop=b.panel.getEl().dom.style.marginTop;if(!Ext.isEmpty(marginTop)){marginTop=parseInt(marginTop,10);}else{marginTop=0;}
var marginBottom=b.panel.getEl().dom.style.marginBottom;if(!Ext.isEmpty(marginBottom)){marginBottom=parseInt(marginBottom,10);}else{marginBottom=0;}}}
b=b.next;}
var frm=PDQ.mainPanel.getFrameHeight();if(h>0){PDQ.mainPanel.setHeight(h+frm);}}
PDQ.block.prototype.calcSelected=function(o){if(this.blockType!='G')return;if(o===undefined)var o={};o.macro=o.macro||null;if(typeof o.refreshBlocks=='undefined'){o.refreshBlocks=null;if(typeof o.refresh=='undefined')o.refresh=false;}else{if(typeof o.refresh=='undefined')o.refresh=true;}
o.cancel=o.cancel||false;for(var i=0;i<this.recordCfg.length;i++){if(this.recordCfg[i].name=='docId'){break;}}
if(i>=this.recordCfg.length){PDQ.log('Cannot open document - docId field is missing from data in block '+this.blockCode);return;}
var doRow=function(rows,o,b){if(b.calcLastRowDone===null){var startRow=0;}else{var startRow=b.calcLastRowDone+1;}
for(var n=startRow;n<b.store.getCount();n++){if(b.grid.selModel.isSelected(n)){break;}}
b.calcLastRowDone=n;var c=b.calcTotalRows-rows.length+1;var p={rowIndex:n,progressMsg:'Updating row '+c+' of '+b.calcTotalRows,progressPercent:c/b.calcTotalRows,macro:o.macro,reconvert:o.reconvert};b.addRowCalcToQ(p);}
var endCalc=function(msg,b,refresh){if(typeof refresh=='undefined')refresh=true;if(b.calcO.refreshBlocks===null){var refreshBlocks=[];}else if(typeof b.calcO.refreshBlocks!='undefined'){var refreshBlocks=b.calcO.refreshBlocks;}else{var refreshBlocks=[];}
b.calcInProcess=false;b.calcTotalRows=null;b.calcO={};if(refresh){for(var i=0;i<refreshBlocks.length;i++){var bLd=PDQ.getActiveBlock(refreshBlocks[i]);var m='Related block update as specified by end of selected row calcs/macro for block '+b.id;bLd.addDataRequestToQ(null,m);}}
PDQ.messageBox.type='';PDQ.messageBox.alert(msg);}
if(!this.calcInProcess){var rows=this.grid.selModel.getSelections();if(rows.length==0){var m='No rows selected.';PDQ.messageBox.alert(m);return;}
this.calcInProcess=true;this.calcTotalRows=rows.length;this.calcO=o;this.calcLastRowDone=null;doRow(rows,this.calcO,this);PDQ.q.exec();return;}
if(o.cancel){endCalc('',this,o.refresh);return;}
var rows=this.grid.selModel.getSelections();if(rows.length==0){endCalc('Processing complete',this)
return;}
if(!Ext.MessageBox.isVisible()){endCalc('Processing cancelled',this)
return;}
doRow(rows,this.calcO,this);PDQ.q.exec();}
PDQ.block.prototype.addRowCalcToQ=function(o){if(typeof o=='undefined'){o={};}
var p={};if(o.macro){p.type='Macro';}else{p.type='Recalc';}
p.rowIndex=o.rowIndex;var row=this.store.getAt(o.rowIndex);p.docId=row.get('docId');if(p.docId==''){PDQ.messageBox.alert('SYSTEM ERROR - row '+(o.rowIndex+1)+' has a blank docId.');return;}
p.progressMsg=o.progressMsg||'';if(typeof o.progressPercent!='undefined'){p.progressPercent=o.progressPercent;}
p.macro=o.macro||'';if(o.reconvert)p.reconvert=true;p.refreshBlocks=o.refreshBlocks;if(this.db){if(this.db!=PDQ.db){p.db=this.db;p.cmdb=PDQ.db;}else{p.db=PDQ.db;}}else{p.db=PDQ.db;}
p.cmPageId=PDQ.cmPageId;p.pageSet=this.id.match(/.*__/i)[0];p.pageSet=p.pageSet.slice(0,p.pageSet.length-2)
p.pageCode=PDQ.pageCode;p.blockPC=this.id.match(/__.*/i)[0];p.blockPC=p.blockPC.slice(2,p.blockPC.length)
p.blockPC=PDQ.pageCode+"-"+p.blockPC;p.blockDocId=this.docId;p.block=this;p.requestFn=this.request;p.params={};var si=PDQ.q.add(p);}
PDQ.block.prototype.callbackMacroExec=function(o,s,r){var m='Block macro callback row '+this.rowIndex+' of block '+this.block.id+'.';PDQ.log(m);if(!s||r.responseText.slice(0,6)=='<html>'){if(this.rowIndex){var m='Error in macro/refresh of row '+this.rowIndex+' of block '+this.block.id+'.';}else{var m='Error in macro/refresh of block '+this.block.id+'.';}
m+='See console at bottom of screen for details';PDQ.messageBox.alert(m);PDQ.showLog=true;PDQ.log(m);if(r.responseText){PDQ.dump(r.responseText);}
return;}
o.scope.status=r.status;o.scope.returnText=r.responseText;o.scope.tId=r.tId;var procResult={};try{o.scope.returnObj=eval(r.responseText);}
catch(exception){if(this.block.calcInProcess){this.block.calcSelected({cancel:true});}
if(this.rowIndex){var m='Eval error in macro/refresh of row '+this.rowIndex+' of block '+this.block.id+'.';}else{var m='Eval error in macro/refresh of block '+this.block.id+'.';}
m+=' See console at bottom of screen for details';PDQ.messageBox.alert(m);PDQ.showLog=true;PDQ.log(m);PDQ.log(exception.message);o.scope.evalErrorMessage=exception.message;return;}
if(procResult.message){PDQ.log('Row '+(this.rowIndex+1)+' update: '+procResult.message);}
if(procResult.messageAlert){PDQ.messageBox.alert(procResult.messageAlert);}
var b=this.block;if(typeof this.rowIndex!='undefined'){if(b.grid){var sm=b.grid.getSelectionModel();sm.deselectRow(this.rowIndex);var rec=b.store.getAt(this.rowIndex);var di=rec.get('docId');var rp={docId:di,mode:'Update'};b.refreshDoc.push(rp);b.addDataRequestToQ(null,'Update row '+(this.rowIndex+1)+' after recalc or macro execution.');}}
if(b.calcInProcess){b.calcSelected();return;}
if(procResult.changed){if(typeof this.skipAutoBlockRefresh=='undefined'){this.skipAutoBlockRefresh=false;}
if(!this.skipAutoBlockRefresh){b.addDataRequestToQ(null,'Block contents changed due to macro execution');}
if(this.refreshBlocks){for(var i=0;i<this.refreshBlocks.length;i++){if(this.refreshBlocks[i]!=b.blockCode){var bLd=PDQ.getActiveBlock(this.refreshBlocks[i]);bLd.addDataRequestToQ(null,'Related block update as specified by '+refreshBlocks);}}}}
if(procResult.refreshBlocks){for(var i=0;i<procResult.refreshBlocks.length;i++){var bLd=PDQ.getActiveBlock(procResult.refreshBlocks[i]);bLd.addDataRequestToQ(null,'Block refresh as specified by drag and drop');}}
PDQ.q.exec();}
PDQ.block.prototype.deleteSelected=function(o){if(this.blockType!='G')return;if(o===undefined)var o={};o.refreshBlocks=o.refreshBlocks||[];if(typeof o.refreshBlocks.length=='undefined'){o.refreshBlocks[0]=o.refreshBlocks;}
for(var i=0;i<this.recordCfg.length;i++){if(this.recordCfg[i].name=='docId'){break;}}
if(i>=this.recordCfg.length){PDQ.log('Cannot delete documents - docId field is missing from data in block '+this.blockCode);return;}
this.deleteRow=this.grid.selModel.getSelected();if(this.deleteCount===null){this.deleteCount=this.grid.selModel.getCount();if(this.deleteCount==0){this.deleteCount=null;PDQ.messageBox.alert('No rows selected');return;}
this.deleteIndex=1;this.deleteRefreshBlocks=o.refreshBlocks;}
var rq={};rq.url=PDQ.pathNSF+'/GenForm?OpenAgent';rq.url+='&PP='+PDQ.portalCode;rq.url+='&PDQsession='+PDQ.session;rq.url+='&PORG='+PDQ.orgCode;if(this.db){if(this.db!=PDQ.db){rq.url+='&DB='+this.db;rq.url+='&CMDB='+PDQ.db;}else{rq.url+='&DB='+PDQ.db;}}else{rq.url+='&DB='+PDQ.db;}
if(this.formName!=''){rq.url+='&Form='+this.formName;}else if(this.deleteRow.get('formCode')!=''){rq.url+='&Form='+this.deleteRow.get('formCode');}
rq.url+='&DocID='+this.deleteRow.get('docId');rq.url+='&Mode=Delete';rq.url+='&RunMacroFromParent=yes';rq.url+='&ExtVer='+PDQ.extVer;if(PDQ.cssTheme!='')rq.url+='&CSSTheme='+PDQ.cssTheme;if(PDQ.extDebug)rq.url+='&ExtDebug=yes';var sendVars=[];for(var i in PDQ.param){if(PDQ.param[i]!==null){sendVars[sendVars.length]=i;}}
var pList=PDQ.getParams(sendVars);for(var nm in pList){if(pList[nm]){rq.url+='&'+nm+'='+encodeURIComponent(pList[nm]);}}
rq.url+='&COBFOM&IFRAME';rq.method='GET';rq.callback=this.deleteSelectedCallback;rq.scope=this;PDQ.isDeleting=true;this.deleteTrans=Ext.Ajax.request(rq);if(this.deleteMsg===null){var m='Deleting...';}else{var m=this.deleteMsg;}
PDQ.messageBox.progressHidePend=false;PDQ.messageBox.progressUpdate(this.deleteIndex/this.deleteCount,'',m);var d=Ext.MessageBox.getDialog();d.tools.close.setDisplayed(true);}
PDQ.block.prototype.deleteSelectedCallback=function(o,s,r){var cancelled=false;if(!Ext.MessageBox.isVisible()){cancelled=true;}
if(!s||r.responseText.slice(0,6)=='<html>'){PDQ.isDeleting=false;var m='Error deleting records - see console at bottom of screen for details.';PDQ.messageBox.alert(m);PDQ.log(m);if(r.responseText){PDQ.dump(r.responseText);}
return;}
var procResult={};try{eval(r.responseText);}
catch(exception){PDQ.isDeleting=false;var m='Eval error deleting records - see console at bottom of screen for details.';PDQ.messageBox.alert(m);PDQ.showLog=true;PDQ.log(m);PDQ.log(r.responseText);PDQ.log(exception.message);return;}
if(typeof procResult.deleted=='undefined'){PDQ.isDeleting=false;var m='Error deleting records - missing procResult.delete - see console at bottom of screen for details.';PDQ.messageBox.alert(m);PDQ.showLog=true;PDQ.log(m);PDQ.log(r.responseText);PDQ.log(exception.message);return;}
if(typeof procResult.returnMsg!='undefined'){this.deleteMsg=procResult.returnMsg;}
if(!procResult.deleted){PDQ.isDeleting=false;var m=procResult.returnMsg||'Document not deleted';PDQ.messageBox.alert(m);this.deleteRow=null;this.deleteTrans=null;this.deleteIndex=null;this.deleteCount=null;this.deleteMsg=null;this.deleteRefreshBlocks=[];return;}
this.store.remove(this.deleteRow);++this.deleteIndex;if(this.deleteIndex>this.deleteCount){PDQ.isDeleting=false;PDQ.messageBox.hide();for(var i=0;i<this.deleteRefreshBlocks.length;i++){if(this.deleteRefreshBlocks[i]!=this.blockCode){var bLd=PDQ.getActiveBlock(this.refreshBlocks[i]);bLd.addDataRequestToQ();}}
this.deleteRow=null;this.deleteTrans=null;this.deleteIndex=null;this.deleteCount=null;this.deleteMsg=null;this.deleteRefreshBlocks=[];if(this.typeParams.selectFirst===true&&this.store.getCount()>0){this.rowclick(this.grid,0);}
if(this.store.getCount()==0){var clearParams={};for(var i=0;i<this.typeParams.paramsClearOnNoRows.length;i++){clearParams[this.typeParams.paramsClearOnNoRows[i]]='';}
PDQ.updateParams(clearParams);PDQ.checkBlocks(this.id);}
return;}
if(cancelled){PDQ.isDeleting=false;PDQ.messageBox.type='';PDQ.messageBox.alert('Delete operation cancelled');this.deleteRow=null;this.deleteTrans=null;this.deleteIndex=null;this.deleteCount=null;this.deleteMsg=null;this.deleteRefreshBlocks=[];return;}
this.deleteSelected();}
PDQ.block.prototype.GetSameSpaceBlocks=function(){var retBlocks={};if(this.sameSpaceCode[0]==''){return retBlocks;}
for(i=0;i<this.sameSpaceCode.length;i++){for(var j in PDQ.blocks){if(j==this.id)continue;for(var k=0;k<PDQ.blocks[j].sameSpaceCode.length;k++){if(PDQ.blocks[j].sameSpaceCode[k]==this.sameSpaceCode[i]&&PDQ.blocks[j].parentId===this.parentId){retBlocks[j]=PDQ.blocks[j];}}}}
return retBlocks;}
PDQ.block.prototype.updateIfNeeded=function(){var refreshBlock=false;var reason='';if(this.toDelete)return false;for(var j=0;j<this.paramMon.length;j++){var pn=this.paramMon[j];if(pn.slice(0,2)=='S_'){var bp=this.param[pn];var mp=PDQ.systemParamValue(pn);}else{var bp=this.param[pn];var mp=PDQ.getParams([pn],this,true);}
if(typeof mp=='undefined')mp='';if(mp===null)mp='';if(typeof bp=='undefined')bp='';if(bp===null)bp='';if(this.paramNoRefreshOnBank.indexOf(pn)>=0&&mp==''){PDQ.log('Block '+this.id+' not refreshed - '+pn+' is blank and on no refresh if blank list.')
return;}
if(bp!=mp){reason=pn+' changed from '+bp+' to '+mp;refreshBlock=true;}}
for(var i=0;i<this.paramNoRefreshOnBank.length;i++){var pn=this.paramNoRefreshOnBank[i];var mp=PDQ.getParams([pn],this,true);if(typeof mp=='undefined')mp='';if(mp===null)mp='';if(mp==''){PDQ.log('Block '+this.id+' not refreshed - '+pn+' is blank and on no refresh if blank list.')
return;}}
if(!this.initialized&&this.blockType!='P'&&this.blockType!='PC'&&this.data===null){refreshBlock=true;reason='Not initialized yet';}
if(!this.initialized&&(this.blockType=='P'||this.blockType=='PC')&&this.paramUpdates.length>0){refreshBlock=true;reason='P/PC Block that sets params and is not initialized yet';}
if(this.isDisplay&&!this.getVisibility()){refreshBlock=false;}
if(refreshBlock){this.initialized=true;if(this.progressIcon!=''){if(PDQ.progressDelayInPage>=0){setTimeout(function(){PDQ.messageBox.progress('','',null,PDQ.progressDelayInPage);},10);}}
this.addDataRequestToQ(null,reason);requestAdded=true;}
return refreshBlock;}
PDQ.block.prototype.trackingUpdate=function(o){if(typeof o=='undefined')o={};if(typeof o!='object')o={};if(PDQ.arrayCompare(this.gAnalyticsLast,this.gAnalytics)){return;}
if(PDQ.gAnalyticsAcct.length==0)return;if(PDQ.gAnalyticsAcct.length==0)return;var gTokens=[];for(var i=0;i<this.gAnalytics.length;i++){if(typeof this.gAnalytics[i]=='object'){if(PDQ.gAnalyticsAcct[i].length>0){for(var j=0;j<this.gAnalytics[i].length;j++){var tkn=this.gAnalytics[i][j];if(tkn!=''){if(o.extra){tkn+='/'+o.extra;}
gTokens.push(tkn);}}}}else{if(this.gAnalytics[i]!=''){var tkn=this.gAnalytics[i];if(o.extra){tkn+='/'+o.extra;}
gTokens.push(tkn);}}}
var msg='';for(var i=0;i<gTokens.length;i++){for(var j=0;j<PDQ.gAnalyticsAcct.length;j++){if(PDQ.gAnalyticsAcct[j]!=''){var txt='Posting Google analytics token '+gTokens[i]+' to '+PDQ.gAnalyticsAcct[j];PDQ.log(txt);_uacct=PDQ.gAnalyticsAcct[j];urchinTracker(gTokens[i]);}}}
this.gAnalyticsLast=this.gAnalytics;}
PDQ.block.prototype.getVisibility=function(o){var b=this;while(b){if(!b.isDisplay){return false;}
b=b.parent;}
return true;}
PDQ.block.prototype.pageUpdateCallback=function(o){debugger;}
Ext.DataView.DragSelector=function(cfg){cfg=cfg||{};var view,regions,proxy,tracker;var rs,bodyRegion,dragRegion=new Ext.lib.Region(0,0,0,0);var dragSafe=cfg.dragSafe===true;this.init=function(dataView){view=dataView;view.on('render',onRender);};function fillRegions(){rs=[];view.all.each(function(el){rs[rs.length]=el.getRegion();});bodyRegion=view.el.getRegion();}
function cancelClick(){return false;}
function onBeforeStart(e){return!dragSafe||e.target==view.el.dom;}
function onStart(e){view.on('containerclick',cancelClick,view,{single:true});if(!proxy){proxy=view.el.createChild({cls:'x-view-selector'});}else{proxy.setDisplayed('block');}
fillRegions();view.clearSelections();}
function onDrag(e){var startXY=tracker.startXY;var xy=tracker.getXY();var x=Math.min(startXY[0],xy[0]);var y=Math.min(startXY[1],xy[1]);var w=Math.abs(startXY[0]-xy[0]);var h=Math.abs(startXY[1]-xy[1]);dragRegion.left=x;dragRegion.top=y;dragRegion.right=x+w;dragRegion.bottom=y+h;dragRegion.constrainTo(bodyRegion);proxy.setRegion(dragRegion);for(var i=0,len=rs.length;i<len;i++){var r=rs[i],sel=dragRegion.intersect(r);if(sel&&!r.selected){r.selected=true;view.select(i,true);}else if(!sel&&r.selected){r.selected=false;view.deselect(i);}}}
function onEnd(e){if(proxy){proxy.setDisplayed(false);}}
function onRender(view){tracker=new Ext.dd.DragTracker({onBeforeStart:onBeforeStart,onStart:onStart,onDrag:onDrag,onEnd:onEnd});tracker.initEl(view.el);}};