var wForm = {
		
    
    
    registerJSONForm : function(cssSelector, options) {
           
            options = $.extend({
                'success' : function(response){
                        
                        if (response.message) {
                                Utils.notify(response.message);
                        }
                        console.log(response);
                        console.log(options);
                        if (response.content && options.container) {
                                $(options.container).html(response.content);
                        }
                },
                'error' : function(response){
                        if (response.message) {
                                Utils.notify(response.message, 'bad');
                        }

                        if (response.form && options.container) {
                                $(options.container).html(response.form);

                        }
                        else if (response.length > 0) {
                                
                                $(cssSelector + ' .message').remove();
                                
                                for (var i = 0; i < response.length; i++) {
                                        $(cssSelector + '_' + response[i].fieldName).after('<div class="message">' + response[i].message + '</div>')
                                }
                        }

                        wForm.registerJSONForm(cssSelector, options);
                }
            }, options);
                  
            
            
            $(cssSelector).unbind();
            $(cssSelector).submit(function(e){
                
                
                $.post($(cssSelector).attr('action'), $(cssSelector).serialize(), function(data){
                 
                        if (data.status && data.status == 1) {
                                options.success.call(this, data);
                        }
                        else {
                                options.error.call(this, data);
                        }
                }, 'json');
                 
                
                e.preventDefault();
            });
    }
    
};
