// JavaScript Document

function rozbalTab(h2)
{
    idSeznam = h2.id.substring(8);
    tabulka = document.getElementById('seznamTable' + idSeznam);
    if (tabs[idSeznam]) {
        tabulka.style.display = msie ? 'block' : 'table';
        tabs[idSeznam] = 0;
    } else {
        tabulka.style.display = 'none';
        tabs[idSeznam] = 1;
    }
}

function fixedRound(cislo)
{
    if (cislo.toFixed) {
        cislo = cislo.toFixed(2);
    } else {
        cislo = Math.round(cislo * 100) / 100;
    }
    return cislo;
}
function cena()
{
    celkovaCena = 0;
    e1 = document.getElementById('cenaProduktu');
    if (e1) {
        cenaProduktu = parseFloat(e1.value);
    } else {
        cenaProduktu = 0;
    }
    e2 = document.getElementById('pocetKsProdukt');
    if (e2) {
        pocetKsProdukt = parseInt(e2.value, 10);
        if (isNaN(pocetKsProdukt) || pocetKsProdukt == 0) {
            pocetKsProdukt = 1;
        }
    } else {
        pocetKsProdukt = 0;
    }
    celkovaCena = celkovaCena + parseFloat(fixedRound(cenaProduktu * pocetKsProdukt));

    e3 = document.getElementsByTagName('input');
    if (e3) {
        for (i = 0;i < e3.length; i++) {
            if (e3[i].id.indexOf('souProd') == 0) {
                if (e3[i].checked) {
                    id = e3[i].id.substring(7);
                    eCena  = document.getElementById('cenaSouProd' + id);
                    ePocet = document.getElementById('pocetSouProd' + id);
                    if (eCena) {
                        cenaSou = parseFloat(eCena.value);
                    } else {
                        cenaSou = 0;
                    }
                    if (ePocet) {
                        pocetSou = parseInt(ePocet.value, 10);
                        if (isNaN(pocetSou) || pocetSou == 0) {
                            pocetSou = 1;
                        }
                    } else {
                        pocetSou = 0;
                    }
                    celkovaCena = celkovaCena + parseFloat(fixedRound(cenaSou * pocetSou));
                }
            }
        }
    }
    celkovaCena = fixedRound(celkovaCena);
    e3 = document.getElementsByTagName('input');
    if (e3) {
        for (i = 0;i < e3.length; i++) {
            if (e3[i].id.indexOf('celkCena') == 0) {
                e3[i].value = celkovaCena;
            }
        }
    }
}

function oznacProd()
{
    id = 'souProd' + this.id.substring(12);
    zatrzitko = document.getElementById(id);
    zatrzitko.checked = true;
    cena();
}

function detailInic()
{
    e = document.getElementsByTagName('table');
    if (e) {
        ii = 0;
        for (i = 0;i < e.length; i++) {
            if (e[i].id.indexOf('seznamTable') > -1) {
                idSeznam = e[i].id.substring(11);
                tabs[idSeznam] = 0;
                if (ii++ > 0) {
                    tabs[idSeznam] = 1;
                    e[i].style.display = 'none';
                }
            }
        }
    }

    ceny = new Array();
    ee = document.getElementsByTagName('input');
    if (ee) {
        for (i = 0;i < ee.length; i++) {
            if (ee[i].id.indexOf('souProd') == 0) {
                ee[i].onclick = cena;
            } else if (ee[i].id.indexOf('pocetKsProdukt') == 0) {
                ee[i].onkeyup = cena;
                ee[i].onchange = cena;
            } else if (ee[i].id.indexOf('pocetSouProd') == 0) {
                ee[i].onkeyup = cena;
                ee[i].onclick  = oznacProd;
                ee[i].onchange = cena;
            } else if (ee[i].id.indexOf('cenaSouProd') == 0) {
                key = parseInt(ee[i].id.substring(11), 10);
                ceny[key] = ee[i].value;
            }
        }
    }
    cena();
}