function total_price_for_selected_packages()
{
    elements = $$('input.package-selector');
    elements = elements.select(function(e) { return e.checked });
    return elements.inject(0, function(s, e) { return(s + parseInt(e.getAttribute('price'))) } );
}

function update_total_price_for_selected_packages() {
  $('total_amount').innerHTML = (total_price_for_selected_packages() / 100).toFixed(2);
}

function follow_link (e, link) {
  Event.extend(e);
  if (e.target.tagName != 'A') {
    Event.stop(e);
    if (link.click)
      link.click();
    else
      window.location.href = link.href;
  }
}

function make_clickable_rows (selection) {
  $$(selection).each(function (table) {
    $A(table.getElementsByTagName('tr')).each(function (row) {
      Element.extend(row);
      var links = $A(row.getElementsByTagName('a'));
      links.each(function (link) { link.style.display = 'block'; });
      if (links.length > 0) {
        row.addClassName('clickable');
        row.observe('mouseover', function (e) { row.addClassName('hover'); });
        row.observe('mouseout', function (e) { row.removeClassName('hover'); });
        row.observe('click', function (e) { follow_link(e, links[0]) });
      }
    });
  });
}

