$(document).ready(function() {
    $('.tablecontainer').each(function(i) {
        var hotel = $(this);
        $('input:radio', this).click(function() {
            var price = 0;
            $('input:radio:checked', hotel).each(function() {
                var room_price = $(this).parent().prev().html();
                price += parseFloat(room_price.substring(1, room_price.length).replace(",", ""));
            });
            var totalPrice = formatCurrency(price);
         //   console.log($('.bottomrate:eq('+i+')'));
            $('span:first', '.bottomrate:eq('+i+')').html(totalPrice);
            $('span:first', '.toprate:eq('+i+')').html(totalPrice);
        });
    });
});

function formatCurrency(price) {
    // add decimal points
    price = price.toFixed(2);
    // add commas
    price += '';
    var parts = price.split(".");
    var pounds = parts[0];
    var pence = parts[1];
    var regexp = /(\d+)(\d{3})/;
    while (regexp.test(pounds)) {
        pounds = pounds.replace(regexp, '$1' + ',' + '$2');
    }
    return '&pound;'+pounds+'.'+pence;
}
