// JS pro verzi s pouzitim jQueryBlock UI 
$(document).ready(function(){    
    bind_demand_form();
});


function bind_demand_form() {
    $('#dostupnost_form').submit(function(event) { 
        if (event.result == false) return; // doslo k chybe -> plugin js-form-required-fields ?
        event.preventDefault();       
        var form = $(this);
        $.post(window.location, $(this).serialize() + '&dostupnost_query=1', function(data) {
            $('.msg', form).html(data);
            $.unblockUI({fadeOut: 4000}); 
        });        
    });
    
    
    $('#poslat_dotaz').click(function(event) {    
        event.preventDefault();           
        $.blockUI({
            message: $('#dostupnost_form'),
            css: {
                padding: '2em',
                border : 'none',
                textAlign: 'left',
                width: '350px',
                top: '100px',
                left: '35%'
            },
            overlayCSS: {
                backgroundColor: '#222',
                opacity : 0.6
            },
            focusInput: true,
            fadeOut:  1000
        });
    });

    $('#close_dostupnost_form').click(function(event){
        event.preventDefault();
        $.unblockUI();
    });
    
    $('#dostupnost_form input[type=text]').focus(function(){
        if ($(this).attr('label') != "") {
            $(this).attr('label',$(this).val());
            $(this).val('');
        }
    });
    
    $('#dostupnost_form input[type=text]').blur(function(){
        if ($(this).attr('label') != "" && $(this).val() == "") {
            $(this).val($(this).attr('label'));
        }
    });
}
