function onShoppingListReady(){
    $('.printShoppingList').click(function (e) {
        e.preventDefault();
        window.open('/recipes/shoppinglist.cfm', 'printList', 'width=700,height=555,left=0,top=0,scrollbars=1;');
    });	   
}
function addShopping(recipeID, ingredients_OnHand){
	try{
		var d = new Object;
		d.doAction = 'addToShoppingList';
		d.recipeID = recipeID;
		d.ingredients_OnHand = ingredients_OnHand;
		$.post('/includes/framework/pageProcessor.cfm', d, function(data){
			// The item will always exists, because you can only add the current recipe
			var recipeName = $('#listItem'+recipeID+' a').html();
			$('#listItem'+recipeID+' div').attr('class', 'removeBtn');
			$('#listItem'+recipeID+' div').html('<a href="/includes/framework/pageProcessor.cfm?doAction=deleteFromShoppingList&amp;RecipeID='+recipeID+'" onclick="return deleteShopping('+recipeID+', '+recipeID+');">'+recipeName+'</a>');
			$('#listItem'+recipeID+' div strong').html('Remove');
		    $('#printListButton').removeClass('printListToggle');
		});
		return false;
	}
	catch(e){
		return true;
	}

}

function deleteShopping(recipeID, formRecipeID){
	try{
		d = new Object;
		d.doAction = 'deleteFromShoppingList';
		d.recipeID = recipeID;
		$.post('/includes/framework/pageProcessor.cfm', d, function(data){
			data = $.trim(data);
			valid = data.split('|')[0];
			msg = data.split('|')[1];
			// For the most part, we are going to want to just delete the li
			if(recipeID != formRecipeID){
				$('#listItem'+recipeID).remove();
			}
			// If they are removing the current recipe, we want to swap it out with a add option.
			else {
				var recipeName = $('#listItem'+recipeID+' a').html();
				$('#listItem'+recipeID+' div').attr('class', 'addBtn');
				$('#listItem'+recipeID+' div').html('<a href="/includes/framework/pageProcessor.cfm?doAction=addToShoppingList&RecipeID='+recipeID+'" onclick="return addShopping('+recipeID+', \'\');">'+recipeName+'</a>');
				$('#listItem'+recipeID+' div strong').html('Add');
			}
				var listLength = $('#shoppingListUL li').length;
		
			if(listLength == 1){
				if($('#shoppingListUL >li > div').hasClass('addBtn')){
					$('#printListButton').addClass('printListToggle');
				}			   
			}
				
	
			
			listDone = false;
		}); 
		return false;
	}
	catch(e){
		return true;
	}
}



