var bundle_price = new Array();
var bundle_tax = new Array();
var bundle_name = new Array();
var bundle_images = new Array();
var bundle_pc_to_group = new Array();
var base_tax = "";
var base_price = "";
var bundle_image_group = "";
var add_price = 0;
var price = new Object();

function round_price(price){
    if (price == 0) return '0,00';
    var decimal_places = 2;
    var tmp_value = price;
    tmp_value = (tmp_value*100);
    tmp_value =  Math.round(tmp_value);
    tmp_value = tmp_value.toString()
    tmp_value_pre = tmp_value.substring(0,tmp_value.length-decimal_places);
    tmp_value_dez = tmp_value.substr(tmp_value.length-decimal_places,decimal_places);
    return tmp_value = tmp_value_pre + ',' + tmp_value_dez;
}

function calculateBundle(checkedID) {
    var tax = base_tax;
    if (checkedID == null){
        jQuery('#bundleInfoContainer').html('');
        jQuery(".selectRow").removeClass("selectRow");
        jQuery(".ac_content input[type=radio]:checked").each(function(i, n) {
                var pc_id = jQuery(this).attr('value');
                var pc_group_id = bundle_pc_to_group[pc_id];
                jQuery(this).parent().parent().addClass('selectRow');
                price[pc_group_id] = bundle_price[pc_id];
                add_price += bundle_price[pc_id];
                var pname = jQuery('#bundle_name_'+pc_id).html();
                var pgroupname = jQuery('#groupName_'+pc_group_id).html();
                var pdesc = jQuery('#pdesc_'+pc_id).html();
                if (pdesc == null) {
                	pdesc="";
                }

                jQuery('#bundleInfoContainer').append('<div id="bundleInfoGroup'+ pc_group_id +'" <div class="head2"><span class="bold">'+pgroupname + ':</span> ' + pname+'</div>' + pdesc);
                if (bundle_image_group == pc_group_id) {
                    var bundle_image = jQuery('#bundle_image_'+ pc_id ).html();
                    jQuery("#imageInfo").css({"background-image": "url("+srv_web+"media/images/info/"+bundle_image+")"});
                    jQuery("#imageInfo .thickbox").attr("href", ""+srv_web+"media/images/popup/"+bundle_image);
                }
                jQuery("#selection_"+pc_group_id).html(pname);
        });
        jQuery("#bundleInfoContainer div").removeClass("hide");
    } else {
        var pc_id = checkedID;
        var pc_group_id = bundle_pc_to_group[pc_id];
        jQuery('#acContent'+ pc_group_id +' .selectRow').removeClass("selectRow");
        jQuery('#tableRow_'+pc_id).addClass('selectRow');
        // remove old price
        if (price[pc_group_id] != undefined) {
            add_price -= price[pc_group_id];
            price[pc_group_id] = bundle_price[pc_id];
        }
        add_price += bundle_price[pc_id];
        var pname = jQuery('#bundle_name_'+pc_id).html();
        jQuery('#bundleInfoGroup'+ pc_group_id).html('<h1 class="head2">'+pname+'</h1>' + jQuery('#pdesc_'+pc_id).html());
        if (bundle_image_group == pc_group_id) {
            var bundle_image = jQuery('#bundle_image_'+ pc_id ).html();
            jQuery("#imageInfo").css({"background-image": "url("+srv_web+"media/images/info/"+bundle_image+")"});
            jQuery("#imageInfo .thickbox").attr("href", ""+srv_web+"media/images/popup/"+bundle_image);
        }
        jQuery("#selection_"+pc_group_id).html(pname);
    }
    if (add_price != 0) {
        jQuery('#calculate_box').removeClass('hide');
    } else {
        jQuery('#calculate_box').addClass('hide');
    }

    if (jQuery('#bundleInfoContainer').is('img')) {

        jQuery('#bundleInfoContainer img').wrap('<a href="'+jQuery('#bundleInfoContainer img').parent().css("background-image").replace('/info/','/popup/').replace('url(','').replace(')','')+'" class="thickbox"></a>');
        tb_init('a.thickbox');
    }
    //jQuery('.bundleTax').html(formatPrice(tax));
    jQuery('.basePrice').html(formatPrice(base_price));
    if (add_price != 0) {
        jQuery('#bundlePrice').html(formatPrice(add_price));
        jQuery('.bundlePriceTotal').html(formatPrice(base_price + add_price));
    }
}

function displayInfo(id) {
        //jQuery(".InfoShort").hide('fast');
        //jQuery("#msInfoShort_"+id).show('fast');
}
