/** The total costs for one album including shipping. */
var total = 0;

/** @ */
var at = "@";

/**
 * Given the country selection, this function calculates
 * and displays the new costs for one album including shipping.
 */
function updateCosts() {
  // Price of CD and packaging.
  var price = 12.28;

  // Shipping.
  var shipping = 3.36;

  // Added value tax (MwSt).
  var tax = (price + shipping) * 0.19;
  tax = Math.round(tax * 100) / 100;

  // Intermediate total.
  var total = price + shipping + tax;

  // PayPal fees.
  var paypal = (total * 0.039 + 0.35) / (1 - 0.039);
  paypal = Math.ceil(paypal * 100) / 100;

  // Price to be paid by customer.
  total = price + tax + shipping + paypal;

  // Generate markup and display.
  markup = '<table>'
         + '<tr><th>Item</th><th class="number">Costs</th></tr>'
         + '<tr><td>Album "Funk + D&ouml;ner" + Packaging</td><td class="number">EUR '+price.toFixed(2)+'</td></tr>'
         + '<tr><td>Shipping</td><td class="number">EUR '+shipping.toFixed(2)+'</td></tr>'
         + '<tr><td>Added value tax</td><td class="number">EUR '+tax.toFixed(2)+'</td></tr>'
         + '<tr><td>PayPal Fees</td><td class="number">EUR '+paypal.toFixed(2)+'</td></tr>'
         + '<tr class="total"><td>Total</td><td class="number">EUR '+total.toFixed(2)+'</td></tr>'
         + '</table>'
         + '<form action="https://www.paypal.com/cgi-bin/webscr" method="POST">'
         + '<input type="hidden" name="cmd" value="_xclick"/>'
         + '<input type="hidden" name="business" value="oliverrivo'+at+'gmail.com"/>'
         + '<input type="hidden" name="item_name" value="RIVO DREI Album: Funk + Doener"/>'
         + '<input type="hidden" name="currency_code" value="EUR"/>'
         + '<input type="hidden" name="amount" value="'+price+'"/>'
         + '<input type="hidden" name="shipping" value="'+shipping+'"/>'
         + '<input type="hidden" name="handling" value="'+paypal+'"/>'
         + '<input type="hidden" name="tax" value="'+tax+'"/>'
         + '<input type="hidden" name="return" value="http://www.rivodrei.de/en/"/>'
         + '<input type="hidden" name="cancel_return" value="http://www.rivodrei.de/en/"/>'
         + '<input id="ordernow" type="submit" value="Order now using PayPal"/>'
         + '</form>';
  document.getElementById("costs").innerHTML = markup;
  document.getElementById("ordernow").focus();
}
