$(document).ready(function() {           

        /*zalamovani textu*/
        var el = $('#content');
        el.html(el.html().replace(/ a /g, ' a&nbsp;'));
        el.html(el.html().replace(/ i /g, ' i&nbsp;'));
        el.html(el.html().replace(/ k /g, ' k&nbsp;'));
        el.html(el.html().replace(/ K /g, ' K&nbsp;'));
        el.html(el.html().replace(/ o /g, ' o&nbsp;'));
        el.html(el.html().replace(/ s /g, ' s&nbsp;'));
        el.html(el.html().replace(/ u /g, ' u&nbsp;'));
        el.html(el.html().replace(/ v /g, ' v&nbsp;'));
        el.html(el.html().replace(/ z /g, ' z&nbsp;'));
        el.html(el.html().replace(/ve /g, 've&nbsp;'));
        el.html(el.html().replace(/Ve /g, "Ve&nbsp;"));
        el.html(el.html().replace(/na /g, "na&nbsp;"));
        el.html(el.html().replace(/Na /g, "Na&nbsp;"));
        el.html(el.html().replace(/nad /g, "nad&nbsp;"));
        el.html(el.html().replace(/Nad /g, "Nad&nbsp;"));
        el.html(el.html().replace(/pod /g, "pod&nbsp;"));
        el.html(el.html().replace(/Pod /g, "Pod&nbsp;"));
        el.html(el.html().replace(/za /g, "za&nbsp;"));
        el.html(el.html().replace(/Za /g, "Za&nbsp;")); 
        el.html(el.html().replace(/do /g, "do&nbsp;"));
        el.html(el.html().replace(/Do /g, "Do&nbsp;"));
        el.html(el.html().replace(/před /g, "před&nbsp;"));
        el.html(el.html().replace(/Před /g, "Před&nbsp;"));
        el.html(el.html().replace(/pro /g, "pro&nbsp;"));
        el.html(el.html().replace(/Pro /g, "Pro&nbsp;"));
        el.html(el.html().replace(/se /g, "se&nbsp;"));
        el.html(el.html().replace(/Se /g, "Se&nbsp;"));
        el.html(el.html().replace(/při /g, "při&nbsp;"));
        el.html(el.html().replace(/Při /g, "Při&nbsp;"));
       
        /*form validation*/
        $('.valid1 .btn').click(function(){
                $('#messageError', $(this).parents('form')).remove();
                var error = '';

                $('.require', $(this).parents('form')).each(function(){
                        /* Text input */
                        if($(this).attr('type') == 'text') {
                                if($(this).hasClass('requireMail')) { /* E-mails */
                                        if($(this).val() == '') {
                                                error += '<p>Pole <strong>'+ $(this).parent().prevAll('label').html().replace(':', '') +'</strong> není vyplněno. Zkontrolujte prosím, zda jste údaj zadali správně.</p>';
                                                $(this).parent().prevAll('label').addClass('error');
                                                $(this).parent().addClass('error');
                                        }
                                        else {
                                                var email = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
                                                if(!email.test($(this).val())) {
                                                        error += '<p><strong>E-mail</strong> není zadán ve správném tvaru (např. jmeno@server.cz)</p>';
                                                        $(this).parent().prevAll('label').addClass('error');
                                                        $(this).parent().addClass('error');                                                        
                                                }
                                                else {
                                                        $(this).parent().prevAll('label').removeClass('error');
                                                        $(this).parent().removeClass('error');                                        
                                                }                                                
                                        }
                                }
                                else { /* Other */
                                        if($(this).val() == '') {
                                                error += '<p>Pole <strong>'+ $(this).parent().prevAll('label').html().replace(':', '') +'</strong> není vyplněno. Zkontrolujte prosím, zda jste údaj zadali správně.</p>';
                                                $(this).parent().prevAll('label').addClass('error');
                                                $(this).parent().addClass('error');
                                        }
                                        else {
                                                $(this).parent().prevAll('label').removeClass('error');
                                                $(this).parent().removeClass('error');                                        
                                        }
                                }
                        }
                        
       
                })
                /* Textarea */                        
                if(document.getElementById('textarea').value == ''){
                        error += '<p><strong>Vyplňte prosím '+ $(this).parent().prevAll('label').html() +'.</strong></p>';
                        $('#textarea').parent().prevAll('label').addClass('error');
                        $('#textarea').parent().addClass('error'); 
                }else{
                        $('#textarea').parent().prevAll('label').removeClass('error');
                        $('#textarea').parent().removeClass('error');                 
                }
                                   
                if(error != '') {
                        $(this).parents('form').prepend('<div class="clearfix"><div id="messageError"><div id="messageErrorIn"><p>Pole označené tímto symbolem nejsou správně vyplněná</p></div></div></div>');
                        return false;
                }
        }); 

});

