// Display a welcome message for 3 seconds before beginning the program.
function welcome() {
	display("Welcome to Goetz's food store.")

	// Wait 3 seconds before asking for prices.
	setTimeout("getprices()",3000)
}

function getprices() {
	// The prices for the items the person enters.
	var items=new Array()

	// Used in loops as well as the index in the array of items.
	var i=0

	// The price of the item entered.	
	var item

	// The total for the items. Total is initially set to 0.
	var total=0

	/* Used to display the right item number. The index in the
	   array of item numbers starts at 0. Since I'm using the index to also
	   be the item number, I want the numbers to start at 1.
 	   So I use this variable to store the corrected number.
	*/
	var j
	
	alert("Enter in the prices for your items.\nPress Cancel when you are done.")

	// Get the price of the first item.
	item=getdecimal("Enter in a price, but do not enter in the $ sign.")
	
	// Keep getting items until the person chooses cancel. cancel returns a 0.
	while(item!=0) {
		// Store the item in the array.
		items[i]=item

		// Add the price of the item to the total.
		total+=item

		// Get the price of the other items.
		item=getdecimal("Enter in a price, but do not enter in the $ sign.")
		
		// Increment the index number.
		i++
	}

	// If the person wants to make a receipt, print it.
	if(confirm("Your total is $"+total+"\nWould you like a printed receipt?")) {
		alert("I will now print to the printer window.\nIt will pop up and you can print by pressing Ctrl-P (for Windows), or Apple-P (for a Mac).")

		for(i=0;i<items.length;i++) {
			// add one to the item number and store it in j.
			j=i+1
			
			// Print out the item's price.
			printer_newline("Item #"+j+" "+"$"+items[i])
		}
		
		// Skip a line.
		printer_skipline()

		// Print the price total.
		printer("Total: $"+total)

		// You are done with the printer
		printer_done()
	}

	// Make the thank you message.
	display_clear()
	display("Thank you for shopping at Goetz's food store.")
}
	

function main() {
	// Display the welcome message.
	welcome()
}
