function bI(url,aL,method){this.ct=false;this.aH= -1;this.aU= -1;this.au= -1;this.cs= -1;this.bk=0;this.cp=0;this.aR=25000;this.bl=false;this.cf=1000;this.cr=15000;this.at=null;this.bj=0;this.cq=0;this.aV='';this.J=new Array();this.aa='';this.aO='';this.cv='';this.bT=0;this.aS=0;this.cu=0;this.al='';this.bN=function(){return this.bj;};this.aW=function(){return this.at;};this.ao=function(){return this.aV;};this.aA=function(){return this.aH;};this.aJ=function(){return this.aU;};this.az=function(){return this.cs;};this.bp=function(){return(this.aa!='');};this.bU=function(){return this.aa;};this.selectMethod=function(method){var connected=this.bp();if(connected){this.disconnect();}this.al=method;if(typeof this.at!='undefined'){delete(this.at);}if(method=='iframe'){this.at=new bL(this);}else if(method=='xhr'){this.at=new bC(this);}else if(method=='multipart'){this.at=new bK(this);}else{this.at=new bG(this);}if(connected){this.connect(true);}return true;};this.connect=function(bq){if(!bq&&(this.aa!=''||typeof this.at=='undefined')){return false;}if(typeof this.al=='undefined'||this.al==''){return false;}BG_AjaxPushHub.publish('bgo.ajaxpush.connection_'+this.az(),{connected:false,retryTimeout:0,error:false,method:this.al});BG_AjaxPush.log('connecting '+(bq?'(retry)':''));clearTimeout(this.aS);this.aS=null;this.aa='connecting';this.aH=BG_AjaxPush.aA();this.bj=0;this.cq=0;this.bT=this.bT+1;var start=((new Date()).getTime());var K=this;this.ay('auth','0.1',function(ap){K.cf=((new Date()).getTime())-start;K.cr=Math.max(Math.min(K.cf*5,15000),5000);if(ap['error']==0){K.aa='auth';BG_AjaxPush.log('connected. starting push: '+K.al);if(ap['id']!=K.aH){BG_AjaxPush.bA(ap['id']);}if(bq&&(ap['id']!=K.aH||ap['O']!=K.aU)){for(var V=0;V<K.J.length;V++){K.J[V].ac=false;K.J[V].aG=true;}}K.aH=ap['id'];K.aU=ap['O'];if(K.at.aP()==true){K.au=K.at.localcid;K.aa='stream';}K.cp=((new Date()).getTime());K.aR=60000;if(K.al!='pull'){clearTimeout(K.aO);K.aO=setTimeout("BG_AjaxPush.an('"+K.ao()+"').am('"+K.au+"','connect')",K.aR);}var data=K.updateSubscriptions();BG_AjaxPushHub.publish('bgo.ajaxpush.connection_'+K.az(),{connected:true,retryTimeout:0,error:false,method:K.al});}else{BG_AjaxPush.log('authentication failed!');K.aa='';K.am(K.au,'authentication');}});return 'bgo.ajaxpush.connection_'+K.az();};this.am=function(O,reason){if(this.au!=O){return;}BG_AjaxPush.log('connection lost: '+reason);this.au= -1;this.disconnect(true,reason);},this.disconnect=function(bz,reason){if(this.aa==''){return;}clearTimeout(this.aS);clearTimeout(this.aO);this.aS=null;this.aO=null;this.aa='';if(!bz){this.ay('disconnect');BG_AjaxPush.log('connection closed by client');this.aU= -1;this.aH= -1;}this.at.aQ();if(bz){var fatal=false;if(reason=='proxy'){BG_AjaxPush.switchPort(true);}var ax=this.bT*1000;if(ax>20000){ax=20000;}if(this.cp-((new Date()).getTime()<10000)){if(ax<5000){ax=5000;}}BG_AjaxPush.log('connection lost due to error, retrying in '+(ax/1000).toFixed(2)+' seconds!');this.cu=ax;this.aS=setTimeout("BG_AjaxPush.an('"+this.ao()+"').connect(true)",ax);BG_AjaxPushHub.publish('bgo.ajaxpush.connection_'+this.az(),{connected:false,retryTimeout:ax,error:true,method:this.al,reason:reason});}else{BG_AjaxPushHub.publish('bgo.ajaxpush.connection_'+this.az(),{connected:false,retryTimeout:false,error:false,method:this.al,reason:null});}},this.delaySubscriptions=function(){this.bl=true;},this.ba=function(ad,data){if(typeof data=='undefined'){data=new Array();}this.J.push({id:ad,data:data,ac:false,aG:true});if(!this.bl&&this.aa=='stream'){this.updateSubscriptions();}return 'bgo.ajaxpush.connection_'+this.az()+'.'+ad;};this.aT=function(ad){for(var i=0;i<this.J.length;i++){if(this.J[i].id==ad){this.J[i].aG=false;if(!this.bl&&this.aa=='stream'){var data=this.updateSubscriptions();}return;}}return true;};this.updateSubscriptions=function(action,bR){if(this.aa!='stream'){return;}var aE=new Array('','');var bb='';var j=0;for(var V=0;V<this.J.length;){if(this.J[V].ac!=this.J[V].aG){bb=this.J[V].id;j=(this.J[V].aG==false?1:0);if(j==0){for(var p=0;p<this.J[V].data.length;p++){bb+=(p==0?'=':':')+this.J[V].data[p];}}this.J[V].ac=this.J[V].aG;aE[j]+=(aE[j]!=''?',':'')+bb;if(!this.J[V].ac){this.J.splice(V,1);}else{V++;}}else{V++;}}if(aE[1]!=''){this.ay('unsubscribe',aE[1]);}if(aE[0]!=''){this.ay('subscribe',aE[0]);}BG_AjaxPush.log('updating subscriptions');this.bl=false;},this.bo=function(text){var lines=text.split("\n");if(lines.length<4+2){return false;}var result=new Array();result['action']=lines[0];result['id']=lines[1];result['O']=lines[2];result['error']=lines[3];if(result['error']!=0){result['errorMessage']=lines[4];}else{result['errorMessage']='';}if(lines[4]!=''){return false;}result['value']='';for(var i=5;i<lines.length-2;i++){result['value']=result['value']+lines[i]+'\n';}if(lines[lines.length-2]!=''){return false;}return result;};this.ay=function(action,data,av){var aI=action+'_'+this.aH+'_'+this.aU;if(typeof data!='undefined'&&data!=''){aI=aI+'%7C'+data;}var K=this;var O=this.au;var url=this.aV;var start=((new Date()).getTime());BG_AjaxPush.ca(url,aI,function(ah){if(ah.readyState==4){if(ah.status!=200){K.am(O,'ay');return;}K.cf=((new Date()).getTime())-start;var hash=K.bo(ah.responseText);if(hash['error']!=0){K.am(O,'ay');}else{if(typeof av!='undefined'){av(hash);}}}});};this.bF=function(){clearTimeout(this.aO);this.aO=setTimeout("BG_AjaxPush.an('"+this.aV+"').am("+this.au+",'ping');",parseInt(this.aR));};this.pushData=function(ad,data){if(ad=='ping'){BG_AjaxPush.log('received heartbeat, sending pong');if(this.bk!=0){this.aR=(((new Date()).getTime())-this.bk);this.aR=(this.aR*2)+1000;}this.bk=(new Date()).getTime();if(this.al!='pull'){this.bF();}this.cq++;this.bT=0;this.ay('pong');return;}else{this.bj++;}var p=ad.indexOf('_');if(p===false){return;}var aw=ad.substr(0,p);var ad=ad.substr(p+1);BG_AjaxPushHub.publish("bgo.ajaxpush.connection_"+this.az()+'.'+aw+'.'+ad,data);};this.getDebugInfo=function(){var info={};var now=((new Date()).getTime())/1000;var connected=this.cp/1000;var span=now-connected;info.connectionId=this.aU;info.clientId=this.aH;info.method=this.al;info.alternativePort=BG_AjaxPush.port?true:false;info.ai=this.aa?this.aa:'not connected';if(this.aa==''&&this.aS!==null){info.bq=(this.cu/1000).toFixed(2);}else{info.bq=false;}info.receivedPushes=this.bj;info.receivedHeartbeats=this.cq;info.connectionDuration=span;info.connectionTimestamp=connected;info.heartbeatTimestamp=this.bk/1000;info.registeredDatasets=[];for(var i=0;i<this.J.length;i++){info.registeredDatasets.push(this.J[i].id);}return info;};this.cs=aL;this.aV=url;this.selectMethod(method);var K=this;bw(window,'unload',function(){K.disconnect(true);});};BG_AjaxPushHub=new function(){var t=true;var f=false;var g=window;this.M={L:{},s:[]};this.A=[];this.aN=0;this.D=0;this.subscribe=function(name,av,scope,by,filter){if(!scope){scope=window;}var aZ=name+"."+this.aN;var sub={scope:scope,r:av,P:filter,data:by,B:this.aN++,bM:aZ};var k=name.split(".");this.R(this.M,k,0,sub);return aZ;};this.publish=function(name,message){var k=name.split(".");this.D++;this.T(this.M,k,0,name,message);this.D--;if((this.A.length>0)&&(this.D==0)){for(var i=0;i<this.A.length;i++)this.unsubscribe(this.A[i].bM);delete(this.A);this.A=[];}};this.unsubscribe=function(sub){var k=sub.split(".");var B=k.pop();this.bx(this.M,k,0,B);};this.R=function(l,k,index,sub){var I=k[index];if(index==k.length)l.s.push(sub);else{if(typeof l.L=="undefined")l.L={};if(typeof l.L[I]=="undefined"){l.L[I]={L:{},s:[]};this.R(l.L[I],k,index+1,sub);}else this.R(l.L[I],k,index+1,sub);}};this.T=function(l,k,index,name,H){if(typeof l!="undefined"){var F;if(index==k.length){F=l;}else{this.T(l.L[k[index]],k,index+1,name,H);this.T(l.L["*"],k,index+1,name,H);F=l.L["**"];}if(typeof F!="undefined"){var o=F.s;var max=o.length;for(var i=0;i<max;i++){if(o[i].r){var C=o[i].scope;var r=o[i].r;var P=o[i].P;var d=o[i].data;if(typeof r=="string"){r=C[r];}if(typeof P=="string"){P=C[P];}if((!P)||(P.call(C,name,H,d))){r.call(C,name,H,d);}}}}}};this.bx=function(l,k,index,B){if(typeof l!="undefined"){if(index<k.length){var aj=l.L[k[index]];this.bx(aj,k,index+1,B);if(aj.s.length==0){for(var x in aj.L)return;delete l.L[k[index]];}return;}else{var o=l.s;var max=o.length;for(var i=0;i<max;i++)if(B==o[i].B){if(this.D>0){o[i].r=null;this.A.push(o[i]);}else o.splice(i,1);return;}}}}};function bw(bs,event,av){if(window.addEventListener){bs.addEventListener(event,av,false);}else{bs.attachEvent('on'+event,av);}};BG_AjaxPush={id: -1,aD:false,bf:'',port:null,ag:new Array(),bd:false,bX:null,bV:null,_domain:null,_readSetting:function(name,def){if(typeof def=='undefined'){def=null;}var ce=document.cookie.split(';');var bh='',cg='',co='';for(var i=0;i<ce.length;i++){bh=ce[i].split('=');cg=bh[0].replace(/^\s+|\s+$/g,'');if(cg==name){if(bh.length>1){return unescape(bh[1].replace(/^\s+|\s+$/g,''));}break;}}return def;},_writeSetting:function(name,value,duration){if(typeof duration=='undefined'){duration=864000;}if(value===false||value===null){duration= -864000;value=0;}var expires=new Date();expires.setTime((new Date()).getTime()+duration);document.cookie=name+"="+value+";expires="+expires.toGMTString()+";path=/;domain="+document.domain;},ci:function(url,aI,av){return BG_AjaxPush.bX.contentWindow.cn(url,aI,av);},ca:function(url,aI,av){return BG_AjaxPush.bX.contentWindow.cl(url,aI,av);},switchPort:function(mode){if(typeof bL!='function'){return false;}var curMode=BG_AjaxPush.port?true:false;if(typeof mode=='undefined'){mode= !curMode;}if(mode!=curMode){BG_AjaxPush._writeSetting('BG_AjaxPushAltPort',mode?1:null);if(BG_AjaxPush.port){BG_AjaxPush.port=null;}else{BG_AjaxPush.port=8181;}if(!mode){BG_AjaxPush.aD=false;BG_AjaxPush.be();BG_AjaxPush.bf=BG_AjaxPush.aD[0];}var con=null;for(var L=0;L<BG_AjaxPush.ag.length;L++){con=BG_AjaxPush.ag[L];con.selectMethod(mode?'iframe':BG_AjaxPush.bf);}}return true;},start:function(){BG_AjaxPush.bd=true;for(var L=0;L<BG_AjaxPush.ag.length;L++){if(BG_AjaxPush.ag[L].ct){BG_AjaxPush.ag[L].connect(false);}}BG_AjaxPushHub.publish('bgo.ajaxpush.start',true);},deinitialize:function(){for(var L=0;L<BG_AjaxPush.ag.length;L++){BG_AjaxPush.ag[L].disconnect();}},useAltPort:function(){if(typeof bL!='function'){return false;}if(BG_AjaxPush._readSetting('BG_AjaxPushAltPort')==1){return true;}return false;},bO:function(){var as=BG_AjaxPush.be();if(as.length<=0){return;}if(BG_AjaxPush.useAltPort()){BG_AjaxPush.port=8181;var supportsIframe=false;for(var i=0;i<as.length;i++){if(as[i]=='iframe'){supportsIframe=true;}}if(supportsIframe){as=['iframe','pull'];}else{as=['pull'];}BG_AjaxPush.aD=as;}BG_AjaxPush.bf=as[0];BG_AjaxPush.selectMethod(BG_AjaxPush.bf);if(BG_AjaxPush._domain==null){var aB=window.location.hostname.split(".");var domain=aB.splice(aB.length-2,2).join('.');document.domain=domain;var iframe=document.createElement('iframe');iframe.src='http://push.'+domain+'/web/iframe.html';iframe.id='push_ajaxproxy';iframe.style.display='none';var f=function(){BG_AjaxPush.start();};if(iframe.addEventListener){iframe.addEventListener('load',f,false);}else{iframe.attachEvent('onload',f);}document.body.appendChild(iframe);BG_AjaxPush.bX=iframe;}else{BG_AjaxPush.bX={contentWindow:{aM:function(){if(typeof XMLHttpRequest!='undefined'){return new XMLHttpRequest();}if(window.ActiveXObject){if(navigator.userAgent.toLowerCase().indexOf("msie 5")!= -1){return new ActiveXObject("Microsoft.XMLHTTP");}else{return new ActiveXObject("Msxml2.XMLHTTP");}}},cn:function(url,aI,L){var ah=BG_AjaxPush.bX.contentWindow.aM();ah.multipart=true;ah.open('POST',BG_AjaxPush._domain+url);ah.onload=function(event){L(event);};ah.send(aI);return ah;},cl:function(url,aI,L){var ah=BG_AjaxPush.bX.contentWindow.aM();ah.open('POST',BG_AjaxPush._domain+url);ah.onreadystatechange=function(){L(ah);};ah.send(aI);return ah;}}};BG_AjaxPush.start();}},bA:function(id){BG_AjaxPush.id=id;},aA:function(){return BG_AjaxPush.id;},an:function(url,bE){for(var L=0;L<BG_AjaxPush.ag.length;L++){if(BG_AjaxPush.ag[L].ao()==url){return BG_AjaxPush.ag[L];}}if(bE==true){if(BG_AjaxPush.bf==''){var as=BG_AjaxPush.be();BG_AjaxPush.bf=as[0];}var L=new bI(url,BG_AjaxPush.ag.length,BG_AjaxPush.bf);BG_AjaxPush.ag[BG_AjaxPush.ag.length]=L;return L;}return;},getConnectionById:function(id){for(var L=0;L<BG_AjaxPush.ag.length;L++){if(BG_AjaxPush.ag[L].aJ()==id){return BG_AjaxPush.ag[L];}}return;},isSupported:function(){var as=BG_AjaxPush.be();return as.length<=0?false:true;},be:function(){if(BG_AjaxPush.aD==false){var cd=navigator.appVersion.match(/WebKit\/([\d\.]*)/g);if(cd){var v=cd[0].substr(7);if(navigator.appVersion.indexOf('iPhone')!= -1){BG_AjaxPush.aD=new Array('xhr','pull');}else{BG_AjaxPush.aD=new Array('xhr','multipart','iframe','pull');}}else{if(navigator.userAgent.indexOf('IEMobile')!= -1||navigator.userAgent.indexOf("NetFront")!= -1||navigator.userAgent.indexOf('Opera Mobi')!= -1||navigator.userAgent.indexOf('BlackBerry')!= -1){BG_AjaxPush.aD=new Array('pull');}else if(navigator.userAgent.indexOf("Firefox")!= -1||navigator.appVersion.indexOf("Safari")!= -1){BG_AjaxPush.aD=new Array('xhr','multipart','iframe','pull');}else if(navigator.appVersion.indexOf("WebKit")!= -1||navigator.appVersion.indexOf("KHTML")!= -1||navigator.appVersion.indexOf("MSIE")!= -1||navigator.userAgent.indexOf('Opera')!= -1){BG_AjaxPush.aD=new Array('iframe','pull');}}}return BG_AjaxPush.aD;},selectMethod:function(method){var as=BG_AjaxPush.be();var bn=false;for(var i=0;i<as.length;i++){if(as[i]==method){bn=true;break;}}if(bn==false){return false;}for(var L=0;L<BG_AjaxPush.ag.length;L++){BG_AjaxPush.ag[L].selectMethod(method);}return true;},connect:function(af){var L=BG_AjaxPush.an(af,true);if(BG_AjaxPush.bd){return L.connect(false);}else{L.ct=true;return 'bgo.ajaxpush.connection_'+L.az();}return false;},disconnect:function(af){var L=BG_AjaxPush.an(af);if(typeof L=='undefined'){return false;}return L.disconnect();},ba:function(af,aw,bi,aI){var L=BG_AjaxPush.an(af,true);return L.ba(aw+'_'+bi,aI);},aT:function(af,aw,bi){var L=BG_AjaxPush.an(af);if(typeof L=='undefined'){return false;}return L.aT(aw+'_'+bi);},getDebugInfo:function(){var info=[];for(var i=0;i<BG_AjaxPush.ag.length;i++){info.push(BG_AjaxPush.ag[i].getDebugInfo());}return info;},log:function(text){if(!BG_AjaxPush.isLogEnabled()|| !(typeof console!='undefined'&&typeof console.log=='function')){return;}var now=(new Date()).getTime()/1000;console.log('[BG_AjaxPush] '+strftime(now,'%H:%M:%S')+' - '+text);},setLogEnabled:function(mode){BG_AjaxPush._writeSetting('BG_AjaxPushLog',mode?1:0);BG_AjaxPush.bV=mode;},isLogEnabled:function(){if(BG_AjaxPush.bV===null){var mode=BG_AjaxPush._readSetting('BG_AjaxPushLog')==1;BG_AjaxPush.bV=mode;}return BG_AjaxPush.bV;}};function initPush(domain){BG_AjaxPush._domain=domain;};bw(window,'load',BG_AjaxPush.bO);bw(window,'beforeunload',BG_AjaxPush.deinitialize);bw(window,'unload',BG_AjaxPush.deinitialize);var EQuoteFields={BID_LAST:0x1,BID_HIGH:0x2,BID_LOW:0x4,BID_PREV_CHANGE:0x8,BID_CLOSE:0x10,BID_TIME:0x20,ASK_LAST:0x200,ASK_HIGH:0x400,ASK_LOW:0x800,ASK_PREV_CHANGE:0x1000,ASK_CLOSE:0x2000,ASK_TIME:0x4000,LAST_LAST:0x20000,LAST_HIGH:0x40000,LAST_LOW:0x80000,LAST_PREV_CHANGE:0x100000,LAST_CLOSE:0x200000,LAST_TIME:0x400000,BID_CHANGE:0x800000,BID_CHANGE_PERCENT:0x1000000,ASK_CHANGE:0x2000000,ASK_CHANGE_PERCENT:0x4000000,LAST_CHANGE:0x8000000,LAST_CHANGE_PERCENT:0x10000000};function bJ(){var exchangeId=false;var instrumentId=false;var fields=false;var values=false;};function bH(i,e,f){this.instrumentId=i;this.exchangeId=e;this.fields=f;this.values={};this.ak=[];this.num=0;};BG_QuotePush={bZ:[5,22,37,20,57,15,16,17,18,38,11,24,27,69,71,43],namespace:'',af:null,connected:false,status:0,buffer:null,ak:[],isPushableExchange:function(id){return true;},bS:function(){if(BG_QuotePush.af===null){BG_QuotePush.setServer('/bgajaxpush');}},setServer:function(af){BG_QuotePush.af=af;},get:function(instrumentId,exchangeId,aC){var s=BG_QuotePush.bm(instrumentId,exchangeId);if(typeof s!='undefined'&&s.fields&aC){return s.values[aC];}return null;},getSubscriptions:function(){var cc=[];for(var i=0;i<BG_QuotePush.ak.length;i++){cc.push({instrumentId:BG_QuotePush.ak[i].instrumentId,exchangeId:BG_QuotePush.ak[i].exchangeId});}return cc;},delaySubscriptions:function(){var G=BG_AjaxPush.an(BG_QuotePush.af);G.delaySubscriptions();},updateSubscriptions:function(){this.bS();var G=BG_AjaxPush.an(BG_QuotePush.af);G.updateSubscriptions();},lockEvents:function(){BG_QuotePush.buffer=[];},releaseEvents:function(){for(var i=0;i<BG_QuotePush.buffer.length;i++){BG_AjaxPushHub.publish(BG_QuotePush.buffer[i].event,BG_QuotePush.buffer[i].event);}BG_QuotePush.buffer=null;},subscribe:function(instrumentId,exchangeId,fields){var cj=fields;if(typeof instrumentId=='undefined'||typeof exchangeId=='undefined'||typeof fields=='undefined'){return;}if(!BG_QuotePush.isPushableExchange(exchangeId)){throw '[BG_QuotePush:subscribe] Exchange '+exchangeId+' is not pushable!';}if(exchangeId==38){for(var aC in EQuoteFields){if(fields&EQuoteFields[aC]){if(aC.indexOf('LAST')!=0){throw "[BG_QuotePush:subscribe] Exchange 38 (indication) only provides LAST_ values. Client tried to register "+aC+'!';}}}}this.bS();var ar=0;if(fields&EQuoteFields.BID_CHANGE||fields&EQuoteFields.BID_CHANGE_PERCENT){fields|=EQuoteFields.BID_LAST;fields|=EQuoteFields.BID_CLOSE;}if(fields&EQuoteFields.ASK_CHANGE||fields&EQuoteFields.ASK_CHANGE_PERCENT){fields|=EQuoteFields.ASK_LAST;fields|=EQuoteFields.ASK_CLOSE;}if(fields&EQuoteFields.LAST_CHANGE||fields&EQuoteFields.LAST_CHANGE_PERCENT){fields|=EQuoteFields.LAST_LAST;fields|=EQuoteFields.LAST_CLOSE;}var bW=fields;for(var aC in EQuoteFields){ar=EQuoteFields[aC];if(fields&ar){bW^=ar;if(ar>=EQuoteFields.BID_CHANGE){fields^=ar;}}}if(bW!=0){throw '[BG_QuotePush:subscribe] Invalid fieldmask specified. Unknown flags: 0x'+(bW).toString(16);}var aK=0;var ac=false;var s=null;for(var i=0;i<BG_QuotePush.ak.length;i++){s=BG_QuotePush.ak[i];if(s.instrumentId==instrumentId&&s.exchangeId==exchangeId){aK=1;if((s.fields&fields)==fields){aK=2;}ac=s;break;}}if(aK!=2){if(aK==0){ac=new bH(instrumentId,exchangeId,fields);BG_QuotePush.ak.push(ac);}else{ac.fields|=fields;}ac.ak.push(cj);for(var aC in EQuoteFields){ar=EQuoteFields[aC];if((ac.fields&ar)&&(typeof ac.values[ar]=='undefined')){ac.values[ar]=0;}}var id=instrumentId+'_'+exchangeId;if(aK==1){BG_AjaxPush.aT(BG_QuotePush.af,'q',id);}BG_AjaxPush.ba(BG_QuotePush.af,'q',id,[parseInt(ac.fields.toString(16))]);}return 'bgo.quotes.'+instrumentId+'.'+exchangeId;},unsubscribe:function(instrumentId,exchangeId,fields){this.bS();var s=null;for(var i=0;i<BG_QuotePush.ak.length;i++){s=BG_QuotePush.ak[i];if(s.instrumentId==instrumentId&&s.exchangeId==exchangeId){var aK=false;for(var j=0;j<s.ak.length;j++){if(s.ak[j]==fields){s.ak.splice(j,1);aK=true;break;}}if(s.ak.length<=0||typeof fields=='undefined'){BG_QuotePush.ak.splice(i,1);var id=instrumentId+'_'+exchangeId;BG_AjaxPush.aT(BG_QuotePush.af,'q',id);}return true;}}return false;},bm:function(instrumentId,exchangeId){var s=null;for(var i=0;i<BG_QuotePush.ak.length;i++){s=BG_QuotePush.ak[i];if(s.instrumentId==instrumentId&&s.exchangeId==exchangeId){return s;}}return undefined;},bD:function(name,data){var instrumentId,exchangeId;var aB=name.replace(BG_QuotePush.namespace+'.','').split('_');instrumentId=aB[0];exchangeId=aB[1];var ac=BG_QuotePush.bm(instrumentId,exchangeId);if(typeof ac=='undefined'){return;}if(data=='EXCHANGE_NOT_AVAILABLE'||data=='ID_NOT_FOUND'){BG_QuotePush.unsubscribe(instrumentId,exchangeId);return;}var p=data.indexOf(':');bu=parseInt(data.substr(0,p),16);fields=data.substr(p+1).split(',');data=new bJ();data.instrumentId=instrumentId;data.exchangeId=exchangeId;data.values={};data.first=ac.num==0?true:false;ac.num++;var i=0,v=0,ar=0,bv=0,ae=0,ab=0;for(var aC in EQuoteFields){ar=EQuoteFields[aC];if(bu&ar){ac.values[ar]=fields[i];i++;}}var ck=0;for(var bY=0;bY<3;bY++){switch(bY){case 0:ar=EQuoteFields.BID_LAST;bv=EQuoteFields.BID_CLOSE;ae=EQuoteFields.BID_CHANGE_PERCENT;ab=EQuoteFields.BID_CHANGE;break;case 1:ar=EQuoteFields.ASK_LAST;bv=EQuoteFields.ASK_CLOSE;ae=EQuoteFields.ASK_CHANGE_PERCENT;ab=EQuoteFields.ASK_CHANGE;break;case 2:ar=EQuoteFields.LAST_LAST;bv=EQuoteFields.LAST_CLOSE;ae=EQuoteFields.LAST_CHANGE_PERCENT;ab=EQuoteFields.LAST_CHANGE;break;}if(bu&ar){v=ac.values[bv];if(v!=0){bu|=ae;bu|=ab;var s=ac.values[ar].toString();var p=s.indexOf('.');if(p== -1){p=0;}else{p=(s.length-s.indexOf('.')-1);}ac.values[ae]=(((ac.values[ar]/v)-1.0)*100).toFixed(2);ac.values[ab]=(ac.values[ar]-v).toFixed(p);}}}data.fields=bu;for(var aC in EQuoteFields){ar=EQuoteFields[aC];if(bu&ar){data.values[ar]=ac.values[ar];}}if(BG_QuotePush.buffer!==null){data.event='bgo.quotes.'+instrumentId+'.'+exchangeId;BG_QuotePush.buffer.push(data);}else{BG_AjaxPushHub.publish('bgo.quotes.'+instrumentId+'.'+exchangeId,data);}},bB:function(name,data){if(!data.connected&& !data.retryTimeout){BG_QuotePush.connected=false;BG_QuotePush.status=0;}else if(data.connected){BG_QuotePush.connected=true;}},connect:function(){if(BG_QuotePush.connected||BG_QuotePush.status>0){return false;}if(!BG_QuotePush.isEnabled()){BG_QuotePush.status= -1;return false;}BG_QuotePush.bS();var G=BG_AjaxPush.connect(BG_QuotePush.af);if(G===false){return false;}BG_QuotePush.status=1;BG_QuotePush.namespace=G+'.q';BG_AjaxPushHub.subscribe(G,BG_QuotePush.bB);BG_AjaxPushHub.subscribe(BG_QuotePush.namespace+'.*',BG_QuotePush.bD);return G;},disconnect:function(){if(BG_QuotePush.status<=0){return;}BG_QuotePush.status=0;BG_AjaxPush.disconnect(BG_QuotePush.af);BG_QuotePush.ak=[];BG_QuotePush.connected=false;},isEnabled:function(){return BG_AjaxPush._readSetting('BG_QuotePush',1)==1;},setEnabled:function(Q){BG_AjaxPush._writeSetting('BG_QuotePush',(!Q)?'0':null,7*86400);if(Q&&BG_QuotePush.status<0){return BG_QuotePush.connect();}else if(!Q&&BG_QuotePush.status>0){return BG_QuotePush.disconnect();}}};function bL(G){this.document='';this.iframe='';this.aF=0;this.O= -1;this.localcid= -1;this.startTimestamp=0;this.aY=function(){if(this.G.aa!='stream'){return;}var numSets=this.G.bN();if(numSets<=0&&((this.iframe.readyState&&this.iframe.readyState!='interactive')||(!this.iframe.readyState&&this.iframe.contentWindow.document.title!='BG_AjaxPush backend'))){var now=((new Date()).getTime());if(now-this.startTimestamp>=this.G.cr){this.G.am(this.localcid,'proxy');}}if(this.iframe.readyState=='complete'){this.G.am(this.localcid,'iframe loaded');}if(numSets>=2000){this.G.am(this.localcid,'iframe refresh');}};this.aP=function(){var id=this.G.aA();var O=this.G.aJ();this.O=O;var src='';var domain;if(BG_AjaxPush._domain){src=BG_AjaxPush._domain;}else{src='http://'+(BG_AjaxPush.port?'':'push.')+document.domain;}if(BG_AjaxPush.port){src+=':'+BG_AjaxPush.port;}src+=this.G.ao()+'?stream_'+id+'_'+O+'%7Ciframe';var aq=document;this.document='';if(navigator.appVersion.indexOf("MSIE")!= -1){if(window.ActiveXObject){try{this.document=new ActiveXObject("htmlfile");this.document.open();this.document.write("<html>");this.document.write("<script>document.domain = '"+document.domain+"'");this.document.write("</html>");this.document.close();this.document.domain=document.domain;aq=this.document;var bt=aq.createElement("div");aq.appendChild(bt);this.iframe=aq.createElement('iframe');bt.appendChild(this.iframe);}catch(e){this.document='';}}}if(typeof this.document=='undefined'||this.document==''){this.iframe=aq.createElement('iframe');this.iframe.style.display='none';aq.body.appendChild(this.iframe);}this.iframe.setAttribute('name','pushiframe');this.iframe.setAttribute('src',src);if(this.iframe.readyState){aq.parentWindow.BG_AjaxPush=BG_AjaxPush;}else{var K=this;this.iframe.onload=function(){K.G.am(K.localcid,'iframe loaded');};}clearInterval(this.aF);this.aF=setInterval("BG_AjaxPush.an('"+this.G.ao()+"').aW().aY()",200);this.startTimestamp=((new Date()).getTime());this.localcid++;return true;};this.aQ=function(){clearInterval(this.aF);if(this.iframe){var aq=document;try{aq.body.removeChild(this.iframe);}catch(e){}delete(this.iframe);}if(this.document){delete(this.document);}this.iframe=false;};this.G=G;};function bK(G){this.G='';this.ah='';this.position=0;this.localcid= -1;this.aP=function(){var id=this.G.aA();var O=this.G.aJ();var src=this.G.ao();var aI='stream_'+id+'_'+O+'%7Cmultipart';var K=this;var U=BG_AjaxPush.ci(src,aI,function(event){var aB=event.target.responseText.split('\n');K.G.pushData(aB[0],aB[1],aB[2]);});this.localcid++;return true;};this.aQ=function(){};this.G=G;};function bG(G){this.G='';this.bg='';this.O= -1;this.bc=false;this.aX=function(data){var lines=data.split("\n");if(lines.length>=2){for(var i=0;i<lines.length-1;i=i+3){var ad=lines[i];var data=lines[i+1];this.G.pushData(ad,data);}}};this.bP=function(){if(this.bc){return;}this.bc=true;var id=this.G.aA();var K=this;var src=this.G.ao();var aI='stream_'+id+'_'+this.O+'%7Cpull';var U=BG_AjaxPush.ca(src,aI,function(){if(U.readyState==4){K.bc=false;K.aX(U.responseText);}});};this.aP=function(){this.O=this.G.aJ();clearInterval(this.bg);this.bg=setInterval("BG_AjaxPush.an('"+this.G.ao()+"').aW().bP()",2000);return true;};this.aQ=function(){clearInterval(this.bg);};this.G=G;};function bC(G){this.G='';this.ah=null;this.position=0;this.O= -1;this.localcid= -1;this.startTimestamp=0;this.aX=function(data){var lines=data.split("\n");if(lines.length>=2){for(var i=0;i<lines.length-1;i=i+3){var ad=lines[i];var data=lines[i+1];this.G.pushData(ad,data);}}};this.aY=function(){if(typeof this.ah=='undefined'){return;}if(this.ah.readyState!=3){if(this.ah.readyState==1){var now=((new Date()).getTime());if(now-this.startTimestamp>=this.G.cr){this.G.am(this.localcid,'proxy');}}return;}if(this.ah.responseText.length>=this.position){var bQ=this.ah.responseText.substr(this.position);this.position=this.ah.responseText.length;this.aX(bQ);if(this.ah.responseText.length>=1024*50){this.G.am(this.localcid,'xhr refresh');}}};this.aP=function(){var id=this.G.aA();this.O=this.G.aJ();var src=this.G.ao();var aI='stream_'+id+'_'+this.O+'%7Cxhr';this.position=0;var K=this;var U=BG_AjaxPush.ca(src,aI,function(ah){if(ah.readyState==4){K.G.am(K.localcid,'xhr timeout');}});this.ah=U;clearInterval(this.aF);this.aF=setInterval("BG_AjaxPush.an('"+this.G.ao()+"').aW().aY()",200);this.startTimestamp=((new Date()).getTime());this.localcid++;return true;};this.aQ=function(){if(typeof this.ah!='object'||this.ah==null){return;}clearInterval(this.aF);this.ah.abort();this.position=0;delete(this.ah);};this.G=G;};

