function TimePeriod(A,B){this.start=new Date(typeof A=="object"?A.getTime():A);this.end=new Date(typeof B=="object"?B.getTime():B);this.clone=function(){return new TimePeriod(this.start,this.end)};this.getDiff=function(){return this.end.getTime()-this.start.getTime()};this.setToHour=function(){this.start.setMinutes(0);this.start.setSeconds(0);this.start.setMilliseconds(0);this.end=this.start.add(Date.HOUR,1);return this.clone()};this.setToDay=function(){this.start.setHours(0);this.start.setMinutes(0);this.start.setSeconds(0);this.start.setMilliseconds(0);this.end=this.start.add(Date.HOUR,24);return this.clone()};this.setToWeek=function(){var C=this.start.getDay();this.start=this.start.add(Date.DAY,C==0?-6:-C+1);this.start.setHours(0);this.start.setMinutes(0);this.start.setSeconds(0);this.start.setMilliseconds(0);this.end=this.start.add(Date.DAY,7);return this.clone()};this.setToMonth=function(){this.start=this.start.getFirstDateOfMonth();this.start.setHours(0);this.start.setMinutes(0);this.start.setSeconds(0);this.start.setMilliseconds(0);this.end=this.start.add(Date.MONTH,1);return this.clone()};this.setToQuarter=function(){this.start=this.start.getFirstDateOfMonth();this.start.setHours(0);this.start.setMinutes(0);this.start.setSeconds(0);this.start.setMilliseconds(0);var C=this.start.getMonth()%3;if(C!=0){this.start=this.start.add(Date.MONTH,-C)}this.end=this.start.add(Date.MONTH,3);return this.clone()};this.setToYear=function(){this.start.setDate(1);this.start.setMonth(0);this.start.setHours(0);this.start.setMinutes(0);this.start.setSeconds(0);this.start.setMilliseconds(0);this.end=this.start.add(Date.MONTH,12);return this.clone()}}(function(){function B(){var D=new Array();D.push({text:"Show Current",tooltip:{text:"Change the time period of this graph to show today, the current week, current month or other time ranges"},menu:[{text:"Day",scope:this,handler:function(){var F=new TimePeriod(Date(),Date());F.setToDay();this.updateGraphPeriod(F.start,F.end)}},{text:"Week",scope:this,handler:function(){var F=new TimePeriod(Date(),Date());F.setToWeek();this.updateGraphPeriod(F.start,F.end)}},{text:"Month",scope:this,handler:function(){var F=new TimePeriod(Date(),Date());F.setToMonth();this.updateGraphPeriod(F.start,F.end)}},{text:"Quarter",scope:this,handler:function(){var F=new TimePeriod(Date(),Date());F.setToQuarter();this.updateGraphPeriod(F.start,F.end)}},{text:"Year",scope:this,handler:function(){var F=new TimePeriod(Date(),Date());F.setToYear();this.updateGraphPeriod(F.start,F.end)}}]});D.push({text:"Show Past",tooltip:{text:"Change the time period of this graph to show the past six hours, past 24 hours, past seven days or other time ranges"},menu:[{text:"6h",scope:this,handler:function(){var F=new Date();var G=new TimePeriod(F.add(Date.HOUR,-6),F);this.updateGraphPeriod(G.start,G.end)}},{text:"12h",scope:this,handler:function(){var F=new Date();var G=new TimePeriod(F.add(Date.HOUR,-12),F);this.updateGraphPeriod(G.start,G.end)}},{text:"24h",scope:this,handler:function(){var F=new Date();var G=new TimePeriod(F.add(Date.HOUR,-24),F);this.updateGraphPeriod(G.start,G.end)},tooltip:{text:"Change the time period of this graph to show the past 24 hours"}},{text:"7 Days",scope:this,handler:function(){var F=new Date();var G=new TimePeriod(F.add(Date.DAY,-7),F);this.updateGraphPeriod(G.start,G.end)}},{text:"Month",scope:this,handler:function(){var F=new Date();var G=new TimePeriod(F.add(Date.MONTH,-1),F);this.updateGraphPeriod(G.start,G.end)}},{text:"Year",scope:this,handler:function(){var F=new Date();var G=new TimePeriod(F.add(Date.YEAR,-1),F);this.updateGraphPeriod(G.start,G.end)}}]});D.push({text:"Shrink/Expand",tooltip:{text:"Change the time period of this graph to to show the hour, day, week, or month that the graph starts in"},menu:[{text:"To Hour",scope:this,handler:function(){var F=this.getGraphPeriod();F.setToHour();this.updateGraphPeriod(F.start,F.end)}},{text:"To Day",scope:this,handler:function(){var F=this.getGraphPeriod();F.setToDay();this.updateGraphPeriod(F.start,F.end)}},{text:"To Week",scope:this,handler:function(){var F=this.getGraphPeriod();F.setToWeek();this.updateGraphPeriod(F.start,F.end)}},{text:"To Month",scope:this,handler:function(){var F=this.getGraphPeriod();F.setToMonth();this.updateGraphPeriod(F.start,F.end)}},{text:"To Quarter",scope:this,handler:function(){var F=this.getGraphPeriod();F.setToQuarter();this.updateGraphPeriod(F.start,F.end)}},{text:"To Year",scope:this,handler:function(){var F=this.getGraphPeriod();F.setToYear();this.updateGraphPeriod(F.start,F.end)}}]});var C=new Ext.menu.DateMenu({scope:this,handler:function(H,F){var G=new TimePeriod(F,F);G.setToDay();this.updateGraphPeriod(G.start,G.end)}});C.picker.startDay=1;D.push({text:"Choose a Day",tooltip:{text:"Change the time period of this graph to show an interactively selected day"},menu:C});D.push({text:"Zoom Out",tooltip:{text:"Change the time period of this graph to show double or triple times the currently viewed time period"},menu:[{text:"2x",scope:this,handler:function(){this.zoomOut(2)}},{text:"3x",scope:this,handler:function(){this.zoomOut(3)}},{text:"4x",scope:this,handler:function(){this.zoomOut(4)}},{text:"5x",scope:this,handler:function(){this.zoomOut(5)}},{text:"6x",scope:this,handler:function(){this.zoomOut(6)}},{text:"7x",scope:this,handler:function(){this.zoomOut(7)}},{text:"12x",scope:this,handler:function(){this.zoomOut(12)}},{text:"24x",scope:this,handler:function(){this.zoomOut(24)}}]});this.undoButton=new Ext.Toolbar.Button({text:"Undo",disabled:true,scope:this,handler:this.undoGraphPeriod,tooltip:{text:"Undo the last action(s)"}});D.push(this.undoButton);var E=new Ext.Toolbar({hideParent:true,items:D});return E}function A(){this.bbarspinner=new Ext.ux.form.Spinner({style:"text-align:right",fieldLabel:"Factor",value:1,width:40,strategy:{xtype:"number",allowBlank:false,allowDecimals:false,minValue:1,maxValue:12}});var C=new Array();C.push({text:"&laquo; Month",scope:this,tooltip:{text:"Shift this graph back in time by the selected count of months"},handler:function(){var E=this.bbarspinner.getValue();if(E<1||E>12){E=1}this.shiftGraph(Date.MONTH,-1*E)}});C.push({text:"&laquo; Week",scope:this,tooltip:{text:"Shift this graph back in time by the selected count of weeks"},handler:function(){var E=this.bbarspinner.getValue();if(E<1||E>12){E=1}this.shiftGraph(Date.DAY,-7*E)}});C.push({text:"&laquo; Day",scope:this,tooltip:{text:"Shift this graph back in time by the selected count of days"},handler:function(){var E=this.bbarspinner.getValue();if(E<1||E>12){E=1}this.shiftGraph(Date.DAY,-1*E)}});C.push({text:"&laquo; Hour",scope:this,tooltip:{text:"Shift this graph back in time by the selected count of hours"},handler:function(){var E=this.bbarspinner.getValue();if(E<1||E>12){E=1}this.shiftGraph(Date.HOUR,-1*E)}});C.push({text:"&laquo; Period",scope:this,tooltip:{text:"Shift this graph back in time by the currently viewed period for the selected count times"},handler:function(){var F=this.bbarspinner.getValue();if(F<1||F>12){F=1}var E=this.getGraphPeriod();this.shiftGraph(Date.MILLI,-E.getDiff()*F)}});C.push(" ",this.bbarspinner," ");C.push({text:"Period &raquo;",scope:this,tooltip:{text:"Shift this graph forward in time by the currently viewed period for the selected count times"},handler:function(){var F=this.bbarspinner.getValue();if(F<1||F>12){F=1}var E=this.getGraphPeriod();this.shiftGraph(Date.MILLI,E.getDiff()*F)}});C.push({text:"Hour &raquo;",scope:this,tooltip:{text:"Shift this graph forward in time by the selected count of hours"},handler:function(){var E=this.bbarspinner.getValue();if(E<1||E>12){E=1}this.shiftGraph(Date.HOUR,1*E)}});C.push({text:"Day &raquo;",scope:this,tooltip:{text:"Shift this graph forward in time by the selected count of days"},handler:function(){var E=this.bbarspinner.getValue();if(E<1||E>12){E=1}this.shiftGraph(Date.DAY,1*E)}});C.push({text:"Week &raquo;",scope:this,tooltip:{text:"Shift this graph forward in time by the selected count of weeks"},handler:function(){var E=this.bbarspinner.getValue();if(E<1||E>12){E=1}this.shiftGraph(Date.DAY,7*E)}});C.push({text:"Month &raquo;",scope:this,tooltip:{text:"Shift this graph forward in time by the selected count of months"},handler:function(){var E=this.bbarspinner.getValue();if(E<1||E>12){E=1}this.shiftGraph(Date.MONTH,1*E)}});var D=new Ext.Toolbar({hideParent:true,items:C});return D}Ext.ux.GraphPanel=Ext.extend(Ext.ux.Portlet,{graphWidth:500,graphHeight:125,graphTitle:false,graphZoom:false,collapsible:true,collapseFirst:false,titleCollapse:true,border:true,width:600,height:300,graphPeriodHistory:null,tools:[{id:"help",qtip:"Shows description of metric(s) in this graph.<br>Click again to hide the description.",handler:function(E,C,D){D.toggleDescription()}},{id:"refresh",qtip:"Refreshes the graph.",handler:function(E,C,D){D.updateGraph()}},{id:"search",qtip:"Enables/Disables zooming of graph.",handler:function(E,C,D){D.toggleGraphZoom()}},{id:"close",qtip:"Removes this graph from the view.",handler:function(E,C,D){D.getEl().fadeOut({duration:0.75,callback:function(){D.ownerCt.remove(D.getId())}})}}],initComponent:function(){this.tbar=B.call(this);this.bbar=A.call(this);Ext.ux.GraphPanel.superclass.initComponent.call(this)},afterRender:function(){Ext.ux.GraphPanel.superclass.afterRender.call(this);var D=this.bbarspinner.getEl();var C=D.parent();C.setStyle("margin-left","auto");C.setStyle("margin-right","auto");var E=D.findParent("td",10,true);E.setStyle("width","100%");if(this.graphId){this.updateGraph()}this.getTopToolbar().hide();this.getBottomToolbar().hide()},afterCollapse:function(){this.hideTools();Ext.ux.GraphPanel.superclass.afterCollapse.call(this)},afterExpand:function(){Ext.ux.GraphPanel.superclass.afterExpand.call(this);this.showTools()},hideTools:function(){for(t in this.tools){if(t!="close"&&t!="toggle"){this.tools[t].hide()}}},showTools:function(){for(t in this.tools){if(t!="close"&&t!="toggle"){this.tools[t].show(true)}}},setGraphStyle:function(C){this.graphStyle=C},setGraphSlopeMode:function(C){this.graphSlopeMode=C},setGraphAltAutoscale:function(C){this.graphAltAutoscale=C},setGraphLowerLimit:function(C){this.graphLowerLimit=C},setGraph:function(C){this.graphId=C},setGraphPeriod:function(D,C){if(this.graphPeriodHistory!=null&&this.graphPeriod){this.graphPeriodHistory.push(this.graphPeriod)}this.graphPeriod=new TimePeriod(D,C)},updateGraphPeriod:function(D,C){this.setGraphPeriod(D,C);this.updateGraph()},getGraphPeriod:function(){return this.graphPeriod.clone()},getGraphStart:function(){return new Date(this.graphPeriod.start.getTime())},getGraphEnd:function(){return new Date(this.graphPeriod.end.getTime())},getGraphWidth:function(){return this.graphWidth},getGraphHeight:function(){return this.graphHeight},hasGraphTitle:function(){return this.graphTitle},shiftGraph:function(C,D){this.updateGraphPeriod(this.graphPeriod.start.add(C,D),this.graphPeriod.end.add(C,D))},undoGraphPeriod:function(){if(this.canUndoGraphPeriod()){this.graphPeriod=this.graphPeriodHistory.pop();this.updateGraph()}},canUndoGraphPeriod:function(){if(this.graphPeriodHistory!=null){return this.graphPeriodHistory.length?true:false}return false},createGraphBox:function(){var D=[];var C="smt-graph";if(this.graphZoom){D=new Ext.ux.GraphPanel.DragSelector();C+=" smt-graph-zoom"}if(this.graphBox){this.remove(this.graphBox)}this.graphBox=new Ext.BoxComponent({plugins:D,autoEl:{cls:"smt-graph-wrap",children:{tag:"img",cls:C,src:this.graphUrl,style:"padding:5px"}}});this.add(this.graphBox);this.doLayout();this.graphBox.el.on("dblclick",this.toggleGraphZoom,this)},toggleGraphZoom:function(){this.graphZoom=this.graphZoom?false:true;this.tools.search.isMasked()?this.tools.search.unmask():this.tools.search.mask();var D=this.getTopToolbar();D.setVisible(D.hidden);var C=this.getBottomToolbar();C.setVisible(C.hidden);this.createGraphBox();this.graphPeriodHistory=this.graphZoom?new Array():null;this.undoButton.disable()},updateGraph:function(){if(!this.graphId||!this.rendered){return }var C={type:"create_graph",id:this.graphId,start:this.graphPeriod.start.format("U"),end:this.graphPeriod.end.format("U"),title:this.graphTitle};if(this.graphStyle){C.style=this.graphStyle}if(this.graphSlopeMode!=null){C.slopemode=this.graphSlopeMode}if(this.graphAltAutoscale!=null){C.altautoscale=this.graphAltAutoscale}if(this.graphLowerLimit!=null){C.lower_limit=this.graphLowerLimit}Ext.Ajax.request({url:"request.pl",params:C,scope:this,callback:function(E,J,F){if(!J){return }var H=Ext.util.JSON.decode(F.responseText);var I={type:"get_graph",handle:H.handle};this.graphUrl="request.pl?"+Ext.urlEncode(I);var G=this.getFrameWidth()+H.width+12;var D=this.getFrameHeight()+H.height+12;this.setSize(G,D,true);this.createGraphBox();this.showTools();if(this.canUndoGraphPeriod()){this.undoButton.enable()}else{this.undoButton.disable()}this.bwrap.unmask()}});this.hideTools();this.bwrap.mask("Loading ...","x-mask-loading")},toggleDescription:function(){var C=this.graphBox.el.down("div.smt-graph-desc-wrap");if(!C){C=Ext.DomHelper.insertFirst(this.graphBox.el,{cls:"smt-graph-desc-wrap"},true);C.alignTo(this.getEl(),"t-t",[0,30])}var D=C.down("div.x-box");if(!D){D=Ext.DomHelper.append(C,{html:this.graphDesc},true).boxWrap();D.on("click",function(){this.slideOut("t",{remove:true})});D.slideIn("t")}else{D.slideOut("t",{remove:true})}},zoomOut:function(C){var E=this.getGraphPeriod();var D=E.getDiff();this.updateGraphPeriod(E.start.add(Date.MILLI,-(D/2)*(C-1)),E.end.add(Date.MILLI,D/2*(C-1)))}});Ext.reg("graphpanel",Ext.ux.GraphPanel)})();Ext.ux.DragTracker=function(A){Ext.ux.DragTracker.superclass.constructor.call(this,A)};Ext.extend(Ext.ux.DragTracker,Ext.dd.DragTracker,{initEl:function(A){Ext.ux.DragTracker.superclass.initEl.call(this,A);A.on("contextmenu",this.onContextMenu,this)},onMouseDown:function(B,A){if(B.button==0){Ext.ux.DragTracker.superclass.onMouseDown.call(this,B,A)}else{B.preventDefault()}},onContextMenu:function(A){A.preventDefault()}});Ext.ux.GraphPanel.DragSelector=function(H){H=H||{};var G,D,J,L;var K,M=new Ext.lib.Region(0,0,0,0);var B=H.dragSafe===true;this.init=function(Q){G=Q;G.on("render",P)};function N(){var S=G.ownerCt.hasGraphTitle()?38:27;var R=56;var V=G.ownerCt.getGraphWidth();var Q=G.ownerCt.getGraphHeight();K=G.el.getRegion();var T=K.top-K.bottom+S+Q;var U=K.left-K.right+R+V;K.adjust(S,R,T,U)}function F(){return false}function I(Q){return !B||Q.target==G.el.dom}function O(Q){if(!J){J=G.el.createChild({cls:"smt-box-selector"})}else{J.setDisplayed("block")}N()}function C(U){var T=L.startXY;var S=L.getXY();var Q=Math.min(T[0],S[0]);var V=Math.min(T[1],S[1]);var R=Math.abs(T[0]-S[0]);M.left=Q;M.top=K.top;M.right=Q+R;M.bottom=K.bottom;M.constrainTo(K);J.setRegion(M)}function A(V){if(J){J.setDisplayed(false)}if(K){var R=M.left-K.left;var U=K.right-M.right;var S=G.ownerCt;var T=S.getGraphWidth();var X=S.getGraphPeriod();var Z=X.getDiff()*(R/T);var Q=X.getDiff()*(U/T)*-1;var a=X.start.add(Date.MILLI,Z);var W=X.end.add(Date.MILLI,Q);var Y=1800000-a.getElapsed(W);if(Y>0){a=a.add(Date.MILLI,Y/2*-1);W=a.add(Date.MILLI,1800000)}S.updateGraphPeriod(a,W)}}function E(Q){Q.preventDefault();G.ownerCt.zoomOut(2)}function P(Q){L=new Ext.ux.DragTracker({onBeforeStart:I,onStart:O,onDrag:C,onEnd:A,onContextMenu:E});L.initEl(Q.el)}};