//////////////////////////
// Globals
//////////////////////////
var objOrder = new Object();
objOrder.count = 0;
objOrder.orderTotal = 0;
objOrder.orderItems = new Array();
var i = 0;

//////////////////////////
// Functions
//////////////////////////

function InitPage()
{
	//InitFloatingObject();
	DoCheeseLogic();
	DoMeatLogic();	
	DisplayOrder();
}

function ShowDailyPriceCode (inID, bSoup)
{
	if (!bSoup) {
		document.write ("<a href=\"javascript:AddItemToOrder('DAILY'," + inID + ")\">" + dailyArray[inID]['price'] + "</a>");
	} else {
		document.write ("<a href=\"javascript:AddItemToOrder('DAILY'," + inID + ",'soup')\">" + dailyArray[inID]['price'] + "</a>");
	}
}


function DisplayOrder()
{
	var myHTML = "";
	var i = 0;
	objOrder.orderTotal = 0;
	objOrder.item_count = 0;
	
	if (IsOrderEmpty()) {
			myHTML = myHTML + "Your order is empty.";
	} else {
			myHTML = myHTML + "<table width=100%>";	
		for (i = 0; i<objOrder.count; i++) 
		{
			if (!objOrder.orderItems[i].deleted) 
			{
				objOrder.item_count = objOrder.item_count + objOrder.orderItems[i].quantity;
				myHTML = myHTML + "<tr><td class=orderTitle><a href=javascript:RemoveItemFromOrder("+i+")><img align=middle src=images/delete.gif border=0></a><a href=javascript:DoUp("+i+")><img align=middle src=images/up.gif border=0></a><a href=javascript:DoDown("+i+")><img align=middle src=images/down.gif border=0></a> " + objOrder.orderItems[i].quantity + " X " + objOrder.orderItems[i].name + "</td><td></td></tr>";
		
				if (objOrder.orderItems[i].condimFlag) 
				{
					myHTML = myHTML + "<tr><td class=orderDetails>" + objOrder.orderItems[i].desc + "</td><td class=orderDetails valign=bottom>$" + FormulateNumber(myRound((objOrder.orderItems[i].price * objOrder.orderItems[i].quantity),2)) + "</td></tr>";
					myHTML = myHTML + "<tr><td class=orderDetails>" + ShowCondiments(i) + "</td><td class=orderDetails valign=top>$" + FormulateNumber(myRound((objOrder.orderItems[i].condimPrice * objOrder.orderItems[i].quantity),2)) + "</td></tr>";
					myHTML = myHTML + "<tr><td class=orderDetails>-- Sandwich for: " + objOrder.orderItems[i].clientName + "<BR>-- Special requests: " + objOrder.orderItems[i].specialRequest + "</td><td class=orderDetails valign=bottom></td></tr>";
					objOrder.orderTotal = objOrder.orderTotal + myRound((objOrder.orderItems[i].condimPrice * objOrder.orderItems[i].quantity),2);					
				} 
				else 
				{
					myHTML = myHTML + "<tr><td class=orderDetails>" + objOrder.orderItems[i].desc + "</td><td class=orderDetails valign=bottom>$" + FormulateNumber(myRound((objOrder.orderItems[i].price * objOrder.orderItems[i].quantity),2)) + "</td></tr>";
				}
				if (objOrder.orderItems[i].dailyFlag)
				{
					myHTML = myHTML + "<tr><td class=orderDetails>-- Daily special for: " + objOrder.orderItems[i].clientName + "<BR>-- Special requests: " + objOrder.orderItems[i].specialRequest + "</td><td class=orderDetails valign=bottom></td></tr>";
				}
				if (objOrder.orderItems[i].specialFlag) 
				{
					myHTML = myHTML + "<tr><td class=orderDetails>-- Special requests: " + objOrder.orderItems[i].specialRequest + "</td><td class=orderDetails valign=bottom></td></tr>";
				}

				objOrder.orderTotal = objOrder.orderTotal + myRound((objOrder.orderItems[i].price * objOrder.orderItems[i].quantity),2);
			}
		}
			myHTML = myHTML + "</table>";			
	}
	
	myHTML = myHTML + "<BR><BR><center><B><font size=2>Estimated order total (before tax): $" + FormulateNumber(myRound(objOrder.orderTotal,2)) + "</font></B></center>";
	myHTML = myHTML + "<center><font size=1>(Final prices will be determined on pickup)</font></center><BR>";	
	myHTML = myHTML + '<table border="0" cellpadding="2" cellspacing="0" align="center"><tr><td class=orderDetails>Company: <input type="text" id="company" size="15" style="font-family: Arial; font-size: 8pt"></td><td class=orderDetails>Name: <input type="text" id="name" size="15" style="font-family: Arial; font-size: 8pt"></td><tr><td class=orderDetails>Phone: <input type="text" id="phone" size="15" style="font-family: Arial; font-size: 8pt"></td><td class=orderDetails>Email: <input type="text" id="email" size="15" style="font-family: Arial; font-size: 8pt"></td></tr>';
	myHTML = myHTML + '<tr><td colspan=2 class=orderDetails>Desired pickup time (optional): <input type="text" id="pickup" size="15" style="font-family: Arial; font-size: 8pt"></td></tr></table>';
	myHTML = myHTML + "<BR><center><input type='button' id='submitButton' onClick='javascript:SubmitOrder()' value='PLACE ORDER'></center>";	
	myHTML = myHTML + "<BR><center><font size=1>Item count for this order: " + objOrder.item_count + "</font></center>";	
	
	DIV_ORDER.innerHTML = myHTML;
	
}

function ShowCheeseMenu()
{
	var i = 0;
	var myHTML = "";
	
	for (i = 0; i < cheeseArray.length; i++) {
		myHTML = myHTML + '<tr><td><font size="2" face="Arial">' + cheeseArray[i].name +'</font></td>';
		myHTML = myHTML + '<td><font size="2" face="Arial">$' + cheeseArray[i].price + '</font></td>';
		myHTML = myHTML + '<td><select size="1" name="cheese_pounds'+i+'"><option value="0.25">0.25 lb.</option><option value="0.50">0.50 lb.</option><option value="0.75">0.75 lb.</option><option value="1.00">1.00 lb.</option><option value="1.25">1.25 lb.</option><option value="1.50">1.50 lb.</option><option value="1.75">1.75 lb.</option><option value="2.00">2.00 lb.</option></select></td>';
		myHTML = myHTML + '<td><font size="2" face="Arial"><input type="radio" value="Thin Slices" name="slices'+i+'"> thin<BR><input type="radio" value="Thick Slices" name="slices'+i+'"> thick</font></td>';
		myHTML = myHTML + "<td><input type='button' onClick=javascript:AddItemToOrder('CHEESE',"+i+",GetDropDownValue(document.FormCheese.cheese_pounds"+i+"),GetRadioValue(document.FormCheese.slices"+i+")) value='Add to order'></td></tr>";
		
		document.write(myHTML);
		myHTML = "";
	}
}

function ShowMeatsMenu()
{
	var i = 0;
	var myHTML = "";
	
	for (i = 0; i < meatsArray.length; i++) {
		myHTML = myHTML + '<tr><td><font size="2" face="Arial">' + meatsArray[i].name +'</font></td>';
		myHTML = myHTML + '<td><font size="2" face="Arial">$' + meatsArray[i].price + '</font></td>';
		myHTML = myHTML + '<td><select size="1" name="meats_pounds'+i+'"><option value="0.25">0.25 lb.</option><option value="0.50">0.50 lb.</option><option value="0.75">0.75 lb.</option><option value="1.00">1.00 lb.</option><option value="1.25">1.25 lb.</option><option value="1.50">1.50 lb.</option><option value="1.75">1.75 lb.</option><option value="2.00">2.00 lb.</option></select></td>';
		myHTML = myHTML + '<td><font size="2" face="Arial"><input type="radio" value="Thin Slices" name="m_slices'+i+'"> thin<BR><input type="radio" value="Thick Slices" name="m_slices'+i+'"> thick</font></td>';
		myHTML = myHTML + "<td><input type='button' onClick=javascript:AddItemToOrder('MEATS',"+i+",GetDropDownValue(document.FormMeats.meats_pounds"+i+"),GetRadioValue(document.FormMeats.m_slices"+i+")) value='Add to order'></td></tr>";
		
		document.write(myHTML);
		myHTML = "";
	}
}

function ShowSaladMenu()
{
	var i = 0;
	var myHTML = "";
	
	for (i = 0; i < saladArray.length; i++) {
		myHTML = myHTML + '<tr><td><font size="2" face="Arial">' + saladArray[i].name +'</font></td>';
		myHTML = myHTML + '<td><font size="2" face="Arial">$' + saladArray[i].price + '</font></td>';
		myHTML = myHTML + '<td><select size="1" name="salad_pounds'+i+'"><option value="0.5">0.5 pint</option><option value="1.00">1 pint</option><option value="2">1 quart</option></select></td>';
		myHTML = myHTML + "<td><input type='button' onClick=javascript:AddItemToOrder('SALAD',"+i+",GetDropDownValue(document.FormSalads.salad_pounds"+i+")) value='Add to order'></td></tr>";
		
		document.write(myHTML);
		myHTML = "";
	}
}

function ValidateCheeseSandwich(inID, inCheese) {
	alert(inCheese);
}

function ShowSandwiches()
{
	var i = 0;
	var myName = "";
	for (i = 0; i < sandwichArray.length; i++) {
	
		var bCheeseFlag = true;
		
		if (i == 11)
		{
			// insert mid-section hearders
			document.write('<TR><TD bgcolor="#dddddd"><font style="font-size: 9pt" color="#000000" size="3" face="arial,helvetica,sans-serif">&nbsp;Sandwiches</font></TD>');
			document.write('<TD bgcolor="#dddddd"align="left"><font style="font-size: 9pt" color="#000000" size="3" face="arial,helvetica,sans-serif">Bread &amp; Cheese</font></TD>');
			document.write('<TD bgcolor="#dddddd"align="left"><FONT face="arial,helvetica,sans-serif" style="font-size: 9pt" color="#000000" size="3">Small (Plain)</FONT></TD>');
			document.write('<TD bgcolor="#dddddd"align="left"><FONT face=arial,helvetica,sans-serif style="font-size: 9pt" color="#000000" size="3">Large (Plain)</FONT></TD>');
			document.write('<TD bgcolor="#dddddd"align="left"><font face=arial,helvetica,sans-serif style="font-size: 9pt">Small<BR>With Works*</font></TD>');
			document.write('<TD bgcolor="#dddddd"align="left"><FONT face=arial,helvetica,sans-serif style="font-size: 9pt">Large<BR>With Works*</FONT></TD></TR>');
		}
	
		// Find out if we need to display the cheese or not
		if (sandwichArray[i]['name'].indexOf(".") != -1) {
			myName = sandwichArray[i]['name'].substr(0,(sandwichArray[i]['name'].length-1));
			bCheeseFlag = false;
		} else {
			myName = sandwichArray[i]['name'];
		}
		document.write ("<tr><TD><FONT face=arial,helvetica,sans-serif><FONT size=2><STRONG>"+myName+"<BR></STRONG></FONT><FONT size=1>"+sandwichArray[i]['desc']+"</FONT></FONT></TD>");
		document.write ('<TD>');
		document.write ('<select size="1" name="select_bread'+i+'" style="font-family: Arial; font-size: 8pt"><option value="Italian Roll">Italian Roll</option><option value="Sliced Wheat">Sliced Wheat</option><option value="Sliced Rye">Sliced Rye</option><option value="Sliced 7 grain">Sliced 7 grain</option><option value="Sliced Italian">Sliced Italian</option></select><BR>');
		if (bCheeseFlag) {
			document.write ('<select size="1" name="select_cheese'+i+'" style="font-family: Arial; font-size: 8pt"><option value="No Cheese">No Cheese</option><option value="American">American</option><option value="Cheddar">Cheddar</option><option value="Havarti">Havarti</option><option value="Horseradish Cheddar">Horseradish Cheddar**</option><option value="Jack">Jack</option><option value="Pepper Jack">Pepper Jack</option><option value="Provolone">Provolone</option><option value="Mozzarella">Mozzarella</option><option value="Muenster">Muenster</option><option value="Swiss">Swiss</option><option value="Water Mozzarella">Water Mozzarella**</option></select>');
		} else {
			document.write ('<select size="1" name="select_cheese'+i+'" style="font-family: Arial; font-size: 8pt"><option value="" selected>Not Applicable</option></select>');
		}
		
		document.write ('</TD>');
		if (GetSandwichPrice(sandwichArray[i]['price'],0) == "NA") {
			document.write ("<TD><FONT face=arial,helvetica,sans-serif>"+GetSandwichPrice(sandwichArray[i]['price'],0)+"</FONT></TD>");		
		} else {
			document.write ("<TD><FONT face=arial,helvetica,sans-serif><a href=javascript:AddItemToOrder('SANDWICH',"+i+",'small,'+GetDropDownValue(document.FormSandwich.select_bread"+i+")+','+GetDropDownValue(document.FormSandwich.select_cheese"+i+"),"+GetSandwichPrice(sandwichArray[i]['price'],0)+",false)>"+GetSandwichPrice(sandwichArray[i]['price'],0)+"</a></FONT></TD>");
		}
		if (GetSandwichPrice(sandwichArray[i]['price'],1) == "NA") {
			document.write ("<TD><FONT face=arial,helvetica,sans-serif>"+GetSandwichPrice(sandwichArray[i]['price'],1)+"</FONT></TD>");
		} else {
			document.write ("<TD><FONT face=arial,helvetica,sans-serif><a href=javascript:AddItemToOrder('SANDWICH',"+i+",'large,'+GetDropDownValue(document.FormSandwich.select_bread"+i+")+','+GetDropDownValue(document.FormSandwich.select_cheese"+i+"),"+GetSandwichPrice(sandwichArray[i]['price'],1)+",true)>"+GetSandwichPrice(sandwichArray[i]['price'],1)+"</a></FONT></TD>");
		}
		if (GetSandwichPrice(sandwichArray[i]['price'],2) == "NA") {
			document.write ("<TD><FONT face=arial,helvetica,sans-serif>"+GetSandwichPrice(sandwichArray[i]['price'],2)+"</FONT></TD>");
		} else {
			document.write ("<TD><FONT face=arial,helvetica,sans-serif><a href=javascript:AddItemToOrder('SANDWICH',"+i+",'small,'+GetDropDownValue(document.FormSandwich.select_bread"+i+")+','+GetDropDownValue(document.FormSandwich.select_cheese"+i+"),"+GetSandwichPrice(sandwichArray[i]['price'],2)+",-1)>"+GetSandwichPrice(sandwichArray[i]['price'],2)+"</a></FONT></TD>");
		}
		if (GetSandwichPrice(sandwichArray[i]['price'],3) == "NA") {
			document.write ("<TD><FONT face=arial,helvetica,sans-serif>"+GetSandwichPrice(sandwichArray[i]['price'],3)+"</FONT></TD></tr>");	
		} else {
			document.write ("<TD><FONT face=arial,helvetica,sans-serif><a href=javascript:AddItemToOrder('SANDWICH',"+i+",'large,'+GetDropDownValue(document.FormSandwich.select_bread"+i+")+','+GetDropDownValue(document.FormSandwich.select_cheese"+i+"),"+GetSandwichPrice(sandwichArray[i]['price'],3)+",-1)>"+GetSandwichPrice(sandwichArray[i]['price'],3)+"</a></FONT></TD>");
		}
	}
}

function GetSandwichPrice(inList, inID)
{
	var myPrices = new Array();
	myPrices = inList.split (",");
	return myPrices[inID];	
}

function GetDropDownValue(inObj)
{

	var i;

	for (i = 0; i < inObj.options.length; i++) {
		if (inObj.options[i].selected) {
			return inObj.options[i].value;
		}
	}
	//alert("GetDropDownValue: Couldn't find selected value");	
}

function SetDropDownValue(inObj,inValue)
{
	var i;
	for (i = 0; i < inObj.options.length; i++) {
		if (inObj.options[i].value == inValue) {
			inObj.options[i].selected = true;
			return;
		}
	}
	//alert("SetDropDownValue: Couldn't set " + inValue);	
}

function InitFloatingObject()
{
	if (navigator.appName == "Netscape") {
		myy=window.pageYOffset+80;
		document.DIV_CART.top=myy;
	} else {
		myy=document.body.scrollTop+80;
		DIV_CART.style.pixelTop=myy;}
		//setTimeout("InitFloatingObject()",10);
}

function AddSpecialToOrder()
{
	// Add to order
	/////////////////////
	objOrder.orderItems[objOrder.count] = new Object();
	var subTotal = 0;
	var i = 0;
	var myCondimPrice = 0;;
	var myDesc = "";	
	var bLarge = false;
	var AddExtraMeatToPrice = false;
	var AddExtraCheeseToPrice = false;
	var myMsg = "Your forgot to...\n\n";
	var meat_cheese_problem = false;

	if (GetDropDownValue(document.FormSandwich.special_meat) == "Choose Your Meat") {
		myMsg = myMsg + "   - Choose your meat\n";
		meat_cheese_problem = true;
	}

	if (GetDropDownValue(document.FormSandwich.special_cheese) == "Choose Your Cheese") {
		myMsg = myMsg + "   - Choose your cheese (or select 'no cheese' if you don't want any)\n";
		meat_cheese_problem = true;
	}

	if (meat_cheese_problem) {
		alert(myMsg);
		return false;
	}
	
	// Figure out the price
	var myType = GetDropDownValue (document.FormSandwich.special_size);
	if (myType == "special1") {
		subTotal = SpecialSandwichPrice[0];
		objOrder.orderItems[objOrder.count].large = false;
		myDesc = "Small " + SpecialSandwichPrice[0] + ",";
		bLarge = false;
	} else if (myType == "special2" ) {
		subTotal = SpecialSandwichPrice[1];
		objOrder.orderItems[objOrder.count].large = true;		
		myDesc = "Large " + SpecialSandwichPrice[1] + ",";		
		bLarge = true;
	} else if (myType == "special3" ) {
		subTotal = SpecialSandwichPrice[2];
		objOrder.orderItems[objOrder.count].large = false;		
		myDesc = "Small w/works $" + SpecialSandwichPrice[2] + ",";		
		bLarge = -1;
	} else if (myType == "special4" ) {
		subTotal = SpecialSandwichPrice[3];
		objOrder.orderItems[objOrder.count].large = true;				
		myDesc = "Large w/works $" + SpecialSandwichPrice[3] + ",";		
		bLarge = -1;		
	}

	myDesc = myDesc + GetDropDownValue(document.FormSandwich.special_bread) + "," + GetDropDownValue(document.FormSandwich.special_meat) + "," + GetDropDownValue(document.FormSandwich.special_cheese) + ",";

	if (GetDropDownValue(document.FormSandwich.special_meat_extra) != "No Extra Meat") { 
		myDesc = myDesc + "Extra meat: " + GetDropDownValue(document.FormSandwich.special_meat_extra) + ", ";
		AddExtraMeatToPrice = true;
	}	

	if (GetDropDownValue(document.FormSandwich.special_cheese_extra) != "No Extra Cheese") { 
		myDesc = myDesc + "Extra cheese: " + GetDropDownValue(document.FormSandwich.special_cheese_extra) + ", ";
		AddExtraCheeseToPrice = true;
	}

	subTotal = parseFloat(subTotal) + 	((AddExtraCheeseToPrice) ? parseFloat(document.FormSandwich.extra_cheese.value) : 0) + 
				((AddExtraMeatToPrice) ? parseFloat(document.FormSandwich.extra_meat.value) : 0);


				
	objOrder.orderItems[objOrder.count].name = "Special (make your own)";
	objOrder.orderItems[objOrder.count].price = subTotal;
	objOrder.orderItems[objOrder.count].deleted = false;		
	objOrder.orderItems[objOrder.count].desc = myDesc;
	objOrder.orderItems[objOrder.count].quantity = 1;
	objOrder.orderItems[objOrder.count].condimFlag = true;
	objOrder.orderItems[objOrder.count].condimArray = new Array();

	for (i = 0; i < condimArray.length; i++) {
		if (bLarge > -1) {
			var isChecked = condimSpecialArray[i];
			//var isChecked = eval("document.FormSandwich.condim_special"+i+".checked");
			objOrder.orderItems[objOrder.count].condimArray[i] = isChecked;
			if (isChecked) {
				myCondimPrice = myCondimPrice + ((bLarge) ? (parseFloat(condimArray[i].price_large)) : (parseFloat(condimArray[i].price_small)));		
			}
		} else {
			myCondimPrice = 0;
		}
	}

	objOrder.orderItems[objOrder.count].condimPrice = myCondimPrice;	
	objOrder.orderItems[objOrder.count].condimExpanded = false;	
	objOrder.orderItems[objOrder.count].large = bLarge;
	objOrder.orderItems[objOrder.count].clientName = prompt ("Please assign a name for this sandwich:", "Unassigned");
	if (!objOrder.orderItems[objOrder.count].clientName) objOrder.orderItems[objOrder.count].clientName = "Unassigned";
	if (bLarge == -1) {
		objOrder.orderItems[objOrder.count].specialRequest = "(The Works) - ";
	}

	objOrder.orderItems[objOrder.count].specialRequest = prompt ("Do you have special requests for this sandwich?", "No special requests");
	if (!objOrder.orderItems[objOrder.count].specialRequest) objOrder.orderItems[objOrder.count].specialRequest = "No special requests";

	if (bLarge > -1) {
		alert("ADD CONDIMENTS OR SANDWICH WILL BE PLAIN!");	
	}

	if (bLarge == -1) {
		objOrder.orderItems[objOrder.count].worksPepper = confirm("Would you like HOT OR MILD peppers?\n\nOK = Hot Peppers\nCANCEL = Mild Peppers");
	}

	objOrder.orderTotal = objOrder.orderTotal + subTotal;
	objOrder.count++;

	// Reset special
	/////////////////////
	SetDropDownValue(document.FormSandwich.special_size, "special1");
	SetDropDownValue(document.FormSandwich.special_bread, "Italian Roll");
	SetDropDownValue(document.FormSandwich.special_meat, "Choose Your Meat");	
	SetDropDownValue(document.FormSandwich.special_cheese, "No Cheese");
	for (i = 0; i < gCONDIM_COUNT; i++) {
		condimSpecialArray[i] = false;
	}
	DoCheeseLogic();
	DoMeatLogic();
	
	ShowCondimentsSpecial();
	UpdateExtras();
	
	// Display the updated order
	/////////////////////
	DisplayOrder();		
	InitFloatingObject();			
}

function AddItemToOrder(inType,inID,inMoreInfo, inMoreInfo1, inbLarge)
{
	objOrder.orderItems[objOrder.count] = new Object();
	var subTotal = 0;
	var i = 0;
	
	if (inType == "SALAD") {
		subTotal = myRound(saladArray[inID].price * inMoreInfo, 2);
		objOrder.orderItems[objOrder.count].name = saladArray[inID].name;
		objOrder.orderItems[objOrder.count].price = subTotal;
		objOrder.orderItems[objOrder.count].deleted = false;
		if (inMoreInfo == 0.5) {
			objOrder.orderItems[objOrder.count].desc = "0.5 pint";
		} else if (inMoreInfo == 1) {
			objOrder.orderItems[objOrder.count].desc = "1.0 pint";
		} else {
			objOrder.orderItems[objOrder.count].desc = "1.0 quart";
		}
		objOrder.orderItems[objOrder.count].quantity = 1;		
		objOrder.orderItems[objOrder.count].condimFlag = false;
		objOrder.orderTotal = objOrder.orderTotal + subTotal;
		objOrder.count++;		
		DisplayOrder();
		InitFloatingObject();	
	} else if (inType == "CHEESE") {
		if (inMoreInfo1 == "") {
			alert ("Please select thin or thick slices to place your order.");
		} else {
			subTotal = 0;
			objOrder.orderItems[objOrder.count].name = cheeseArray[inID].name + " Cheese (" + inMoreInfo1 + ")";
			objOrder.orderItems[objOrder.count].price = subTotal;
			objOrder.orderItems[objOrder.count].deleted = false;
			objOrder.orderItems[objOrder.count].desc = inMoreInfo + " lb. ($" + cheeseArray[inID].price + " per pound - Weight Approximate)";
			objOrder.orderItems[objOrder.count].quantity = 1;		
			objOrder.orderItems[objOrder.count].condimFlag = false;
			objOrder.orderTotal = objOrder.orderTotal + subTotal;
			objOrder.count++;		
			DisplayOrder();
			InitFloatingObject();	
		}
	} else if (inType == "MEATS") {
		if (inMoreInfo1 == "") {
			alert ("Please select thin or thick slices to place your order.");
		} else {
			subTotal = 0;
			objOrder.orderItems[objOrder.count].name = "Sliced " + meatsArray[inID].name + " (" + inMoreInfo1 + ")";
			objOrder.orderItems[objOrder.count].price = subTotal;
			objOrder.orderItems[objOrder.count].deleted = false;
			objOrder.orderItems[objOrder.count].desc = inMoreInfo + " lb. ($" + meatsArray[inID].price + " per pound - Weight Approximate)";
			objOrder.orderItems[objOrder.count].quantity = 1;		
			objOrder.orderItems[objOrder.count].condimFlag = false;
			objOrder.orderTotal = objOrder.orderTotal + subTotal;
			objOrder.count++;		
			DisplayOrder();
			InitFloatingObject();	
		}
	} else if (inType == "SANDWICH") {

		// Make sure some cheese was selected for the cheese sandwich
		if (inID == 2) {
			var tmpMoreInfoArr = new Array();
			tmpMoreInfoArr = inMoreInfo.split(",");	
			//alert(tmpMoreInfoArr[2]);
			if (tmpMoreInfoArr[2] == "No Cheese") {
				alert("You must choose a cheese for your cheese sandwich!");
				return;
			}
		}
		subTotal = inMoreInfo1;
		objOrder.orderItems[objOrder.count].name = sandwichArray[inID].name + " (" + inMoreInfo + ")";
		objOrder.orderItems[objOrder.count].price = subTotal;
		objOrder.orderItems[objOrder.count].deleted = false;		
		objOrder.orderItems[objOrder.count].desc = sandwichArray[inID].desc;
		objOrder.orderItems[objOrder.count].quantity = 1;
		objOrder.orderItems[objOrder.count].condimFlag = true;
		objOrder.orderItems[objOrder.count].condimArray = new Array();
		for (i = 0; i < condimArray.length; i++) {
			objOrder.orderItems[objOrder.count].condimArray[i] = false;
		}
		objOrder.orderItems[objOrder.count].condimPrice = 0;
		objOrder.orderItems[objOrder.count].condimExpanded = false;	
		objOrder.orderItems[objOrder.count].clientName = prompt ("Please assign a name for this sandwich:", "Unassigned");
		if (!objOrder.orderItems[objOrder.count].clientName) objOrder.orderItems[objOrder.count].clientName = "Unassigned";
		objOrder.orderItems[objOrder.count].large = inbLarge;
		if (inbLarge == -1) {
			objOrder.orderItems[objOrder.count].worksPepper = confirm ("Would you like HOT OR MILD peppers?\n\nOK = Hot Peppers\nCANCEL = Mild Peppers");
			objOrder.orderItems[objOrder.count].specialRequest = "The Works (" + prompt ("Do you have special requests for this sandwich?", "No special requests") + ")";
		} else {
			objOrder.orderItems[objOrder.count].specialRequest = prompt ("Do you have special requests for this sandwich?", "No special requests");
			alert("ADD CONDIMENTS OR SANDWICH WILL BE PLAIN!");
		}
		objOrder.orderTotal = objOrder.orderTotal + subTotal;
		objOrder.count++;		
		DisplayOrder();		
		InitFloatingObject();		
	} else if (inType == "DAILY") {
		// Confirm the day
		var myToday = new Date();
		
		if ((dailyArray[inID].day == -1) || (dailyArray[inID].day == myToday.getDay())) 
		{
			objOrder.orderItems[objOrder.count].clientName = prompt ("Please assign a name for this item:", "Unassigned");
			objOrder.orderItems[objOrder.count].specialRequest = prompt ("Do you have special requests for this sandwich?", "No special requests");
			objOrder.orderItems[objOrder.count].name = dailyArray[inID].name;
			objOrder.orderItems[objOrder.count].price = parseFloat(dailyArray[inID].price);
			objOrder.orderItems[objOrder.count].deleted = false;		
			objOrder.orderItems[objOrder.count].desc = "";
			objOrder.orderItems[objOrder.count].quantity = 1;
			objOrder.orderItems[objOrder.count].condimFlag = false;
			objOrder.orderItems[objOrder.count].dailyFlag = true;
			//objOrder.orderItems[objOrder.count].specialFlag = true;
			
			if (inMoreInfo == "soup") {
				objOrder.orderItems[objOrder.count].desc = prompt ("Please provide the soup name:\n(if you're not sure, hit cancel, and call for the today's soups):", "Not sure...");
				if ((!objOrder.orderItems[objOrder.count].desc) || (objOrder.orderItems[objOrder.count].desc == "Not sure...")) {
					objOrder.orderItems[objOrder.count].deleted = true;
				}
			}
			/*
			if (inID == 1 || inID == 2)
			{
				// Special case for Chicken Parmesan 
				if (confirm ("Would you like HOT OR MILD peppers?\n\nOK = Hot Peppers\nCANCEL = Mild Peppers"))
				{
					objOrder.orderItems[objOrder.count].specialRequest = "Hot Peppers, " + objOrder.orderItems[objOrder.count].specialRequest;
				}
				else
				{
					objOrder.orderItems[objOrder.count].specialRequest = "Mild Peppers, " + objOrder.orderItems[objOrder.count].specialRequest;
				}
			}
			*/
			
			if (!objOrder.orderItems[objOrder.count].clientName) objOrder.orderItems[objOrder.count].clientName = "Unassigned";
			if (!objOrder.orderItems[objOrder.count].specialRequest) objOrder.orderItems[objOrder.count].specialRequest = "No special requests";

			objOrder.orderTotal = objOrder.orderTotal + dailyArray[inID].price;
			objOrder.count++;		
			DisplayOrder();	
			InitFloatingObject();			
		} else {
			alert("You can't order this today");
		}
	} else {
		alert("Unknown type!");
	}
//	alert("adding item type: " + inType + ", ID: " + inID + ", more info: " + inMoreInfo);
}

function RemoveItemFromOrder(inItem)
{
	objOrder.orderItems[inItem].deleted = true;
	DisplayOrder();	
}

function IsOrderEmpty()
{
	var i = 0;
	result = true;
	
	for (i = 0; i<objOrder.count; i++) {
		if (!objOrder.orderItems[i].deleted) {
			result = false;
		}
	}
	
	return result;
}

function ShowCondimentsSpecial()
{
	var i = 0;
	var result = "";
	var lineCounter = 1;
	
	// This is the "make your own" sandwich
	
	var bLarge = (GetDropDownValue(document.FormSandwich.special_size) == "special2");
	var bWorks = ((GetDropDownValue(document.FormSandwich.special_size) == "special3") || (GetDropDownValue(document.FormSandwich.special_size) == "special4"));
	
	if (bWorks) {
		result = result + "The Works - condiments included in price";
	} else {
		result = result + "Condiments: ";		
			
		// Show condiments selection
		result = result + "<BR><TABLE width=100% cellspacing=0 cellpadding=0>";
			
		for (i = 0; i < condimArray.length; i++) {
			if (lineCounter == 1) {
				result = result + "<TR>";
			}
			var myPrice = ((bLarge) ? (condimArray[i].price_large) : (condimArray[i].price_small));
			var isSelected = (condimSpecialArray[i]) ? "checked " : "";
			result = result + "<TD class=specialCondiments><input "+isSelected+"onClick='ToggleCondimSpecial("+i+")' type=checkbox name=condim_special"+i+">"+ condimArray[i].name + " $" + myPrice + "</TD>";
			if (lineCounter == 2) {
				result = result + "</TR>";
				lineCounter = 1;
			} else {
				lineCounter++;
			}
		}
			
		result = result + "</TABLE>";
	}

	DIV_SPECIAL_CONDIMENTS.innerHTML = result;	
}

function ShowCondiments(inID)
{

	var i = 0;
	var result = "";
	var lineCounter = 1;
	var	bLarge = objOrder.orderItems[inID].large;	
	var myPeppers = (objOrder.orderItems[inID].worksPepper?"hot peppers":"mild peppers");

	if (bLarge == -1) return "The Works ("+myPeppers+") - condiments included in price"; // No condiments on The Works
	
	if (objOrder.orderItems[inID].condimExpanded) {
		result = result + "<a class=orderDetails href=javascript:MinimizeCondiments("+inID+")><img align=middle src=images/minimize.gif border=0></a>";		
		
		for (i = 0; i < condimArray.length; i++) {
			result = result + ((objOrder.orderItems[inID].condimArray[i]) ? condimArray[i].name+"," : "");
		}
		
		// Show condiments selection
		result = result + "<BR><TABLE width=100% cellspacing=0 cellpadding=0>";
		
		for (i = 0; i < condimArray.length; i++) {
			if (lineCounter == 1) {
				result = result + "<TR>";
			}
			var myPrice = ((bLarge) ? (condimArray[i].price_large) : (condimArray[i].price_small));
			var isChecked = (objOrder.orderItems[inID].condimArray[i])?" checked":"";
			
			result = result + "<TD class=orderDetails><input type=checkbox" + isChecked + " onClick=ToggleCondiment("+i+","+inID+","+bLarge+")>" + condimArray[i].name + " $" + myPrice + "</TD>";
			if (lineCounter == 2) {
				result = result + "</TR>";
				lineCounter = 1;
			} else {
				lineCounter++;
			}
		}
		
		result = result + "</TABLE>";
	} else {
		result = result + "<a class=orderDetails href=javascript:ExpandCondiments("+inID+")><img align=middle src=images/expand.gif border=0></a>";	
		
		for (i = 0; i < condimArray.length; i++) {
			result = result + ((objOrder.orderItems[inID].condimArray[i]) ? condimArray[i].name+"," : "");
		}		
	}	

	return result;
}

function ToggleCondiment (inCondiment, inID, inbLarge)
{
	var myFactor = -1;
	var price = 0;
	
	objOrder.orderItems[inID].condimArray[inCondiment] = !objOrder.orderItems[inID].condimArray[inCondiment];
	if (objOrder.orderItems[inID].condimArray[inCondiment]) {
		myFactor = 1;
	}
	
	if (inbLarge) {
		price = condimArray[inCondiment].price_large;
	} else {
		price = condimArray[inCondiment].price_small;
	}
	
	objOrder.orderItems[inID].condimPrice = myRound (objOrder.orderItems[inID].condimPrice + (price * myFactor), 2);
	DisplayOrder();		
}

function MinimizeCondiments(inID)
{
	objOrder.orderItems[inID].condimExpanded = false;
	DisplayOrder();		
}

function ExpandCondiments (inID)
{
	objOrder.orderItems[inID].condimExpanded = true;
	DisplayOrder();	
}

function myRound (inNumber, digits)
{
	return (Math.round(inNumber*Math.pow(10,digits)))/Math.pow(10,digits);
}

function DoUp (inID)
{
	objOrder.orderItems[inID].quantity++;
	DisplayOrder();
}

function DoDown (inID)
{
	if (objOrder.orderItems[inID].quantity > 1) {
		objOrder.orderItems[inID].quantity--;
		DisplayOrder();
	}
}

function UpdateExtras()
{
	var bLarge = ((GetDropDownValue(document.FormSandwich.special_size) == "special2") || (GetDropDownValue(document.FormSandwich.special_size) == "special4"));
	
	if (bLarge) {
		document.FormSandwich.extra_meat.value=2.35;
		document.FormSandwich.extra_cheese.value=0.60;
		DIV_EXTRA_MEAT_PRICE.innerHTML = "Extra Meat...2.35";
		DIV_EXTRA_CHEESE_PRICE.innerHTML = "Extra Cheese...0.60";		
	} else {
		document.FormSandwich.extra_meat.value=1.25;
		document.FormSandwich.extra_cheese.value=0.45;
		DIV_EXTRA_MEAT_PRICE.innerHTML = "Extra Meat...1.25";
		DIV_EXTRA_CHEESE_PRICE.innerHTML = "Extra Cheese...0.45";		
	}
}

function DoCheeseLogic()
{
	if (GetDropDownValue(document.FormSandwich.special_cheese) == "No Cheese") {
		SetDropDownValue(document.FormSandwich.special_cheese_extra,"No Extra Cheese")
		document.FormSandwich.special_cheese_extra.disabled = true;
	} else {
		document.FormSandwich.special_cheese_extra.disabled = false;
	}
}
function DoMeatLogic()
{
	if (GetDropDownValue(document.FormSandwich.special_meat) == "Choose Your Meat") {
		SetDropDownValue(document.FormSandwich.special_meat_extra,"No Extra Meat")
		document.FormSandwich.special_meat_extra.disabled = true;
	} else {
		document.FormSandwich.special_meat_extra.disabled = false;
	}
}

function UpdateSpecial()
{
	ShowCondimentsSpecial();
	UpdateExtras();
}


function SubmitOrder()
{
	var bContinue = confirm("To place your order, click 'OK'.\n\nIf you would like to review your order and make sure you haven't forgotten anything (such as editing condiments for your sandwich), click 'CANCEL' and you will be taken back to the order page");

	if (!bContinue) return false;

	var myForm = document.FormOrder;
	var myError = "Some of the information is missing or invalid:\n\n";
	var bOK = true;
	
	// Empty?
	if (IsOrderEmpty()) {
		alert("Your order is empty.");
		return;
	}	
	
	// Full Name
	if (myForm.name.value == "") {
		myError = myError + "- Please provide your full name\n";
		bOK = false;
	}
	
	// Company
	if (myForm.company.value == "") {
		myError = myError + "- Please provide your company name\n";
		bOK = false;
	}	
	
	// Email
	if (myForm.email.value == "") {
		myError = myError + "- Please provide an email address\n";
		bOK = false;
	} else {
		if ((myForm.email.value.indexOf("@") == -1) || (myForm.email.value.indexOf(".") == -1)) {
			myError = myError + "- Please provide a valid email address\n";
			bOK = false;
		}
	}
	
	// Phone
	if (myForm.phone.value == "") {
		myError = myError + "- Please provide your phone number\n";
		bOK = false;
	}

	if (!bOK) {
		myError = myError + "\nPlease correct and try again.";
		alert(myError);
		return false;
	}
	document.getElementById('submitButton').disabled = true;
	GenerateOrder();
}

function GenerateOrder()
{

	var myHTML = "";
	var i = 0;
	objOrder.orderTotal = 0;
	var myForm = document.FormOrder;	
	var myNow = new Date();
	
	myHTML = myHTML + "<HTML><TITLE>NAME: " + myForm.name.value + " COMPANY: " + myForm.company.value + " PHONE: " + myForm.phone.value + " EMAIL: " + myForm.email.value + "</TITLE><body><font size=4><B>NAME: " + myForm.name.value + "<BR>COMPANY: " + myForm.company.value + "<BR>PHONE: " + myForm.phone.value + "<BR>EMAIL: " + myForm.email.value + "<BR>ORDER TIME: " + myNow + "<BR>PICKUP TIME (OPTIONAL): " + myForm.pickup.value + "<BR><BR>";
	
	myHTML = myHTML + "<table width=700 border=1 cellpadding=2 cellspacing=0>";	
	for (i = 0; i<objOrder.count; i++) {
		if (!objOrder.orderItems[i].deleted) 
		{
			myHTML = myHTML + "<tr><td bgcolor=#cccccc><font face=arial size=3><B>" + objOrder.orderItems[i].quantity + " X " + objOrder.orderItems[i].name + "</b></font></td></tr>";
	
			if (objOrder.orderItems[i].condimFlag) 
			{
				myHTML = myHTML + "<tr><td><font face=arial size=2>" + objOrder.orderItems[i].desc + "</font></td></tr>";
				myHTML = myHTML + "<tr><td><font face=arial size=2>" + ShowCondimentsForOrder(i) + "</font></td></tr>";
				myHTML = myHTML + "<tr><td><font face=arial size=2>Sandwich for: " + objOrder.orderItems[i].clientName + "</font></td></tr>";
				myHTML = myHTML + "<tr><td><font face=arial size=2>Special requests: " + objOrder.orderItems[i].specialRequest + "</font></td></tr>";
				objOrder.orderTotal = objOrder.orderTotal + myRound((objOrder.orderItems[i].condimPrice * objOrder.orderItems[i].quantity),2);					
			} else 
			{
				myHTML = myHTML + "<tr><td><font face=arial size=2>" + objOrder.orderItems[i].desc + "</font></td></tr>";
			}
			
			if (objOrder.orderItems[i].dailyFlag)
			{
				myHTML = myHTML + "<tr><td><font face=arial size=2>Sandwich for: " + objOrder.orderItems[i].clientName + "</font></td></tr>";
				myHTML = myHTML + "<tr><td><font face=arial size=2>Special requests: " + objOrder.orderItems[i].specialRequest + "</font></td></tr>";
			}
			objOrder.orderTotal = objOrder.orderTotal + myRound((objOrder.orderItems[i].price * objOrder.orderItems[i].quantity),2);
		}
	}
	myHTML = myHTML + "</table>";			
	
	myHTML = myHTML + "<BR><BR><B><font size=4>Estimated order total (before tax): $" + FormulateNumber(myRound(objOrder.orderTotal,2)) + "</font></B>";
	
	myHTML = myHTML + "<BR><BR><B><font size=4>Item count for this order: " + objOrder.item_count + "</font></B>";
	
	myHTML = myHTML + "</body></html>";				
	
	document.SubmitOrderForm.theOrder.value = escape(myHTML);
	document.SubmitOrderForm.name.value = myForm.name.value;
	document.SubmitOrderForm.company.value = myForm.company.value ;
	document.SubmitOrderForm.email.value = myForm.email.value;
	document.SubmitOrderForm.phone.value = myForm.phone.value;
	document.SubmitOrderForm.pickup.value = myForm.pickup.value;
	document.SubmitOrderForm.orderTime.value = myNow;
	document.SubmitOrderForm.submit();
}

function FormulateNumber (inNumber)
{
	var result = "";
	if ((inNumber*100) == (Math.round(inNumber)*100)) {
		result = inNumber + ".00";
	} else if ((inNumber*100) == (Math.round(inNumber*10)*10)) {
		result = inNumber + "0";
	} else {
		result = inNumber;
	}
	
	return result;
}

function ShowCondimentsForOrder(inID)
{

	var i = 0;
	var result = "";
	var lineCounter = 1;
	var	bLarge = objOrder.orderItems[inID].large;	
	var myPeppers = (objOrder.orderItems[inID].worksPepper?"hot peppers":"mild peppers");

	if (bLarge == -1) return "The Works ("+myPeppers+") - condiments included in price"; // No condiments on The Works
	
	result = result + " Condiments: ";	
		
	for (i = 0; i < condimArray.length; i++) {
		result = result + ((objOrder.orderItems[inID].condimArray[i]) ? condimArray[i].name+"," : "");
	}	

	return result;
}

function ToggleCondimSpecial (inID)
{
	condimSpecialArray[inID] = !condimSpecialArray[inID];
}

function GetRadioValue(inObj)
{
	var rad_val = "";

	for (var i=0; i < inObj.length; i++) {
		if (inObj[i].checked) {
			rad_val = inObj[i].value;
		}
	}
	return rad_val;
}

function ShowSpecialSandwichDropdown()
{
	document.write ("<select size=1 name='special_size' style='font-family: Arial; font-size: 8pt' onchange='UpdateSpecial()'>");
	document.write ("<option value='special1'>Small ($" + SpecialSandwichPrice[0] + ")</option>");
	document.write ("<option value='special2'>Large ($" + SpecialSandwichPrice[1] + ")</option>");
	document.write ("<option value='special3'>Small w/works ($" + SpecialSandwichPrice[2] + ")</option>");
	document.write ("<option value='special4'>Large w/works ($" + SpecialSandwichPrice[3] + ")</option></select>");

}


