 function clog(){if(window.console&&window.console.firebug){window.console.log.apply(this,arguments);}} String.prototype.cap1stChar=function(){return this.substring(0,1).toUpperCase()+ this.substring(1,this.length);};Array.prototype.equals=function(oa){if(oa&&oa.length==this.length){if(this===oa){return true;} for(var idx=0;idx<this.length;idx++){if(this[idx]!==oa[idx]){return false;}} return true;} return false;};Array.prototype.contains=function(element){for(var i=0;i<this.length;i++){if(this[i]==element){return true;}} return false;};Array.prototype.getRandomItem=function(){var idx=Math.floor(Math.random()*this.length);return this[idx];};if(!Array.prototype.forEach){Array.prototype.forEach=function(fun){var len=this.length>>>0;if(typeof fun!="function"){throw new TypeError();} var thisp=arguments[1];for(var i=0;i<len;i++){if(i in this){fun.call(thisp,this[i],i,this);}}};} var bats=bats||{};bats.getRandomInt=function(min,max){return Math.floor(Math.random()*(max-min+1))+min;};bats.apply=function(o,c,defaults){if(defaults){bats.apply(o,defaults);} if(o&&c&&typeof c=='object'){for(var p in c){o[p]=c[p];}} return o;};bats.applyIf=function(o,c){if(o&&c&&typeof c=='object'){for(var p in c){if(typeof(o[p])==='undefined'){o[p]=c[p];}}} return o;};bats.applyIf(bats,{copyright:"Copyright(c) 2007-2010, BATS Trading, Inc.",MT_CSV:'text/csv',MT_HTML:'text/html',MT_JAVASCRIPT:'text/javascript',region:null,envOffset:null,localOffset:new Date().getGMTOffset()/100,tzOffset:function(){if(bats.envOffset===null){return 0;} return bats.envOffset-bats.localOffset;},isEcn:function(){return(bats.region=='ecn')?true:false;},isMtf:function(){return(bats.region=='mtf')?true:false;},messages:{'matched volume':{title:'Matched Volume',icon:'INFO',modal:false,msg:'Volume that is matched internally on the BATS book.'+' All volume that is not routed.'}},txtMap:{'key':'value'},openWin:function(config){config=typeof config=="object"?config:{};defaults={name:"_blank",src:"",scrollbars:0,menubar:0,toolbar:0,status:0,resizable:0,location:0};for(var key in defaults){if(!config[key]){config[key]=defaults[key];}} if(config.center){x=window.screenX?window.screenX:window.screenLeft;y=window.screenY?window.screenY:window.screenTop;x=Math.floor(x/screen.width)*screen.width;y=Math.floor(y/screen.height)*screen.height;config.left=(screen.width-config.width)/2+x;config.top=(screen.height-config.height)/2+y;} props=((config.width>0)?",width="+config.width:"")+ ((config.height>0)?",height="+config.height:"")+ ((config.top>0)?",top="+config.top:"")+ ((config.left>0)?",left="+config.left:"")+ ((config.scrollbars===0)?",scrollbars=0":",scrollbars=1")+ ((config.menubar===0)?",menubar=0":",menubar=1")+ ((config.toolbar===0)?",toolbar=0":",toolbar=1")+ ((config.status===0)?",status=0":",status=1")+ ((config.resizable===0)?",resizable=0":",resizable=1")+ ((config.location===0)?",location=0":",location=1");props=props.substring(1,props.length);return window.open(config.src,config.name,props);},wait:function(msecs){var start=new Date().getTime();var cur=start;while(cur-start<msecs){cur=new Date().getTime();}},roundNumber:function(val,rlength){var rnum=val;var newnumber;if(rnum>8191&&rnum<10485){rnum=rnum-5000;newnumber=Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);newnumber=newnumber+5000;} else{newnumber=Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);} return newnumber;},formatNumericComma:function(v){v+='';parts=v.split('.');var whole=parts[0];var dec=parts.length>1?'.'+parts[1]:'';var r=/(\d+)(\d{3})/;while(r.test(whole)){whole=whole.replace(r,'$1'+','+'$2');} return whole+dec;},comma_zero_dec:function(val){var parts=(''+Math.round(val)).split(".");switch(parts.length){case 0:return"0";} if(parts[0]===""){parts[0]="0";} return bats.formatNumericComma(parts[0]);},comma_two_dec:function(val){var parts=(""+(Math.round(val*100)/100)).split(".");switch(parts.length){case 0:return"0.00";case 1:parts.push("0");} if(parts[0]===""){parts[0]="0";} if(parts[1]===""){parts[1]="0";} if(parts[1].length==1){parts[1]+="0";} return bats.comma_zero_dec(parts[0])+"."+parts[1].charAt(0)+parts[1].charAt(1);},comma_four_dec_trimmed_to_two:function(val){var parts=(""+(Math.round(val*10000)/10000)).split(".");switch(parts.length){case 0:return"0.00";case 1:parts.push("00");} if(parts[0]===""){parts[0]="0";} if(parts[1]===""){parts[1]="0";} switch(parts[1].length){case 1:parts[1]+="0";break;case 2:break;case 3:parts[1]+="0";case 4:if(parts[1].charAt(2)=='0'&&parts[1].charAt(3)=='0'){parts[1]=parts[1].slice(0,2);} break;default:parts[1]=parts[1].slice(0,4);} return bats.comma_zero_dec(parts[0])+"."+parts[1];},comma_two_dec_perc:function(val){return bats.comma_two_dec(100.0*val);},clone:function(oClone){if(typeof(oClone)!='object'){return oClone;} if(oClone===null){return oClone;} var retVal={};for(var i in oClone){retVal[i]=bats.clone(oClone[i]);} return retVal;},XMLtoString:function(elem){var serializer=null;var serialized;try{serializer=new XMLSerializer();serialized=serializer.serializeToString(elem);} catch(e){if(Ext.isIE){serialized=elem.xml;}} if(serializer!==null){serializer=null;} return serialized;},formatAjaxErrorMessage:function(xmlHttpRequest,bHtml){bHtml=bHtml?true:false;if(bHtml){newline='<br/>';bold=['<strong>','</strong>'];}else{newline='\n';bold='';} retVal=bold[0]+'ERROR: '+xmlHttpRequest.status+' - '+xmlHttpRequest.statusText+ newline+ xmlHttpRequest.responseText+ bold[1];return retVal;},copy2clip:function(txt){var clipboard;if(!document.getElementById('ext-clipboard')){clipboard=document.createElement('textarea');clipboard.id='ext-clipboard';clipboard.style.display="none";document.body.appendChild(clipboard);} clipboard=document.getElementById('ext-clipboard');clipboard.value=txt;if(clipboard.createTextRange){var range=clipboard.createTextRange();if(range){range.execCommand('Copy');}} else{var flashcopier='flashcopier';if(!document.getElementById(flashcopier)){var divholder=document.createElement('div');divholder.id=flashcopier;document.body.appendChild(divholder);} document.getElementById(flashcopier).innerHTML='';var divinfo='<embed src="/res/flashcopier/clipboard.swf" FlashVars="clipboard='+encodeURIComponent(clipboard.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';document.getElementById(flashcopier).innerHTML=divinfo;}},removeAllChildren:function(extElem){while(extElem.dom.firstChild){extElem.dom.removeChild(extElem.dom.firstChild);}},formFailure:function(frm,action){if(action.result){bats.formSuccess(frm,action);}else{bats.failureHandler(action.response.statusText);}},ajaxFailure:function(response,request){bats.failureHandler(response.statusText);},failureHandler:function(failureTxt){var msg='There was a failure while communicating with the server.';bats.showMsg({title:failureTxt,icon:'ERROR',msg:msg});},formSuccess:function(frm,action,fn){var result=action.result;bats.successHandler(result,fn);},ajaxSuccess:function(response,request,fn){var result=Ext.decode(response.responseText);bats.successHandler(result,fn);},successHandler:function(result,fn){if(result.msg){if(!result.level){result.level='INFO';} var msgCfg={icon:result.level,msg:result.msg};if(fn){msgCfg.fn=fn;} this.showMsg(msgCfg);}},formErrors:function(frm,result){if(result.errors){var errors=result.errors;var errMsg,f;for(fieldName in errors){errMsg=errors[fieldName];f=frm.findField(fieldName);f.markInvalid(errMsg);}}},showMsg:function(config){config=config||{};if(typeof config!='object'){config={msg:config};} msgConfig={modal:true,title:'',icon:'INFO',msg:'',buttons:'OK',maxWidth:600};bats.apply(msgConfig,config);if(typeof Ext!='object'){return alert(msgConfig.msg);} msgConfig.icon=Ext.MessageBox[msgConfig.icon];msgConfig.buttons=Ext.MessageBox[msgConfig.buttons];Ext.Msg.maxWidth=msgConfig.maxWidth;Ext.Msg.show(msgConfig);}});
 function WinPop(winName,winSrc,winWidth,winHeight,scrollbars,menubar,toolbar,winStatus,resizable,winLocation,winTop,winLeft){winProps="";winProps=winProps+((winWidth>0)?",width="+winWidth:"")+ ((winHeight>0)?",height="+winHeight:"")+ ((winTop>0)?",top="+winTop:"")+ ((winLeft>0)?",left="+winLeft:"")+ ((scrollbars==0)?",scrollbars=0":",scrollbars=1")+ ((menubar==0)?",menubar=0":",menubar=1")+ ((toolbar==0)?",toolbar=0":",toolbar=1")+ ((winStatus==0)?",status=0":",status=1")+ ((resizable==0)?",resizable=0":",resizable=1")+ ((winLocation==0)?",location=0":",location=1");winProps=winProps.substring(1,winProps.length);var winLeft=(screen.width-winWidth)/2;var winTop=(screen.height-winHeight)/2;wname=window.open(winSrc,winName,winProps);};
 Ext.ns('Bats');Bats.mostActive={failureCnt:0,ttl:5000,deferID:0,symbolType:'all',rows:25,tradeOpen:null,small:true,volumeBias:true,openColumnsVol:['symbol','vol','bs1','bp1','ap1','as1'],closedColumnsVol:['symbol','vol','last_price','change','high','low'],openColumnsNoVol:['symbol','notional','bs1','bp1','ap1','as1'],closedColumnsNoVol:['symbol','notional','last_price','change','high','low'],loadFailed:function(){Bats.mostActive.failureCnt++;if(Bats.mostActive.failureCnt==4){return;} Bats.mostActive.ttl=Bats.mostActive.ttl*2;Bats.mostActive.deferID=Bats.mostActive.load.defer(Bats.mostActive.ttl,this);},show:function(data){res=Ext.decode(data.responseText);data=res.data;if(res.tradeOpen){columns=Bats.mostActive.volumeBias?Bats.mostActive.openColumnsVol:Bats.mostActive.openColumnsNoVol;}else{columns=Bats.mostActive.volumeBias?Bats.mostActive.closedColumnsVol:Bats.mostActive.closedColumnsNoVol;} if(Bats.mostActive.tradeOpen!=res.tradeOpen){if(!document.getElementById('activeList')){return false;} var activeList=document.getElementById('activeList');var mostactiveData_tbl=document.getElementById('mostActiveData');var table=mostactiveData_tbl.getElementsByTagName("table");var thead=table[0].getElementsByTagName("thead");var tr=thead[0].getElementsByTagName("tr");for(var maxRows=tr.length,y=maxRows-1;y>=0;y--){thead[0].removeChild(tr[y]);} tr=document.createElement('tr');if(res.tradeOpen){var td=document.createElement('td');td.colSpan="3";var rankText=document.createTextNode(" ");td.appendChild(rankText);tr.appendChild(td);td=document.createElement('th');td.colSpan="2";td.className="insideBid";rankText=document.createTextNode("Inside Bid");td.appendChild(rankText);tr.appendChild(td);td=document.createElement('th');td.colSpan="2";td.className="insideAsk";rankText=document.createTextNode("Inside Ask");td.appendChild(rankText);tr.appendChild(td);thead[0].appendChild(tr);tr=document.createElement('tr');var classNames=['rank','symbol'];var textNodes=["#","Symbol"];if(Bats.mostActive.volumeBias){classNames.push('shares');if(ma_region=='opt'){textNodes.push("Contracts");} else{textNodes.push("Shares");}}else{classNames.push('notional');textNodes.push("EUR Value");} classNames.push("bid bid_shares","bid bid_price","ask","ask");if(ma_region=='opt'){textNodes.push("Contracts","Price","Price","Contracts");} else{textNodes.push("Shares","Price","Price","Shares");} if(ma_public_options!='True'){for(var i=0,len=classNames.length;i<len;++i){td=document.createElement('th');td.className=classNames[i];rankText=document.createTextNode(textNodes[i]);td.appendChild(rankText);tr.appendChild(td);}}}else{var classNames=['rank','symbol'];var textNodes=["#","Symbol"];if(Bats.mostActive.volumeBias){classNames.push('shares');if(ma_region=='opt'){textNodes.push("Contracts");} else{textNodes.push("Shares");}}else{classNames.push('notional');textNodes.push("EUR Value");} if(ma_public_options=='False'){classNames.push("lastPrice","change","high","low");textNodes.push("Last","Change","High","Low");} for(var i=0,len=classNames.length;i<len;++i){var td=document.createElement('th');td.className=classNames[i];var rankText=document.createTextNode(textNodes[i]);td.appendChild(rankText);tr.appendChild(td);}} thead[0].appendChild(tr);var tbody=table[0].getElementsByTagName("tbody");var tr=tbody[0].getElementsByTagName("tr");for(var i=0,maxRows=tr.length;i<maxRows;++i){var td=tr[i].getElementsByTagName("td");for(var j=0,maxCol=td.length-1;j<maxCol;++j){td[j+1].className=columns[j];}}} Bats.mostActive.tradeOpen=res.tradeOpen;if(res.success){Bats.mostActive.setVolumeMatch(res.batsVolume,res.batsInternalMatch,res.batsNotional,res.header);Bats.mostActive.ttl=res.ttl;if(document.getElementById('mostActiveData')){var mostActiveData=document.getElementById('mostActiveData');var htmlClass=mostActiveData.className;var classSearch=htmlClass.match("loading");if(classSearch){Bats.mostActive.removeClass(mostActiveData,'loading','');}} if(!document.getElementById('mostActiveData')){return false;} var activeList=document.getElementById('activeList');var mostactiveData_tbl=document.getElementById('mostActiveData');var table=mostactiveData_tbl.getElementsByTagName("table");tbody=table[0].getElementsByTagName("tbody");tr=tbody[0].getElementsByTagName("tr");var maxRows=tr.length;if(maxRows>data.length){for(y=maxRows-1;y>=data.length;y--){tbody[0].removeChild(tr[y]);}} if(ma_public_options=='True'){colLen=2;} else{colLen=columns.length;} var hasMenu=false;try{Bats.ext.menu.CtxMenuMgr;hasMenu=true;}catch(e){} if(maxRows<data.length){for(var i=maxRows;i<data.length;i++){row=document.createElement("tr");if(i%2){row.className="odd";} else{row.className="even";} rankTD=document.createElement("td");rankTD.setAttribute("id","rank_"+i);rankTD.className="rank";rankText=document.createTextNode(i+1);if(ma_public_options=='True'){symbolLink=document.createElement("span");} else{symbolLink=document.createElement("a");} symbolAbbr=document.createElement("span");symbolAbbr.className='abbr';rankTD.appendChild(rankText);row.appendChild(rankTD);for(x=0;x<colLen;x++){colTD=document.createElement("td");colTD.setAttribute("id","col_"+i+"_"+x);colTD.className=columns[x];if(x==0){symbolText=document.createTextNode(data[i][x]);symbolAbbr.appendChild(symbolText);symbolLink.appendChild(symbolAbbr);colTD.setAttribute("bats:symbol",data[i][x]);colTD.appendChild(symbolLink);} else{colTDText=document.createTextNode(data[i][x]);colTD.appendChild(colTDText);} row.appendChild(colTD);} row.setAttribute("id","row_"+i);if(hasMenu){symbolLink.setAttribute("href","#");}else{symbolLink.setAttribute("href","/book/"+data[i][0]+"/");} symbolAbbr.setAttribute("title",data[i][8]);tbody[0].appendChild(row);}} for(var i=0;i<data.length;i++){rankTD=document.getElementById('rank_'+i);rankTD.firstChild.nodeValue=i+1;for(x=0;x<colLen;x++){col=document.getElementById(['col_'+i+'_'+x]);if(x==0){if(ma_region=='opt'){col.firstChild.firstChild.firstChild.nodeValue=data[i][(data[i].length-1)];} else{col.firstChild.firstChild.firstChild.nodeValue=data[i][0];} col.setAttribute('bats:symbol',data[i][0]);col.firstChild.firstChild.setAttribute('title',data[i][8]);if(hasMenu){col.firstChild.setAttribute('href','#');}else{col.firstChild.setAttribute('href','/book/'+data[i][0]+'/');}} else{if(col){if(x==1){if(Bats.mostActive.volumeBias) col.innerHTML=data[i][x];else col.innerHTML=data[i][x+1];}else if(!Bats.mostActive.tradeOpen&&x==3){col.innerHTML=data[i][10];col.className=data[i][11];}else if(!Bats.mostActive.tradeOpen&&x>3){col.innerHTML=data[i][x];}else if(x>1){col.innerHTML=data[i][x+1];}}} if(col&&(x==3||x==4)){var elClass=col.className;var classSearch=elClass.match("penny");if(data[i][10]&&Bats.mostActive.tradeOpen){if(!classSearch){col.className+=' penny';}}else{if(classSearch){Bats.mostActive.removeClass(col,'penny','');}}}}} if(Bats.mostActive.ttl>0){Bats.mostActive.deferID=Bats.mostActive.load.defer(Bats.mostActive.ttl,this);}}else{Bats.mostActive.dataError();}},load:function(symbolType,rows){clearTimeout(Bats.mostActive.deferID);var symbolType=Bats.mostActive.symbolType;var rows=Bats.mostActive.rows;if(document.getElementById('mostActiveData')){var mostActiveData=document.getElementById('mostActiveData');var htmlClass=mostActiveData.className;var classSearch=htmlClass.match("loading");if(classSearch){Bats.mostActive.removeClass(mostActiveData,'loading','');}else{mostActiveData.className+=' loading';}} if(!symbolType){symbolType="all";} Ext.Ajax.request({url:'/most_active/data/'+symbolType+'/'+rows+'/',disableCaching:false,success:Bats.mostActive.show,failure:Bats.mostActive.loadFailed});},refresh:function(){clearTimeout(Bats.mostActive.deferID);},dataError:function(){if(Bats.mostActive.ttl<180000){Bats.mostActive.ttl=Bats.mostActive.ttl*2;Bats.mostActive.deferID=Bats.mostActive.load.defer(Bats.mostActive.ttl,this);}else{Bats.mostActive.deferID=Bats.mostActive.load.defer(Bats.mostActive.ttl,this);}},setVolumeMatch:function(volume,internal,notional,header){overviewBox=document.getElementById('activeVolume');if(!overviewBox)return;span=overviewBox.getElementsByTagName('span');for(i=0;i<span.length;i++){switch(span[i].className){case'volume':span[i].firstChild.nodeValue=volume;break;case'internal':span[i].firstChild.nodeValue=internal+"%";break;case'notional':span[i].innerHTML=notional;break;case'ma_title':if(span[i]&&span[i].firstChild){if(header!='All'){span[i].firstChild.nodeValue=res.header;}else{span[i].firstChild.nodeValue='Total';}} break;}}},maNav:function(){var nav=document.getElementById("maNav");if(!nav)return false;var navItems=nav.getElementsByTagName("td");for(i=0;i<navItems.length;i++){link=navItems[i].getElementsByTagName("a");navItems[i].onclick=function(){clearTimeout(Bats.mostActive.deferID);Bats.mostActive.removeNavClass(this,'selected','',nav);this.className+=" selected";};link[0].onclick=function(){Bats.mostActive.symbolType=this.className;Bats.mostActive.load(Bats.mostActive.symbolType,Bats.mostActive.rows);return false;};}},maxRowsNav:function(){if(document.getElementById('maxRows')){var maxRows=document.getElementById('maxRows');var listElements=maxRows.getElementsByTagName('li');for(i=0;i<listElements.length;i++){link=listElements[i].getElementsByTagName('a');if(link.length>0){link[0].onclick=function(){clearTimeout(Bats.mostActive.deferID);Bats.mostActive.rows=this.firstChild.nodeValue;Bats.mostActive.load(Bats.mostActive.symbolType,Bats.mostActive.rows);return false;};}}}},symbolLinks:function(){if(ma_region=='opt'){return false;} var mostActiveData=document.getElementById('mostActiveData');var hasMenu=false;try{Bats.ext.menu.CtxMenuMgr;hasMenu=true;}catch(e){} for(i=0;i<Bats.mostActive.rows;i++){var symbolLink=document.getElementById('col_'+i+'_0');if(!symbolLink)continue;var link=symbolLink.getElementsByTagName('a');link[0].onclick=function(){if(hasMenu){return false;} if(ma_region=='opt'){Bats.mostActive.spawnSymbolOPT(this.href);} else{Bats.mostActive.spawnSymbol(this.firstChild.firstChild.nodeValue);} return false;}}},spawn:function(){Bats.mostActive.openWin({src:'/most_active/',scrollbars:true,width:500,height:580});},spawnSymbol:function(s){if(s!="")s+="/";Bats.mostActive.openWin({src:'/book/'+s,scrollbars:false,width:375,height:370});},spawnSymbolOPT:function(href){Bats.mostActive.openWin({src:href,scrollbars:false,width:375,height:370});},removeNavClass:function(el,removeClass,newClass,nav){var navItems=nav.getElementsByTagName('td');for(i=0;i<navItems.length;i++){strSearch=navItems[i].className;navItems[i].className=strSearch.replace(removeClass,newClass);}},removeClass:function(el,removeClass,newClass){strSearch=el.className;el.className=strSearch.replace(removeClass,newClass);return el;},openWin:function(config){config=typeof config=="object"?config:{};defaults={name:"_blank",src:"",scrollbars:false,menubar:0,toolbar:0,status:0,resizable:true,location:0};for(key in defaults){if(!config[key]){config[key]=defaults[key];}} if(config.center){x=window.screenX?window.screenX:window.screenLeft;y=window.screenY?window.screenY:window.screenTop;x=Math.floor(x/screen.width)*screen.width;y=Math.floor(y/screen.height)*screen.height;config.left=(screen.width-config.width)/2+x;config.top=(screen.height-config.height)/2+y;} props=((config.width>0)?",width="+config.width:"")+ ((config.height>0)?",height="+config.height:"")+ ((config.top>0)?",top="+config.top:"")+ ((config.left>0)?",left="+config.left:"")+ ((config.scrollbars==0)?",scrollbars=0":",scrollbars=1")+ ((config.menubar==0)?",menubar=0":",menubar=1")+ ((config.toolbar==0)?",toolbar=0":",toolbar=1")+ ((config.status==0)?",status=0":",status=1")+ ((config.resizable==0)?",resizable=0":",resizable=1")+ ((config.location==0)?",location=0":",location=1");props=props.substring(1,props.length);return window.open(config.src,config.name,props);}};Ext.onReady(function(){if(document.getElementById('mostActive')){try{if(typeof(ma_limit)!="undefined"){Bats.mostActive.rows=parseInt(ma_limit,10);}} catch(e){} if(typeof(ma_type)!='undefined'){Bats.mostActive.symbolType=ma_type;} if(typeof(ma_bias)!='undefined'){Bats.mostActive.volumeBias=ma_bias=='vol';} if(Bats.mostActive.ttl>0){Bats.mostActive.deferID=Bats.mostActive.load.defer(Bats.mostActive.ttl,this);} Bats.mostActive.maNav();Bats.mostActive.maxRowsNav();Bats.mostActive.symbolLinks();if(document.getElementById('current_session').value){Bats.mostActive.tradeOpen=true;}}});
