/*!
 * LiveForm v1.0.2
 * http://www.esencia.cz/
 *
 * Copyright 2010, Esencia.cz
 * Author Michal Suran, suran@esencia.cz
 *
 * Release: 2010-08-10 23:40
 */
 
 jQuery.extend({
    //esencia.liveForm: {
        esenciaLiveForm: {
            /** konfigurace **/
            controlErrorClass: 'ui-state-error',
            /** funkcnost **/
            handleAddError: function(el, msg){
                el = $(el);
                el.addClass(this.controlErrorClass);
                this.writeError(el, msg);
                this.afterAddError(el, msg);
                
            },
            handleRemoveError: function(el){
                el = $(el);
                el.removeClass(this.controlErrorClass);
                this.removeError(el);
                this.afterRemoveError(el);
            },
            writeError: function(el, msg){
                //existence UL pro chyby
                var form = el.parent('form');
                if(!form.has('ul.error').length){
                    form.prepend('<ul class="error"></ul>');
                }
                var errBox = $(form.children('ul.error'));
                var errLiId = 'err_li_'+el.attr('id');
                if(!errBox.has('li#'+errLiId).length){
                    errBox.append('<li id="'+errLiId+'" style="display: none;">'+msg+'</li>');
                }
                $("li#"+errLiId).fadeIn(400);
            },
            removeError: function(el){
                $("li#err_li_"+el.attr('id')).fadeOut(400, function(){
                    $(this).remove();
                });
            },
            afterAddError: function(el, msg){},
            afterRemoveError: function(el){}
        }
    //}
 });
 
 

