var partner_bubble = false; function hide_partner_bubble() { window.setTimeout(real_hide_partner_bubble, 50); partner_bubble = false; } function remain_partner_bubble() { partner_bubble = true; } function real_hide_partner_bubble() { if (!partner_bubble) { $$('div.pop').setStyle('display', 'none'); } } function check_charges(form) { for (i = 0; i < form.elements.length; i++) { if (form.elements[i].name.substring(0,3) == 'cat') { if (form.elements[i].value > 0) { return true; } } } alert('Nastavte, prosím, nejdříve své útraty dle kategorií.'); return false; } var in_recalc = 0; function handle_slide(shop) { return function(step) { $('upd' + shop.id).setHTML(step); $('updX' + shop.id).setHTML(step); shop.setValue(step); } } function Shop(id, category, slider, discount, value) { this.id = id; this.category = category; this.slider = slider; this.discount = discount; this.value = value; this.getDiscount = function() { return Math.round((this.discount * this.value)/100); } this.setValue = function (value) { var old_value = this.value; this.value = value; /* var diff = value - old_value; if (diff != 0) { if (category.shops.length == 1) { this.value = this.category.max; this.slider.set(this.value); } else { var shop = category.shops[category.shops.length -1]; if (diff < 0) { shop.value -= diff; shop.slider.set(shop.value); } else { if (shop.value > 0) { if (shop.value >= diff) { shop.value -= diff; shop.slider.set(shop.value); } else { diff -= shop.value; shop.value = 0; shop.slider.set(shop.value); i = category.shops.length - 2; while(i >= 0 || diff > 0) { shop = category.shops[i]; if (shop != this && shop.value > 0) { if (shop.value >= diff) { shop.value -= diff; shop.slider.set(shop.value); diff = 0; } else { diff -= shop.value; shop.value = 0; shop.slider.set(0); } } i--; } } } else { i = category.shops.length - 2; while(i >= 0 || diff > 0) { shop = category.shops[i]; if (shop != this && shop.value > 0) { if (shop.value >= diff) { shop.value -= diff; shop.slider.set(shop.value); diff = 0; } else { diff -= shop.value; shop.value = 0; shop.slider.set(0); } } i--; } } } } }*/ this.category.recalc(); } } function Category(id, max) { this.id = id; this.max = max; this.shops = []; this.discount = -1; this.value = -1; this.addShop = function (id, slider, discount, value) { var shop = new Shop(id, this, slider, discount, value); this.shops[this.shops.length] = shop; return shop; }; this.recalc = function() { var sum = 0; var sum2 = 0; for (i = 0; i < this.shops.length; i++) { sum += this.shops[i].getDiscount(); sum2 += this.shops[i].value; } this.discount = sum; this.value = sum2; // $('save' + this.id).setHTML(sum); konfigurator.recalc(); }; this.getDiscount = function() { if (this.discount == -1) { this.recalc(); } return this.discount; } this.getValue = function() { if (this.value == -1) { this.recalc(); } return this.value; } } function Konfigurator() { this.cats = []; this.addCat = function (id, max) { return this.cats[this.cats.length] = new Category(id, max); }; this.recalc = function() { var sum = 0; var sum2 = 0; for(i = 0; i < this.cats.length; i++) { sum += this.cats[i].getDiscount(); sum2 += this.cats[i].getValue(); } $('total_save').setHTML(sum); $('total_save2').setHTML(sum); $('month_cost').setHTML(sum2); $('year_save').setHTML(sum * 12); } }