// 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();
    feedbackForm();
}

function newWindowLink(URI, nazev, width, height) {
    if (width && height) {
        newWin = window.open(URI, nazev, 'width=' + width + ', height=' + height + ', scrollbars, resizable');
    } else {
        newWin = window.open(URI);
    }
    return (typeof(newWin) == 'object') ? false : true;
}

function kosikInic()
{ 
    e = document.getElementsByTagName('input');
    if (e) {
        for (i = 0;i < e.length; i++) {
            if (e[i].id.indexOf('vyberPotisku') == 0) {
                e[i].onchange = divvyberPotisku;
                e[i].onclick  = divvyberPotisku;
                e1 = document.getElementById('label' + e[i].id);
                if (e1) {
                    e1.onclick  = divvyberPotisku;
                }
                if (! e[i].checked) {
                    e2 = document.getElementById('div' + e[i].id);
                    if (e2) {
                        e2.style.display  = 'none';
                    }
                }
            }
        }
    }
}
function divvyberPotisku()
{
    if (this.id.indexOf('label') == 0) {
        eInput = document.getElementById(this.id.substr(5));
    } else {
        eInput = this;
    }
    e = document.getElementById('div' + eInput.id);
    if (e) {
        e1 = document.getElementById('pocetks' + eInput.id);
        if (eInput.checked == true) {
            e.style.display = 'block';
            if (e1) {
                e1.disabled = false;
            }
        } else {
            e.style.display = 'none';
            if (e1) {
                e1.disabled = true;
            }

        }
    }
}

function feedbackForm() {
    e = document.getElementById('captcha');
    if (e) {
        e1 = e.getElementsByTagName('label');
        if (e1 && e1.length) {
            var text = e1[0].innerHTML.split("");
            text = text.reverse();
            text = text.join("");
            var levyOperand = text.substr(7, 4);
            levyOperand = levyOperand.split("");
            levyOperand = levyOperand.reverse();
            levyOperand = parseInt(levyOperand.join(""));
            if (text.substr(5, 1) == '+') {
                 answer = levyOperand + parseInt(text.substr(3, 1));
            } else {
                 answer = levyOperand - parseInt(text.substr(3, 1));
            }
            e2 = e.getElementsByTagName('input');
            if (e2 && e2.length) {
                e2[0].value = answer;
                e.style.display = 'none';
            }
        }
    }

    e = document.getElementById('kontaktform');
    if (e) {
        startDate = new Date();
        e.onsubmit = submitTime;
    }
}

function submitTime() {
    do { curDate = new Date(); }
    while(curDate - startDate < 5000);
}