function displayHideCategory(categoryId, ignore){
	if(ignore == null)
		ignore = false;
		
	categoryMenuNew = document.getElementById("category-menu-" + categoryId);
	categoryTitleNew = document.getElementById("category-title-" + categoryId);
	
	if(oldCategoryId != -1 && oldCategoryId != categoryId) {
		categoryMenuOld = document.getElementById("category-menu-" + oldCategoryId);
		categoryTitleOld = document.getElementById("category-title-" + oldCategoryId);
		categoryTitleOld.className = "not-current-category";
		// uses scriptaculous
		height = Element.getHeight("category-menu-" + oldCategoryId);
		shrinkCategory(oldCategoryId, height, 0, height);
	}

	if (oldCategoryId == categoryId && !ignore && categoryMenuNew.style.display == "block") {
		oldCategoryId = -1;
		categoryTitleNew.className = "not-current-category";
		// uses scriptaculous
		height = Element.getHeight("category-menu-" + categoryId);
		shrinkCategory(categoryId, height, 0, height);
	} else {
		if(!ignore){
			// uses scriptaculous
			height = Element.getHeight("category-menu-" + categoryId);
			categoryMenuNew.style.height = '0px';
			categoryMenuNew.style.overflow = 'hidden';		
			categoryMenuNew.style.display = "block";
			categoryTitleNew.className = "current-category";
			oldCategoryId = categoryId;
			expandCategory(categoryId, 0, height);
		}
	}
}

function shrinkCategory(categoryId, currentHeight, totalHeight, defaultHeight){
	categoryMenu = document.getElementById("category-menu-" + categoryId);
	currentHeight-=45;
	if(totalHeight <= currentHeight){
		categoryMenu.style.height = currentHeight + 'px';
		setTimeout('shrinkCategory(' + categoryId + ', ' + currentHeight + ', ' + totalHeight + ', ' + defaultHeight + ')', 1);
	}
	else{
		categoryMenu.style.display = 'none';		
		categoryMenu.style.height = defaultHeight + 'px';
	}
}

function expandCategory(categoryId, currentHeight, totalHeight){
	categoryMenu = document.getElementById("category-menu-" + categoryId);
	currentHeight+=65;

	if(currentHeight <= totalHeight){
		categoryMenu.style.height = currentHeight + 'px';
		setTimeout('expandCategory(' + categoryId + ', ' + currentHeight + ', ' + totalHeight + ')', 1);
	}
	else{
		categoryMenu.style.height = totalHeight + 'px';
	}
}

function displayMenuItemAjax(menuItemId, buildingCoupon, groupId, category, categoryIgnore){
	
	if (buildingCoupon == null)
		buildingCoupon = false;
	
	if(categoryIgnore == null)
		categoryIgnore = false;
	
	menuItemDiv = document.getElementById("menu-item");

	if (buildingCoupon)
		currentMenuItem = document.getElementById("menu-item-" + groupId + "-" + menuItemId);
	else
		currentMenuItem = document.getElementById("menu-item-" + menuItemId);
		 
	currentMenuItem.className += " current-menu-item";

	if(oldMenuItemId != -1 && oldMenuItemId != menuItemId) {
		if (buildingCoupon)
			oldMenuItem = document.getElementById("menu-item-" + groupId + "-" + oldMenuItemId);
		else
			oldMenuItem = document.getElementById("menu-item-" + oldMenuItemId);
		classes = oldMenuItem.className;
		loc = classes.indexOf(" current-menu-item");
		oldMenuItem.className = classes.substring(0, loc);
	}

	if(category != null){
		displayHideCategory(category, categoryIgnore);
	}
	
	oldMenuItemId = menuItemId;
	
	contentBody = document.getElementById('menu-item');
	
	// Remove previous menuItem
	while (contentBody.firstChild) 
	 {
	    contentBody.removeChild(contentBody.firstChild);
	 };
	
	loadingDiv = document.createElement("div");
	loadingDiv.className = "itam_added_to_cart"; 
	loadingDiv.appendChild(document.createTextNode("Loading..."));
	contentBody.appendChild(loadingDiv);
	
	var sendData = "menuItemId=" + menuItemId;
			
	if (buildingCoupon != false)
		sendData += "&couponId=" + buildingCoupon + "&groupId=" + groupId;
	ajax = new ajaxRequest;
	ajax.send(false, "/viewMenu.food?event=doViewMenuItem", sendData, "displayMenuItem", menuItemId + ", " + buildingCoupon + ", " + groupId + ", " + category);
}

function displayMenuItem(dom, menuItemId, buildingCoupon, groupId, category) {
	
	contentBody = document.getElementById('menu-item');
	
	// Remove previous menuItem
	while (contentBody.firstChild) 
	 {
	    contentBody.removeChild(contentBody.firstChild);
	 };
			
	var menuItem = dom.getElementsByTagName("menu-item")[0];
	
	form = document.createElement('form');
    form.id = "menuItemForm";	
    form.name = "menuItemForm"
	form.action = "viewMenu.food?event=doAddToCart";
	form.method = "POST";
	form.onsubmit = function(){return validateMenu(this);};
	
	menuInfoDiv = document.createElement('div');

	menuNameSpan = document.createElement('span');						
	menuNameSpan.className = "item_title";
	menuName = document.createTextNode(menuItem.getAttribute("name"));
	menuNameSpan.appendChild(menuName);


	menuDescriptionSpan = document.createElement('span');
	menuDescriptionSpan.className = "menu_description";
	description = document.createTextNode(menuItem.getAttribute("description"));
	menuDescriptionSpan.appendChild(description);

	menuInfoDiv.appendChild(menuNameSpan);
	menuInfoDiv.appendChild(menuDescriptionSpan);						
						
	baseCost = menuItem.getAttribute('baseCost');
	if(baseCost != "0.00"){
		menuBaseCostDiv = document.createElement('div');
		menuBaseCostDiv.className = "menu_prices";
		baseCostText = document.createTextNode("$" + baseCost);
		menuBaseCostDiv.appendChild(baseCostText);
		
		if(menuItem.getAttribute('orignalPrice') != null){
			orginalPriceSpan = document.createElement('span');
			orginalPriceSpan.className = "special_strikethrough";
			orginalPriceText = document.createTextNode("$" + menuItem.getAttribute('orignalPrice'));
			orginalPriceSpan.appendChild(orginalPriceText);
			menuBaseCostDiv.appendChild(orginalPriceSpan);
		}						
		
		menuInfoDiv.appendChild(menuBaseCostDiv);
	}
	else{
		menuPrices = dom.getElementsByTagName("menu-price");
		menuPricesDiv = document.createElement('div');
		menuPricesDiv.className = "menu_prices";
		for(i = 0; i < menuPrices.length; i++){
			menuPrice = menuPrices[i];
			menuPriceSpan = document.createElement('span');
			menuPriceSpan.className = "menu_price_span";
			menuPriceText = document.createTextNode(menuPrice.getAttribute("name") + " $" + menuPrice.getAttribute("price"));
			menuPriceSpan.appendChild(menuPriceText);
			
			if(menuPrice.getAttribute('orignalPrice') != null){
				orginalPriceSpan = document.createElement('span');
				orginalPriceSpan.className = "special_strikethrough";
				orginalPriceText = document.createTextNode("$" + menuPrice.getAttribute('orignalPrice'));
				orginalPriceSpan.appendChild(orginalPriceText);
				menuPriceSpan.appendChild(orginalPriceSpan);
			}
			
			menuPricesDiv.appendChild(menuPriceSpan);								
		}
		menuInfoDiv.appendChild(menuPricesDiv);
	}
	
	imageSrc = menuItem.getAttribute('image');
	if(imageSrc != null && imageSrc != ''){
		menuImageSpan = document.createElement('span');						
		menuImage = document.createElement('img');
		menuImage.src = "images/menu/" + imageSrc;
		menuImageSpan.appendChild(menuImage);
		menuInfoDiv.appendChild(menuImageSpan);
	}
	menuOrderDiv = document.createElement('div');																					

	menuItemHidden = createInput("hidden", "menuItemId");
	menuItemHidden.value = menuItem.getAttribute("id");
	menuOrderDiv.appendChild(menuItemHidden);
	
	if (!buildingCoupon) {
		qtySelect = createInput("select", "Qty");
		addEvent(qtySelect,'change',function(){updateMenuItemPriceAjax(form.name, qtySelect.name);});
	
		for(i = 0; i < 6; i++){
			option = document.createElement('option');							
			option.value = i;
			if(i == 0){
				option.text = "Qty";
			}
			else{
				option.text = i;
				if (i == 1)
					option.selected = true;
			}	
			
			try{
				qtySelect.add(option, null);
			}
			catch(ex){
				qtySelect.add(option);
			}
		}
	} else {
		qtySelect = createInput("hidden", "Qty");
		qtySelect.value = "1";
		qtyText = document.createTextNode("Qty: 1");
		menuOrderDiv.appendChild(qtyText);
	}
	menuOrderDiv.appendChild(qtySelect);
	
	menuAttributesGroups = dom.getElementsByTagName("menu-attribute-group");

	for(i = 0; i < menuAttributesGroups.length; i++){
		menuAttributesGroup = menuAttributesGroups[i];
		
		multipleSelectFlag = menuAttributesGroup.getAttribute("multipleSelectFlag");
		pizzaFlag = menuAttributesGroup.getAttribute("pizzaFlag");
		numberFree = menuAttributesGroup.getAttribute("numberFree");
		toppingAmount = menuAttributesGroup.getAttribute("toppingAmount");
		numOfMenuAttributes = menuAttributesGroup.getAttribute("numOfMenuAttributes");
		groupDiv = document.createElement("div");
		
		// Header Information
		if(multipleSelectFlag == "true" && pizzaFlag == "true"){
			pizzaTable = document.createElement("table");
			pizzaTable.className = "byo_table";
			
			pizzaTableTHead = document.createElement("thead");
			
			pizzaTable.appendChild(pizzaTableTHead);
			
			pizzaTableTBody = document.createElement("tbody");
			
			trHeader = document.createElement("tr");
			trHeader.className = "byo_headers";
			
			td = document.createElement("td");
			td.className = "blank_byo_header"
			if (toppingAmount != "" || numberFree != 0) {
				text = "";
				if (toppingAmount != "") {
					text += menuAttributesGroup.getAttribute("label") + " (Max " + (parseInt(toppingAmount) + parseInt(numberFree)) + ") ";
				} else if (numberFree != 0){
					text += menuAttributesGroup.getAttribute("label") + " (" + numberFree + " Free)";
				}
				text = document.createTextNode(text);
			} else {
				text = document.createTextNode(menuAttributesGroup.getAttribute("label"));
			}

			td.appendChild(text);
			trHeader.appendChild(td);
			
			td = document.createElement("td");
			text = document.createTextNode("None");							
			td.appendChild(text);
			trHeader.appendChild(td);
			
			td = document.createElement("td");
			text = document.createTextNode("Whole");							
			td.appendChild(text);
			trHeader.appendChild(td);
			
			td = document.createElement("td");
			text = document.createTextNode("1st Half");							
			td.appendChild(text);
			trHeader.appendChild(td);
			
			td = document.createElement("td");
			text = document.createTextNode("2nd Half");							
			td.appendChild(text);
			trHeader.appendChild(td);
			
			pizzaTableTHead.appendChild(trHeader);
			
		}
		else if(multipleSelectFlag == "true"){					
			otherTable = document.createElement("table");
			otherTable.className = "byo_table";
			
			
			otherTableTHead = document.createElement("thead");
			
			otherTable.appendChild(otherTableTHead);
			
			otherTableTBody = document.createElement("tbody");
			
			trHeader = document.createElement("tr");
			trHeader.className = "byo_headers";
			
			td = document.createElement("td");
			td.className = "blank_byo_header"
			text = document.createTextNode(menuAttributesGroup.getAttribute("label"));							
			td.appendChild(text);
			trHeader.appendChild(td);
			otherTableTHead.appendChild(trHeader);
		}
		else{
			if(numOfMenuAttributes == 1){
				labelSpan = document.createElement("span");
				labelText = document.createTextNode(menuAttributesGroup.getAttribute("label"))
				labelSpan.appendChild(labelText);
			}
			else{
				if (dom.getElementsByTagName("menu-attribute-" + menuAttributesGroup.getAttribute("id")).length != 1) {
					select = createInput("select", menuAttributesGroup.getAttribute("label"));
					//try {
					//	select = document.createElement('<select name="' + menuAttributesGroup.getAttribute("label") + '">');
					//} catch (e) {
					//	select = document.createElement("select");
					//	select.name = menuAttributesGroup.getAttribute("label");
					//}
					addEvent(select,'change',function(){updateMenuItemPriceAjax(form.name, select.name);});
					firstOption = document.createElement("option");
					firstOption.value = 0;
					firstOption.text = menuAttributesGroup.getAttribute("label");
					try{
						select.add(firstOption, null);	
					}
					catch(ex){
						select.add(firstOption);
					}
					
				} else {
					select = createInput("hidden", menuAttributesGroup.getAttribute("label"));
					//try {
					//	select = document.createElement('<input type="hidden" name="' + menuAttributesGroup.getAttribute("label") + '">');
					//} catch (e) {
					//	select = document.createElement("input");
					//	select.name = menuAttributesGroup.getAttribute("label");
					//	select.type = "hidden";
					//}
				}
			}
		}
														
		menuAttributes = dom.getElementsByTagName("menu-attribute-" + menuAttributesGroup.getAttribute("id"));
		var sizeText = null;
		for(j = 0; j < menuAttributes.length; j++){
			menuAttribute = menuAttributes[j];
			maId = menuAttribute.getAttribute("id");
			maName = menuAttribute.getAttribute("name");
			maPrice = menuAttribute.getAttribute("price");
			
			if(multipleSelectFlag == "true" && pizzaFlag == "true"){
				tr = document.createElement("tr");
				if(j%2 == 0){
					tr.className = "even";
				}
				else{
					tr.className = "odd";
				}
				
				td = document.createElement("td");
				
				if(maPrice == 0.00){
					nameText = document.createTextNode(maName);
				}
				else{
					nameText = document.createTextNode(maName + " (+$" + maPrice + ")");
				}
				
				td.appendChild(nameText);
				tr.appendChild(td);
				
				td = document.createElement("td");
				radio = createInput("radio", "topping" + maId, true);
				//try {
				//	radio = document.createElement('<input type="radio" name="topping'+maId+'">');
				//} catch (e) {
				//	radio = document.createElement("input");
				//	radio.type = "radio";
				//	radio.name = "topping" + maId;			
				//}
				radio.value = "0";
				radio.checked = true;
				addEvent(radio,'click',function(){updateMenuItemPriceAjax(form.name, "topping" + maId);});
				td.appendChild(radio);
				tr.appendChild(td);
				
				td = document.createElement("td");
				radio = createInput("radio", "topping" + maId);
				//try {
				//	radio = document.createElement('<input type="radio" name="topping'+maId+'">');
				//} catch (e) {
				//	radio = document.createElement("input");
				//	radio.type = "radio";
				//	radio.name = "topping" + maId;			
				//}
				radio.id = "topping" + maId;
				radio.value = "Whole Pizza";
				addEvent(radio,'click',function(){updateMenuItemPriceAjax(form.name, "topping" + maId);});
				td.appendChild(radio);								
				tr.appendChild(td);
				
				td = document.createElement("td");
				radio = createInput("radio", "topping" + maId);
				//try {
				//	radio = document.createElement('<input type="radio" name="topping'+maId+'">');
				//} catch (e) {
				//	radio = document.createElement("input");
				//	radio.type = "radio";
				//	radio.name = "topping" + maId;			
				//}
				radio.value = "1st Half";
				addEvent(radio,'click',function(){updateMenuItemPriceAjax(form.name, "topping" + maId);});
				td.appendChild(radio);
				tr.appendChild(td);
				
				td = document.createElement("td");
				radio = createInput("radio", "topping" + maId);
				//try {
				//	radio = document.createElement('<input type="radio" name="topping'+maId+'">');
				//} catch (e) {
				//	radio = document.createElement("input");
				//	radio.type = "radio";
				//	radio.name = "topping" + maId;			
				//}
				radio.value = "2nd Half";
				addEvent(radio,'click',function(){updateMenuItemPriceAjax(form.name, "topping" + maId);});
				td.appendChild(radio);
				tr.appendChild(td);
				
				pizzaTableTBody.appendChild(tr);						
			}
			else if(multipleSelectFlag == "true"){
				tr = document.createElement("tr");
				if(j%2 == 0){
					tr.className = "even";
				}
				else{
					tr.className = "odd";
				}
				
				td = document.createElement("td");
				
				checkbox = createInput("checkbox", menuAttributesGroup.getAttribute("label"));

				checkbox.value = maId;
				addEvent(checkbox,'click',function(){updateMenuItemPriceAjax(form.name, "topping" + maId);});
				
				if(maPrice == 0.00){
					titleText = document.createTextNode(maName);
				}
				else{
					titleText = document.createTextNode(maName + " (+$" + maPrice + ")");
				}
				
				td.appendChild(checkbox);
				td.appendChild(titleText);
				tr.appendChild(td);
				
				otherTableTBody.appendChild(tr);
			}
			else{
				if (menuAttributes.length != 1) {
					option = document.createElement("option");							
			
					option.value = menuAttribute.getAttribute("id");								

					if(maPrice == 0.00){
						option.text = menuAttribute.getAttribute("name");
					}
					else{
						option.text = menuAttribute.getAttribute("name") + "  +" + maPrice;
					}	
					
					try{
						select.add(option, null);
					}
					catch(ex){
						select.add(option);
					}
				} else {
					select.value = menuAttribute.getAttribute("id");
					sizeText = document.createTextNode(menuAttributesGroup.getAttribute("label") + ": " + menuAttribute.getAttribute("name"));
				}
			}
			
			
		}
		
		menuOrderDiv.appendChild(groupDiv);
		
		if(multipleSelectFlag == "true" && pizzaFlag == "true"){
			pizzaTable.appendChild(pizzaTableTBody);
			menuOrderDiv.appendChild(pizzaTable);
		}
		else if(multipleSelectFlag == "true"){
			otherTable.appendChild(otherTableTBody);
			menuOrderDiv.appendChild(otherTable);
		}
		else{
			menuOrderDiv.appendChild(select);
			if (sizeText != null) {
				menuOrderDiv.appendChild(sizeText);
				sizeText = null;
			}						
		}					
	}
							
	specialRequests = document.createElement('textarea');
	specialRequests.name = "specialRequests";
	specialRequests.value = "Add Special Requests Here";
	specialRequests.cols = 30;
	addEvent(specialRequests,'click',function(){this.value = '';});
	specialReqInfoSpan = document.createElement('span');
	specialReqInfoSpan.className = "special_requests_text";
	specialReqInfo = document.createTextNode('special requests may add additional costs');
	specialReqInfoSpan.appendChild(specialReqInfo);
	finalDivWhole = document.createElement('div');
	finalDivWhole.className = "final_div_whole";
	finalDivWhole.id = "iePositionFix"; 
	finalDiv = document.createElement('div');
	finalDiv.className = 'final_order_block';
	finalDivTop = document.createElement('div');
	finalDivTop.className = 'final_order_block_top';
	basePriceDiv = document.createElement('div');
	basePriceSpan1 = document.createElement('span');
	basePriceSpan1.className = 'final_total';
	basePriceSpan1.appendChild(document.createTextNode('Item Total'));
	basePriceSpan2 = document.createElement('span');
	basePriceSpan2.className = 'final_price';
	basePriceSpan2.id = 'currentCost';
	basePriceSpan2.appendChild(document.createTextNode("$" + menuItem.getAttribute('baseCost')));
	basePriceDiv.appendChild(basePriceSpan1);
	basePriceDiv.appendChild(basePriceSpan2);
	finalDiv.appendChild(basePriceDiv);
	finalDivWhole.appendChild(finalDivTop);
 	finalDivWhole.appendChild(finalDiv);
	
	finalPriceDiv = document.createElement('div');
	finalPriceDiv.className = 'final_order_block final_order_block2';	
	base2PriceDiv = document.createElement('div');
	base2PriceSpan1 = document.createElement('span');
	base2PriceSpan1.className = 'final_total';
	base2PriceSpan1.appendChild(document.createTextNode('Item Total'));
	base2PriceSpan2 = document.createElement('span');
	base2PriceSpan2.className = 'final_price';
	base2PriceSpan2.id = 'currentCost2';
	base2PriceSpan2.appendChild(document.createTextNode("$" + menuItem.getAttribute('baseCost')));
	base2PriceDiv.appendChild(base2PriceSpan1);
	base2PriceDiv.appendChild(base2PriceSpan2);
	finalPriceDiv.appendChild(base2PriceDiv);
	
	if(true) {//menuItem.getAttribute("restaurantOpen") == "true"){
		if(buildingCoupon){
			submitBtnText = document.createTextNode("  Next");	
			submitBtnText2 = document.createTextNode("  Next");
		}
		else{
			submitBtnText = document.createTextNode("Add to Cart!");
			submitBtnText2 = document.createTextNode("Add to Cart!");
		}
	
		var submitDiv = document.createElement('div');
		submitDiv.className = "dynamic_button";
		
		var spanOne = document.createElement('span');
		spanOne.className = "db1";		
		
		submitBtn = document.createElement('a');
		submitBtn.className = "db2";
		submitBtn.onclick = function(){if(validateMenu(document.forms["menuItemForm"])) addToCartAjax(buildingCoupon);};
		submitBtn.appendChild(submitBtnText);		
		
		var spanTwo = document.createElement('span');
		spanTwo.className = "db3";	
		
		submitDiv.appendChild(spanOne);
		submitDiv.appendChild(submitBtn);
		submitDiv.appendChild(spanTwo);	

		var submitDiv2 = document.createElement('div');
		submitDiv2.className = "dynamic_button";
		
		var spanOne2 = document.createElement('span');
		spanOne2.className = "db1";		
		
		submitBtn2 = document.createElement('a');
		submitBtn2.className = "db2";
		submitBtn2.onclick = function(){if(validateMenu(document.forms["menuItemForm"])) addToCartAjax(buildingCoupon);};
		submitBtn2.appendChild(submitBtnText2);		
		
		var spanTwo2 = document.createElement('span');
		spanTwo2.className = "db3";	
		
		submitDiv2.appendChild(spanOne2);
		submitDiv2.appendChild(submitBtn2);
		submitDiv2.appendChild(spanTwo2);	
		
		
		finalDiv.appendChild(submitDiv);		
		finalPriceDiv.appendChild(submitDiv2);
	}
	else{
		closedImage = document.createElement("img");
		closedImage.src = "images/closed_button.jpg";
		closedImage.className = "closed_button";
		finalDiv.appendChild(closedImage);
		
		closedImage2 = document.createElement("img");
		closedImage2.src = "images/closed_button.jpg";
		closedImage2.className = "closed_button";
		finalPriceDiv.appendChild(closedImage2);
	}
	
	if (buildingCoupon) {
		hiddenField = createInput("hidden", "couponId");
		hiddenField.value = buildingCoupon;
		finalDiv.appendChild(hiddenField);
		hiddenField = createInput("hidden", "groupId");
		hiddenField.value = groupId;
		finalDiv.appendChild(hiddenField);
	}
						
	menuOrderDiv.appendChild(specialRequests);
	menuOrderDiv.appendChild(specialReqInfoSpan);
	menuOrderDiv.appendChild(finalDivWhole);
	menuOrderDiv.appendChild(finalPriceDiv);
	
	fixedBox = document.createElement('div');
	fixedBox.className = "fixedBoxPosition";
	
	fixedBox.appendChild(finalDivWhole);
	
	rightColDiv = document.createElement('div');
	rightColDiv.className = 'menu_order_right_col';
	rightColDiv.appendChild(fixedBox);
	
	if (buildingCoupon == false)
		rightColDiv.appendChild(createCouponShelf(dom.getElementsByTagName("coupon"), dom, menuItemId));
		
	form.appendChild(rightColDiv);
	form.appendChild(menuInfoDiv);
	form.appendChild(menuOrderDiv);
	contentBody.appendChild(form);
	updateMenuItemPriceAjax(form.name, "");
	contentBody.style.visibility = "visible";
	
	finalDivBottom = document.createElement('div');
	finalDivBottom.className = 'final_order_block_bottom';
	finalDivWhole.appendChild(finalDivBottom);
}

function createCouponShelf(coupons, dom, menuItemId){

	var wrapperDiv = null;
	var couponsDiv = null;
	shelfDiv = document.createElement('div');
	shelfDiv.className = 'coupon_shelf';
	shelfDiv.id = 'coupon_box';

	direction = 1;
	end = 0;
	speed = 25;
	currTop = 1;
	lastCoupon = coupons.length;
	couponsPerGroup = 2;
	
	if (coupons.length != 0) {
		 
		couponPrevNext = document.createElement('div');
		couponPrevNext.className = "coupon_prev_next"
		couponPrevNext.id = "coupon_prev_next";
		shelfDiv.appendChild(couponPrevNext);
		
		var spanElm = document.createElement("a");
		spanElm.id = "coupon_prev_id";
		spanElm.className ="coupon_prev coupon_button_off";
		addEvent(spanElm, "click", function() { preMove('theCoupons', 'prev'); } );
		couponPrevNext.appendChild(spanElm);
		
		spanElm = document.createElement("a");
		spanElm.id = "coupon_next_id";
		spanElm.className = "coupon_next";
		if (lastCoupon <= couponsPerGroup) {
			spanElm.className += " coupon_button_off";
		}
		addEvent(spanElm, "click", function() { preMove('theCoupons', 'next'); } );
		couponPrevNext.appendChild(spanElm);
		
		couponHeader = document.createElement('div');
		couponHeader.className ="coupons_menu_header";
		couponHeader.appendChild(document.createTextNode('Coupons'));
		shelfDiv.appendChild(couponHeader);
		
		wrapperDiv = document.createElement('div');
		wrapperDiv.id = "coupon_shelf_wrapper";
		 
		couponsDiv = document.createElement('div');
		couponsDiv.id = 'theCoupons';
		couponsDiv.style.position = 'relative';
		couponsDiv.style.left = '0px';
		couponsDiv.style.top = '0px';
		couponsDiv.style.height = (250 * coupons.length) + 'px';
		couponsDiv.style.width = '158px'; 
	}
	if (coupons.length != 0) {
		wrapperDiv.appendChild(couponsDiv);
		shelfDiv.appendChild(wrapperDiv);
		
		
	}
	for(i = 0; i < coupons.length; i++){
		coupon = coupons[i];
		couponDiv = document.createElement('div');
		couponDiv.className = 'coupon_parent';
		couponDiv.id = "coupon" + (i+1);
		if (i >= couponsPerGroup) {
			couponDiv.style.visibility = "hidden";
			if (i % couponsPerGroup == 0) {
				var spacerDiv = document.createElement('div');
				spacerDiv.style.height = '100px';
				spacerDiv.style.clear = 'both';
				spacerDiv.appendChild(document.createTextNode(' '));
				couponsDiv.appendChild(spacerDiv);
			}
		} else {
			couponDiv.style.visibility = "visible";
		}
		
		couponHeaderDiv = document.createElement('div');
		couponHeaderDiv.className = 'coupon_header';
		couponTitle = document.createElement('h3');
		couponTitleText = document.createTextNode(coupon.getAttribute('name') + ' Coupon');
		couponTitle.appendChild(couponTitleText);
		couponHeaderDiv.appendChild(couponTitle);
		
		couponBodyDiv = document.createElement('div');
		couponBodyDiv.className = 'coupon_body';
		
		couponItemsDiv = document.createElement('div');
		breakEle = document.createElement('br');
		items = dom.getElementsByTagName('couponItems' + coupon.getAttribute('id'));
		for(j = 0; j < items.length; j++){
			var item = items[j];
			couponItemsDiv.appendChild(document.createTextNode(item.getAttribute('name')));
			couponItemsDiv.appendChild(document.createElement('br'));
		}
		couponBodyDiv.appendChild(couponItemsDiv);
		couponPriceSpan = document.createElement('span');
		couponType = coupon.getAttribute('couponType');
		if(couponType == 1){
			couponPriceText = document.createTextNode('$' + coupon.getAttribute('price'));
		} else if (couponType == 2) {
			couponPriceText = document.createTextNode((coupon.getAttribute('price')*100) + "% Off Order");
		} else if (couponType == 0){
			couponPriceText = document.createTextNode('$' + coupon.getAttribute('price') + ' off');		
		}
		couponPriceSpan.appendChild(couponPriceText);
		couponBodyDiv.appendChild(couponPriceSpan);
		couponDeliveryType = coupon.getAttribute('deliveryType');
		var numMatches = 0;
		var couponText = "";
		if(couponDeliveryType == '1' || couponDeliveryType == '3' || couponDeliveryType == '5' || couponDeliveryType == '7'){
			couponText = "Delivery/";
			numMatches++;
		}
		if(couponDeliveryType > 3){
			couponText += "Carry Out/";
			numMatches++;
		}
		if (couponDeliveryType == '2' || couponDeliveryType == '3' || couponDeliveryType == '6' || couponDeliveryType == '7') {
			couponText += "Dine In/";
			numMatches++;
		}
		couponText = couponText.substring(0, couponText.length-1);
		if (numMatches == 1) {
			couponText += " Only";
		} else if (numMatches == 3) {
			couponText = "";
		}
		couponDeliveryTypeText = document.createTextNode(couponText);
		
		breakEle = document.createElement('br');
		couponDeliveryTypeSpan = document.createElement('span');
		couponDeliveryTypeSpan.appendChild(couponDeliveryTypeText);
		couponBodyDiv.appendChild(breakEle);
		couponBodyDiv.appendChild(couponDeliveryTypeSpan);
		
		couponFooterDiv  = document.createElement('div');
		couponFooterDiv.className = 'coupon_footer';
		submitBtn = document.createElement('a');
		submitBtn.className = "profile_add_to_cart";
		submitBtn.href = "/viewMenu.food?event=doBuildCoupon&id=" + coupon.getAttribute("id") + "&menuItemId=" + menuItemId;
		submitBtnText = document.createTextNode("Build Coupon");
		submitBtn.appendChild(submitBtnText);
		couponFooterDiv.appendChild(submitBtn);
				
		couponDiv.appendChild(couponHeaderDiv);
		couponDiv.appendChild(couponBodyDiv);
		couponDiv.appendChild(couponFooterDiv);
		
		couponsDiv.appendChild(couponDiv);
	}
	
	
	
	return shelfDiv;
}

function displayOrder(dom){
	cart = dom.getElementsByTagName('cart')[0];
	var mycart = document.getElementById('mycart');

	// Remove previous cart
	while (mycart.firstChild) 
	{
	   mycart.removeChild(mycart.firstChild);
	};
	
	// build new cart
	personSpan = document.createElement('span');
	personSpan.className = 'icebox_title';
	personText = document.createTextNode(dom.getElementsByTagName('cart')[0].getAttribute('user') + "'s Order");
	personSpan.appendChild(personText);
	mycart.appendChild(personSpan);
	orderTable = document.createElement('div');
	orderTable.className = "orderTable";
	cartItems = dom.getElementsByTagName('cart-item');
	
	count = 0;
	for(i = 0; i < cartItems.length; i++){
		cartItem = cartItems[i];
		rowSpan = document.createElement('span');
		if(i%2 != 0){
			rowSpan.className = 'even';
		}
		else{
			rowSpan.className = 'odd';
		}
		oneSpan = document.createElement('span');
		oneSpan.className = 'one';
		oneSpan.appendChild(document.createTextNode(cartItem.getAttribute('name')));
		twoSpan = document.createElement('span');
		twoSpan.className = 'two';
		twoSpan.appendChild(document.createTextNode(cartItem.getAttribute('qty')));
		threeSpan = document.createElement('span');
		threeSpan.className = 'three';
		threeSpan.appendChild(document.createTextNode(cartItem.getAttribute('price')));		
		
		rowSpan.appendChild(oneSpan);		
		rowSpan.appendChild(twoSpan);
		rowSpan.appendChild(threeSpan);
		
		orderTable.appendChild(rowSpan);
		count++;
	}
	
	for(i = count; i < 5; i++){
		rowFillerDiv = document.createElement('div');
		if (!window.ActiveXObject)
			rowFillerDiv.style.padding = '6px';
		if(i%2 != 0){
			rowFillerDiv.className = 'even fillerrow';
		}
		else{
			rowFillerDiv.className = 'odd fillerrow';
		}
		//rowFillerDiv.appendChild(document.createTextNode('    '));
		orderTable.appendChild(rowFillerDiv);
	}
	
	mycart.appendChild(orderTable);
	
	checkoutDiv = document.createElement('div');
	checkoutDiv.className = 'total_checkout';
	
	subTotalDiv = document.createElement('div');
	subTotalDiv.appendChild(document.createTextNode('SUBTOTAL'));
	
	subTotalNumDiv = document.createElement('div');
	subTotalNumDiv.className = 'main_total';
	subTotalNumDiv.appendChild(document.createTextNode(cart.getAttribute('subtotal')));
	
	subTotalDiv.appendChild(subTotalNumDiv);
	
	checkoutDiv.appendChild(subTotalDiv);
	
	loginSpan = document.createElement('span');
	if(cart.getAttribute('checkout')){
		var imageFolder = dom.getElementsByTagName('imageFolder')[0].getAttribute('name');
		checkoutLink = document.createElement('a');
		checkoutLink.id = 'checkoutLinkId';
		checkoutLink.href = '/checkout.food?event=toCheckout';
		addEvent(checkoutLink, "click", function (){this.href=this.href.replace(/^http:/i,'https:');});
		checkoutImg = document.createElement('img');
		checkoutImg.src = 'images/' + imageFolder + '/checkout-small.jpg';
		checkoutImg.alt = 'Checkout!';
		checkoutImg.style.margin = '0px';
		checkoutLink.appendChild(checkoutImg);
		loginSpan.appendChild(checkoutLink);
		loginSpan.style.marginTop = "7px";
	}
	
	if(cart.getAttribute('user') != 'Guest'){
		logoutSpan = document.createElement('span');
		logoutSpan.id = 'logout';
		logoutLink = document.createElement('a');
		logoutLink.href = '/logout.food';
		logoutLink.appendChild(document.createTextNode('Logout'));
		logoutSpan.appendChild(logoutLink);
		//loginSpan.appendChild(logoutSpan);
	}
	checkoutDiv.appendChild(loginSpan);
	
	mycart.appendChild(checkoutDiv);
	
	/*var sslLink = document.getElementById('checkoutLinkId');
	if(sslLink.href.substr(0, 5) != "https:"){
		sslLink.href = "https:" + sslLink.href.substr(5, sslLink.href.length);
	}*/
}

function displayLeftNav(dom){
	// Display Header Checkout Link
	var emptyCheckout = document.getElementById('headerEmptyCheckout');
	var checkoutLink1 = document.getElementById('headerCheckoutLink1');
	var checkoutLink2 = document.getElementById('headerCheckoutLink2');
	
	if(checkoutLink1 != null && checkoutLink2 != null && emptyCheckout != null){
		checkoutLink1.style.display = 'inline';
		checkoutLink2.style.display = 'inline';		
		emptyCheckout.style.display = 'none';
		
		var subtotalPrice = document.getElementById('headerCheckoutTotal');
		var cart = dom.getElementsByTagName('cart')[0];
		
		if(subtotalPrice != null && cart != null){
			while(subtotalPrice.firstChild){
				subtotalPrice.removeChild(subtotalPrice.firstChild);
			}
			
			subtotalPrice.appendChild(document.createTextNode('$' + cart.getAttribute('subtotal')));
		}
	}
	
	// Display Order Tab
	var viewOrderTab = document.getElementById('headerNavigation4');
	
	if(viewOrderTab != null){
		viewOrderTab.style.display = 'block';
	}
	
	//update LeftNav ChangeLocation
	var changeLocationSelect = document.getElementById('locationChangeId');
	if(changeLocationSelect){
		changeLocationSelect.onchange = null;
		addEvent(changeLocationSelect, 'change', function(){locationChange(cart.getAttribute('subtotal'))});
	}
}

function displayUpsaleCoupon(dom){
	contentBody = document.getElementById('menu-item');
	
	itemAddedDiv = document.createElement("div");
	itemAddedDiv.className = "itam_added_to_cart"; 
	itemAddedDiv.appendChild(document.createTextNode("Item Added to Cart"));
	contentBody.appendChild(itemAddedDiv);
	
	contentBody.appendChild(createCouponShelf(dom.getElementsByTagName("coupon"), dom, ""));
	
	upsaleItems = dom.getElementsByTagName('upsaleItem');
	
	if(upsaleItems.length > 0){
		upsaleDiv = document.createElement("div");
		
		h3title = document.createElement("h3");
		h3title.className = "you_might_also_like";
		h3title.appendChild(document.createTextNode("You Might Also Like..."));
		upsaleDiv.appendChild(h3title);
		
		for(i = 0; i < upsaleItems.length; i++){
			var upsaleItem = upsaleItems[i];
			upsaleItemDiv = document.createElement('div');
			upsaleItemId = upsaleItem.getAttribute("id");
			upsaleItemCategory = upsaleItem.getAttribute("category");
			h3UpsaleItemTitle = document.createElement("h4");
			h3UpsaleItemTitle.className = "upsale_item_name";
			h3UpsaleItemTitle.appendChild(document.createTextNode(upsaleItem.getAttribute("name") + "?"));
	
			descriptionDiv = document.createElement("div");
			descriptionDiv.appendChild(document.createTextNode(upsaleItem.getAttribute("description")));
	
			submitBtn = document.createElement('a');
			submitBtn.href = "javascript:displayMenuItemAjax(" + upsaleItemId + ", false, 0, " + upsaleItemCategory + ", true);";
			//submitBtn.href = "#";			
			//addEvent(submitBtn,'click',function(){displayMenuItemAjax(upsaleItemId, false, 0, upsaleItemCategory, true);});
			submitBtnText = document.createTextNode("add to order");		
			submitBtn.appendChild(submitBtnText);
			
			upsaleItemDiv.appendChild(h3UpsaleItemTitle);
			upsaleItemDiv.appendChild(descriptionDiv);
			upsaleItemDiv.appendChild(submitBtn);	
			upsaleDiv.appendChild(upsaleItemDiv);

		}
		
		contentBody.appendChild(upsaleDiv);
	}

	//displayHideCategory(upsaleItem.getAttribute("category"));
}

function addToCartAjax(buildingCoupon){
	formParameters = getFormAsString('menuItemForm');
	ajax = new ajaxRequest;
	if (!buildingCoupon)
		ajax.send(false, "/viewMenu.food?event=doAddToCart", formParameters, "addToCart");
	else {
		oldMenuItemId = -1;
		ajax.send(false, "/viewMenu.food?event=doAddCoupon", formParameters, "addToCart", '\'' + buildingCoupon + '\'');
	}
}

function addToCart(dom, buildingCoupon){
	var tooManyToppings = false;
	var minimumError = false;
	var doneCoupon = dom.getElementsByTagName("doneCoupon");
	if (doneCoupon.length != 0)
		doneCoupon = true;
	else
		doneCoupon = false;
		
	if (buildingCoupon && !doneCoupon) {
		if (dom.getElementsByTagName("tooManyToppings").length > 0)
			tooManyToppings = dom.getElementsByTagName("tooManyToppings")[0].getAttribute("value");
			if (tooManyToppings == "false")
				tooManyToppings = false;
		if (dom.getElementsByTagName("minimumError").length > 0)
			minimumError = dom.getElementsByTagName("minimumError")[0].getAttribute("minimum");
	}
	if (minimumError) {
		alert("This coupon is only valid on an order of more than " + minimumError + ".  Please add more to your order and then try again.");
	} else if (tooManyToppings) {
		var couponReqType = dom.getElementsByTagName("couponReqType")[0].getAttribute("value");
		var toppingLimit = dom.getElementsByTagName("toppingLimit")[0].getAttribute("value");
		if (couponReqType == "1")
			alert("You must choose " + toppingLimit + " toppings for this item. Please edit your topping selection.");
		else if (couponReqType == "2")
			alert("You must choose at least " + toppingLimit + " toppings for this item. Please edit your topping selection.");
		else if (couponReqType == "3")
			alert("You can only choose " + toppingLimit + " toppings for this item. Please edit your topping selection.");
	} else {
		contentBody = document.getElementById('menu-item');
		while (contentBody != null && contentBody.firstChild) {
		    contentBody.removeChild(contentBody.firstChild);
		};
		if (!buildingCoupon) {
			displayLeftNav(dom);
			displayOrder(dom);
			displayUpsaleCoupon(dom);
			window.location = "#pageTop";
		} else if (doneCoupon) {
			window.location = "viewMenu.food?event=doList";
		} else {
			step++;		
			updateCurrentCouponItem(step);
			couponMeterFill();
			itemAddedDiv = document.createElement("div");
			itemAddedDiv.className = "itam_added_to_cart";
			tempText = document.createTextNode("Item added to coupon.  Choose next item.");
			itemAddedDiv.appendChild(tempText);
			contentBody.appendChild(itemAddedDiv);
			var newGroup = dom.getElementsByTagName("nextGroupId")[0].getAttribute("value");
			if(dom.getElementsByTagName("displayNextMenuItem")[0].getAttribute("menuItemId") != -1){
				nextMenuItemId = dom.getElementsByTagName("displayNextMenuItem")[0].getAttribute("menuItemId");
				coupId = dom.getElementsByTagName("displayNextMenuItem")[0].getAttribute("couponId");
				displayMenuItemAjax(nextMenuItemId, coupId, newGroup, newGroup);
			}
			else{
				displayHideCategory(newGroup);
			}
			window.location = "#pageTop";
		}
	} 
}

function updateMenuItemPriceAjax(formName, lastEntered){
	var formParameters = getFormAsString(formName, lastEntered);
	ajax = new ajaxRequest;
	ajax.send(false, "/viewMenu.food?event=doUpdateMenuItemPrice", formParameters, "updateMenuItemPrice", '\'' + formName + '\'');
}

function updateMenuItemPrice(dom, formName){
	var resetLastEntered;
	var turnOffWholes;
	var turnOffHalves;
	
	costVal = dom.getElementsByTagName("price");
	var cost = document.getElementById("currentCost");
	var cost2 = document.getElementById("currentCost2");
	cost.firstChild.nodeValue = costVal[0].childNodes[0].nodeValue;
	cost2.firstChild.nodeValue = costVal[0].childNodes[0].nodeValue;	
	
	turnOffWholes = dom.getElementsByTagName("turnOffWholes")[0].childNodes[0].nodeValue;
	turnOffHalves = dom.getElementsByTagName("turnOffHalves")[0].childNodes[0].nodeValue;

	var resetElms = document.forms[formName].elements;
	for (var i = 0; i < resetElms.length; i++) {
		var currElmName = resetElms[i].name;
		if (currElmName.substring(0,7) == "topping") {
        	if (turnOffHalves == "true" || turnOffWholes == "true") {
				if (resetElms[i].checked) {
					if (turnOffWholes == "true")
						resetElms[i+1].disabled = true;
					if (turnOffHalves == "true") {
						resetElms[i+2].disabled = true;
						resetElms[i+3].disabled = true;
					} else {
						resetElms[i+2].disabled = false;
						resetElms[i+3].disabled = false;
					}
				} else if (resetElms[i+1].checked) {
					resetElms[i+2].disabled = false;
					resetElms[i+3].disabled = false;
				} else {
					if (turnOffHalves == "true")
						resetElms[i+1].disabled = true;
					else
						resetElms[i+1].disabled = false;
				}
			} else {
				resetElms[i+1].disabled = false;
				resetElms[i+2].disabled = false;
				resetElms[i+3].disabled = false;
			}
			i += 3;
		}
	}
}