jQuery(function($){
	$("a[inplace=1]").live("click", function(event){
		// stops the link from loading
		event.preventDefault();
		
		// Adds an "active" class to the link
		$(this).addClass("active");
		
		var container = $(this).attr("inplace_container");
		
		$.ajax({
			type: "POST",
			url: "/j-query/index",
			data: "forward=" + $(this).attr("href") + "&inplace=1",
			success: function(data){
				$(container).replaceWith(data);
			}
		});
	});
	$("input[type=submit][inplace=1]").live("click", function(event){
		// stops the link from loading
		event.preventDefault();
		// Adds an "active" class to the link
		$(this).addClass("active");
		var formData = $(this).parents("form").serialize();
		
		var container = $(this).attr("inplace_container");
		var validationContainer = $(this).attr("validation_container");
		var urlAction = $(this).attr("inplace_action");
		
		$.ajax({
			type: "POST",
			url: urlAction,
			data: "inplace=1&" + formData,
			dataType: "json",
			error: function(response, desc, exceptionobj) {
				$(validationContainer).replaceWith(response.responseText);
			},
			success: function(data){
//				if (String(data).indexOf('class="errors"') != -1)
	//			{
		//			$(validationContainer).replaceWith(data);
			//	}
				//else
				//{
					if (data.redirect)
					{
						window.location.replace(data.redirect);
					}
					else
					{
						$(container).replaceWith(data.form);
					}
				//}
			}
		});
	});
})
