// kontrola zapsání věcí do formu
(function () {
    'use strict';
    window.addEventListener('load', function () {
        // nahraje všechny formy
        var forms = document.getElementsByClassName('needs-validation');
        // projedou se a zamezí se uložení
        var validation = Array.prototype.filter.call(forms, function (form) {
            form.addEventListener('submit', function (event) {
                if (form.checkValidity() === false) {
                    event.preventDefault();
                    event.stopPropagation();
                }
                form.classList.add('was-validated');
            }, false);
        });
    }, false);
})();

function clock(){
    //calculate angle
    var d, h, m, s;
    d = new Date;

    h = 30 * ((d.getHours()) + d.getMinutes() / 60);
    m = 6 * d.getMinutes();
    s = 6 * d.getSeconds();

    //move hands
    setAttr('h-hand', h);
    setAttr('m-hand', m);
    setAttr('s-hand', s);
    setAttr('s-tail', s+180);

    //display time
    h = d.getHours();
    m = d.getMinutes();
    s = d.getSeconds();

    setText('sec', s);
    setText('min', m);
    setText('hr', h);

    //call every second
    setTimeout(clock, 1000);

};

function setAttr(id,val){
    var v = 'rotate(' + val + ', 70, 70)';
    document.getElementById(id).setAttribute('transform', v);
};

function setText(id,val){
    if(val < 10){
        val = '0' + val;
    }
    document.getElementById(id).innerHTML = val;
};

window.onload=clock;