function addRecipeBox(idRecipe, idUser) {
	if (idUser==undefined || idUser==0) {
		alert('To use the recipe box, you must first log in to your account');
	}
	else {
		$.getJSON('/ajax/add-bookmark.html',{id:idRecipe, type:'recipe'},
			function(data) {
				//window.location.reload();
				$('#recipeboxicon'+idRecipe).html('<a href="/recipes/recipe-box.html"><img src="/images/ver2/favoriteicon.gif" width="23" height="18" alt="in my recipe box" title="in my recipe box"/></a>');
				$('#recipeboxlink'+idRecipe).html(makeRemoveRecipeBookmarkLink(idRecipe, idUser));
				bookmarkAlert(data.text);				
			}
		);
	}
}

function removeBookmark(idBookmark, idUser, typeBookmark) {
	if (idUser==undefined || idUser==0) {
		alert('To use the recipe box, you must first log in to your account');
	} else {
		var txt;
		if (typeBookmark=="recipe") {
			txt = "Remove this recipe from my recipe box?";
		}
		else if (typeBookmark=="article") {
			txt = "Remove this article from my favorites";
		}
		
		if (idBookmark!=undefined && confirm(txt)) {
			$.getJSON('/ajax/remove-bookmark.html',{id:idBookmark, type:typeBookmark},
			function(data) {
				//window.location.reload();
				if (typeBookmark=="recipe") {
					$('#recipeboxicon'+idBookmark).empty();
					$('#recipeboxlink'+idBookmark).html(makeAddRecipeBookmarkLink(idBookmark, idUser));
				}
				bookmarkAlert(data.text);
			}
			);
		}
	}
}

function bookmarkAlert(msg) {
				$('<div></div>').attr('id','bookmarkalert').appendTo('body');
				$('#bookmarkalert').hide();
				// center the popup
				var sTop = window.pageYOffset || document.documentElement && document.documentElement.scrollTop ||	document.body.scrollTop;
				var wHeight = window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight;
				var elHeight = $('#bookmarkalert').height();
		    	var elTop = sTop + (wHeight / 2) - (elHeight / 2);
				$('#bookmarkalert').css({
				          position: 'absolute',
				          marginTop: '0',
				          top: elTop
				        });
				$('#bookmarkalert').html(msg);
				$('#bookmarkalert').fadeIn('slow', function() {
					$(this).animate({opacity: 1.0}, 3000);
					$(this).fadeOut('slow', function() {
						$(this).remove();
						});
					
				 });

}

function makeRemoveRecipeBookmarkLink(idRecipe, idUser) {
	return '<a href="#" onclick="removeBookmark('+idRecipe+', '+idUser+', \'recipe\'); return false;">remove from recipe box</a>';
}

function makeAddRecipeBookmarkLink(idRecipe, idUser) {
	return '<a href="#" onclick="addRecipeBox('+idRecipe+', '+idUser+'); return false;">add to my recipe box</a>';
}