﻿
$(document).ready(function () {
    // top produkt navigation
    selNav = lastNav = $('#nav .act');
    $('#nav').children().mouseenter(function () {
        lastNav.removeClass();
        lastNav = $(this).addClass('act');
    });
    $('#nav').mouseleave(function () {
        lastNav.removeClass();
        selNav.addClass('act');
        lastNav = selNav;
    });

    // show/hide input tooltip
    $('.jsInputLabel[name!="Heslo"]').focus(function () {
        if (this.value == this.getAttribute('title')) this.value = '';
    }).blur(function () {
        if (this.value == '') this.value = this.getAttribute('title');
    }).each(function () {
        if (this.value == '') {
            this.value = this.getAttribute('title');
        }
    });

    // auto send produkt filters
    $('#sortPanel input, #sortPanel select').change(function () {
        this.form.submit();
    });
    $('#sortPanel input[type="checkbox"]').click(function () {
        this.form.submit();
    });

    // u starych IE nejde menit atribut type u elementu input,
    // proto vytvorime novy input element typu text, ktery bude obsahovat
    // popisek pro pole s heslem, a kdyz dostane focus, tak ho skryjeme
    // a focus predame poli, co obsahuje heslo

    // input pro zadavani hesla
    passwordInput = $('.jsInputLabel[name="Heslo"]').first();

    // vytvorime input s popiskem
    passwordInput.parent().append('<input type="text" name="desc_password" value="" title="" />');
    descPasswordInput = $('input[name="desc_password"]').first();
    descPasswordInput.val(passwordInput.attr("title"));
    descPasswordInput.attr("title", passwordInput.attr("title"));

    // skryjeme box pro zadavani hesla
    passwordInput.hide();

    descPasswordInput.focus(function () {
        descPasswordInput.hide();
        passwordInput.show();
        passwordInput.focus();
    });

    passwordInput.blur(function () {
        if (passwordInput.val() == '') {
            passwordInput.hide();
            descPasswordInput.show();
        }
    });

    // potvrzeni zruseni objednavky
    $("#zrusitUlozenouObjednavku button").click(function () {
        return confirm("Opravdu chcete tuto objednávku stornovat?");
    });
});

