/*****************************************************************
  This uses params to dynamically size three images that when
  placed together form a barchart. The result is inserted into
  a table cell based on the cellId param.

  Parameter Descriptions :

  buyNos......number of buy trades
  sellNos.....number of sell trades
  unkNos......number of unknown trades
  barLen......overall length of barchart (pixels)
  barHeight...overall height of barchart (pixels)
  cellId......places barchart in cell with stated id attribute

****************************************************************/

function fnBarChart(buyNos, sellNos, unkNos, barLen, barHeight, cellId){

  // Calculate cell widths.
  var totalNos = parseInt(buyNos)+parseInt(sellNos)+parseInt(unkNos);
  var buyPer = (buyNos / totalNos) * 100;
  var buyWidth  = (buyNos / totalNos) * barLen;
  var sellPer = (sellNos / totalNos) * 100;
  var sellWidth = (sellNos / totalNos) * barLen;
  var unkPer = (unkNos / totalNos) * 100;
  var unkWidth = (unkNos / totalNos) * barLen;

  if (buyNos == 0 && sellNos == 0 && unkNos == 0){
  }else{

    buyWidth = roundOff(buyWidth,0);
    sellWidth = roundOff(sellWidth,0);
    unkWidth = roundOff(unkWidth,0);

    // Get the reference for the body.
    var barChartPosition=document.getElementById(cellId);
    //alert();

    // Create buy, sell & unknown images
    var buyImg = '', sellImg = '', unkImg = '';
    if (buyWidth > 0) buyImg = '<img src="/hsretail/images/buy.gif" style="width:'+parseInt(buyWidth)+'px; height:'+barHeight+'px; margin-right:1px;" alt="Buy indicator" title="'+roundOff(buyPer,2)+'%" />';
    if (sellWidth > 0) sellImg = '<img src="/hsretail/images/sell.gif" style="width:'+parseInt(sellWidth)+'px; height:'+barHeight+'px; margin-right:1px;" alt="Sell indicator" title="'+roundOff(sellPer, 2)+'%" />';
    if (unkWidth > 0) unkImg = '<img src="/hsretail/images/unknown.gif" style="width:'+parseInt(unkWidth)+'px; height:'+barHeight+'px; margin-right:1px;" alt="Unknown indicator" title="'+roundOff(unkPer, 2)+'%" />';

    barChartPosition.innerHTML = buyImg + sellImg + unkImg;
  }
}

