var stavSouhlasu = true;

function zmenUcast(hodnota) {

    var oAdresa = document.getElementById('adresa');
    var oPostovne = document.getElementById('postovne');

    if (hodnota == "osobne") {
        oAdresa.style.display = "none";
        oPostovne.style.display = "none";
        prepniSouhlas(true);
        //oSouhlas.style.display = "table-row";
    } else {
        oAdresa.style.display = "block";
        //oSouhlas.style.display = "none";
        oPostovne.style.display = "table-row";
        prepniSouhlas(false);
    }
}

function prepniSouhlas (povoleno) {

    var oSouhlas = document.getElementById('souhlas');
    var oZverejnit = document.getElementsByName('zverejnit')[0];
    
    if (povoleno) {
        oSouhlas.className = "";
        oZverejnit.disabled = false;
        oZverejnit.checked = stavSouhlasu;
    } else {
        oSouhlas.className = "zakazano";
        stavSouhlasu = oZverejnit.checked;
        oZverejnit.checked = false;
        oZverejnit.disabled = true;
    }
}

function zobraz(strOdkaz, width, height) {
   
    var strOptions = "status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=1";

    if ( width !== undefined ) {
        width = width + 10;
        strOptions += ", width="+width;
    } else {
        width = 150;
    }
    if ( height !== undefined ) {
        height = height + 30;
        strOptions += ", height="+height;
    } else {
        height = 150;
    }

    var nahledOkno = window.open(strOdkaz, "nahled", strOptions);

    nahledOkno.moveTo(30,30);
    nahledOkno.resizeTo(width, height);
    nahledOkno.focus();
    return false;
}

function zacatek() {
//    alert(document.getElementById("ucast::postou").checked);
    if (document.getElementById("ucast::postou").checked) {
        zmenUcast("postou");
    } else {
        zmenUcast("osobne");
        document.getElementById("ucast::osobne").checked = true;
    }

}

function najdiInput(td) {
    var node = td.firstChild;
    while (node.nodeName != "INPUT") {
        if (!(node = node.nextSibling)) { //will skip out when no next node
            return false;
        }
    }
    return node;
    //now node conatins a input field
}

function pridejKus(td) {
    //alert(td);
    var input = najdiInput(td);
    if (input) {
        input.value++;
    }
}

function odeberKus(td) {
    //alert(td);
    var input = najdiInput(td);
    if (input) {
        input.value = Math.max(input.value -1 , 0);
    }
}

function kontrolaIntegeru(node) {
    if (isNaN(node.value)) {
        node.value = 0;
    } else {
        node.value = Math.max(Math.floor(node.value),0);
    }
}
