$(function(){ingredientCount=1;ingredientOptionalCount=1;stepCount=2;newIngredientId=0;$("#addIngredientRow").click(function(){var a=$("#ingredientValue").val();if(newIngredientId>0)a=newIngredientId;else newIngredientId=a;var d=$("#Recipe_Id").val(),e=$("#ingredientDiv"),b="ingredient"+ingredientCount,c=$("<div></div>").attr("id",b);c.html('<p class="ingredTitle">Ingredient '+ingredientCount+' <span class="noteLink">(<a href="javascript:;" onclick="removeIngredientRow(\''+b+"')\">Remove ingredient "+ingredientCount+'</a>)</span></p><input id="Recipe_Ingredient_Index" name="Recipe.Ingredient.Index" type="hidden" value="'+a+'" /><input id="Recipe_Ingredient_'+a+'__RecipeId" name="Recipe.Ingredient['+a+'].RecipeId" type="hidden" value="'+d+'" /><input id="Recipe_Ingredient_'+a+'__Optional" name="Recipe.Ingredient['+a+'].Optional" type="hidden" value="False" /><label for="Recipe.Ingredient['+a+'].Title">Ingredient Name:</label><input id="Recipe_Ingredient_'+a+'__Title" name="Recipe.Ingredient['+a+'].Title" type="text" size="60" /><br /><label for="Recipe.Ingredient['+a+'].Quantity">Quantity:</label><input id="Recipe_Ingredient_'+a+'__Quantity" name="Recipe.Ingredient['+a+'].Quantity" type="text" /><br /><label for="Recipe.Ingredient['+a+'].GroupTitle">Group title:</label><input id="Recipe_Ingredient_'+a+'__GroupTitle" name="Recipe.Ingredient['+a+'].GroupTitle" type="text" size="60" /><br /><label for="Recipe.Ingredient['+a+'].Measurement">Measurement:</label><select name="Recipe.Ingredient['+a+'].Measurement"><option selected value="">Select a measurement</option><optgroup label="Weight"><option value="g">Grams</option><option value="kg">Kilograms</option><option value="oz">Ounces</option><option value="lb">Pounds</option><option value="imperial pint weight">Pint (Imperial)</option><option value="usa pint weight">Pint (US)</option></optgroup><optgroup label="Liquids"><option value="ml">Millelitre</option><option value="litre">Litre</option><option value="usa fl oz">Fluid Ounces (US)</option><option value="imperial fl oz">Fluid Ounces (Imperial)</option><option value="juice">Juice(s)</option></optgroup><optgroup label="Size"><option value="small">Small</option><option value="medium">Medium</option><option value="large">Large</option></optgroup><optgroup label="Thickness"><option value="thin slice">Thin slice(s)</option><option value="medium slice">Medium slice(s)</option><option value="thick slice">Thick slice(s)</option></optgroup><optgroup label="Other"><option value="bunch">Bunch</option><option value="bottle">Bottle</option><option value="box">Box</option><option value="bulb">Bulb</option><option value="can">Can</option><option value="clove">Clove</option><option value="cube">Cube</option><option value="cup">Cup</option><option value="drizzle">Drizzle</option><option value="drop">Drop</option><option value="glass">Glass</option><option value="handful">Handful</option><option value="head">Head</option><option value="jar">Jar</option><option value="knob">Knob</option><option value="packet">Packet</option><option value="piece">Piece</option><option value="pinch">Pinch</option><option value="imperial pint">Pint (Imperial)</option><option value="usa pint">Pint (US)</option><option value="rib">Rib</option><option value="scoop">Scoop</option><option value="sheet">Sheet</option><option value="sprig">Sprig</option><option value="sprinkle">Sprinkle</option><option value="stalk">Stalk</option><option value="stick">Stick</option><option value="tablespoon">Tablespoon</option><option value="heaped tablespoon">Tablespoon (heaped)</option><option value="teaspoon">Teaspoon</option><option value="heaped teaspoon">Teaspoon (heaped)</option><option value="tin">Tin</option><option value="wedge">Wedge</option><option value="zest">Zest</option></optgroup></select><br /><label for="Recipe.Ingredient['+a+'].Description">Additional note:</label><input id="Recipe_Ingredient_'+a+'__Description" name="Recipe.Ingredient['+a+'].Description" size="60" type="text" />');e.append(c);ingredientCount+=1;newIngredientId++});$("#addOptionalIngredientRow").click(function(){var a=$("#ingredientValue").val();if(newIngredientId>0)a=newIngredientId;else newIngredientId=a;var d=$("#Recipe_Id").val(),e=$("#optionalIngredientDiv"),b="optionalIngredient"+ingredientOptionalCount,c=$("<div></div>").attr("id",b);c.html('<p class="ingredTitle">Optional ingredient '+ingredientOptionalCount+' <span class="noteLink">(<a href="javascript:;" onclick="removeOptionalIngredientRow(\''+b+"')\">Remove optional ingredient "+ingredientOptionalCount+'</a>)</span></p><input id="Recipe_Ingredient_Index" name="Recipe.Ingredient.Index" type="hidden" value="'+a+'" /><input id="Recipe_Ingredient_'+a+'__RecipeId" name="Recipe.Ingredient['+a+'].RecipeId" type="hidden" value="'+d+'" /><input id="Recipe_Ingredient_'+a+'__Optional" name="Recipe.Ingredient['+a+'].Optional" type="hidden" value="True" /><label for="Recipe.Ingredient['+a+'].Title">Ingredient Name:</label><input id="Recipe_Ingredient_'+a+'__Title" name="Recipe.Ingredient['+a+'].Title" type="text" size="60" /><br /><label for="Recipe.Ingredient['+a+'].Quantity">Quantity:</label><input id="Recipe_Ingredient_'+a+'__Quantity" name="Recipe.Ingredient['+a+'].Quantity" type="text" /><br /><label for="Recipe.Ingredient['+a+'].GroupTitle">Group title:</label><input id="Recipe_Ingredient_'+a+'__GroupTitle" name="Recipe.Ingredient['+a+'].GroupTitle" type="text" size="60" /><br /><label for="Recipe.Ingredient['+a+'].Measurement">Measurement:</label><select name="Recipe.Ingredient['+a+'].Measurement"><option selected value="">Select a measurement</option><optgroup label="Weight"><option value="g">Grams</option><option value="kg">Kilograms</option><option value="oz">Ounces</option><option value="lb">Pounds</option><option value="imperial pint weight">Pint (Imperial)</option><option value="usa pint weight">Pint (US)</option></optgroup><optgroup label="Liquids"><option value="ml">Millelitre</option><option value="litre">Litre</option><option value="usa fl oz">Fluid Ounces (US)</option><option value="imperial fl oz">Fluid Ounces (Imperial)</option><option value="juice">Juice(s)</option></optgroup><optgroup label="Size"><option value="small">Small</option><option value="medium">Medium</option><option value="large">Large</option></optgroup><optgroup label="Thickness"><option value="thin slice">Thin slice(s)</option><option value="medium slice">Medium slice(s)</option><option value="thick slice">Thick slice(s)</option></optgroup><optgroup label="Other"><option value="bunch">Bunch</option><option value="bottle">Bottle</option><option value="box">Box</option><option value="bulb">Bulb</option><option value="can">Can</option><option value="clove">Clove</option><option value="cube">Cube</option><option value="cup">Cup</option><option value="drizzle">Drizzle</option><option value="drop">Drop</option><option value="glass">Glass</option><option value="handful">Handful</option><option value="head">Head</option><option value="jar">Jar</option><option value="knob">Knob</option><option value="packet">Packet</option><option value="piece">Piece</option><option value="pinch">Pinch</option><option value="imperial pint">Pint (Imperial)</option><option value="usa pint">Pint (US)</option><option value="rib">Rib</option><option value="scoop">Scoop</option><option value="sheet">Sheet</option><option value="sprig">Sprig</option><option value="sprinkle">Sprinkle</option><option value="stalk">Stalk</option><option value="stick">Stick</option><option value="tablespoon">Tablespoon</option><option value="heaped tablespoon">Tablespoon (heaped)</option><option value="teaspoon">Teaspoon</option><option value="heaped teaspoon">Teaspoon (heaped)</option><option value="tin">Tin</option><option value="wedge">Wedge</option><option value="zest">Zest</option></optgroup></select><br /><label for="Recipe.Ingredient['+a+'].Description">Additional note:</label><input id="Recipe_Ingredient_'+a+'__Description" name="Recipe.Ingredient['+a+'].Description" size="60" type="text" />');e.append(c);ingredientOptionalCount+=1;newIngredientId++})});function removeIngredientRow(a){ingredientCount-=1;newIngredientId--;var c=document.getElementById("ingredientDiv"),b=document.getElementById(a);c.removeChild(b)}function removeOptionalIngredientRow(a){ingredientOptionalCount-=1;newIngredientId--;var c=document.getElementById("optionalIngredientDiv"),b=document.getElementById(a);c.removeChild(b)}function addStep(){var e=$("#stepDiv"),d=stepCount,a=stepCount-1,c="step"+stepCount,b=$("<div></div>").attr("id",c);b.html('<p class="ingredTitle">Step '+stepCount+' <span class="noteLink">(<a href="javascript:;" onclick="removeStep(\''+d+'\')"><img src="/content/images/remove.png" alt="remove step" />Remove step '+stepCount+'</a>)</span></p><label for="Step_'+a+'__Content">Step instruction</label><textarea id="Step_'+a+'__Content" name="Step['+a+'].Content" cols="63" rows="7"></textarea><br /><label for="uploadedFile'+stepCount+'">Photograph of step (optional) </label><input id="uploadedFile'+stepCount+'" name="uploadedFile" onchange="fileSelected()" type="file" size="50" /><div class="clear" />');e.append(b);stepCount+=1}function removeStep(b){var a=parseInt(b);jConfirm("Are you sure you want to remove step "+a+"?","Remove step",function(g){if(g){stepCount-=1;for(a;a<stepCount;a++){var d=a+1,e=$("#step"+d);if(e!=null){e.attr("id","step"+a);var c=e.html(),f=a-1;c=c.replace("Step_"+a,"Step_"+f);c=c.replace("Step_"+a,"Step_"+f);c=c.replace("Step["+a+"]","Step["+f+"]");c=c.replace("step "+d,"step "+a);c=c.replace("step"+d,"step"+a);c=c.replace("Step "+d,"Step "+a);c=c.replace("removeStep('"+d+"')","removeStep('"+a+"')");c=c.replace("></textarea>",">"+$("#Step_"+a+"__Content").val()+"</textarea>");e.html(c)}}$("#step"+b).remove()}else return false})};
