
var pageHandler=new HomeHandler();var TRADE_STATS_TAB_TITLES=['Now','Previous Day'];var TRADE_STATS_TAB_CALLS=['doRealTimeTradeStats','doPrevTradeStats'];var TOP_TRADE_TITLES=['Dollar Volume','Trade Volume','Share Volume'];var TOP_TRADE_CALLS=['doDollarVolume','doTrades','doVolume'];var MOVERS_TITLES=['Over $1','Over $0.05','All'];var GAINERS_CALLS=['doGainersOverDollar','doGainersOver5Cents','doAllGainers'];var LOSERS_CALLS=['doLosersOverDollar','doLosersOver5Cents','doAllLosers'];function initPage()
{PreLoader.start(['/common/scripts/preLoaderDefault.js']);}
function HomeHandler()
{this.appNav=appNav;this.qxNav=new OtcqxAppNav(globalInfo.otcqxBaseUrl);this.commonCaller=new PinkCommonCalls();this.iqCaller=new OtcIQCalls();}
HomeHandler.prototype.gotoQuote=function(symbol,securityId)
{this.appNav.gotoQuotePage(symbol,securityId);}
HomeHandler.prototype.gotoQXQuote=function(symbol,securityId)
{this.qxNav.gotoQuotePage(symbol);}
HomeHandler.prototype.gotoQXSecurityList=function()
{this.qxNav.gotoSecurityList();}
HomeHandler.prototype.paintPage=function()
{try
{var viewer=new ListQXSecuritySnapshot();var handler=new ListQXSecuritySimple(this.commonCaller,viewer,document.getElementById('qxList'),5,this.iqCaller,this);handler.doLatest();viewer=new ListPinkNewsSmall(this.iqCaller,appNav);handler=new ListPinkNewsSimple(this.iqCaller,viewer,undefined,undefined,true);handler.doPsHome(document.getElementById('pinkNewsReleases'));viewer=new ListLatestNewsSmall();handler=new ListNewsReleaseSimple(this.iqCaller,viewer,PAGE_SIZE_SUBLISTING,undefined,appNav);handler.doLatest(document.getElementById('latestNewsReleases'));handler=new ListFinancialReportSimple(this.iqCaller,viewer,PAGE_SIZE_SUBLISTING,undefined,undefined,appNav);handler.doHomePageLatest(document.getElementById('latestFinancialReports'));}
catch(error){window.alert(error);}}
HomeHandler.prototype.paintTradeStats=function()
{this.rtHandler=new RTTradeStatsHandler(document.getElementById('realTimeTradeStats'),document.getElementById('realTimeTimestamp'),PAGE_SIZE_SUBLISTING,APPLICATION_ID_PINKSHEETS,this);this.rtHandler.TAB_CAPTIONS=['Market Makers','Most Active','Advancers','Decliners'];this.rtHandler.TAB_CALLS=['doTopMarketMakers','doTopSymbols','doGainers','doLosers'];this.rtHandler.init('/home');this.rtHandler.run();var gen=new TradeStatsTotals();this.rtTotalsHandler=new RTTradeStatTotalsHandler(gen);this.iqCaller.getAggregateWombatTradesForTierGroup(TIER_GROUP_ALL,this.rtTotalsHandler);var handler=new TradeStatsHandler(document.getElementById('prevTradeStats'),'/home',PAGE_SIZE_SUBLISTING);handler.run();this.commonCaller.getTradeStatSummary('ALL',new TradeStatTotalsHandler(gen));handler=new TierSecurityStatsWorklistSimple(this.commonCaller,new TierSecurityStatsWorklistDOM(),undefined,this,PAGE_SIZE_SUBLISTING);handler.init(document.getElementById('tierSecurityStats'));var me=this;this.realTimeTradeSummaryIntervalId=window.setInterval(function(){me.doRealTimeDaemon();},30000);}
HomeHandler.prototype.doRealTimeDaemon=function()
{this.rtHandler.doLast();this.iqCaller.getAggregateWombatTradesForTierGroup(TIER_GROUP_ALL,this.rtTotalsHandler);}
HomeHandler.prototype.handleTabbed=function(value)
{restartPageServices('/home/realtime/'+value);}
function RTTradeStatTotalsHandler(viewer){this.viewer=viewer;}
RTTradeStatTotalsHandler.prototype.handleRequestData=function(value)
{var criteria=(undefined!=value)?new TradeStatsTotalsCriteria(Formatter.toVolume(value.volume),Formatter.toVolume(value.dollarVolume)):new TradeStatsTotalsCriteria(0,0);var body=document.getElementById('realTimeVolumeTotals');body.innerHTML='';body.appendChild(this.viewer.generate(criteria));}
RTTradeStatTotalsHandler.prototype.handleRequestError=function(error)
{document.getElementById('realTimeVolumeTotals').innerHTML=(error.message?error.message:error);}
function TradeStatTotalsHandler(viewer){this.viewer=viewer;}
TradeStatTotalsHandler.prototype.handleRequestData=function(value)
{document.getElementById('prevTradeDate').appendChild(document.createTextNode(Formatter.toFullDate(value.tradeDate)));document.getElementById('prevVolumeTotals').appendChild(this.viewer.generate(new TradeStatsTotalsCriteria(Formatter.toVolume(value.sumVolume),Formatter.toVolume(value.sumDollarVolume))));}
TradeStatTotalsHandler.prototype.handleRequestError=function(error)
{document.getElementById('prevVolumeTotals').innerHTML=(error.message?error.message:error);}

function ListLatestNewsSmall(){}
ListLatestNewsSmall.prototype=new WorklistDOM();ListLatestNewsSmall.prototype.generate=function(value,callback)
{var output;var records=value.records;if((undefined==records)||(0==records.length))
{output=document.createElement('span');output.appendChild(document.createTextNode('No '+value.plural+' Found.'));return output;}
output=document.createElement('table');output.className='listPinkNewsSmall';output.cellSpacing=0;for(var i=0;i<value.records.length;i++)
{var record=value.records[i];var row=output.insertRow(i);var td=row.insertCell(0);td.className='newsSymbol';var anchor=document.createElement('a');anchor.href='javascript:void(null);';anchor.appendChild(document.createTextNode(record.primarySymbol));anchor.myRecord=record;anchor.myCallback=callback;anchor.onclick=callback.handleSelection;td.appendChild(anchor);var title=(record.getTitle)?record.getTitle():record.name;td=row.insertCell(1);td.className='newsTitle';td.innerHTML='  '+trimToLength(title,95);}
return output;}

function ListPinkNewsSmall(caller,appNav)
{this.caller=caller;this.appNav=appNav;}
ListPinkNewsSmall.prototype.generate=function(value,callback)
{var o,me=this;var records=value.records;if((undefined==records)||(0==records.length))
{o=document.createElement('span');o.appendChild(document.createTextNode('No '+value.plural+' found.'));return o;}
o=document.createElement('table');o.className='listPinkNewsSmall';o.cellSpacing=0;for(var i=0;i<records.length;i++)
{var record=records[i];var row=o.insertRow(i);var td=row.insertCell(0);td.appendChild(document.createTextNode(Formatter.toDate(record.releaseDate)));td.className='newsDate';td=row.insertCell(1);td.className='newsTitle';var elem=document.createElement('a');elem.innerHTML=this.trim(record.title);if(record.isCoverage)
{elem.href=record.contents;elem.target='_new';}
else
{elem.href='javascript:void(null);';elem.myRecord=record;elem.onclick=function(ev){me.handleOpen(this);return false;};}
td.appendChild(elem);}
return o;}
ListPinkNewsSmall.prototype.trim=function(value)
{if(95>value.length)
return value;return value.substr(0,95)+"...";}
ListPinkNewsSmall.prototype.handleOpen=function(elem)
{this.appNav.gotoPinkNews(elem.myRecord.id);}

function TradeStatsTotals(){}
TradeStatsTotals.prototype.generate=function(value)
{var output=document.createElement('table');var row=output.insertRow(0);var cell=row.insertCell(0);cell.className='volume';cell.appendChild(document.createTextNode('Total Share Volume: '+value.volume));row=output.insertRow(1);cell=row.insertCell(0);cell.className='dollarVolume';cell.appendChild(document.createTextNode('Total $ Volume: '+value.dollarVolume));return output;}
function TradeStatsTotalsCriteria(volume,dollarVolume)
{this.volume=volume;this.dollarVolume=dollarVolume;}

function TradeStatsHandler(body,uriPrefix,pageSize)
{this.body=body;this.pageSize=(pageSize==undefined)?PAGE_SIZE_WORKLIST:pageSize;var caller=new PinkCommonCalls();var viewerVol=new TradeStatsWorklistDOM(undefined,true);this.handlerVol=new TradeStatsWorklistSimple(caller,viewerVol,undefined,this,this.pageSize);var viewerNet=new TradeStatsWorklistDOM(undefined,false);this.handlerNet=new TradeStatsWorklistSimple(caller,viewerNet,undefined,this,this.pageSize);this.anchorList=new FancyAnchorList();this.tabberOptions={'ids':undefined,'defaultTab':0,'titles':this.TAB_CAPTIONS,'calls':this.TAB_CALLS,'onClick':function(args){restartPageServices(this.uriPrefix+'/marketactivity/TradeStats/'+this.calls[args.index]);if(!args.tab.isEmpty)
return true;try{this.callback[this.calls[args.index]](args.tab.body);}
catch(error){window.alert(error);return false;}
args.tab.isEmpty=false;return true;},'onLoad':function(args){this.onClick(args);},'uriPrefix':(undefined==uriPrefix)?'':uriPrefix}
this.tabberOptions.callback=this;this.tabber=new Tabbers(this.tabberOptions);}
TradeStatsHandler.prototype.TAB_CAPTIONS=['Volume','Advancers','Decliners'];TradeStatsHandler.prototype.TAB_CALLS=['doTopSymbols','doGainers','doLosers'];TradeStatsHandler.prototype.TOP_TRADE_TITLES=['$ Volume','Share Volume','# Trades'];TradeStatsHandler.prototype.TOP_TRADE_CALLS=['doDollarVolume','doVolume','doTrades'];TradeStatsHandler.prototype.MOVERS_TITLES=['Over $1','Over $0.05','All'];TradeStatsHandler.prototype.GAINERS_CALLS=['doGainersOverDollar','doGainersOver5Cents','doAllGainers'];TradeStatsHandler.prototype.LOSERS_CALLS=['doLosersOverDollar','doLosersOver5Cents','doAllLosers'];TradeStatsHandler.prototype.run=function()
{this.tabber.run(this.body);}
TradeStatsHandler.prototype.doTopSymbols=function(body)
{this.createTabBody(this.TOP_TRADE_TITLES,this.TOP_TRADE_CALLS,body,this);}
TradeStatsHandler.prototype.doGainers=function(body)
{this.createTabBody(this.MOVERS_TITLES,this.GAINERS_CALLS,body,this);}
TradeStatsHandler.prototype.doLosers=function(body)
{this.createTabBody(this.MOVERS_TITLES,this.LOSERS_CALLS,body,this);}
TradeStatsHandler.prototype.handleAnchorSelect=function(action,caption,criteria)
{var me=criteria.myCallback;var body=criteria.myBody;me[action](body);}
TradeStatsHandler.prototype.doDollarVolume=function(body){this.handlerVol.doFilter(new TradeStatFilter(undefined,FIELD_DOLLAR_VOLUME,undefined,undefined),body);}
TradeStatsHandler.prototype.doVolume=function(body){this.handlerVol.doFilter(new TradeStatFilter(undefined,FIELD_VOLUME,undefined,undefined),body);}
TradeStatsHandler.prototype.doTrades=function(body){this.handlerVol.doFilter(new TradeStatFilter(undefined,'tradeCount',undefined,undefined),body);}
TradeStatsHandler.prototype.doGainersOverDollar=function(body){this.handlerNet.doFilter(new TradeStatFilter(undefined,FIELD_GAIN,1,undefined),body);}
TradeStatsHandler.prototype.doGainersOver5Cents=function(body){this.handlerNet.doFilter(new TradeStatFilter(undefined,FIELD_GAIN,0.05,undefined),body);}
TradeStatsHandler.prototype.doAllGainers=function(body){this.handlerNet.doFilter(new TradeStatFilter(undefined,FIELD_GAIN,undefined,undefined),body);}
TradeStatsHandler.prototype.doLosersOverDollar=function(body){this.handlerNet.doFilter(new TradeStatFilter(undefined,FIELD_LOSS,1,undefined),body);}
TradeStatsHandler.prototype.doLosersOver5Cents=function(body){this.handlerNet.doFilter(new TradeStatFilter(undefined,FIELD_LOSS,0.05,undefined),body);}
TradeStatsHandler.prototype.doAllLosers=function(body){this.handlerNet.doFilter(new TradeStatFilter(undefined,FIELD_LOSS,undefined,undefined),body);}
TradeStatsHandler.prototype.gotoQuote=function(symbol,securityId)
{appNav.gotoQuotePage(symbol,securityId);}
TradeStatsHandler.prototype.createTabBody=function(captions,actions,body,callback)
{body.innerHTML='';var subBody=document.createElement('div');this.createAnchors(captions,actions,subBody,callback,body);subBody.className="bodyContainer";body.appendChild(subBody);callback[actions[0]](subBody);}
TradeStatsHandler.prototype.createAnchors=function(captions,actions,body,callback,parentBody)
{var listItems={ids:actions,values:captions};var criteria=new AnchorListCriteria(listItems,actions[0],this);criteria.myCallback=callback;criteria.myBody=body;var elem=document.createElement('div');elem.className='anchorContainer';parentBody.appendChild(elem);this.anchorList.run(criteria,elem);}
