
function QuoteHandler(){this.quoteBlock=undefined;}
QuoteHandler.prototype.QUOTE_BLOCK_URI='/otcmarkets/quoteBlock';QuoteHandler.prototype.NO_INFO_URL='/no-information-warning';QuoteHandler.prototype.NO_INFO_IMG='/content/doc/ps/images/insider_trading_warning.gif';QuoteHandler.prototype.BANKRUPTCY_URL='http://www.sec.gov/investor/pubs/bankrupt.htm';QuoteHandler.prototype.BANKRUPTCY_IMG='/content/doc/ps/images/bankruptcy_warning.gif';QuoteHandler.prototype.UNSOLICITED_URL='http://www.sec.gov/answers/unsolicitedquotations.htm';QuoteHandler.prototype.UNSOLICITED_IMG='/content/doc/ps/images/unsolicited_warning.gif';QuoteHandler.prototype.decorateGlossary=function(){glossaryDecorator.doSection(document.getElementById('quoteContentContainer'));}
QuoteHandler.prototype.run=function(){var filter={secId:security.id,symbol:symbolSecurity,appId:APPLICATION_ID_OTCMARKETS,body:document.getElementById('tradeSummary')};var tradeInsideCallback=new AjaxDataHandler(this,filter);tradeInsideCallback.handleRequestData=this.handleTradeAndInside;iqCaller.getTradeAndInside(symbolSecurity,APPLICATION_ID_OTCMARKETS,tradeInsideCallback);this.resetWarnings();if(security.symbol)
this.paintChart(security.symbol);var tsFilter={pageSize:5,symbol:security.symbol,body:document.getElementById('lastTrades')};if(tsFilter.body){var tsCallback=new AjaxDataHandler(this,tsFilter);tsCallback.handleRequestData=this.handleTimeAndSales;commonCaller.getTimeAndSalesWorklist(tsFilter,tsCallback);}}
QuoteHandler.prototype.checkCaveat=function(){if(security.isCaveatEmptor){try{this.quoteBlock=commonCaller.getQuoteBlock(undefined,security.symbol);if(undefined!=this.quoteBlock){this.quoteBlock.comments=contentCaller.getPageText(undefined,this.QUOTE_BLOCK_URI).contents;}}catch(error){if(window.console){console.log(error);}}}}
QuoteHandler.prototype.resetWarnings=function(){if(security.symbol!=undefined&&security.symbol.length>0){var warningBody=document.getElementById("warningContent");warningBody.innerHTML='';if((5==security.symbol.length)&&('Q'==security.symbol.substr(4,1))){this.createExtraQuoteSection('Bankruptcy Warning',this.BANKRUPTCY_IMG,this.BANKRUPTCY_URL,warningBody,true);}
else if(security.tierId==TIER_NO_INFO){this.createExtraQuoteSection('No Information Warning',this.NO_INFO_IMG,this.NO_INFO_URL,warningBody,false);}
else if(iqCaller.isSecurityUnsolicited(security.symbol)){this.createExtraQuoteSection('Unsolicited Warning',this.UNSOLICITED_IMG,this.UNSOLICITED_URL,warningBody,true);}
else
{warningBody.style.display='none';}}}
QuoteHandler.prototype.paintChart=function(symbol){var chartSection=document.getElementById('nonOTC-intradayChart');if(chartSection){this.symbol=symbol;var chart=new EdgarChartAdvancedSimple(new PinkEdgarCalls(),new EdgarChartAdvancedDOM(),undefined,this,new PinkContentCalls()).doLinkedSymbolSnapShot(symbol,chartSection,APPLICATION_ID_OTCIQ);}}
QuoteHandler.prototype.openChart=function(){appNav.gotoChart(this.symbol);}
QuoteHandler.TICK_ICONS={'+':'/images/icon-tick-up.png','-':'/images/icon-tick-down.png'}
QuoteHandler.prototype.handleTradeAndInside=function(value){tradeHeaderHandler.populate(value);var val,formatCall;$('#tradeSummary span').each(function(){val=value[$(this).attr('val')];formatCall=$(this).attr('formatCall');if(val){val=formatCall?(Formatter[formatCall](val)):val;}
else
{if($(this).children('span').length==0)
val='N/A';}
if($(this).attr('val')!='tradeTime')
$(this).html(val);});var montageFilter={pageSize:5,symbol:security.symbol,tradeInside:value,body:document.getElementById('bidAsk-table-group')};if(montageFilter.body){var me=this.callback;var montageCallback=new AjaxDataHandler(me,montageFilter);montageCallback.handleRequestData=me.handleMontage;iqCaller.getMontage(security.symbol,security.secId,APPLICATION_ID_OTCMARKETS,false,montageCallback);}
if(value.showRealtimeAd==true)
{document.getElementById('realTimeAdCompany').innerHTML=value.companyName;document.getElementById('realTimeAd').style.display='block';}}
QuoteHandler.prototype.handleTimeAndSales=function(value){var table=document.getElementById('lastTrades');var row,src;if(value==undefined||value.records==undefined||value.records.length==0){var rowNum=table.rows.length;for(var i=0;i<rowNum;i++)
table.deleteRow(i);row=table.insertRow(-1);var cell=row.insertCell(0);cell.appendChild(document.createTextNode('No data found.'));return;}
var records=value.records;var filter={includeHeading:false};this.callback.populateTable(table,records,QuoteHandler.TIME_AND_SALES_FIELDS,QuoteHandler.TIME_AND_SALES_FORMAT,QuoteHandler.TIME_AND_SALES_CSS,'populateTimeAndSalesRow',QuoteHandler.TIME_AND_SALES_ROW_CSS,filter);}
QuoteHandler.prototype.populateTable=function(table,records,fields,formatter,css,createRow,rowCss,filter){if(records==undefined||records.length==0)
return;var row,src;var startRow=(filter.includeHeading)?1:0;for(var i=records.length+startRow;i<table.rows.length;i++){table.deleteRow(i);}
var me=this;var rowCount=table.rows.length;for(var i=startRow;i<(records.length+startRow);i++){record=records[i-startRow];if(i<rowCount){row=table.rows[i];for(var j=0;j<fields.length;j++)
row.cells[j].className=css[j];}
else{row=table.insertRow(-1);for(var j=0;j<fields.length;j++)
row.insertCell(-1).className=css[j];}
me[createRow](row,record,fields,formatter,filter);}}
QuoteHandler.TIME_AND_SALES_FIELDS=['tradeDateTime','price','volume','tick'];QuoteHandler.TIME_AND_SALES_CSS=['firstCol','','','tick lastCol'];QuoteHandler.TIME_AND_SALES_ROW_CSS=['odd','even'];QuoteHandler.TIME_AND_SALES_FORMAT=['toDateOrTime','toPrice','toVolume',undefined];QuoteHandler.prototype.populateTimeAndSalesRow=function(row,record,fields,formatter){var formatterCall,value,src;for(var i=0;i<fields.length-1;i++){formatterCall=formatter[i];value=record[fields[i]];row.cells[i].innerHTML=(formatterCall)?(Formatter[formatterCall](value)):value;}
src=QuoteHandler.TICK_ICONS[record.tick];if(src)
row.cells[3].innerHTML='<img src="'+src+'" />';return;}
QuoteHandler.MONTAGE_FIELDS=['mmIdDisplay','priceDisplay','sizeDisplay','transTimeDisplay'];QuoteHandler.MONTAGE_CSS=['firstCol','','','lastCol'];QuoteHandler.MONTAGE_ROW_CSS=['montageClosedTd','montageBBInsideTd','montageInsideTd','montageBBTd','montageNormalTd'];QuoteHandler.CSS_MONTAGE_TEXT_COLORS=['montageClosedText','montageBBInsideText','montageInsideText','montageBBText','montagePSText'];QuoteHandler.prototype.handleMontage=function(value){if(value==undefined||(value.buyList==undefined&&value.sellList==undefined)){$('#bidTableSection, #askTableSection').hide();$('#no-montage').show();return;}
$('#bidTableSection, #askTableSection').show();$('#no-montage').hide();var table=document.getElementById('bidTable');var filter={comparePrice:this.criteria.tradeInside.bidPrice,includeHeading:true};this.callback.populateTable(table,value.buyList,QuoteHandler.MONTAGE_FIELDS,undefined,QuoteHandler.MONTAGE_CSS,'populateMontage',QuoteHandler.MONTAGE_ROW_CSS,filter);table=document.getElementById('askTable');filter={comparePrice:this.criteria.tradeInside.askPrice,includeHeading:true};this.callback.populateTable(table,value.sellList,QuoteHandler.MONTAGE_FIELDS,undefined,QuoteHandler.MONTAGE_CSS,'populateMontage',QuoteHandler.MONTAGE_ROW_CSS,filter);}
QuoteHandler.prototype.populateMontage=function(row,record,fields,formatter,filter){var cell,index=(record.isClosed)?0:((record.price!=0)&&(record.price==filter.comparePrice))?((record.isOtcbb)?1:2):(record.isOtcbb)?3:4;if(index==1||index==3)
document.getElementById("otcbbLegend").style.display="block";row.className=QuoteHandler.MONTAGE_ROW_CSS[index];cell=row.cells[0];cell.className+=((cell.className)?' ':'')+row.className;cell.myCallback=this;cell.myRecord=record;cell.onmouseover=this.handleMMOnMouseOver;cell.onmouseout=this.handleMMOnMouseOut;cell.innerHTML='<a class="mmId">'+record[fields[0]]+'</a>';for(var i=1;i<fields.length;i++){cell=row.cells[i];cell.className+=((cell.className)?' ':'')+row.className;row.cells[i].innerHTML=record[fields[i]];}
return;}
QuoteHandler.prototype.handleMMOnMouseOver=function(ev)
{var record=this.myRecord;this.style.cursor='pointer';this.myCallback.getMMInfo().open(this,record.mmId,record.traderId);}
QuoteHandler.prototype.handleMMOnMouseOut=function(ev)
{this.style.cursor='default';this.myCallback.getMMInfo().close();}
QuoteHandler.prototype.getMMInfo=function()
{if(undefined==this.mmInfo)
this.mmInfo=new MarketMakerInfo(iqCaller,new MiniMarketMakerHtml(),this);return this.mmInfo;}
QuoteHandler.prototype.createExtraQuoteSection=function(title,imgSrc,link,body,openNew)
{var a=document.createElement('a');a.href=link;if(openNew)
a.target='_blank';a.appendChild(Elements.genImage(imgSrc,title));body.appendChild(a);return body;}
