var mode = 0; //primary

function calc_mode() {
	var modes = ["primary", "secondary", "tertiary"];
	return modes[mode];
}

$(function() {
	$(".add").button();
	$(".edit").button();
	$(".delete").button().click(function() {
		var res = confirm("Are you sure you want to delete this item?");
		if (res)
			window.location.href=$(this).attr('href');
		else
			return false;
	});
	$(".view").button();
	$(".submit").button();
	
	$("#ingredients_table table").tablesorter();
	$("#effects_table table").tablesorter();
	
	$("#calc_ingredients tbody").find('tr').each(function(){
		$(this).click(function(){
			$('#'+calc_mode()).html($(this).text());
		});
	});
});

@@ -648,12 +648,237 @@
 );%0A%09%7D);%0A
+%09%0A%09$(%22#primary%22).click(function()%7B%0A%09%09$(this).text('--');%0A%09%09mode = 0;%0A%09%7D);%0A%09%0A%09$(%22#secondary%22).click(function()%7B%0A%09%09$(this).text('--');%0A%09%09mode = 1;%0A%09%7D);%0A%09%0A%09$(%22#tertiary%22).click(function()%7B%0A%09%09$(this).text('--');%0A%09%09mode = 2;%0A%09%7D);%0A
 %7D);%0A

Add events handler on selected ingredients