function nums_only(e)

{

    switch (e.keyCode) {

        case 8:

        case 9:

        case 13:

        case 46:

        case 116:

            return true;

            break;

    }



    k = (e.which) ? e.which : e.keyCode;

    var r = !((k < 48 || k > 57) && (k < 35 || k > 40));



    return r;

}



function date_only(e)

{

    switch (e.keyCode) {

        case 8:

        case 9:

        case 13:

        case 46:

            return true;

            break;

    }



    k = (e.which) ? e.which : e.keyCode;

    dot = (k == 46);



    var r = ((k < 48 || k > 57) && !dot && (k < 35 || k > 40));



    return !r;

}



function change(obj)

{

    if(obj.options[obj.options.selectedIndex].title == "volna-mista") {

        $("div.opt label").each(function(){this.style.display = "none";});

        $("div.opt input").each(function(){this.style.display = "none";});

        $("#semi").attr('value', 'true');

    } else {

        $("div.opt label").each(function(){this.style.display = "block";});

        $("div.opt input").each(function(){this.style.display = "block";});

        $("#semi").attr('value', 'false');

    }

}



function sumprice(pocet_noci, ucitel_zdarma) {



    var deti = document.getElementById('skola_deti');

    var dospelych = document.getElementById('skola_dospelych');

    var skola_cena = document.getElementById('skola_cena');

    var cena_osoba = document.getElementById('cena_osoba_display');



    if (!deti || !dospelych || !skola_cena || !cena_osoba) {

        return false;

    }



    cena_osoba = cena_osoba.firstChild.nodeValue;



    deti = deti.value;

    dospelych = dospelych.value;



    // ucitel_zdarma - pokud je > 0 tak: udava pocet deti, za kolik je jeden ucitel zdarma

    if (ucitel_zdarma > 0) {

        var ucitelu_zdarma = Math.floor(deti / ucitel_zdarma);

        dospelych = dospelych - ucitelu_zdarma;



        if (dospelych<0) {

            dospelych = 0;

        }

    }



    skola_cena.value = (parseInt(deti)+parseInt(dospelych)) * cena_osoba * pocet_noci;

}



function changeStravovani(elem) {

    var cena_osoba = document.getElementById('cena_osoba');

    var cena_osoba_display = document.getElementById('cena_osoba_display');

    var str = document.getElementById('str');



    if (!cena_osoba || !cena_osoba_display || !str) {

        return false;

    }



    cena_osoba = cena_osoba.value;

    cena_osoba = parseInt(cena_osoba) + parseInt(elem.value);



    cena_osoba_display.firstChild.nodeValue = cena_osoba;



    for (var i=0; i<elem.options.length; i++) {

        if (elem.options[i].value == elem.value) {

            str.value = elem.options[i].text;

        }

    }

}



$(document).ready(function(){



    // hover efekt v eshope

    $("div#produkty div").hover(

        function(){

	       $(this).addClass("over");

        },

        function(){

	       $(this).removeClass("over");

	    }

    );

    

    // hover v terminech pobytu - seznam

    $("div.seznam-terminu").hover(

        function(){

	       $(this).addClass("over-nopointer");

        },

        function(){

	       $(this).removeClass("over-nopointer");

	    }

    );



    $("div#produkty div").mouseup(

        function(){

            window.location = this.childNodes[1].childNodes[0].href;

	    }

    );



    // aktualizacia obejdnavky

    $("a#aktualizovat").click(

        function(){

            $("input#akcia").attr({'value':'aktualizovat'});

            $("form#o_kosik").submit();

            

            return false;

	    }

    );



    // aktualizacia obejdnavky

    $("a#go-to-step-2").click(

        function(){

            $("input#akcia").attr({'value':'objednat'});

            $("form#previewform").submit();



            return false;

	    }

    );



    // aktualizacia (odebirani zbozi - resp.radku) obejdnavky

    $("a.odebrat-zbozi").click(

        function(){

            $("input#akcia").attr({'value':'odebrat' + this.rel});

            $("form#o_kosik").submit();



            return false;

	    }

    );



    // kontrola kontaktnych udajov v objednavke

    $("form#udaje").submit(

        function(){



            var submit = true;

            var mess   = "Vyplňte prosím pole %pole%.";

            

            $("input.req").each(

                function(){

                    if ($.trim(this.value) == '' && this.style.display != "none"){

                        label = $.trim(($("label[@for='" + this.name + "']").parent().text() == '')? $(this).parent().text() : $("label[@for='" + this.name + "']").parent().text());

                        label = mess.replace(/%pole%/, label.replace('*', ''));

                        alert(label);



                        submit = false;

                        return submit;

                    }

                }

            );

            return submit;

        }

    );



    // kontrola kontaktnych udajov v objednavke

    $("form#odeslani-obj-terminu").submit(

        function(){

            return window.confirm("Opravdu si přejete tuto objednávku odeslat?");

        }

    );

});



function goBack() {

    history.go(-1);

    return false;

}



function kontrolaRegistraceSkoly() {

    var elem;

    var povinne = new Array('sss_nazev_skoly', 'sss_adresa', 'sss_email', 'sss_telefon', 'sss_ic', 'sss_zpusob_uhrady', 'sss_cislo_uctu', 'sss_kod_banky', 'sss_ucitele');



    for (var i=0; i<povinne.length; i++) {

        elem = document.getElementById(povinne[i]);

        if (elem) {

            if (elem.value=='') {

                // element ma prazdnou hodnotu

                alert('Vyplňte všechny povinné údaje (označené hvězdičkou).');

                return false;

            }

        } else {

            // element nenalezen

            return false;

        }

    }



    return true;

}



// pouzivano misto (v norme Strict) zakazaneho target='_blank'

function external(url) {

	win = window.open(url);

	return (typeof(win)=='object') ? false : true;

}



// otevre nove okno - url se zjisti z parametru href

// pouzivano misto (v norme Strict) zakazaneho target='_blank'

function external_link(elem) {

	if (elem.getAttribute('href')) {

		return external(elem.getAttribute('href'));

	}

	return true;

}


