/*
 *	@description:
 *
 */
jQuery(document).ready(function(){
    (function(jQuery){
        jQuery.fn.validator = function(params) {
            var options = {
                url         : '',
                errorplace  : '',
                type        : 'POST',
                onSuccess   : null,
                params      : null
            }
           jQuery.extend(options, params);
           var formid = jQuery(this).attr("id"); 
           if(options.params == null) {               
               var formparams = jQuery('#'+formid).serialize();
           } else {
               var formparams = options.params;
           }
           jQuery('#'+options.errorplace).html('');
           jQuery('#'+formid).css('opacity','0.3');
           ajax = true;
           jQuery.ajax({
               type: options.type,
               data: formparams,
               url: options.url,
               success: function(ret) {
                   jQuery('#'+formid).css('opacity','1');
                   if(typeof ret.errortext == 'undefined') {
                       if(jQuery.isFunction(options.onSuccess)) {
                           options.onSuccess();
                       } else {
                           alert('Sikeres művelet');
                       }
                   } else {
                       ajax = false;
                       jQuery('#'+options.errorplace).html(ret.errortext);
                       //jQuery('#'+options.errorplace).animate({scrollTop:0}, 'slow');
                       var offs = jQuery('#'+formid).offset();
                       jQuery('html, body').animate({scrollTop:offs.top}, 'fast');
                   } 
               }
           });
         
        }
    })(jQuery);
});
