function Calc()
{
	//*************
	for (i=0; i <= document.getElementById('txtshares').value; i++) 
		var decimalShares = document.getElementById('txtshares').value.replace(',','.');
	//*************

  var shares = parseFloat(decimalShares);
  var Dividend = parseFloat(document.getElementById('shareprice').value);
  var result = Dividend * shares;
  var numTwoDecimal =  thousandCommas(twoDP(result));

  document.getElementById('txtdistribution').value = '£ '+numTwoDecimal;
}

function twoDP(theValue){
  if(isNaN(theValue)){
    return '-'
  } else {
    theValue = Math.round(theValue*100)/100
    theValue = theValue.toString()
    if(theValue.indexOf('.') == -1){
      theValue = theValue + '.00'
    } else if((theValue.indexOf('.') + 2) == theValue.length){
      theValue = theValue + '0'
    }
    return theValue
  }
}

//puts thousand commas , in.
function thousandCommas(theNumber) {
  var fullNumber=String(theNumber)
  dpStr = false
  if(fullNumber.indexOf('.') != -1){
    dpStr = '.' + fullNumber.split('.')[1]
    fullNumber = fullNumber.split('.')[0]
  }
  var numLength=fullNumber.length-1
  var withCommas=''
  for (i=0; i<=numLength;i++) {
    withCommas+=fullNumber.charAt(i)
    if (((numLength-i)%3==0) && (i<numLength)){
      withCommas+=','
    }
  }
  if(dpStr){withCommas += dpStr}
  return withCommas
}
