function update_localized_account() {
if (localize) {
var o_acc  = document.getElementById('account');
var o_lacc = document.getElementById('local_account');
o_lacc.innerHTML = (Number(o_acc.innerHTML) * exchange[currency]).toFixed(precision);
}
}
function update_prices() {
var i;
for (i=0;i<ids.length;i++) {
recalculate_price(ids[i]);
}
}
function allow_negative(name) {
if (negative_fields && negative_fields.length) {
for (i=0; i<negative_fields.length; i++) {
if (negative_fields[i] == name) {
return 1;
}
}
}
return 0;
}
function recalculate_price(prep) {
var o_unit    = document.getElementById(prep + '_unit');
var o_amount  = document.getElementById(prep + '_amount');
var o_price   = document.getElementById(prep + '_price');
var o_vat     = document.getElementById(prep + '_vat');
var o_vprice  = document.getElementById(prep + '_vat_price');
var value     = 0;
if (isNaN(o_amount.value) ||
(parseInt(o_amount.value) < 0 &&
!allow_negative(prep))) {
document.getElementById(prep).style.cssText = style_input_err;
value = 0;
} else {
document.getElementById(prep).style.cssText = style_input_ok;
o_amount.value = parseInt(o_amount.value);
value          = o_amount.value;
}
o_price.innerHTML  = calculate_price(Number(o_unit.innerHTML), Number(value), 0).toFixed(precision);
if (use_vat) {
o_vprice.innerHTML = calculate_price(Number(o_unit.innerHTML), Number(value), Number(o_vat.innerHTML)).toFixed(precision);
}
if (localize) {
var o_lvprice = document.getElementById(prep + '_local_vat_price');
o_lvprice.innerHTML = (calculate_price(Number(o_unit.innerHTML),
Number(value),
(use_vat ? Number(o_vat.innerHTML) : 0)) * exchange[currency]).toFixed(precision);
}
update_total();
}
function calculate_price(unit, amount, vat) {
var price = 0;
if (!isNaN(amount)) {
price = unit * amount;
price = price + price / 100 * vat;
}
return price;
}
function update_total() {
var o_account = document.getElementById('account');
var o_total   = document.getElementById('total');
var o_account_after = document.getElementById('account_after');
var total     = 0;
var i;
var o_amount;
var o_unit;
var o_vat;
var no_vat_price = 0;
var o_no_vat_price = document.getElementById('price_without_vat');
for (i=0; i<ids.length; i++) {
o_unit   = document.getElementById(ids[i] + '_unit');
o_amount = document.getElementById(ids[i] + '_amount');
o_vat    = document.getElementById(ids[i] + '_vat');
if (!isNaN(o_amount.value) &&
(parseInt(o_amount.value) > 0 ||
allow_negative(ids[i]))) {
total += calculate_price(Number(o_unit.innerHTML), Number(o_amount.value), (use_vat ? Number(o_vat.innerHTML) : 0));
no_vat_price += Number(o_unit.innerHTML) * Number(o_amount.value);
}
}
if (localize) {
var o_ltotal         = document.getElementById('local_total');
var o_laccount_after = document.getElementById('local_account_after');
o_ltotal.innerHTML         = (total * exchange[currency]).toFixed(precision);
if (direction == '-') {
o_laccount_after.innerHTML = ((Number(o_account.innerHTML) - total) * exchange[currency]).toFixed(precision);
} else {
o_laccount_after.innerHTML = ((Number(o_account.innerHTML) + total) * exchange[currency]).toFixed(precision);
}
}
o_total.innerHTML         = total.toFixed(precision);
if (direction == '-') {
o_account_after.innerHTML = Number(Number(o_account.innerHTML) - total).toFixed(precision);
} else {
o_account_after.innerHTML = Number(Number(o_account.innerHTML) + total).toFixed(precision);
}
o_no_vat_price.value      = no_vat_price.toFixed(precision);
}
function initAfterLoad() {
update_localized_account();
update_prices();
update_total();
}
