var prumerTrubky = new Array ();
 
prumerTrubky['3,5'] = ['M'];
prumerTrubky['4,5'] = ['M', 'T'];
prumerTrubky['4,75'] = ['E', 'F', 'B', 'T', 'G'];
prumerTrubky['6,0'] = ['E', 'F', 'B'];
prumerTrubky['6,35'] = ['M', 'T', 'G', 'E', 'F'];
prumerTrubky['8,0'] = ['E', 'F', 'B', 'G'];
prumerTrubky['10,0'] = ['E', 'F', 'B', 'G'];
prumerTrubky['11,0'] = ['E', 'F', 'B', 'G'];

function ChangeSecondDropContent() {
    document.getElementById('koncovka_potrubi1').style.visibility = 'visible';
    document.getElementById('koncovka_potrubi2').style.visibility = 'visible';
    document.getElementById('koncovkaRow').style.display = '';

    var select1 = document.getElementById('prumer_potrubi');
    var select2 = document.getElementById('zakonceni_potrubi1');
    var select3 = document.getElementById('zakonceni_potrubi2');
    var select4 = document.getElementById('koncovka_potrubi1');
    var select5 = document.getElementById('koncovka_potrubi2');

    var prumer = select1.options[select1.selectedIndex].text;
 
    // removes all options from select 2, 3
    while (select2.options.length) {
        select2.removeChild(select2.options[0]);
    }
    while (select3.options.length) {
        select3.removeChild(select3.options[0]);
    }
    while (select4.options.length) {
        select4.removeChild(select4.options[0]);
    }
    while (select5.options.length) {
        select5.removeChild(select5.options[0]);
    }
 
    // adds new options to select 2, 3
    var zakonceniArray = prumerTrubky[prumer];
 
    if (zakonceniArray) {
        for (var i=0; i < zakonceniArray.length; i++) {
            var option = new Option(zakonceniArray[i], zakonceniArray[i]);
            var option2 = new Option(zakonceniArray[i], zakonceniArray[i]);
            var option3 = new Option(zakonceniArray[i], zakonceniArray[i]);
            var option4 = new Option(zakonceniArray[i], zakonceniArray[i]);
            select2.options.add(option);
            select3.options.add(option2);
            select4.options.add(option3);
            select5.options.add(option4);
        }
    }
}

function ChangeHadiceKoncovkaDropContent() {
    var select1 = document.getElementById('prumer_hadice');
    var select2 = document.getElementById('koncovka_hadice1');
    var select3 = document.getElementById('koncovka_hadice2');

    var prumer = select1.options[select1.selectedIndex].text + ",0";

    // removes all options from select 2, 3
    while (select2.options.length) {
        select2.removeChild(select2.options[0]);
    }
    while (select3.options.length) {
        select3.removeChild(select3.options[0]);
    }

    // adds new options to select 2, 3
    var zakonceniArray = prumerTrubky[prumer];

    if (zakonceniArray) {
        for (var i = 0; i < zakonceniArray.length; i++) {
            var option = new Option(zakonceniArray[i], zakonceniArray[i]);
            var option2 = new Option(zakonceniArray[i], zakonceniArray[i]);
            select2.options.add(option);
            select3.options.add(option2);
        }
    }
}



function SkryjDodaciAdresu() {
    document.getElementById('dodaci_adresa_ulice').style.display = 'none';
    document.getElementById('dodaci_adresa_nadpis').style.display = 'none';
    document.getElementById('dodaci_adresa_cislodomu').style.display = 'none';
    document.getElementById('dodaci_adresa_mesto').style.display = 'none';
    document.getElementById('dodaci_adresa_psc').style.display = 'none';
    document.getElementById('dodaci_adresa_separator').style.display = 'none';
    document.getElementById('dodaci_stejna').style.display = 'none';
}

function ZobrazDodaciAdresu() {
    //alert(document.getElementById('dodaci_stejna_chk').value);
    if (document.getElementById('dodaci_stejna_chk').checked == true) {
        document.getElementById('dodaci_stejna').style.display = '';
    } else {

        document.getElementById('dodaci_adresa_ulice').style.display = '';
        document.getElementById('dodaci_adresa_nadpis').style.display = '';
        document.getElementById('dodaci_adresa_cislodomu').style.display = '';
        document.getElementById('dodaci_adresa_mesto').style.display = '';
        document.getElementById('dodaci_adresa_psc').style.display = '';
        document.getElementById('dodaci_adresa_separator').style.display = '';
        document.getElementById('dodaci_stejna').style.display = '';
    }
}
function koncovkaHide(FireElement, ElementName) {
    var selectBox = document.getElementById(ElementName);
    var fireSelectBox = document.getElementById(FireElement);
    //alert(fireSelectBox.value);
    if (fireSelectBox.value == "B" || fireSelectBox.value == "T" || fireSelectBox.value == "G") {
        //select1.options[select1.selectedIndex].text;
        selectBox.style.visibility = 'hidden';
    } else {
        selectBox.style.visibility = 'visible';
    }
    //alert (document.getElementById('koncovka_potrubi1').style.display);
    if (document.getElementById('koncovka_potrubi1').style.visibility == "hidden" && document.getElementById('koncovka_potrubi2').style.visibility == "hidden") {
        document.getElementById('koncovkaRow').style.display = 'none';
    } else {
        document.getElementById('koncovkaRow').style.display = '';
    }
}

var mainArray = Array();

function createArrays(pocetkoncovek) {
    for (i = 0; i < pocetkoncovek; i++) {
        mainArray[i] = new Array();
    }
}

function setKoncArray(index, id, prumer_trubky, zakonceni_trubky) {
    mainArray[index]['id'] = id;
    //mainArray[index]['kod'] = kod;
    mainArray[index]['prumer_trubky'] = prumer_trubky;
    mainArray[index]['zakonceni_trubky'] = zakonceni_trubky;

    //alert(mainArray[index]['cenaposleve']);
}

function naplnKoncovky() {
    var pp = document.getElementById('prumer_potrubi');
    var zp1 = document.getElementById('zakonceni_potrubi1');
    var zp2 = document.getElementById('zakonceni_potrubi2');
    var k1 = document.getElementById('koncovka_potrubi1');
    var k2 = document.getElementById('koncovka_potrubi2');
    //alert(pp.value);

    while (k1.options.length) {
        k1.removeChild(k1.options[0]);
    }
    while (k2.options.length) {
        k2.removeChild(k2.options[0]);
    }


    /*while (k1.options.length) {
        k1.options.remove(0);
    }

    while (k2.options.length) {
        k2.options.remove(0);
    }*/

    for (var konc in mainArray) {
        if (mainArray[konc]['prumer_trubky'] == pp.value && mainArray[konc]['zakonceni_trubky'] == zp1.value) {
            var option = new Option(konc, konc);
            k1.options.add(option);
        }

        if (mainArray[konc]['prumer_trubky'] == pp.value && mainArray[konc]['zakonceni_trubky'] == zp2.value) {
            var option = new Option(konc, konc);
            k2.options.add(option);
        }
    }
}

function naplnKoncovky1() {
    var pp = document.getElementById('prumer_potrubi');
    var zp1 = document.getElementById('zakonceni_potrubi1');
    var zp2 = document.getElementById('zakonceni_potrubi2');
    var k1 = document.getElementById('koncovka_potrubi1');
    var k2 = document.getElementById('koncovka_potrubi2');
    //alert(pp.value);
    while (k1.options.length) {
        k1.removeChild(k1.options[0]);
    }

    for (var konc in mainArray) {
        if (mainArray[konc]['prumer_trubky'] == pp.value && mainArray[konc]['zakonceni_trubky'] == zp1.value) {
            var option = new Option(konc, konc);
            k1.options.add(option);
        }
    }
}

function naplnKoncovky2() {
    var pp = document.getElementById('prumer_potrubi');
    var zp1 = document.getElementById('zakonceni_potrubi1');
    var zp2 = document.getElementById('zakonceni_potrubi2');
    var k1 = document.getElementById('koncovka_potrubi1');
    var k2 = document.getElementById('koncovka_potrubi2');
    //alert(pp.value);

    while (k2.options.length) {
        k2.removeChild(k2.options[0]);
    }

    for (var konc in mainArray) {

        if (mainArray[konc]['prumer_trubky'] == pp.value && mainArray[konc]['zakonceni_trubky'] == zp2.value) {
            var option = new Option(konc, konc);
            k2.options.add(option);
        }
    }
}

function isInteger(s) {
    return (s.toString().search(/^-?[0-9]+$/) == 0);
}

function upravPocet(idpole, idzbozi, value) {
    //alert(id + ", " + value);
    if (isInteger(value)) {
        if (value == 0) {
            document.location.href = 'index.php?akce=zkosiku&id=' + idpole;
        } else {
            document.location.href = 'index.php?akce=upravakosiku&id=' + idpole + '&id_zbozi=' + idzbozi + '&pocet=' + value + '&back_url=http://www.bekas.cz/obsah-kosiku';
            //alert('index.php?akce=dokosiku&id_zbozi=' + idzbozi + '&pocet=' + value + '&back_url=http://www.bekas.cz/obsah-kosiku');
        }
    }
}

function disableEnterKey(e) {
    var key;
    if (window.event)
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox
    if (key == 13)
        return false;
    else
        return true;
}
