// /root/js/json_parse.js
// Last Updated : 05 December 2006

// These functions parse the returned JSON array and present the information
// in a table to be put in the search box

// Parses the JSON array into a product list
function create_none()
{
	aref = document.createElement("a");
	p = document.createElement("p");
	if(sectionID>0)
       	aref.href = "javascript:MA_create('recipe','recipeid=" + sectionID  +"');"; 
	else 
		aref.href = "javascript:MA_create('diary','');";

	aref.appendChild(document.createTextNode('click here'));	
	p.innerHTML='None of these - please refine your search or <a href="'+aref+'">click here</a> to manually add a new line';
	return p;
}
function productList(parent,arraylist) {
	// Create the table to display the product data
	table = document.createElement("table");
	table.setAttribute("cellpadding","0");
	table.setAttribute("cellspacing","0");
	tbody = document.createElement("tbody");
	
	// If there are no returned results.
	if (arraylist == null) 
	{
		tr = document.createElement("tr");
		td = document.createElement("td");
		
		// Create a link
		aref = create_none();
		
		// Append to document
		td.appendChild(aref);
		tr.appendChild(td);
		tbody.appendChild(tr);
	}
	else { // Otherwise there are results	
		
		// Parse through the JSON array
		for(x=0; x<arraylist.length; x++) 
		{
			// Create a new row
			tr = document.createElement("tr");
			td = document.createElement("td");
			
			// Create a link
			aref = document.createElement("a");
			if (arraylist[x].product_id < 0 ) 
			{
				if(arraylist[x].product_description.substring(0,7)=="Recipe ")
				{
				aref.className = "search_product_nonbarcode";
				aref.href = "process.jsp?section=diary&action=&subaction=search&searchtype=found&recipeid=" + Math.abs(arraylist[x].product_id);
				aref.appendChild(document.createTextNode(arraylist[x].product_description + ' ' + ax_entity('&dagger;') ));
					
				}
				else
				{
				aref.className = "search_product_nonbarcode";
				//aref.href = "process.jsp?section=diary&action=&subaction=search&searchtype=found&userproductid=" + Math.abs(arraylist[x].product_id);
					aref.href = "javascript:SearchServings(" + arraylist[x].product_id   + "," + arraylist[x].wizard_id +")";
				}
	        } 
			else {
				//aref.href = "process.jsp?section=diary&action=&subaction=search&searchtype=found&productid=" + arraylist[x].product_id;
				if(section=='compare')
					aref.href ="/process.jsp?section=compare&action=1&subaction=search&searchtype=found&productid=" + arraylist[x].product_id  + "&searchclass=barcode";
				else
				
					aref.href = "javascript:SearchServings(" + arraylist[x].product_id   + "," + arraylist[x].wizard_id +")";
			}
			
			if (arraylist[x].mine == "1") 
			{
				aref.className = "search_product_mine";
			}
			
			// Add in description
			aref.appendChild(document.createTextNode(arraylist[x].product_description));
			
			// Add to document structure
			td.appendChild(aref);
			if (arraylist[x].product_id < 0 ){
				td.appendChild(document.createTextNode(ax_entity('&dagger;')));
			}			
			tr.appendChild(td);
			
			tbody.appendChild(tr);
		}
		
		tr = document.createElement("tr");
		td = document.createElement("td");
		
		aref = create_none();
		
		// Append to document
		td.appendChild(aref);
		tr.appendChild(td);
		tbody.appendChild(tr);
	}
	
	table.appendChild(tbody);
	// Add table to the parent
	parent.appendChild(table);
	

	
	
	
	
	
}

// Parses the JSON array into an exercise list
function exerciseList(parent,arraylist) {
	// Create a table to display the data
	table = document.createElement("table");
	table.setAttribute("cellpadding","0");
	table.setAttribute("cellspacing","0");
	tbody = document.createElement("tbody");
		
	// Parse the JSON array
	for(x=0; x<arraylist.length; x++) 
	{
		// Create a new row
		tr = document.createElement("tr");
		td = document.createElement("td");
		
		// Create a new link
		aref = document.createElement("a");
		
		// Only if bottom level
		if (arraylist[x].bl != "-1") {
			//aref.href = "/process.jsp?section=diary&action=&subaction=energyout&item=" + arraylist[x].name + "&kcal=" + arraylist[x].kph;
			aref.href = "javascript:drawExerciseBoxSingle('" + arraylist[x].name + "'," + arraylist[x].kph + ")";
			
		} else {
			aref.href = "javascript:SearchExerciseBL(" + arraylist[x].id + ",'" + arraylist[x].name + "');";
		}
		
		// Add in the name
		aref.appendChild(document.createTextNode(arraylist[x].name));
		td.appendChild(aref);
		tr.appendChild(td);
		
		// Only if bottom level
		if (arraylist[x].bl != "-1") {
			// Add in the kcal details in a new column
			td = document.createElement("td");
			p = document.createElement("p");
			p.className = "kcalperhour";
			p.appendChild(document.createTextNode(arraylist[x].kph + "kcal/hour"));
			
			td.appendChild(p);
			tr.appendChild(td);
		}
		
		tbody.appendChild(tr);
	}
	
	table.appendChild(tbody);
	// Add tale to the parent
	content.appendChild(table);
}

// Parses the JSON array into a servings list.
function servingList(parent,arraylist) {
	// Create a table to display the data
	table = document.createElement("table");
	table.setAttribute("cellpadding","0");
	table.setAttribute("cellspacing","0");
	tbody = document.createElement("tbody");
	
	// Set up the titles
	tr = document.createElement("tr");
	td = document.createElement("td");
	h1 = document.createElement("h1");
	h1.innerHTML = "Description";
	td.appendChild(h1);
	td.className = "search_product_title_co11";
	tr.appendChild(td);
	td = document.createElement("td");
	h1 = document.createElement("h1");
	h1.innerHTML = "Serving Sizes";
	td.appendChild(h1);
	td.className = "search_product_title_co12";
	tr.appendChild(td);
	td = document.createElement("td");
	h1 = document.createElement("h1");
	h1.innerHTML = "Quantity";
	td.appendChild(h1);
	td.className = "search_product_title_co15";
	tr.appendChild(td);
	td = document.createElement("td");
	h1 = document.createElement("h1");
	h1.innerHTML = "kCal";
	td.appendChild(h1);
	td.className = "search_product_title_co13";
	tr.appendChild(td);
	td = document.createElement("td");
	h1 = document.createElement("h1");
	h1.innerHTML = "Fat(g)";
	td.appendChild(h1);
	td.className = "search_product_title_co14";
	tr.appendChild(td);
	td = document.createElement("td");
	//h1 = document.createElement("h1");
	//h1.innerHTML = "";
	//td.appendChild(h1);
	td.className = "search_product_title_co16";
	tr.appendChild(td);	
	tbody.appendChild(tr);
	
	// Parse the JSON array
	for(x=0; x<arraylist.length; x++) 
	{
		// Create a new row
		tr = document.createElement("tr");
		
		// Create a description (only first row)
		if (x == 0) 
		{
			td = document.createElement("td");
			description = ax_texttag(td, "p", arraylist[x].product_description);
			td.className = "search_product_co1";
			
			td.setAttribute("valign","top");
			tr.appendChild(td);
		}
		else
		{
			td = document.createElement("td");
			td.className = "search_product_co1";
			ax_texttag(td, "p", " ");
			td.setAttribute("valign","top");
			tr.appendChild(td);	
		}
		
		
		// Add in the serving size
		td = document.createElement("td");
		td.className = "search_product_co1";
		td.innerHTML = "";
		aref = document.createElement("a");
		aref.className = "search_product_co1_link";
		if(arraylist[x].serving_formula=='add weight'){
			//create add weight href
			aref.href = "javascript:showHideLayers('enterspecificweight','show');showHideLayers('description','hide');";
		}
		else{
			aref.href = "javascript:diarySearch_Consume(" + arraylist[x].factor + ",'" + arraylist[x].serving_formula + "'," + x + ")";
		}
		aref.appendChild(document.createTextNode(arraylist[x].serving_formula));
		td.appendChild(aref);
		tr.appendChild(td);
		

		if(arraylist[x].serving_formula=='add weight'){
			//create add weight row
			td = document.createElement("td");
			td.className = "search_product_co1";		
			td.innerHTML = "&nbsp;";
			tr.appendChild(td);
			td = document.createElement("td");
			td.className = "search_product_co1";		
			td.innerHTML = "&nbsp;";
			tr.appendChild(td);
			td = document.createElement("td");
			td.className = "search_product_co1";		
			td.innerHTML = "&nbsp;";
			tr.appendChild(td);			
			td = document.createElement("td");
			td.className = "search_product_co1end";		
			td.innerHTML = "&nbsp;";
			tr.appendChild(td);
			}	
		
		else{
		
			// Add in the quantity picker and value
			td = document.createElement("td");
			td.className = "search_product_co1";
			
			// Minus Button
			aref = document.createElement("a");
			aref.href = "javascript:diarySearch_ServingSubtract(" + x + ")";
			img = document.createElement("img");
			img.src = "/media/images/buttons/minus.gif";
			img.style.border = "none";
			img.style.margin = "4px 0 0 5px";
			aref.appendChild(img);
			td.appendChild(aref);			
			
			// Plus Button
			aref = document.createElement("a");
			aref.href = "javascript:diarySearch_ServingAdd(" + x + ")";
			img = document.createElement("img");
			img.src = "/media/images/buttons/plus.gif";
			img.style.border = "none";
			img.style.margin= "4px 3px 0 3px";
			aref.appendChild(img);
			td.appendChild(aref);
			
			// Quantity Label
			label = document.createElement("label");
			label.className = "quantity";
			label.id = "quan" + x;
			label.innerHTML = "&nbsp;1x&nbsp;";
			td.appendChild(label);
			
			tr.appendChild(td);
			
			// Add in the kCal
			td = document.createElement("td");
			td.className = "search_product_co1";
			label = document.createElement("label");
			label.id = "kcal" + x;
			label.innerHTML = "&nbsp;" + Math.round(arraylist[x].kcal);
			//label.appendChild(document.createTextNode(arraylist[x].kcal));
			p = document.createElement("p");
			p.className = "alignright";
			p.appendChild(label);
			td.appendChild(p);
			tr.appendChild(td);
			
			// Add in the fatg
			td = document.createElement("td");
			td.className = "search_product_co1";
			label = document.createElement("label");
			label.id = "fatg" + x;
			label.innerHTML = "&nbsp;" + (1 * arraylist[x].fatg).toFixed(1);
			//label.appendChild(document.createTextNode("&nbsp;" + arraylist[x].fatg));
			p = document.createElement("p");
			p.className = "alignright";
			p.appendChild(label);
			td.appendChild(p);
			tr.appendChild(td);
			
			// Add button
			td = document.createElement("td");
			aref = document.createElement("a");
			td.className = "search_product_co1end";
			img = document.createElement("img");
			img.src = "/media/images/buttons/addfood.gif";
			img.style.border = "none";
			img.style.margin = "3px 0 0 3px";
			if(arraylist[x].serving_formula=='add weight'){
				//create add weight href
				aref.href = "javascript:showHideLayers('enterspecificweight','show');showHideLayers('description','hide');";
			}
			else{
				aref.href = "javascript:diarySearch_Consume(" + arraylist[x].factor + ",'" + arraylist[x].serving_formula + "'," + x + ")";
			}
			aref.appendChild(img);
			td.appendChild(aref);
			tr.appendChild(td);
		}
			// Append to document
			tbody.appendChild(tr);

	}
	
	table.appendChild(tbody);
	
	// Add tale to the parent
	content.appendChild(table);
	productid="";
	userproductid="";
        rid="";
        fid="";
	if(arraylist.length>0)
	{
		productid = arraylist[0].product_id;
		if(productid=="-1")
		{
				productid="";
				userproductid = arraylist[0].user_product_id
		}
                else if(productid=="-2")
                {
                    productid="";
                    rid=arraylist[0].recipe_id;
                }
                else if(productid=="-3")
                { 
                    productid="";
                    fid=arraylist[0].favourites_id;
                
                }
	}
	
	frmserving = document.createElement("form");
	input1 = document.createElement("input");
	input1.type="hidden";
	input1.name="subaction";
	input1.value="eat";
	frmserving.appendChild(input1);
	input1 = document.createElement("input");
	input1.type="hidden";
	input1.name="productid";
	input1.value=productid;	
	frmserving.appendChild(input1);
	input1 = document.createElement("input");
	input1.type="hidden";
	input1.name="userproductid";
	input1.value=userproductid;	
	frmserving.appendChild(input1);
	input1 = document.createElement("input");
	input1.type="hidden";
	input1.name="recipeid";
	input1.value="";	
	frmserving.appendChild(input1);
	input1 = document.createElement("input");
	input1.type="hidden";
	input1.name="factor";
	input1.id="searchresults_factor";
	input1.value="";	
	frmserving.appendChild(input1);	
	input1 = document.createElement("input");
	input1.type="hidden";
	input1.name="servingdescription";
	input1.id="searchresults_servingdescription";
	input1.value="";	
	frmserving.appendChild(input1);
	input1 = document.createElement("input");
	input1.type="hidden";
	input1.name="quantity";
	input1.id = "searchresults_quantity";
	input1.value="1";
	frmserving.appendChild(input1);
	input1 = document.createElement("input");
	input1.type="hidden";
	input1.name="measure";
	input1.id="searchresults_measure";
	input1.value="";
	frmserving.appendChild(input1);
	input1 = document.createElement("input");
	input1.type="hidden";
	input1.name="txt_size";	
	input1.id="searchresults_txt_size";
	input1.value="";
	frmserving.appendChild(input1);
	input1 = document.createElement("input");
	input1.type="hidden";
	input1.name="addweight";	
	input1.id="searchresults_addweight";
	input1.value="0";
	frmserving.appendChild(input1);
	input1 = document.createElement("input");
	input1.type="hidden"; 
	input1.name="section";	
	input1.id="searchresults_section";
	input1.value="diary";
	frmserving.appendChild(input1);
	input1 = document.createElement("input");
	input1.type="hidden"; 
	input1.name="action";	
	input1.id="searchresults_action";
	input1.value="";
	frmserving.appendChild(input1);
	input1 = document.createElement("input");
	input1.type="hidden"; 
	input1.name="txt_recipeid";	
	input1.id="searchresults_txt_recipeid";
	input1.value="";
	frmserving.appendChild(input1);
        input1 = document.createElement("input");
	input1.type="hidden"; 
	input1.name="rid";	
	input1.id="searchresults_rid";
	input1.value=rid;
	frmserving.appendChild(input1);
        input1 = document.createElement("input");
	input1.type="hidden"; 
	input1.name="fid";	
	input1.id="searchresults_fid";
	input1.value=fid;
	frmserving.appendChild(input1);

	frmserving.name="searchresults";
	frmserving.id="searchresults";
	frmserving.action="/process.jsp";
	frmserving.method="post";
	
	content.appendChild(frmserving);


	try
	{
				diarySearch_Initialise(arraylist);
	}
	catch(err)
	{
		alert(err);
	}
}

// Parses the JSON array into a category list
function categoryMore(parent,arraylist) {
	// Create the table to display the product data
	table = document.createElement("table");
	table.setAttribute("cellpadding","0");
	table.setAttribute("cellspacing","0");
	tbody = document.createElement("tbody");
	
	// If there are no returned results.
	if (arraylist == null) 
	{
		tr = document.createElement("tr");
		td = document.createElement("td");
		
		aref = create_none();
		
		// Append to document
		td.appendChild(aref);
		tr.appendChild(td);
		tbody.appendChild(tr);
	} 
	else { // Otherwise there are results	
		
		// Parse through the JSON array
		for(x=0; x<arraylist.length; x++) {
			// Create a new row
			tr = document.createElement("tr");
			td = document.createElement("td");
			
			// Create a link
			aref = document.createElement("a");
			aref.className = "search_categories";
			
			// If a bottom level category, then search for the products.
			if (arraylist[x].bl != "0") 
			{
				aref.href = "javascript:SearchCategoryBl(" + arraylist[x].id + ",'" + arraylist[x].category_name + "');";
			} 
			else {
				aref.href = "javascript:SearchCategory(" + arraylist[x].id + ", '" + arraylist[x].category_name + "');";
			}
			
			// Add in description
			aref.appendChild(document.createTextNode(arraylist[x].category_name));
			
			// Add to document structure
			td.appendChild(aref);
			tr.appendChild(td);
			
			tbody.appendChild(tr);
		}
	}
	
	// Add table to the parent
	table.appendChild(tbody);
	parent.appendChild(table);
}

// Parses the JSON array into a product list for Food Swap
function fsProductList(parent,arraylist) {
	// Create the table to display the product data
	table = document.createElement("table");
	table.setAttribute("cellpadding","0");
	table.setAttribute("cellspacing","0");
	tbody = document.createElement("tbody");
	
	// If there are no returned results.
	if (arraylist == null) 
	{
		tr = document.createElement("tr");
		td = document.createElement("td");
		
		aref = create_none();
		
		// Append to document
		td.appendChild(aref);
		tr.appendChild(td);
		tbody.appendChild(tr);
	}
	else { // Otherwise there are results	
		
		// Parse through the JSON array
		for(x=0; x<arraylist.length; x++) 
		{
			// Create a new row
			tr = document.createElement("tr");
			td = document.createElement("td");
			
			// Create a link
			aref = document.createElement("a");
			if (arraylist[x].product_id < 0 ) 
			{
				aref.className = "search_product_nonbarcode";
				aref.href = "food_swap.jsp?userproductid=" + Math.abs(arraylist[x].product_id);
			} 
			else {
				aref.href = "/Action?section=foodswap&OnSuccess=/foodswap/foodswap_2.jsp&productid=" + arraylist[x].product_id + "&brandid=-1&ranking=3";
				//aref.href = "food_swap.jsp?productid=" + arraylist[x].product_id;
			}
			
			if (arraylist[x].mine == "1") 
			{
				aref.className = "search_product_mine";
			}
			
			// Add in description
			aref.appendChild(document.createTextNode(arraylist[x].product_description));
			
			// Add to document structure
			td.appendChild(aref);
			tr.appendChild(td);
			
			tbody.appendChild(tr);
		}
		
		tr = document.createElement("tr");
		td = document.createElement("td");
		
		aref = create_none();
		
		// Append to document
		td.appendChild(aref);
		tr.appendChild(td);
		tbody.appendChild(tr);
	}
	
	table.appendChild(tbody);
	// Add table to the parent
	parent.appendChild(table);
}

// Food Swap Flavour List
function fsFlavourList(i, arraylist, cmb) {
	// Parse through the JSON array
	for(x=0; x<arraylist.length; x++) {
		addOption = new Option(arraylist[x].flavour_description ,arraylist[x].flavour_id);
		cmb.options[i] = addOption;
		i++;
	}	
}

// Food Swap Brand List
function fsBrandList(i, arraylist, cmb) {
	// Parse through the JSON array
	for(x=0; x<arraylist.length; x++) {
		addOption = new Option(arraylist[x].brandname ,arraylist[x].brand_id);
		cmb.options[i] = addOption;
		i++;
	}	
}

// Food Swap Servings List
function fsServingList(i, arraylist, cmb) {
	// Parse through the JSON array
	for(x=0; x<arraylist.length; x++) {
		addOption = new Option(arraylist[x].serving_description ,arraylist[x].serving_id);
		cmb.options[i] = addOption;
		i++;
	}	
}
// Parses the JSON array into a servings list.
function diaryservingList(parent,arraylist,diaryobject) {
	var found = -1;
	var s="";
	serving = diaryobject.serving;
	quantity = diaryobject.quantity;
	
	if(diaryobject.productid==-1)
	{
		s = '<div class="srvSize"><p class="por">&nbsp;' + diaryobject.serving + '</p><div class="quanBoxText"><div style="float:left;"><label id="squan99">&nbsp;' + (quantity==0.5?'&frac12;':quantity) + 'x&nbsp;</label><a href="javascript:diaryServing_ServingSubtract(99)"><img src="/media/images/buttons/minus.gif"></a><a href="javascript:diaryServing_ServingAdd(99)"><img src="/media/images/buttons/plus.gif"></a></div><div class="quanBoxValue" style="float:right"><table><tr><td class="col1"><label id="skcal99">&nbsp;' + Math.round(diaryobject.kcal * quantity) + '&nbsp;</label></td><td class="col1"><label id="sfatg99">&nbsp;' + (quantity * diaryobject.fatg).toFixed(1) + '&nbsp;</label></td><td><a href="javascript:diaryServing_Consume(\'' + diaryobject.serving + '\',' + '0' +',99)"><img src="/media/images/buttons/ok.gif"></a></td></tr></table></div></div></div>' + s;	
	}
	else
	{
		
		if(serving.indexOf("]")>0)
		{
			serving = serving.substr(serving.indexOf("]")+2);	
			diaryobject.serving = serving;
		}
		
		for(x=0; x<arraylist.length; x++) 
		{
			if(arraylist[x].serving_formula=='add weight')
			{
				
				s = s + '<div id="addWeight"><p>Add weight</p><input type="text" class="addsrv" id="sweight" maxlength="4"/><select id="ssize"><option value="g">g</option><option value="oz">oz</option><option value="ml">ml</option></select><div class="quanBoxValue" style="float:right"><table style="width:10px;"><tr><td><a href="javascript:diaryServing_ConsumeWeight()"><img src="/media/images/buttons/ok.gif"></a></td></tr></table></div></div>';
			}
			else
			{
				if(arraylist[x].serving_formula==serving)
				{
		s = '<div class="srvSize"><p class="por">&nbsp;' + arraylist[x].serving_formula + '</p><div class="quanBoxText"><div style="float:left;"><label id="squan' + x + '">&nbsp;' + (quantity==0.5?'&frac12;':quantity) + 'x&nbsp;</label><a href="javascript:diaryServing_ServingSubtract(' + x + ')"><img src="/media/images/buttons/minus.gif"></a><a href="javascript:diaryServing_ServingAdd(' + x + ')"><img src="/media/images/buttons/plus.gif"></a></div><div class="quanBoxValue" style="float:right"><table><tr><td class="col1"><label id="skcal' + x + '">&nbsp;' + Math.round(arraylist[x].kcal * quantity) + '&nbsp;</label></td><td class="col1"><label id="sfatg' + x + '">&nbsp;' + (quantity * arraylist[x].fatg).toFixed(1) + '&nbsp;</label></td><td><a href="javascript:diaryServing_Consume(\'' + arraylist[x].serving_formula + '\',' + arraylist[x].factor +',' + x + ')"><img src="/media/images/buttons/ok.gif"></a></td></tr></table></div></div></div>' + s;			
				 found = x;	
				}
				else
				{
		
		s = s + '<div class="srvSizeAlt"><p class="por">&nbsp;' + arraylist[x].serving_formula + '</p><div class="quanBoxText"><div style="float:left;"><label id="squan' + x + '">&nbsp;1x&nbsp;</label><a href="javascript:diaryServing_ServingSubtract(' + x + ')"><img src="/media/images/buttons/minus.gif"></a><a href="javascript:diaryServing_ServingAdd(' + x + ')"><img src="/media/images/buttons/plus.gif"></a></div><div class="quanBoxValue" style="float:right"><table><tr><td class="col1"><label id="skcal' + x + '">&nbsp;' + Math.round(arraylist[x].kcal) + '&nbsp;</label></td><td class="col1"><label id="sfatg' + x + '">&nbsp;' + (1 * arraylist[x].fatg).toFixed(1) + '&nbsp;</label></td><td><a href="javascript:diaryServing_Consume(\'' + arraylist[x].serving_formula + '\',' + arraylist[x].factor +',' + x + ')"><img src="/media/images/buttons/ok.gif"></a></td></tr></table></div></div></div>';
				}
			}
		
		}
		if(found==-1)
		{
			s = '<div class="srvSize"><p class="por">&nbsp;' + diaryobject.serving + '</p><div class="quanBoxText"><div style="float:left;"><label id="squan99">&nbsp;' + quantity + 'x&nbsp;</label><a href="javascript:diaryServing_ServingSubtract(99)"><img src="/media/images/buttons/minus.gif"></a><a href="javascript:diaryServing_ServingAdd(99)"><img src="/media/images/buttons/plus.gif"></a></div><div class="quanBoxValue" style="float:right"><table><tr><td class="col1"><label id="skcal99">&nbsp;' + Math.round(diaryobject.kcal * quantity) + '&nbsp;</label></td><td class="col1"><label id="sfatg99">&nbsp;' + (quantity * diaryobject.fatg).toFixed(1) + '&nbsp;</label></td><td><a href="javascript:diaryServing_Consume(\'' + diaryobject.serving + '\',' + '0' +',99)"><img src="/media/images/buttons/ok.gif"></a></td></tr></table></div></div></div>' + s;			
			
		}
	}
	s = s + '</div>'
	if(diaryobject.ingredientid!=null){
	s = s + '<form id="diaryserving" method="post" action="/Action?section=recipe&amp;action=changequantity1&amp;ingredientid=' + diaryobject.ingredientid + '"><input type="hidden" id="diaryserving_quantity" name="quantity"><input type="hidden" id="diaryserving_addweight" name="addweight"><input type="hidden" id="diaryserving_servingdescription" name="servingdescription"><input type="hidden" id="diaryserving_factor" name="factor"><input type="hidden" id="diaryserving_servingweight" name="servingweight"><input type="hidden" id="diaryserving_servingsize" name="servingsize"></form>'		
	}
	else{
	s = s + '<form id="diaryserving" method="post" action="/Action?section=diary&amp;action=changequantity1&amp;diaryid=' + diaryobject.diaryid + '"><input type="hidden" id="diaryserving_quantity" name="quantity"><input type="hidden" id="diaryserving_addweight" name="addweight"><input type="hidden" id="diaryserving_servingdescription" name="servingdescription"><input type="hidden" id="diaryserving_factor" name="factor"><input type="hidden" id="diaryserving_servingweight" name="servingweight"><input type="hidden" id="diaryserving_servingsize" name="servingsize"></form>'
	}
	s = '<div class="quanBoxTitle"><a class="right" href="javascript:removeDiaryServingsBox()"><img src="/media/images/buttons/close.gif"></a>' + s;
	
	parent.innerHTML = s;
	
	try
	{
				diaryServing_Initialise(arraylist,quantity,diaryobject,found);
	}
	catch(err)
	{
		alert(err);
	}

	

}

