function calculate_bundle_options(price)
{
    add_to_cart_avail = true;
    modified_total_price = price;
    for (var p in bundle_options) {
        b_variants = bundle_variants[p];
        for (var a in bundle_options[p]) {
            bundle_class = bundle_options[p][a];
            for (var c in bundle_class) {
                bundle_option = bundle_class[c];
                for (var o in bundle_option) {
                        if (document.getElementById("bo_"+p+"_"+a+"_"+c).value == o) {
                        modified_total_price = modified_total_price + bundle_option[o].replace(/,/,".")/1;
                    }
               }
            }
            if (b_variants) {
                for (var gb in b_variants) {
                    if (b_variants[gb][0][0] > 0) {
                        b_avail_variantid = gb;
                    }
                    if (b_variants[gb][1].length == 0)
                        continue;
                    b_variantid = gb;
                    for (var vc in b_variants[gb][1]) {
                        if (getBPOValue(p,a,vc) != b_variants[gb][1][vc]) {
                            b_variantid = false;
                            break;
        }
    }
                        if (b_variantid)
                        break;
                }
                b_avail = b_variants[b_variantid][0][0];
                if (b_avail <= 0) {
                    document.getElementById('bundle_out_of_stock_'+p+"_"+a).style.display = "";
                    add_to_cart_avail = false;
                    alert(lbl_no_items_available);
                } else {
                    document.getElementById('bundle_out_of_stock_'+p+"_"+a).style.display = "none";
                }
            }
        }
    }
    if (!add_to_cart_avail) {
        document.getElementById('add_to_cart_button').style.display = "none";
    } else {
        document.getElementById('add_to_cart_button').style.display = "";
    }
    document.getElementById('product_price').innerHTML = currency_symbol+price_format(modified_total_price);
}
function getBPOValue(pid, aid, cid) {

    if (!document.getElementById('bo_'+pid+"_"+aid+"_"+cid))

        return false;

    return document.getElementById('bo_'+pid+"_"+aid+"_"+cid).options[document.getElementById('bo_'+pid+"_"+aid+"_"+cid).selectedIndex].value;

}
function show_additional_bundle_options(id_amount)
{
    if (document.getElementById(id_amount).style.display == "") {
        document.getElementById(id_amount).style.display = "none";
    } else {
        document.getElementById(id_amount).style.display = "";
    }
}

