/*
 * PostBackJSON (for jQuery)
 * version: 1.0 (12/03/2009)
 * @requires jQuery v1.2 or later
 *
  *
 * Licensed under the MIT:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Copyright 2009 Byss.pl
 *
 */
 
(function($) {
	
  $.postJSON = function() {
		
  }

  /*
   * Public, $.postJSON methods
   */

  $.extend($.postJSON, {
		
		
	});	
	
  $.fn.postJSON = function(options) {
		
		_self = $(this);
		_form = getObject(options.form);
		_update = getObject(options.update);
		
		getObject('faction').val(options.action);
		
    options = $.extend({
			dataType: "json",
			beforeSubmit:  function (){
				activateProgress(_self);
			},
			success: function (jsonData, responseText) {
				deactivateProgress();
				
				if (jsonData.feedback){
					
						_update.dialog('close');
						
						if( options.callback )
							options.callback.apply();							
						
						if (jsonData.success){
							jQuery.showDialogFeedback(jsonData.message, jsonData.width, 'success');					
						}	
					
					
					
				}else{
					
					if (options.debug == 1)
						alert(jsonData.content);
					
					if (_update)
						_update.html(jsonData.content);
					
				}
				
				//unbind submit event
				if (options.unbind)
					_form.unbind('submit');
				
			}
    }, options || {});
		
		_form.submit(function(){
			
			$(this).ajaxSubmit(options);
			
			return false;
			
		});
					
		_form.submit();
		
	}
})(jQuery);

