function showRecipeDetail(id) {
	var idx = getRecipeIdx(id);
	document.getElementById("recipedescription").innerHTML = recipes[idx].description+'<br><a href="javascript:shareRecipe();" onMouseOver="MM_swapImage(\'btnShareThisRecipe\',\'\',\'../pics/button/sharethisrecipe_on.gif\',1)" onMouseOut="MM_swapImgRestore()"><img id="btnShareThisRecipe" src="/pics/button/sharethisrecipe_off.gif" vspace="2" border="0"></a> <a href="javascript:printRecipe();" onMouseOver="MM_swapImage(\'btnPrintRecipe\',\'\',\'../pics/button/print_on.gif\',1)" onMouseOut="MM_swapImgRestore()"><img id="btnPrintRecipe" src="/pics/button/print_off.gif" vspace="2" border="0"></a>';
	document.getElementById("recipepic").src = "pics/"+recipes[idx].id+"/pic.png";
	document.getElementById("recipetitle").src = "pics/"+recipes[idx].id+"/title.png";
	document.getElementById("recipeingredient").innerHTML = recipes[idx].ingredient+"<br><br>"+recipes[idx].serving;
	document.getElementById("recipemethod").innerHTML = recipes[idx].method;
}

function getRecipeDetail(idx) {
	document.getElementById("tdArrow"+open_idx).innerHTML = "&nbsp;";
	var sXML = "xml/"+recipes[idx].id+".xml";
	if (window.XMLHttpRequest) {
		axRecipeDetail = new XMLHttpRequest();
		bIE = false;
	} else if (window.ActiveXObject) {
		axRecipeDetail = new ActiveXObject("Microsoft.XMLHTTP");
	}
	axRecipeDetail.open("GET", sXML, true);
	axRecipeDetail.onreadystatechange = parseDetail;
	axRecipeDetail.send(null);
}

function parseDetail() {
	if (axRecipeDetail.readyState == 4) {
		switch (axRecipeDetail.status) {
			case 200:
				var xmldoc = axRecipeDetail.responseXML;
				var root = xmldoc.getElementsByTagName("recipe")[0];
				var recipe_id = root.getAttribute("id");
				var recipe_idx = getRecipeIdx(recipe_id);
				open_idx = recipe_idx;
				document.getElementById("tdArrow"+open_idx).innerHTML = '<img src="../pics/yellowarrow.png" width="11" height="11" align="texttop">';
				for (var i=0; i<root.childNodes.length; i++) {
					var nItem = root.childNodes.item(i);
					switch (nItem.nodeName) {
						case "description":
							recipes[recipe_idx].description = nItem.firstChild.nodeValue;
							break;
						case "ingredients":
							recipes[recipe_idx].ingredient = nItem.firstChild.nodeValue;
							break;
						case "method":
							recipes[recipe_idx].method = nItem.firstChild.nodeValue;
							break;
						case "serving":
							recipes[recipe_idx].serving = nItem.firstChild.nodeValue;
							break;
					}
				}
				axRecipeDetail = null;
				showRecipeDetail(recipes[open_idx].id);
				break;
			case 404:
				alert("Recipe information is not available.");
				break;
			default: 
				alert("Error "+axCardFeature.status+" in loading recipe information.");
				break;
		}
	}
}

function printRecipe() {
	window.open('print.htm?'+recipes[open_idx].id);
}

function shareRecipe() {
	var w = 320;
	var h = 390;
	var l = (screen.width/2) - (w/2);
	var t = (screen.height/2) - (h/2) - 40;
	var feat = "scrollbars=0,toolbar=0,menubar=0,status=1,location=0,width=" + w + ",height=" + h + ",top=" + t + ",left=" + l + ",resizable=0";
	window.open('../share/?recipe,'+recipes[open_idx].id+':'+recipes[open_idx].name, "wShare", feat);
}