var concerts = new Array();

function updateRow(concertId, prijs, arrangementPrijs)
{
  var total = 0;
  
  var prijsInput = document.getElementById('Prijs_'+concertId);
  if ( prijsInput )
    total += getNumericValue(prijsInput) * prijs;
    
  var arrangementPrijsInput = document.getElementById('ArrangementPrijs_'+concertId);
  if ( arrangementPrijsInput )
    total += getNumericValue(arrangementPrijsInput) * arrangementPrijs;

  var label = document.getElementById('Totaal_'+concertId);
      
  label.innerHTML = formatPrice(total);
  
  updateTotal();
}


function updateTotal()
{
  var total = 0;
  
  for (var i=0; i<concerts.length; i++)
  {
    total += getNumericValueSimple( document.getElementById('Totaal_'+concerts[i]).innerHTML );
  }
  
	alert(getNumericValueSimple( document.getElementById('Totaal_Administratie').innerHTML ) );
  total += getNumericValueSimple( document.getElementById('Totaal_Administratie').innerHTML ); 
   
  document.getElementById('Totaal_Reserveren').innerHTML = formatPrice(total);
}


/* Helper Functions: */

function formatPrice( price )
{
  var result = '' +price;
  result = result.replace('.',',');
  result = result.replace(',00',',-');
  if ( result.indexOf(',') == -1 )
    result += ',-';
  else if (result.indexOf(',') > result.length - 3)
    result += '0';    
  return result;
}

function getNumericValue( input )
{
  if ( input )
  {
    var inputStr = input.value;
    var res = getNumericValueSimple(inputStr);
    res = parseInt(res, 10);
    if (res == 0)
    {
      input.value = '';
    }
    else
      input.value = res;
    
    return res;
  }
  return 0;
}
function getNumericValueSimple( inputStr )
{
  var res = '0';
  for(var i=0; i< inputStr.length; i++)
  {
    var c = inputStr.charAt(i);
    if ( c >= '0' && c <= '9' )
      res += c;
    else if ( c == ',' || c == '.' )
      res += '.';
    else
      break;
  }
  return parseFloat(res,10); //decimaal!
}
