/*
 *  Copyright © 2008 Fair Oaks Labs, Inc.
 *  All rights reserved.
 */
var Parser,Mdef,app;Parser=new function(){this.hLut=new Array(256);this.cLut=new Array(256);this.rvHex0=new Array(8);this.rvTxt0=new Array(8);this.rvHex1=new Array(8);this.rvTxt1=new Array(8);var D,A,C,B=String("0123456789ABCDEF").split("");for(D=0;D<16;D++){for(A=0;A<16;A++){this.hLut[D*16+A]=B[D]+B[A]}}this.hLut[undefined]="\u00a0\u00a0";for(C=0;C<256;C++){if((C<32)||(C>126)){this.cLut[C]="."}else{if(C==32){this.cLut[C]="\u00a0"}else{this.cLut[C]=String.fromCharCode(C)}}}this.cLut[undefined]="\u00a0";this.DwordToHex=function(F){var E=[];while(F){E.unshift(this.hLut[F&255]);F>>=8}while(E.length<4){E.unshift("00")}return E.join("")};this.PrintSegment=function(E,G,H,F){var I,J;for(I=0;I<8;I++){J=E[G+I];H[I]=this.hLut[J];F[I]=this.cLut[J]}};this.PrintRowDetail=function(E,F){this.PrintSegment(E,F,this.rvHex0,this.rvTxt0);this.PrintSegment(E,F+8,this.rvHex1,this.rvTxt1);return this.DwordToHex(F)+"\u00a0\u00a0"+this.rvHex0.join(" ")+"\u00a0--\u00a0"+this.rvHex1.join(" ")+"\u00a0\u00a0"+this.rvTxt0.join("")+this.rvTxt1.join("")};this.AppendRowDetail=function(H,E,F){var G=H.appendChild(document.createElement("P")).appendChild(document.createElement("SPAN"));G.className="row"+((F>>4)&1);G.appendChild(document.createTextNode(this.PrintRowDetail(E,F)))};this.PrintRowSimple=function(E,F){this.PrintSegment(E,F,this.rvHex0,this.rvTxt0);this.PrintSegment(E,F+8,this.rvHex1,this.rvTxt1);return this.rvHex0.join(" ")+"\u00a0--\u00a0"+this.rvHex1.join(" ")+"\u00a0\u00a0"+this.rvTxt0.join("")+this.rvTxt1.join("")};this.AppendRowSimple=function(H,E,F){var G=document.createElement("P");G.appendChild(document.createTextNode(this.PrintRowSimple(E,F)));H.appendChild(G)};this.Display=function(J,H,F){var I=document.getElementById(J),G,E;while(I.firstChild){I.removeChild(I.firstChild)}if(!H){I=I.appendChild(document.createElement("P"));I.appendChild(document.createTextNode("No data available"))}else{I=I.appendChild(document.createElement("TABLE"));I.id="hexdump";I=I.appendChild(document.createElement("TBODY"));I=I.appendChild(document.createElement("TR"));I=I.appendChild(document.createElement("TD"));G=F?this.AppendRowDetail:this.AppendRowSimple;for(E=0;E<H.length;E+=16){G.call(this,I,H,E)}}}}();Mdef=new function(){var B,A=this;this.RcodeToCtor=function(C){switch(C){case 1:return this.MeterHeader;case 10:return this.ChannelHeader;case 9999:return this.TrailerRecord;default:if((C>=1001)&&(C<=9998)){return this.IntervalRecord}else{return this.UnkRecord}}};A.RepeatString=function(D,F){var C,E=new Array(F);for(C=0;C<F;C++){E[C]=D}return E.join("")};A.DecodeFlagsToCSV=function(C,E){var D,F=[];for(D=0;D<E.length;D++,C>>=1){if(C&1){F.unshift(E[D])}}return F.join(", ")};A.DecodeFlagsToText=function(C,E){var D,F=[];for(D=0;D<E;D++,C>>=1){F.unshift(C&1)}return F.join("")};A.UnrecoverableP=function(D){for(var C=0;C<D.length;C++){if(D[C][0]=="U"){return true}}return false};A.EqualArrayP=function(D,C){if(D.length!=C.length){return false}for(var E=0;E<D.length;E++){if(D[E]!=C[E]){return false}}return true};A.PrintTime=function(E){var I,C,F,D,G;I=""+E.getUTCFullYear();C=("0"+(E.getUTCMonth()+1)).slice(-2);F=("0"+E.getUTCDate()).slice(-2);D=("0"+E.getUTCHours()).slice(-2);G=("0"+E.getUTCMinutes()).slice(-2);return I+"/"+C+"/"+F+"\u00a0"+D+":"+G};A.CreateGenericCopyFxn=function(C,E,D){return function(){C.app.CopyRows(E,D);alert("Data copied to clipboard");return false}};A.CreateGenericTableDC=function(C,I,K,G){var D,E,J,F,H=document.getElementById(C.panel[G]);while(H.firstChild){H.removeChild(H.firstChild)}D=H.appendChild(document.createElement("P")).appendChild(document.createElement("BUTTON"));D.onclick=A.CreateGenericCopyFxn(C,I,K);D.setAttribute("type","button");D.appendChild(document.createTextNode("Copy data to clipboard"));E=H.appendChild(document.createElement("TABLE"));J=E.appendChild(document.createElement("THEAD")).appendChild(document.createElement("TR"));for(F=0;F<I.length;F++){J.appendChild(document.createElement("TD")).appendChild(document.createTextNode(I[F]))}return E.appendChild(document.createElement("TBODY"))};A.DisplayGenericRows=function(C,D,I,H,L,G){var F,E,K,J;if((C.mode!=G)&&(C.viewCache[C.mode]==1)){return[C,D,I,H,L]}if(I==undefined){I=0}if(H==undefined){H=1}H=Math.min(H,L.length-I);for(F=0;F<H;F++){K=D.appendChild(document.createElement("TR"));J=L[I+F];for(E=0;E<J.length;E++){K.appendChild(document.createElement("TD")).appendChild(document.createTextNode(J[E]))}}if((I+H)<L.length){return[C,D,I+H,Math.min(Math.ceil(H*1.5),100),L]}else{C.viewCache[G]=2}};A.MakeArray=function(C,E){var D,F=[];for(D=0;D<E;D++){F.push(new Array(C))}return F};A.IntervalA=function(C){if(!C){C=[]}this.ParseData.apply(this,C)};B=A.IntervalA.prototype;B.fmt="f";B.dataLen=Struct.CalcLength(B.fmt);B.nDataElts=1;B.ParseData=function(C){this.read=C;this.cStatus=0;this.iStatus=0};B.Display=function(C,D){D.appendChild(document.createElement("TD")).appendChild(document.createTextNode(this.read));D.appendChild(document.createElement("TD")).appendChild(document.createTextNode(A.DecodeFlagsToText(this.cStatus,16)));D.appendChild(document.createElement("TD")).appendChild(document.createTextNode(A.DecodeFlagsToText(this.iStatus,16)))};A.IntervalAx=function(C){A.IntervalA.call(this,C)};B=A.IntervalAx.prototype=new A.IntervalA();B.fmt="fH";B.dataLen=Struct.CalcLength(B.fmt);B.nDataElts=2;B.ParseData=function(D,C){this.read=D;this.cStatus=C;this.iStatus=0};A.IntervalAy=function(C){A.IntervalA.call(this,C)};B=A.IntervalAy.prototype=new A.IntervalA();B.fmt="fH";B.dataLen=Struct.CalcLength(B.fmt);B.nDataElts=2;B.ParseData=function(C,D){this.read=C;this.cStatus=0;this.iStatus=D};A.IntervalAxy=function(C){A.IntervalA.call(this,C)};B=A.IntervalAxy.prototype=new A.IntervalA();B.fmt="f2H";B.dataLen=Struct.CalcLength(B.fmt);B.nDataElts=3;B.ParseData=function(D,C,E){this.read=D;this.cStatus=C;this.iStatus=E};this.Record=function(C,D){this.idx=D?D.idx:0;this.data=C;this.bParsed=false};B=this.Record.prototype;B._fmt="";B._fmtLen=Struct.CalcLength(B._fmt);B._names=[];B._internal={};B.LongDesc="Unknown Record Type";B.ShortDesc="Unknown";B.ValidateField=function(L,G,J,D){var I,M,H,E,C,K,F;I=this[L];M=L+" in Record #"+this.idx+" ";switch(G){case"A/N":H=function(N){return((N>=32)&&(N<=126))};E=D?D:"2";break;case"A":H=function(N){return(((N>=32)&&(N<=126))&&((N<48)||(N>57)))};E=D?D:"2";break;case"N":H=function(N){return(((N>=48)&&(N<=57))||(N==46))};E=D?D:"1";break;default:H=function(N){return true};E=D?D:"4";break}K=false;for(F=0;F<I.length;F++){C=I.charCodeAt(F);if(!H(C)){if(C==0){K=true}else{J.push([E,M+"contained unexpected characters"]);return false}}}if(K){J.push([D?D:"3",M+"contained NULLs"]);return false}return true};B.ValidateEnum=function(I,H,K,G,C){var E,L,D,J,F;E=this[I];L=I+" in Record #"+this.idx+" ";if(K){if(E==" "){return true}if(E=="\u0000"){G.push(["3",L+"contained NULLs"]);return false}}for(D=0;D<H.length;D++){if(E==H.charAt(D)){return true}}J="";F=[];if(H.length>1){J=" or "}J=J+'"'+H.charAt(H.length-1)+'"';for(D=H.length-2;D>=0;D--){F.unshift('"'+H.charAt(D)+'"')}G.push([C,L+"must be "+F.join(", ")+J]);return false};B.ValidateTimestamp=function(N,F,D,M,G){var K,O,H,E,L,J,I,C;K=this[N];O=N+" in Record #"+this.idx+" ";H=G?G:"U";if(!this.ValidateField(N,"N",M,H)){return }if(!(E=Time_US.UnpackDate(K.slice(0,8)+"0000"))){M.push([H,O+"specifies an illegal date"]);return }if(K.slice(8,12)=="2400"){E.setUTCDate(E.getUTCDate()+1)}else{if(!(E=Time_US.UnpackDate(K))){M.push([H,O+"specifies an illegal time"]);return }}if(F){C=Time_US.DstInfo(E);if(!C){M.push([H,O+"specifies a year for which no DST information is available"]);return }J=new Date(C[0]);J.setUTCHours(2);J.setUTCMinutes(0);I=new Date(C[0]);I.setUTCHours(3);I.setUTCMinutes(0);if((E>J)&&(E<I)){M.push(["1",O+"falls within the missing hour of the DST transition-in day"])}J=new Date(C[1]);J.setUTCHours(1);J.setUTCMinutes(0);I=new Date(C[1]);I.setUTCHours(2);I.setUTCMinutes(0);if((!D)&&(E>=J)&&(E<=I)){M.push([H,O+"may not fall within the ambiguous hour of the DST transition-out day"]);return }else{if((E>=I)&&(E<=I)){M.push(["1",O+"falls on 0200 of the DST transition-out day, and will be treated as a DST time"]);L=new Date(E);L.setUTCHours(L.getUTCHours()-1)}else{if(!(L=Time_US.PrevailingToStandard(E))){M.push([H,O+"could not be converted to Standard Time"]);return }}}}else{L=new Date(E)}return L};B.ValidateRLEN=function(D){if(this._fmtLen!=this.RLEN){var C="Record #"+this.idx+" had an unexpected RLEN value (expected "+this._fmtLen+", found "+this.RLEN+")";D.push(["R",C])}};B.ParseData=function(){if(this.bParsed){return }var D,C=Struct.Unpack(this._fmt,this.data,0);if(!C){C=[]}for(D=0;D<this._names.length;D++){this[this._names[D]]=C[D]}this.bParsed=true};B.LaunderField=function(E){if(!E.length){return E}for(var C=[],D=0;D<E.length;D++){C.push(E.charCodeAt(D)?E.charCodeAt(D):248)}return String.fromCharCode.apply(undefined,C).replace(/ /g,"\u00a0")};B.Display=function(G){if(!this.bParsed){this.ParseData()}var I,C,H,F,E,D,J=document.getElementById(G.panel.exp);while(J.firstChild){J.removeChild(J.firstChild)}I=document.createElement("TBODY");for(C=0;C<this._names.length;C++){if(!G.reserved_vis&&(this._names[C].slice(0,3)=="XX_")){continue}if(this._internal[this._names[C]]){continue}H=I.appendChild(document.createElement("TR"));F=H.appendChild(document.createElement("TD"));E=H.appendChild(document.createElement("TD"));D=E.appendChild(document.createElement("SPAN"));D.className="blockVal";F.appendChild(document.createTextNode(this._names[C]));D.appendChild(document.createTextNode(this.LaunderField(this[this._names[C]])))}J.appendChild(document.createElement("TABLE")).appendChild(I)};this.UnkRecord=function(C,D){Mdef.Record.call(this,C,D)};B=this.UnkRecord.prototype=new this.Record();B.Display=function(C){Parser.Display(C.panel.exp,this.data,true)};this.MeterHeader=function(C,D){Mdef.Record.call(this,C,D)};B=this.MeterHeader.prototype=new this.Record();B._fmt="2H20s20s20s20s20s7s4s4s12s12ss72s";B._fmtLen=Struct.CalcLength(B._fmt);B._names=["RLEN","RCODE","CM_CUSTID","CM_NAME","CM_ADDR1","CM_ADDR2","CM_ACCOUNT","XX_0","CM_LOGCHANS","XX_1","TA_START","TA_STOP","DSTFLAG","XX_2"];B._internal={};B.LongDesc="Meter (Recorder/Site) Record";B.ShortDesc="Meter Header";B.RespectDstP=function(){if(!this.bParsed){this.ParseData()}return((this.DSTFLAG=="Y")||(this.DSTFLAG==" "))};B.Validate=function(){if(!this.bParsed){this.ParseData()}var D,C,E,F=[];this.ValidateRLEN(F);this.ValidateField("CM_CUSTID","A/N",F,undefined);this.ValidateField("CM_NAME","A/N",F,undefined);this.ValidateField("CM_ADDR1","A/N",F,undefined);this.ValidateField("CM_ADDR2","A/N",F,undefined);this.ValidateField("CM_ACCOUNT","A/N",F,undefined);this.ValidateField("XX_0","A/N",F,"4");this.ValidateField("CM_LOGCHANS","A/N",F,undefined);this.ValidateField("XX_1","A",F,"4");D=this.RespectDstP();C=this.ValidateTimestamp("TA_START",D,true,F,undefined);E=this.ValidateTimestamp("TA_STOP",D,false,F,undefined);if(C&&E&&(E<C)){F.push(["U","TA_STOP preceeds TA_START (in Standard Time) in Record #"+this.idx])}this.ValidateEnum("DSTFLAG","YN ",false,F,"R");this.ValidateField("XX_2","A/N",F,"4");return F};this.ChannelHeader=function(C,D){Mdef.Record.call(this,C,D);this.ParseData();D.CHANSTAT=this.CHANSTAT;D.INTSTAT=this.INTSTAT};B=this.ChannelHeader.prototype=new this.Record();B._fmt="2H20s14s6s12s12s12s12ss2sH2sss12s12ss10s30ss10s2s14s2s15ssHs2s";B._fmtLen=Struct.CalcLength(B._fmt);B._names=["RLEN","RCODE","DC_CUSTID","DC_RECID","XX_3","DC_METERID","TA_START","TA_STOP","XX_4","XX_5","DC_PYSCHAN","DC_LOGCHAN","DC_UMCODE","CHANSTAT","INTSTAT","STRTMTR","STOPMTR","XX_6","DC_MMULT","XX_7","DC_SERVTYPE","XX_8","DR_INPHR","XX_9","TD_STATUS","XX_10","DC_FLOW","DC_KVASET","TD_ORIGIN","XX_11"];B._internal={};B.LongDesc="Channel Header Record";B.ShortDesc="Channel Header";B._lutUOM=[undefined,"KWH","Reserved","KVARH","KVAR","\u00b0F","Reserved","V\u00b2H","KQH","msec","I\u00b2H","Volts","Amps","\u00b0C","KQH30","KQH45","PARH","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","Reserved for Load Research","CCF - Uncorrected Volume (Gas)","CCF - Corrected Volume (Gas)","PSI - Pressure","PSI - Differential Pressure","Specific Gravity","BTU","Therms","Gallons - Volume (Water)","MWH","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","Reserved","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined","User Defined"];B.DecodeUOM=function(C){return this._lutUOM[C]};B.Validate=function(E){if(!this.bParsed){this.ParseData()}var D,C,F,G=[];this.ValidateRLEN(G);this.ValidateField("DC_CUSTID","A/N",G,undefined);this.ValidateField("DC_RECID","A/N",G,undefined);if(this.DC_RECID.match(/^[\u0000\s]*$/)){D="DC_RECID in Record #"+this.idx+" ";G.push(["R",D+"is blank"])}this.ValidateField("XX_3","A/N",G,"4");this.ValidateField("DC_METERID","A/N",G,undefined);C=this.ValidateTimestamp("TA_START",E,true,G,undefined);F=this.ValidateTimestamp("TA_STOP",E,false,G,undefined);if(C&&F&&(F<C)){G.push(["U","TA_STOP preceeds TA_START (in Standard Time) in Record #"+this.idx])}this.ValidateField("XX_4","A/N",G,"4");this.ValidateField("XX_5","A/N",G,"4");if(this.ValidateField("DC_PYSCHAN","N",G,"U")){if(this.DC_PYSCHAN.indexOf(".")>=0){D="DC_PYSCHAN in Record #"+this.idx+" ";G.push(["U",D+"may not contain decimal points"])}}if(this.ValidateField("DC_UMCODE","N",G,"U")){D="DC_UMCODE in Record #"+this.idx+" ";if(this.DC_UMCODE.indexOf(".")>=0){G.push(["U",D+"may not contain decimal points"])}if((parseInt(this.DC_UMCODE,10)<1)||(parseInt(this.DC_UMCODE,10)>99)){G.push(["U",D+"must be between 1 and 99"])}}this.ValidateEnum("CHANSTAT","YN",false,G,"R");this.ValidateEnum("INTSTAT","YN",false,G,"R");this.ValidateField("STRTMTR","N",G,undefined);this.ValidateField("STOPMTR","N",G,undefined);if((!this.STRTMTR.match(/^[\u0000\s]*$/))&&isNaN(parseFloat(this.STRTMTR))){D="STRTMTR in Record #"+this.idx+" ";G.push(["1",D+"should evaluate to a number"])}if((!this.STOPMTR.match(/^[\u0000\s]*$/))&&isNaN(parseFloat(this.STOPMTR))){D="STOPMTR in Record #"+this.idx+" ";G.push(["1",D+"should evaluate to a number"])}this.ValidateField("XX_6","A/N",G,"4");this.ValidateField("DC_MMULT","N",G,"R");if(isNaN(parseFloat(this.DC_MMULT))){D="DC_MMULT in Record #"+this.idx+" ";G.push(["R",D+"should evaluate to a number"])}this.ValidateField("XX_7","A/N",G,"4");this.ValidateEnum("DC_SERVTYPE","WD+-",true,G,"R");this.ValidateField("XX_8","A/N",G,"4");if(this.ValidateField("DR_INPHR","N",G,"U")){D="DR_INPHR in Record #"+this.idx+" ";if(this.DR_INPHR.indexOf(".")>=0){G.push(["U",D+"may not contain decimal points"])}if(!(60%parseInt(this.DR_INPHR,10)==0)){G.push(["U",D+"must be a factor of 60"])}}this.ValidateField("XX_9","A/N",G,"4");this.ValidateField("TD_STATUS","A",G,undefined);this.ValidateField("XX_10","A/N",G,"4");this.ValidateEnum("DC_FLOW","DR",true,G,"R");this.ValidateEnum("TD_ORIGIN","TRIPS",true,G,"R");this.ValidateField("XX_11","A/N",G,"4");return G};this.IntervalRecord=function(C,D){Mdef.Record.call(this,C,D);this.CHANSTAT=D.CHANSTAT;this.INTSTAT=D.INTSTAT};B=this.IntervalRecord.prototype=new this.Record();B._fmt="2H20s192A";B._fmtLen=Struct.CalcLength(B._fmt);B._names=["RLEN","RCODE","CM_CUSTID","INTERVAL"];B._internal={INTERVAL:true};B.LongDesc="Interval Data Record";B.ShortDesc="Interval Data";B._CalcIntervalType=function(){return A["IntervalA"+(this.CHANSTAT=="Y"?"x":"")+(this.INTSTAT=="Y"?"y":"")]};B._ParseInterval=function(C){var G,F,D,E;G=new Array(this.INTERVAL.length/C.prototype.dataLen);F=Struct.Unpack(A.RepeatString(C.prototype.fmt,G.length),this.INTERVAL,0);for(D=0,E=0;D<G.length;D++,E+=C.prototype.nDataElts){G[D]=new C(F.slice(E,E+C.prototype.nDataElts))}return G};B.Display=function(E){var H,G,F,C,D;Mdef.Record.prototype.Display.call(this,E);G=document.createElement("TBODY");F=G.appendChild(document.createElement("TR"));F.appendChild(document.createElement("TD")).appendChild(document.createTextNode("Read Index"));F.appendChild(document.createElement("TD")).appendChild(document.createTextNode("Meter Reading"));F.appendChild(document.createElement("TD")).appendChild(document.createTextNode("Channel Status Flags"));F.appendChild(document.createElement("TD")).appendChild(document.createTextNode("Interval Status Flags"));C=this._ParseInterval(this._CalcIntervalType());for(D=0;D<C.length;D++){F=G.appendChild(document.createElement("TR"));F.appendChild(document.createElement("TD")).appendChild(document.createTextNode(D));C[D].Display(E,F)}H=document.getElementById(E.panel.exp);H.appendChild(document.createElement("TABLE")).appendChild(G)};B.Validate=function(){if(!this.bParsed){this.ParseData()}var C=[];this.ValidateRLEN(C);this.ValidateField("CM_CUSTID","A/N",C,undefined);return C};this.TrailerRecord=function(C,D){Mdef.Record.call(this,C,D)};B=this.TrailerRecord.prototype=new this.Record();B._fmt="2H30s10s160s12s";B._fmtLen=Struct.CalcLength(B._fmt);B._names=["RLEN","RCODE","XX_12","TOTREC","XX_13","XF_TSTAMP"];B._internal={};B.LongDesc="Trailer Record";B.ShortDesc="Trailer";B.Validate=function(D){if(!this.bParsed){this.ParseData()}var C,E=[];this.ValidateRLEN(E);this.ValidateField("XX_12","A/N",E,"4");if(this.ValidateField("TOTREC","N",E,"R")){C="TOTREC in Record #"+this.idx+" ";if(this.TOTREC.indexOf(".")>=0){E.push(["R",C+"may not contain decimal points"])}if(parseInt(this.TOTREC,10)!=D){E.push(["R",C+"should equal "+D])}}this.ValidateField("XX_13","A",E,"4");if(!this.XF_TSTAMP.match(/^[\u0000\s]*$/)){this.ValidateTimestamp("XF_TSTAMP",false,true,E,"R")}else{this.ValidateField("XF_TSTAMP","N",E,"R")}return E};this.RecordList=function(C,D){if(C){this.ParseData(C,D)}else{this.records=[]}};B=this.RecordList.prototype;B.ParseData=function(C,G){var D,F,E;E={};this.records=[];while(G<C.length){E.idx=this.records.length;D=Struct.Unpack("2H",C,G);if(!D){D=[C.length-G,undefined]}else{if(!D[0]){D[0]=C.length-G}}F=Mdef.RcodeToCtor(D[1]);this.records.push(new F(C.slice(G,G+D[0]),E));G+=D[0]}};B.MakeNavigationLinkFxn=function(C){return function(){C.app.SetDetailIndex(this.href.split("#")[1]);return false}};B.Display=function(F){var J,H,I,E,G,D,C;J=document.getElementById(F.nav_id);while(J.firstChild){J.removeChild(J.firstChild)}H=this.MakeNavigationLinkFxn(F);I=document.createElement("TBODY");for(E=0;E<this.records.length;E++){G=I.appendChild(document.createElement("TR"));D=G.appendChild(document.createElement("TD"));C=D.appendChild(document.createElement("A"));C.appendChild(document.createTextNode(this.records[E].LongDesc));C.href="#"+E;C.onclick=H}J.appendChild(document.createElement("TABLE")).appendChild(I)};A.Segment=function(C){this._ch=C;this._intervals=[]};B=A.Segment.prototype;B._ChannelFlags=["Not Used (15)","Not Used (14)","Not Used (13)","Not Used (12)","Not Used (11)","Harmonic Distorion","Alarm","Energy Type (Register Changed)","Parity","Excluded Data","Data Out of Limits","Pulse Overflow","Estimated Interval (Data Correction)","Replaced Interval (Data Correction)","Added Interval (Data Correction)","Retransmitted/Updated Data"].reverse();B._IntervalFlags=["Not Used (15)","Not Used (14)","Not Used (13)","Load Control","Test Mode","Time Reset Occurred","Watchdog Time-out","Reset Occurred","Clock Error","Data Missing","ROM Checksum Error","RAM Checksum Error","CRC Error","Long Interval (Missing for Mag Tape)","Short Interval (False for Mag Tape)","Power Outage"].reverse();B._CalcIntervalType=function(){return A["IntervalA"+(this.bChanStat?"x":"")+(this.bIntStat?"y":"")]};B._ParseIntervals=function(K,O){var H,C,Q,I,N,J,G,F,L,M,E,D,P;Q=this.MakeTag();if(!(this.duration%this.intLen==0)){O.push(["1",Q+"has a duration of "+this.duration+"m, which is not a multiple of "+this.intLen])}I=Math.ceil(this.duration/this.intLen);N=[];for(H=0;H<this._intervals.length;H++){N.push(this._intervals[H].INTERVAL)}N=Array.prototype.concat.apply([],N);J=Math.floor(N.length/K.prototype.dataLen);if(J<I){O.push(["U",Q+"should have "+I+" reads, but only "+J+" were available"]);return[]}G=new Array(2);if(!Struct.Pack("H",G,0,[32767])){O.push(["U",Q+"could not be validated because a pad could not be constructed"]);return[]}if(I*K.prototype.dataLen&1){G.reverse()}for(H=I*K.prototype.dataLen;H<N.length;H++){if(N[H]!=G[H&1]){O.push(["R",Q+"had incorrectly padded Interval Data records"]);break}}if((N.length-I*K.prototype.dataLen)>192){O.push(["1",Q+"had one or more Interval Data records surplus to requirements"])}F=new Array(I);L=Struct.Unpack(A.RepeatString(K.prototype.fmt,F.length),N,0);M=1584;E=766;D=0;P=0;for(H=0,C=0;H<F.length;H++,C+=K.prototype.nDataElts){F[H]=new K(L.slice(C,C+K.prototype.nDataElts));D|=(F[H].cStatus&M);P|=(F[H].iStatus&E)}for(H=0;H<16;H++,D>>=1){if(D&1){O.push(["1",Q+'includes one or more reads with the "'+this._ChannelFlags[H]+'" flag set'])}}for(H=0;H<16;H++,P>>=1){if(P&1){O.push(["1",Q+'includes one or more reads with the "'+this._IntervalFlags[H]+'" flag set'])}}return F};B.AddInterval=function(C){this._intervals.push(C)};B.MakeTag=function(){return"Channel Segment beginning at "+this._ch.TA_START+" for Channel #"+this._ch.DC_PYSCHAN+' of Meter "'+this._ch.DC_RECID+'" '};B.Process=function(D){var E,F,C=[];C.push(this._ch.Validate(D));for(E=0;E<this._intervals.length;E++){C.push(this._intervals[E].Validate())}F=Array.prototype.concat.apply([],C);if(A.UnrecoverableP(F)){return{unrecoverable:true,errors:F}}C=[F,[]];F=C[1];this.idx=this._ch.idx;this.DC_RECID=this._ch.DC_RECID;this.channelId=parseInt(this._ch.DC_PYSCHAN,10);this.dtStart=new Date(this._ch.ValidateTimestamp("TA_START",D,true,[],undefined)-60000);this.dtStop=this._ch.ValidateTimestamp("TA_STOP",D,false,[],undefined);this.bChanStat=this._ch.CHANSTAT=="Y";this.bIntStat=this._ch.INTSTAT=="Y";this.intLen=60/parseInt(this._ch.DR_INPHR,10);this.uomCode=parseInt(this._ch.DC_UMCODE,10);this.uomName=this._ch.DecodeUOM(this.uomCode);this.duration=(this.dtStop-this.dtStart)/60000;this.txtStart=this._ch.TA_START;this.txtStop=this._ch.TA_STOP;this.reads=this._ParseIntervals(this._CalcIntervalType(),F);return{unrecoverable:A.UnrecoverableP(F),errors:Array.prototype.concat.apply([],C)}};A.Channel=function(C){this._segments=C};B=A.Channel.prototype;B._Validate=function(){var C,D,F,E,G=[];for(C=1,F=this.segments[0],D=this.segments[1];C<this.segments.length;C++,F=D,D=this.segments[C]){if(D.DC_RECID!=this.DC_RECID){E=D.MakeTag()+'was assigned to a channel with a RECID of "'+this.DC_RECID+'"';G.push(["R",E])}if(D.dtStart-F.dtStop){E=D.MakeTag()+"is discontinuous with previous Segment ending at "+F.txtStop;G.push(["U",E])}if(D.idx<F.idx){E=D.MakeTag()+"preceeded, in MDEF record order, the earlier "+F.MakeTag();G.push(["1",E])}}return G};B.MakeTag=function(){return"Channel #"+this.channelId+' of Meter "'+this.DC_RECID+'" '};B.Organization=function(){if(this.segments==undefined){return }var C,D=[];for(C=1;C<this.segments.length;C++){D.push(this.segments[C].txtStart)}return D};B.ForcedBreaks=function(){if(this.segments==undefined){return }var C,D,E,F=[];for(C=1,E=this.segments[0],D=this.segments[1];C<this.segments.length;C++,E=D,D=this.segments[C]){if((D.intLen!=E.intLen)||(D.uomCode!=E.uomCode)){F.push(D.txtStart)}}return F};B.Process=function(){var D,C,E;if(this._segments.length==0){return{unrecoverable:true,errors:[["U","An anonymous Channel was assigned no Channel Segments"]]}}C=[];for(D=0;D<this._segments.length;D++){if(this._segments[D][0]){return{unrecoverable:true,errors:[]}}C.push(this._segments[D][1])}C.sort(function(G,F){return G.dtStart-F.dtStart});this.DC_RECID=C[0].DC_RECID;this.channelId=C[0].channelId;this.dtStart=C[0].dtStart;this.dtStop=C[C.length-1].dtStop;this.txtStart=C[0].txtStart;this.txtStop=C[C.length-1].txtStop;this.segments=C;E=this._Validate();return{unrecoverable:A.UnrecoverableP(E),errors:E}};A.Meter=function(C){this._mh=C;this._segments=[]};B=A.Meter.prototype;B._Validate=function(){var D,C,J,G,F,I,E,H=[];if(!this._mh.CM_LOGCHANS.match(/^[\u0000\s]*$/)&&(parseInt(this._mh.CM_LOGCHANS,10)!=this.channels.length)){E='CM_LOGCHANS in Meter "'+this.DC_RECID+'" was expected to be '+this.channels.length;H.push(["R",E])}F={};for(D=0;D<this.channels.length;D++){G=this.channels[D].ForcedBreaks();for(C=0;C<G.length;C++){F[G[C]]=true}}I=this.channels[0].Organization();for(D=0;D<this.channels.length;D++){J=this.channels[D];if(J.DC_RECID!=this.DC_RECID){E=J.MakeTag()+'was assigned to a meter with a RECID of "'+this.DC_RECID+'"';H.push(["R",E])}if(J.dtStart-this.dtStart){E=J.MakeTag()+"had a start time of "+J.txtStart+", while the meter had a start time of "+this.txtStart;H.push(["U",E])}if(J.dtStop-this.dtStop){E=J.MakeTag()+"had a stop time of "+J.txtStop+", while the meter had a stop time of "+this.txtStop;H.push(["U",E])}G=J.Organization();if(!A.EqualArrayP(I,G)){E=J.MakeTag()+"was divided into different segments as compared to the meter's first channel";H.push(["R",E])}for(C=0;C<G.length;C++){if(!F[G[C]]){E=J.MakeTag()+"was split between two segments at "+G[C]+" and this change was not justified by any DR_INPHR or DC_UMCODE change";H.push(["1",E])}}}return H};B.AddSegment=function(C){this._segments.push(new A.Segment(C))};B.RemoveSegment=function(){this._segments.pop()};B.AddInterval=function(C){this._segments[this._segments.length-1].AddInterval(C)};B.Process=function(){var D,L,H,K,E,J,C,I,F,G;E=[];J=[];C={};F=[];G=this._mh.RespectDstP();F.push(this._mh.Validate());if(this._segments.length==0){F.push([["U","An anonymous Meter was assigned no Channel Segments"]])}for(D=0;D<this._segments.length;D++){L=this._segments[D];K=L.Process(G);F.push(K.errors);if(!C[L.channelId]){J.push(L.channelId);C[L.channelId]=[]}C[L.channelId].push([K.unrecoverable,L])}if(C[undefined]){return{unrecoverable:true,errors:Array.prototype.concat.apply([],F)}}for(D=0;D<J.length;D++){H=new A.Channel(C[J[D]]);K=H.Process();F.push(K.errors);if(!K.unrecoverable){E.push(H)}}E.sort(function(N,M){return N.channelId-M.channelId});if(A.UnrecoverableP(F[0])||(E.length==0)){return{unrecoverable:true,errors:Array.prototype.concat.apply([],F)}}this.DC_RECID=E[0].DC_RECID;this.dtStart=new Date(this._mh.ValidateTimestamp("TA_START",G,true,[],undefined)-60000);this.dtStop=this._mh.ValidateTimestamp("TA_STOP",G,false,[],undefined);this.txtStart=this._mh.TA_START;this.txtStop=this._mh.TA_STOP;this.channels=E;F.push(this._Validate());I=Array.prototype.concat.apply([],F);return{unrecoverable:A.UnrecoverableP(I),errors:I}};A.Column=function(D,E,C){E=E.replace(/^\s*/,"").replace(/\s*$/,"");this.key=D+"."+C.channelId+"."+C.uomCode;this.header=E+"/"+C.channelId+" ("+C.uomName+")";this.segments=[C]};B=A.Column.prototype;B.OverlapsP=function(G){var F,E,D,C;for(F=0;F<G.segments.length;F++){D=G.segments[F];for(E=0;E<this.segments.length;E++){C=this.segments[E];if((D.dtStart<C.dtStop)&&(D.dtStop>C.dtStart)){return true}}}return false};B.Merge=function(C){this.segments=this.segments.concat(C.segments);return true};A.Grid=function(D,E,C){var F=new A.Column(D,E,C);this.intLen=C.intLen*60000;this.dtStart=C.dtStart;this.dtStop=C.dtStop;this.lColumns=[F];this.dColumns={};this.dColumns[F.key]=F};B=A.Grid.prototype;B.EndTimeForcedP=function(){return((this.dtStop-this.dtStart)%this.intLen)};B.Merge=function(E){var D,C;if(this.intLen!=E.intLen){return false}if((this.dtStart-E.dtStart)%this.intLen){return false}if((this.dtStop<E.dtStop)&&this.EndTimeForcedP()){return false}if((this.dtStop>E.dtStop)&&E.EndTimeForcedP()){return false}for(D=0;D<E.lColumns.length;D++){C=E.lColumns[D];if(this.dColumns[C.key]&&this.dColumns[C.key].OverlapsP(C)){return false}}this.dtStart=new Date(Math.min(this.dtStart,E.dtStart));this.dtStop=new Date(Math.max(this.dtStop,E.dtStop));for(D=0;D<E.lColumns.length;D++){C=E.lColumns[D];if(this.dColumns[C.key]){this.dColumns[C.key].Merge(C)}else{this.lColumns.push(C);this.dColumns[C.key]=C}}return true};B.Width=function(){return this.lColumns.length+2};B.Height=function(){return Math.ceil((this.dtStop-this.dtStart)/this.intLen)};B.Header=function(){var C,D=["Interval Begin (ST)","Interval End (ST)"];for(C=0;C<this.lColumns.length;C++){D.push(this.lColumns[C].header)}return D};B.Plot=function(C,D,N){var M,L,F,E,J,I,H,G,K,O;for(L=N,F=this.dtStart,J=F.getTime()+this.intLen,E=new Date(J);F<this.dtStop;L++,F=E,E=new Date(J+=this.intLen)){C[L][D+0]=A.PrintTime(F);C[L][D+1]=A.PrintTime(E)}if(L>N){C[L-1][D+1]=A.PrintTime(this.dtStop)}for(I=0;I<this.lColumns.length;I++){K=this.lColumns[I];M=D+2+I;for(H=0;H<K.segments.length;H++){O=K.segments[H];L=N+(O.dtStart-this.dtStart)/this.intLen;for(G=0;G<O.reads.length;G++){C[L+G][M]=O.reads[G].read}}}return C};A.Table=function(){this.grids=[]};B=A.Table.prototype;B.AddSegment=function(E,G,D){var C,F=new A.Grid(E,G,D);for(C=0;C<this.grids.length;C++){if(this.grids[C].Merge(F)){return }}this.grids.push(F)};B.Width=function(){var C,D=0;for(C=0;C<this.grids.length;C++){D+=this.grids[C].Width()}return D+this.grids.length?(this.grids.length-1)*2:0};B.Height=function(){var C,D=0;for(C=0;C<this.grids.length;C++){D=Math.max(D,this.grids[C].Height())}return D};B.Header=function(){var C,D=[];for(C=0;C<this.grids.length;C++){D.push(this.grids[C].Header());D.push(["",""])}if(D.length){D.length=D.length-1}else{D=[["The pivot view contains no data"]]}return Array.prototype.concat.apply([],D)};B.Plot=function(G,F,I){var E,C,J,D=this.Width()+F,H=this.Height()+I;for(E=0,C=F,J=I;E<this.grids.length;E++){this.grids[E].Plot(G,C,J);C=C+this.grids[E].Width()+2}for(J=I;J<H;J++){for(C=F;C<D;C++){G[J][C]=G[J][C]==undefined?"":G[J][C]}}return G};A.MeterList=function(){this.meters=[];this.trailer=undefined;this.errors=[];this.flat=undefined;this.cross=undefined};B=A.MeterList.prototype;B.lutErrorLevels={U:"Unrecoverable Error",R:"Recoverable Error"};B.lutValidRecords={"Meter Header":true,"Channel Header":true,"Interval Data":true,Trailer:true};B._Validate=function(D){var H,C={},E,F,G=[];for(E=0;E<this.meters.length;E++){H=this.meters[E].DC_RECID;if(!C[H]){C[H]=1}else{if(C[H]==1){F='Meter ID (DC_RECID) "'+H+'" was used for more than one meter';G.push(["R",F]);C[H]=2}}}if(this.trailer){G=G.concat(this.trailer.Validate(D))}return G};B.FilterRecords=function(F){var C,H=[],D,G=[];function E(J,I){var K="Record #"+I.idx+" is of an unexpected type ("+I.ShortDesc+")";G.push([J,K])}for(C=0;C<F.length;C++){if(!this.lutValidRecords[F[C].ShortDesc]){E("R",F[C]);continue}if(F[C]._fmtLen>F[C].data.length){D="Record #"+C+" was incomplete (needed "+F[C]._fmtLen+" bytes, found "+F[C].data.length+" bytes)";G.push(["R",D]);continue}if(F[C]._fmtLen<F[C].data.length){D="Record #"+C+" had excess data (needed "+F[C]._fmtLen+" bytes, found "+F[C].data.length+" bytes)";G.push(["R",D])}H.push(F[C])}return{rl:H,errors:G}};B.ParseRecords=function(G){var C,J,F,H,E,I,K=[];function D(M,L){var N="Record #"+L.idx+" is of an unexpected type ("+L.ShortDesc+")";K.push([M,N])}C="0";J=[];F=undefined;H={0:{},1:{},2:{},3:{},"3a":{},4:{}};H["0"]["Meter Header"]=function(L){C="1";J.push(new A.Meter(L))};H["0"]["Trailer"]=function(L){C="2";F=L};H["1"]["Meter Header"]=function(L){D("R",L);J.pop();C="1";J.push(new A.Meter(L))};H["1"]["Channel Header"]=function(L){C="3";J[J.length-1].AddSegment(L)};H["1"]["Trailer"]=function(L){D("R",L);J.pop();C="2";F=L};H["2"]["Meter Header"]=function(L){D("R",L);F=undefined;C="1";J.push(new A.Meter(L))};H["2"]["Trailer"]=function(L){D("R",L);F=undefined;C="2";F=L};H["3"]["Meter Header"]=function(L){D("R",L);J.pop();C="1";J.push(new A.Meter(L))};H["3"]["Channel Header"]=function(L){D("R",L);J[J.length-1].RemoveSegment();C="3";J[J.length-1].AddSegment(L)};H["3"]["Interval Data"]=function(L){C="4";J[J.length-1].AddInterval(L)};H["3"]["Trailer"]=function(L){D("R",L);J.pop();C="2";F=L};H["3a"]["Meter Header"]=function(L){D("R",L);J[J.length-1].RemoveSegment();C="1";J.push(new A.Meter(L))};H["3a"]["Channel Header"]=function(L){D("R",L);J[J.length-1].RemoveSegment();C="3a";J[J.length-1].AddSegment(L)};H["3a"]["Interval Data"]=function(L){C="4";J[J.length-1].AddInterval(L)};H["3a"]["Trailer"]=function(L){D("R",L);J[J.length-1].RemoveSegment();C="2";F=L};H["4"]["Meter Header"]=function(L){C="1";J.push(new A.Meter(L))};H["4"]["Channel Header"]=function(L){C="3a";J[J.length-1].AddSegment(L)};H["4"]["Interval Data"]=function(L){C="4";J[J.length-1].AddInterval(L)};H["4"]["Trailer"]=function(L){C="2";F=L};for(E=0;E<G.length;E++){I=H[C][G[E].ShortDesc];if(I){I(G[E])}else{D("U",G[E]);break}}if((E>=G.length)&&(C!="2")){K.push(["R","MDEF did not terminate with a Trailer Record"]);switch(C){case"1":case"3":J.pop();break;case"3a":J[J.length-1].RemoveSegment();break;default:break}}return{ms:J,tr:F,errors:K}};B.LoadRecordList=function(G){var D,F,E,C=[];this.meters=[];this.trailer=undefined;do{F=this.FilterRecords(G.records);C.push(F.errors);if(A.UnrecoverableP(F.errors)){break}F=this.ParseRecords(F.rl);C.push(F.errors);if(A.UnrecoverableP(F.errors)){break}for(D=0;D<F.ms.length;D++){E=F.ms[D].Process();C.push(E.errors);if(!E.unrecoverable){this.meters.push(F.ms[D])}}this.trailer=F.tr;C.push(this._Validate(G.records.length))}while(0);this.errors=Array.prototype.concat.apply([],C)};B.FlattenData=function(){var H,G,F,E,N,K,O,C,M,I,J,L,D=[];for(H=0;H<this.meters.length;H++){N=this.meters[H];for(G=0;G<N.channels.length;G++){K=N.channels[G];for(F=0;F<K.segments.length;F++){O=K.segments[F];M=O.dtStart.getTime();I=O.dtStop.getTime();J=O.intLen*60000;for(E=0;E<O.reads.length;E++){C=O.reads[E];L=[N.DC_RECID,K.channelId,A.PrintTime(new Date(M+E*J)),A.PrintTime(new Date(Math.min(I,M+E*J+J))),C.read,O.uomName];D.push(L)}}}}this.flat=D};B.CrossData=function(){var F,D,C,E,I,G,H=new A.Table();for(F=0;F<this.meters.length;F++){E=this.meters[F];for(D=0;D<E.channels.length;D++){I=E.channels[D];for(C=0;C<I.segments.length;C++){G=I.segments[C];H.AddSegment(F,E.DC_RECID,G)}}}this.cross={headings:H.Header(),rows:H.Plot(A.MakeArray(H.Width(),H.Height()),0,0)}};B.DisplayFlatMeters=function(F,D,H,E,C){if(C==undefined){C=this.flat}if(D==undefined){var G=["Meter ID","Channel","Interval Begin (ST)","Interval End (ST)","Read","UOM"];D=A.CreateGenericTableDC(F,G,C,"vis")}return A.DisplayGenericRows(F,D,H,E,C,"vis")};B.DisplayCrossMeters=function(E,C,G,D,F){if(F==undefined){F=this.cross.rows}if(C==undefined){C=A.CreateGenericTableDC(E,this.cross.headings,F,"pvt")}return A.DisplayGenericRows(E,C,G,D,F,"pvt")};B.PrintErrorCode=function(C){return this.lutErrorLevels[C]?this.lutErrorLevels[C]:"Warning ("+C+")"};B.DisplayErrors=function(F,D,I,E,H){var C,G;if(H==undefined){H=[];for(C=0;C<this.errors.length;C++){H.push([C+1,this.PrintErrorCode(this.errors[C][0]),this.errors[C][1]])}}if(D==undefined){G=["Index","Type","Description"];D=A.CreateGenericTableDC(F,G,H,"val")}return A.DisplayGenericRows(F,D,I,E,H,"val")}}();function App(){this.background={event:undefined,continuations:[]};this.cbTools=new ClipboardTools("code/clip/_clipboard.swf");this.blockList=new Mdef.RecordList();this.meterList=new Mdef.MeterList();this.displayOpts={app:this,mode:"",viewCache:{},detailIndex:0,reserved_vis:false,nav_id:"ex_nav",panel:{exp:"display",vis:"page_vis",pvt:"page_pvt",val:"page_val"}};this.Halt();this.DisplayNotification("Please load an MDEF file, or view the demo data");this.SetMode("pvt")}App.prototype.legalModes=["exp","vis","pvt","val"];App.prototype.viewStates={0:"Not Started",1:"Started",2:"Complete"};App.prototype.AddContinuation=function(C,B,A){var D=function(){A=C.apply(B,A);if(A){return D}};this.background.continuations.push(D);if(this.background.event==undefined){this.background.event=setTimeout("app._Service();",75)}return D};App.prototype.ClearContinuation=function(A){for(var B=0;B<this.background.continuations.length;B++){if(!A||(this.background.continuations[B]==A)){this.background.continuations[B]=undefined}}};App.prototype._Service=function(){var A,B,C;if(this.background.continuations.length){A=[];for(B=0;B<this.background.continuations.length;B++){C=this.background.continuations[B];if(C){A.push(C())}}this.background.continuations=A;this.background.event=setTimeout("app._Service();",0)}else{this.background.event=undefined}};App.prototype.DisplayNotification=function(C){var A,B;for(A=0;A<this.legalModes.length;A++){if(this.displayOpts.viewCache[this.legalModes[A]]){continue}B=document.getElementById(this.displayOpts.panel[this.legalModes[A]]);while(B.firstChild){B.removeChild(B.firstChild)}B.appendChild(document.createElement("P")).appendChild(document.createTextNode(C))}};App.prototype.SetMode=function(B){if((this.displayOpts.viewCache[B]==undefined)||(this.displayOpts.mode==B)){return }this.displayOpts.mode=B;for(var A=0;A<this.legalModes.length;A++){B=this.legalModes[A];document.getElementById("mode_"+B).className=(this.displayOpts.mode==B)?"aTab":""}this.AddContinuation(this._SetActivePane,this,[])};App.prototype.CopyRows=function(D,C){var B,A=[D.join("\t")];for(B=0;B<C.length;B++){A.push(C[B].join("\t"))}this.cbTools.Copy(A.join("\r\n"))};App.prototype.ToggleCopy=function(B){var D,A,C;D=document.getElementById("copy");A=document.getElementById("copy_switch");C=A.firstChild.nodeValue.slice(0,4);if(B){C=B}if(C=="Hide"){D.style.display="none";A.firstChild.nodeValue="Show Introduction"}else{D.style.display="block";A.firstChild.nodeValue="Hide Introduction"}return false};App.prototype.SetReservedVisibility=function(A){if(this.displayOpts.viewCache.exp!=2){return }this.displayOpts.reserved_vis=A;this.RenderExplorerDetail()};App.prototype.SetDetailIndex=function(A){if(this.displayOpts.viewCache.exp!=2){return }this.displayOpts.detailIndex=A;this.RenderExplorerDetail()};App.prototype._SetActivePane=function(){var A,B;for(A=0;A<this.legalModes.length;A++){B=this.legalModes[A];document.getElementById("mode_"+B).className=(this.displayOpts.mode==B)?"aTab":"";document.getElementById("page_"+B).style.display=(this.displayOpts.mode==B)?"block":"none"}};App.prototype.RenderExplorerSummary=function(){this.blockList.Display(this.displayOpts)};App.prototype.RenderExplorerControls=function(){document.getElementById("show_reserved").checked=this.displayOpts.reserved_vis;document.getElementById("hide_reserved").checked=!this.displayOpts.reserved_vis};App.prototype.RenderExplorerDetail=function(){if(this.blockList.records[this.displayOpts.detailIndex]){this.blockList.records[this.displayOpts.detailIndex].Display(this.displayOpts)}else{var A=document.getElementById(this.displayOpts.panel.exp);while(A.firstChild){A.removeChild(A.firstChild)}A.appendChild(document.createElement("P")).appendChild(document.createTextNode("No data available for display"))}};App.prototype.Halt=function(){this.ClearContinuation();for(var A=0;A<this.legalModes.length;A++){this.displayOpts.viewCache[this.legalModes[A]]=0}this.AddContinuation(this._SetActivePane,this,[])};App.prototype.Start=function(){this.Halt();this.DisplayNotification("Loading data - please wait.")};App.prototype.LoadData=function(B){var C,A=document.getElementsByTagName("FORM");for(C=0;C<A.length;C++){if(A[C].getAttribute("action")==B){this.Start();A[C].submit();break}}return false};App.prototype.LoadUserData=function(){this.ToggleCopy("Hide");return this.LoadData("/bba/load.php3")};App.prototype.LoadDemoData=function(){return this.LoadData("demo.html")};App.prototype.ProcessAjaxResponse=function(){this.Halt();this.AddContinuation(this._RefreshModel,this,[])};App.prototype._UpdateFlatDisplay=function(A,B){if((this.displayOpts.mode!="vis")&&(this.displayOpts.viewCache[this.displayOpts.mode]==1)){return[A,B]}if(!A){A=0}switch(A){case 0:this.meterList.FlattenData();this.DisplayNotification("Parsed meters to flat table");return[A+1];case 1:this.AddContinuation(this.meterList.DisplayFlatMeters,this.meterList,[this.displayOpts]);this.displayOpts.viewCache.vis=1;return ;default:return }};App.prototype._UpdateCrossDisplay=function(A,B){if((this.displayOpts.mode!="pvt")&&(this.displayOpts.viewCache[this.displayOpts.mode]==1)){return[A,B]}if(!A){A=0}switch(A){case 0:this.meterList.CrossData();this.DisplayNotification("Built pivot table");return[A+1];case 1:this.AddContinuation(this.meterList.DisplayCrossMeters,this.meterList,[this.displayOpts]);this.displayOpts.viewCache.pvt=1;return ;default:return }};App.prototype._RefreshModel=function(A,B){if(!A){A=0}switch(A){case 0:this.DisplayNotification("Received file");return[A+1,window.frames.ajax.document.getElementById("payload")];case 1:B=Base64.Decode(B.innerHTML);this.DisplayNotification("Decoded file");return[A+1,B];case 2:this.blockList.ParseData(B,0);this.DisplayNotification("Parsed file to records");return[A+1];case 3:this.displayOpts.detailIndex=0;this.RenderExplorerSummary();this.RenderExplorerControls();this.RenderExplorerDetail();this.displayOpts.viewCache.exp=2;return[A+1];case 4:this.meterList.LoadRecordList(this.blockList);this.DisplayNotification("Parsed records to meters");return[A+1];case 5:this.AddContinuation(this._UpdateFlatDisplay,this,[]);this.AddContinuation(this._UpdateCrossDisplay,this,[]);this.AddContinuation(this.meterList.DisplayErrors,this.meterList,[this.displayOpts]);this.displayOpts.viewCache.val=1;return ;default:return }};app=new App();