/*
 * jQuery Ajax Link Plugin
 * version: 1.0 (10-NOV-2009)
 * @requires jQuery v1.2.2 or later
 * @Author Ernesto Chicas
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

;(function($){
	$.fn.ajaxLink = function(options){
		
		var defaults = {
			target		: "#Result",
			dataType	: "html",
			method		: "get",
			cache		: false,
			async		: true,
			beforeSend	: false,
			complete	: false,
			error		: false
			
		};
		var options = $.extend(defaults, options);
		
		return this.each(function(){
			$(this).click(function(){
				$.ajax({
					type		: options.method,
					url			: $(this).attr('href'),
					dataType 	: options.dataType,
					cache		: options.cache,
					async		: options.async,
					data		: $(this).attr('data'),
					beforeSend	: function(){ 
									//confirm("test");
									$('#Result').html('<table border="0" cellpadding="0" style="position:relative;top:50px" cellspacing="0" align="center"><tr align="center"><td align="center"><img src="images/load.gif"/></td></tr></table>');
									 
									if(options.beforeSend) options.beforeSend(); 
					},
					complete	: function(XMLHttpReq, textStatus){
									if(options.complete) options.complete(XMLHttpReq, textStatus);
					},
					success		: function(data){
							$('#Result').html(data);
					},
					error		: function (event, request, settings){ 
									if (options.error) options.error(event, request, settings); 
					}
				});
				return false;
			});
		});
	};
})(jQuery);



;(function($){
	$.fn.ajaxPost = function(options){
		
		var defaults = {
			target		: "#Result",
			dataType	: "html",
			method		: "post",
			cache		: false,
			async		: true,
			beforeSend	: false,
			complete	: false,
			error		: false
			
		};
		var options = $.extend(defaults, options);
		
		return this.each(function(){
			$(this).submit(function(){
				$.ajax({
					type		: options.method,
					url			: $(this).attr('action'),
					dataType 	: options.dataType,
					cache		: options.cache,
					async		: options.async,
					data		: $(this).serialize(),
					beforeSend	: function(){ 
									$('#Result').html('<table border="0" cellpadding="0" style="position:relative;top:50px" cellspacing="0" align="center"><tr align="center"><td align="center"><img src="images/load.gif"/></td></tr></table>');
									if(options.beforeSend) options.beforeSend(); 
					},
					complete	: function(XMLHttpReq, textStatus){
									if(options.complete) options.complete(XMLHttpReq, textStatus);
					},
					success		: function(data){
									$('#grid').load('plugins/Tgrid.php');
									$("#request").load("plugins/request.php");
									$('#Result').html(data);
					},
					error		: function (event, request, settings){ 
									if (options.error) options.error(event, request, settings); 
					}
				});
				return false;
			});
		});
	};
})(jQuery);

;(function($){
	$.fn.post = function(){
		//confirm('d');
		$.post($(this).attr('action'), $(this).serialize(),
		   function(data) {
			   $('#grid').load('plugins/Tgrid.php');
			 $('#Result').html(data);
			 $("#request").load("plugins/request.php");
		});
		return false;
	};
})(jQuery);
function getCurrentAdd(){
	$.post('plugins/getCurrentAdd.php', function(data) {
		$('#Result').load(data+"index.php?op=show&view=tree");
	});
}
;(function($){
	$.fn.tree_post = function(){
		$.post($(this).attr('action'), $(this).serialize(),
		   function(data) {
			 getCurrentAdd();
			 $("#"+$(this).attr("target")).html(data);
			 
		});
		return false;
	};
})(jQuery);
