function updateTotals(index) {
  var el = $('fieldset_product_'+index+'_quantity');
  var quantity = (el.type == 'checkbox' ? (el.checked ? 1 : 0) : parseInt(el.value));

  if(isNaN(quantity)) { return null; }

  var price_text = $('product_'+index+'_price_value').innerHTML.split(' ');
  var price = price_text[0];
  var tax = $('product_'+index+'_tax_value').innerHTML;

  var subtotal = quantity * price;
  var new_total = parseFloat(subtotal + (subtotal * tax / 100.0));
  var old_total = parseFloat($('product_'+index+'_total_value').innerHTML);
  var grand_total = parseFloat($('form_products_total').innerHTML);

  if(isNaN(old_total)) { old_total = 0.00; }
  if(isNaN(grand_total)) { grand_total = 0.00; }

  if(el.type != 'checkbox') { el.value = quantity; }
  $('product_'+index+'_total_value').innerHTML = new_total.toFixed(2) + ' ' + price_text[1];
  $('form_products_total').innerHTML = (grand_total - old_total + new_total + 0.0000000001).toFixed(2) + ' ' + price_text[1];
}

