var jsCartSummaryManager = Class.create ();
jsCartSummaryManager.prototype = {

	divsInitialized: false,
	isCorporateMultiple: false,
	cartItems: new Object (),
	cartItemCount: 0,
	firstContentDownload: true,
	displayCantCheckout: false,
	displayCheckCart: false,
	displayNoItems: false,
	displayChooseSuburb: false,
	deliveryIsFree: false,
	hasReachedMinimum: false,
	allowEditDiscountComments: false,
	allowFreeDeliveryInfo: false,
	cartType: "",
	suburbId: 0,
	discountIds: new Object (),
	groupDealIds: new Object (),
	isCheckoutPage: false,

	uri_renderCartSummary: "",
	uri_updateGroupDealComments: "",
	uri_updateDiscountComments: "",
	uri_updateFreeDeliveryInfo: "",

	cartComplete: false,
	amount_subTotal: "",
	amount_tax: "",
	amount_deliveryFee: "",
	amount_deliveryFeeFree: "",
	amount_deliveryTax: "",
	amount_orderTotal: "",
	amount_total: "",
	amount_minimumOrderAmount: "",
	amount_minimumOrderAmountFree: "",

	text_yourOrderSoFar: "",
	text_yourFinalOrder: "",
	text_shoppingCartEmpty: "",
	text_subTotal: "",
	text_tax: "",
	text_deliveryFee: "",
	text_deliveryTax: "",
	text_orderTotal: "",
	text_tip: "",
	text_total: "",
	text_applicableGroupDeals: "",
	text_applicableDiscounts: "",
	text_cantCheckout: "",
	text_checkCart: "",
	text_noItems: "",
	text_chooseSuburb: "",
	text_minimumOrderAmount: "",
	text_minimumOrderAmountFree: "",
	text_freeDelivery: "",
	text_completeOrder: "",
	url_checkout: "",
	text_checkoutImageUri: "",

	langDir: 'l2r',
	left: 'left',
	right: 'right',

	updateDiscountCommentsTimeout: "",
	updateGroupDealsCommentsTimeout: "",

	// constructor
	initialize: function (langDir) {
		if (langDir == 'r2l') {
			this.langDir = langDir;
			this.left = 'right';
			this.right = 'left';
		}
		return true;
	},

	// specify the text that this object is to render
	set_static_text: function (text_yourOrderSoFar, text_yourFinalOrder, text_shoppingCartEmpty, text_tip, text_cantCheckout, text_checkCart, text_noItems, text_chooseSuburb, text_freeDelivery, text_completeOrder, url_checkout, text_checkoutImageUri) {
		this.text_yourOrderSoFar = text_yourOrderSoFar;
		this.text_yourFinalOrder = text_yourFinalOrder;
		this.text_shoppingCartEmpty = text_shoppingCartEmpty;
		this.text_tip = text_tip;
		this.text_cantCheckout = text_cantCheckout;
		this.text_checkCart = text_checkCart;
		this.text_noItems = text_noItems;
		this.text_chooseSuburb = text_chooseSuburb;
		this.text_freeDelivery = text_freeDelivery;
		this.text_completeOrder = text_completeOrder;
		this.url_checkout = url_checkout;
		this.text_checkoutImageUri = text_checkoutImageUri;
		return true;
	},

	// specify the text that this object is to render
	set_dynamic_text: function (text_subTotal, text_tax, text_deliveryFee, text_deliveryTax, text_orderTotal, text_total, text_applicableGroupDeals, text_applicableDiscounts, text_minimumOrderAmount, text_minimumOrderAmountFree) {
		this.text_subTotal = text_subTotal;
		this.text_tax = text_tax;
		this.text_deliveryFee = text_deliveryFee;
		this.text_deliveryTax = text_deliveryTax;
		this.text_orderTotal = text_orderTotal;
		this.text_total = text_total;
		this.text_applicableGroupDeals = text_applicableGroupDeals;
		this.text_applicableDiscounts = text_applicableDiscounts;
		this.text_minimumOrderAmount = text_minimumOrderAmount;
		this.text_minimumOrderAmountFree = text_minimumOrderAmountFree;
		return true;
	},

	// specify the url that this object submits to
	set_uris: function (uri_renderCartSummary, uri_updateGroupDealComments, uri_updateDiscountComments, uri_updateFreeDeliveryInfo) {
		this.uri_renderCartSummary = uri_renderCartSummary;
		this.uri_updateGroupDealComments = uri_updateGroupDealComments;
		this.uri_updateDiscountComments = uri_updateDiscountComments;
		this.uri_updateFreeDeliveryInfo = uri_updateFreeDeliveryInfo;
		return true;
	},

	// specify if the user is on the checkout page
	set_is_checkout_page: function (isCheckoutPage) {
		this.isCheckoutPage = isCheckoutPage;
		return true;
	},

	// specify this cart to be a corporate multiple
	set_is_corporate_multiple: function (isCorporateMultiple) {
		this.isCorporateMultiple = isCorporateMultiple;
		return true;
	},

	// specify if the cart is complete or not (controls the cart summary title: "Your order so far" or "Your final order")
	set_cart_complete: function (cartComplete) {
		this.cartComplete = cartComplete;
		return true;
	},

	// specify if the object should render the message telling the user they can't check out
	set_display_cant_check_out: function (displayCantCheckout) {
		this.displayCantCheckout = displayCantCheckout;
		return true;
	},

	// specify if the object should render the message telling the user they can't check out
	set_display_no_items: function (displayNoItems) {
		this.displayNoItems = displayNoItems;
		return true;
	},

	// specify if the object should render the message telling the user they can't check out
	set_display_choose_suburb: function (displayChooseSuburb) {
		this.displayChooseSuburb = displayChooseSuburb;
		return true;
	},

	// specify if the object should render the message telling the user they should check their cart
	set_display_check_cart: function (displayCheckCart) {
		this.displayCheckCart = displayCheckCart;
		return true;
	},

	// specify if delivery is free
	set_delivery_is_free: function (deliveryIsFree) {
		this.deliveryIsFree = deliveryIsFree;
		return true;
	},

	// specify if the user is allowed to edit discount comments or not
	set_allow_edit_discount_comments: function (allowEditDiscountComments) {
		this.allowEditDiscountComments = allowEditDiscountComments;
		return true;
	},

	set_allow_free_delivery_info: function (allowFreeDeliveryInfo) {
		this.allowFreeDeliveryInfo = allowFreeDeliveryInfo;
	},

	// specify if the user has reached the required mimimum for their order
	set_has_reached_minimum: function (hasReachedMinimum) {
		this.hasReachedMinimum = hasReachedMinimum;
		return true;
	},

	// set values used in this cart
	set_values: function (amount_subTotal, amount_tax, amount_deliveryFee, amount_deliveryFeeFree, amount_deliveryTax, amount_orderTotal, amount_total, amount_minimumOrderAmount, amount_minimumOrderAmountFree) {
		this.amount_subTotal = amount_subTotal;
		this.amount_tax = amount_tax;
		this.amount_deliveryFee = amount_deliveryFee;
		this.amount_deliveryFeeFree = amount_deliveryFeeFree;
		this.amount_deliveryTax = amount_deliveryTax;
		this.amount_orderTotal = amount_orderTotal;
		this.amount_total = amount_total;
		this.amount_minimumOrderAmount = amount_minimumOrderAmount;
		this.amount_minimumOrderAmountFree = amount_minimumOrderAmountFree;
		return true;
	},

	// add a food item's html to the cart
	add_cart_item: function (cartItemId, cartItemHtml) {
		this.cartItems[cartItemId] = cartItemHtml;
		this.cartItemCount++;
		return true;
	},

	// reset the list of items in the cart
	reset_cart_items: function (cartItemId, cartItemHtml) {
		this.cartItems = new Object ();
		this.cartItemCount = 0;
		return true;
	},

	// add a discountId so the object is aware of which discounts it's showing
	add_discount_id: function (discountId) {
		this.discountIds[discountId] = discountId;
		return true;
	},

	// add a groupDealId so the object is aware of which group deals it's showing
	add_group_deal_id: function (groupDealId) {
		this.groupDealIds[groupDealId] = groupDealId;
		return true;
	},

	init_divs: function () {
		var tempHtml = this.init_summary_without_cart_items () + this.init_summary_with_cart_items ();
		$("cartSummary").innerHTML = tempHtml;
		this.divsInitialized = true;
		return true;
	},

	init_summary_without_cart_items: function () {
		var tempHtml = "";
		tempHtml = tempHtml + '<div id="cartSummaryWithoutCartItems" style="display: none;"></div>';
		return tempHtml;
	},

	init_summary_with_cart_items: function () {
		var tempHtml = "";
		tempHtml = tempHtml + '<div id="cartSummaryWithCartItems" style="display: none;">';

		tempHtml = tempHtml + '<div class="cartSummaryBlock" style="margin: 0px 0px 0px auto; padding: 0px;">';
		tempHtml = tempHtml + '<div class="cartSummaryBlockPart" style="margin-bottom: -2px;">';
		if (this.isCorporateMultiple)
			tempHtml = tempHtml + '<div class="wideArea">';
		else
			tempHtml = tempHtml + '<div class="thinArea">';


		if (!this.isCorporateMultiple) {
			tempHtml = tempHtml + '<div id="cartSummaryCloseWithCartItems" style="float: ' + this.right + ';"></div>';
			// title
			tempHtml = tempHtml + '<div style="margin-bottom: 20px; text-align: ' + this.left + ';"><span id="cartSummary_title" class="formTitle"></span></div>';
			// cart items
			tempHtml = tempHtml + '<div id="cartSummary_cartItems"></div>';
		}
		// group deals message
		tempHtml = tempHtml + '<div id="cartSummaryMessage_applicableGroupDeals" style="float: ' + this.right + '; text-align: ' + this.right + '; width: 250px; clear: both;"></div>';
		// discounts message
		tempHtml = tempHtml + '<div id="cartSummaryMessage_applicableDiscounts" style="float: ' + this.right + '; text-align: ;' + this.right + '; width: 250px; clear: both;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		// the cart totals
		tempHtml = tempHtml + '</div>';
		tempHtml = tempHtml + '</div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';


		if (this.isCorporateMultiple)
			tempHtml = tempHtml + '<div class="totalArea wideArea" style="height: 100%;">';
		else
			tempHtml = tempHtml + '<div class="totalArea thinArea">';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_subTotal" style="float: ' + this.right + '; width: 252px; margin-bottom: 6px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_tax" style="float: ' + this.right + '; width: 252px; margin-bottom: 6px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_deliveryFee" style="float: ' + this.right + '; width: 252px; margin-bottom: 6px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_deliveryTax" style="float: ' + this.right + '; width: 252px; margin-bottom: 6px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_orderTotal" style="float: ' + this.right + '; width: 252px; margin-bottom: 6px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_tip" style="float: ' + this.right + '; width: 252px; margin-bottom: 6px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_total" style="float: ' + this.right + '; width: 252px; margin-top: 20px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '</div>';



		tempHtml = tempHtml + '<div class="cartSummaryBlockPart">';
		if (this.isCorporateMultiple)
			tempHtml = tempHtml + '<div class="wideArea">';
		else
			tempHtml = tempHtml + '<div class="thinArea">';

		// minimum order amount excluding delivery message
		tempHtml = tempHtml + '<div id="cartSummaryMessage_minimumOrderAmount" style="float: ' + this.right + '; width: 250px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		if (!this.isCorporateMultiple) {
			tempHtml = tempHtml + '<div id="cartSummary_checkoutButton" style="padding: 0px; margin-top: 40px; width: 250px; text-align: ' + this.right + ';"></div>';
			tempHtml = tempHtml + '<div class="contentEnd"></div>';
		}
		if (this.isCorporateMultiple) {
			tempHtml = tempHtml + '<div id="cartSummaryMessage_freeDeliveryAfter" style="float: ' + this.right + '; width: 252px; margin-top: 10px;"></div>';
			tempHtml = tempHtml + '<div class="contentEnd"></div>';
		}

		tempHtml = tempHtml + '</div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '</div>';
		tempHtml = tempHtml + '</div>';
		tempHtml = tempHtml + '</div>';
		return tempHtml;
	},

	update_summary: function (reRenderCartItems, reRenderComments) {
		if (!this.divsInitialized)
			this.init_divs ();
		this.update_summary_without_cart_items ();
		this.update_summary_with_cart_items (reRenderCartItems, reRenderComments);
		// if there are items in the cart,  display the cart items and show the summary
		// force it to show the cart items one for corporate multiple carts
		if ((this.isCorporateMultiple) || (this.cartItemCount > 0)) {
			$("cartSummaryWithoutCartItems").hide ();
			$("cartSummaryWithCartItems").show ();
		}
		// or display the empty cart version
		else {
			$("cartSummaryWithoutCartItems").show ();
			$("cartSummaryWithCartItems").hide ();
		}
		this.firstContentDownload = false;

		this.set_display_cant_check_out (false);
		this.set_display_check_cart (false);
		this.set_display_no_items (false);
		this.set_display_choose_suburb (false);

		// if the menu manager exists (ie. the user is on a menu page),  update the cart summary popover if it's showing
		if (typeof (jsMenuManager.currentFoodItemId) != "undefined")
			jsMenuManager.update_cart_popover_content ();

		return true;
	},

	update_summary_without_cart_items: function () {
		var tempHtml = "";
		tempHtml = tempHtml + '<div class="cartSummaryBlock" style="margin: 0px 0px 2px auto; padding: 0px;">';
		tempHtml = tempHtml + '<div class="cartSummaryBlockPart" style="margin-bottom: -10px;">';
		tempHtml = tempHtml + '<div style="margin-bottom: 20px; text-align: ' + this.left + '; float: ' + this.left + '; width: 220px;"><span class="formTitle">' + (this.cartComplete ? this.text_yourFinalOrder : this.text_yourOrderSoFar) + '</span></div>';
		tempHtml = tempHtml + '<div id="cartSummaryCloseWithoutCartItems" style="float: ' + this.right + '; width: 20px;"></div>';
		tempHtml = tempHtml + '<div style="margin-bottom: 10px; width: 250px; clear: both;"><em>' + this.text_shoppingCartEmpty + '</em></div>';
		tempHtml = tempHtml + '</div>';

		if (this.isCorporateMultiple)
			tempHtml = tempHtml + '<div class="totalArea wideArea" style="height: 100%;">';
		else
			tempHtml = tempHtml + '<div class="totalArea thinArea">';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_subTotal2" style="float: ' + this.right + '; width: 252px; margin-bottom: 6px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_tax2" style="float: ' + this.right + '; width: 252px; margin-bottom: 6px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_deliveryFee2" style="float: ' + this.right + '; width: 252px; margin-bottom: 6px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_deliveryTax2" style="float: ' + this.right + '; width: 252px; margin-bottom: 6px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_orderTotal2" style="float: ' + this.right + '; width: 252px; margin-bottom: 6px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_tip2" style="float: ' + this.right + '; width: 252px; margin-bottom: 6px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '<div id="cartSummaryTotal_total2" style="float: ' + this.right + '; width: 252px; margin-top: 20px;"></div>';
		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		tempHtml = tempHtml + '</div>';

		tempHtml = tempHtml + '<div class="cartSummaryBlockPart">';

		// minimum order amount excluding delivery message
//		tempHtml = tempHtml + '<div id="cartSummaryMessage_minimumOrderAmount2" style="float: ' + this.right + '; width: 250px;"></div>';
//		tempHtml = tempHtml + '<div class="contentEnd"></div>';
		if (!this.isCorporateMultiple) {
			tempHtml = tempHtml + '<div id="cartSummary_checkoutButton2" style="padding: 0px; margin-top: 40px; width: 250px; text-align: ' + this.right + ';"></div>';
			tempHtml = tempHtml + '<div class="contentEnd"></div>';
		}

		// delivery fee
		if ((this.cartType == 'delivery') && (this.suburbId != 0)) {
//			if (this.deliveryIsFree)
//				tempHtml = tempHtml + '<div style="float: ' + this.right + '; width: 250px; margin-bottom: 10px;"><div style="float: ' + this.right + '; text-align: ' + this.right + ';"><strong>' + this.text_freeDelivery.escapeHTML () + '</strong></div></div>';
//			else if (this.amount_deliveryFee != "")
//				tempHtml = tempHtml + '<div style="float: ' + this.right + '; width: 250px; margin-bottom: 10px;"><div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_deliveryFee.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_deliveryFee.escapeHTML () + '</div></div>';
		}
		// minimum order amount excluding delivery message
//		if (this.amount_minimumOrderAmount != "")
//			tempHtml = tempHtml + '<div style="float: ' + this.right + '; width: 250px;"><div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_minimumOrderAmount.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_minimumOrderAmount.escapeHTML () + '</div></div>';

		tempHtml = tempHtml + '<div class="contentEnd"></div>';

//		if (message_cantCheckout || message_checkCart || message_noItems)
//			tempHtml = tempHtml + '<div style="margin: 10px 0px 0px 0px;">' + message_cantCheckout + message_checkCart + message_noItems + message_chooseSuburb + '</div>';

		tempHtml = tempHtml + '</div>';
		tempHtml = tempHtml + '</div>';
		$("cartSummaryWithoutCartItems").innerHTML = tempHtml;



		
		this.update_div ("cartSummaryTotal_subTotal2",				this.amount_subTotal != "",				'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_subTotal.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_subTotal.escapeHTML () + '</div>');
		this.update_div ("cartSummaryTotal_tax2",					this.amount_tax != "",					'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_tax.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_tax.escapeHTML () + '</div>');
		this.update_div ("cartSummaryTotal_deliveryFee2",			this.amount_deliveryFee != "",			'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + (this.amount_deliveryFee != "" ? this.amount_deliveryFee.escapeHTML () : this.amount_deliveryFeeFree.escapeHTML ()) + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_deliveryFee.escapeHTML () + '</div>');
		this.update_div ("cartSummaryTotal_deliveryTax2",			this.amount_deliveryTax != "",			'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_deliveryTax.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_deliveryTax.escapeHTML () + '</div>');
		this.update_div ("cartSummaryTotal_orderTotal2",			this.amount_orderTotal != "",			'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_orderTotal.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_orderTotal.escapeHTML () + '</div>');
		if (this.firstContentDownload)
			this.update_div ("cartSummaryTotal_tip2",				this.text_tip != "",					this.text_tip);
		this.update_div ("cartSummaryTotal_total2",					this.amount_total != "",				'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_total.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_total.escapeHTML () + '</div>');
//		this.update_div ("cartSummaryMessage_minimumOrderAmount2",	this.amount_minimumOrderAmount != "",	'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_minimumOrderAmount.escapeHTML () + '</div><div style="float: ;' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_minimumOrderAmount.escapeHTML () + '</div>');

		var message_cantCheckout = '';
		var message_checkCart = '';
		var message_noItems = '';
		var message_chooseSuburb = '';
		if (!this.cartComplete) {
			if ((this.displayCantCheckout) && (this.text_cantCheckout))
				message_cantCheckout = '<div style="text-align: ' + this.right + '; width: 250px; padding: 0px 6px 5px 0px;">' + this.text_cantCheckout + '</div>';
			if ((this.displayCheckCart) && (this.text_checkCart))
				message_checkCart = '<div style="text-align: ' + this.right + '; width: 250px; padding: 0px 6px 5px 0px;">' + this.text_checkCart + '</div>';
			if ((this.displayNoItems) && (this.text_noItems))
				message_noItems = '<div style="text-align: ' + this.right + '; width: 250px; padding: 0px 6px 5px 0px;">' + this.text_noItems + '</div>';
			if ((this.displayChooseSuburb) && (this.text_chooseSuburb))
				message_chooseSuburb = '<div style="text-align: ' + this.right + '; width: 250px; padding: 0px 6px 5px 0px;">' + this.text_chooseSuburb + '</div>';
		}


/**/
		if (!this.isCorporateMultiple) {

			// check to see if the user has chosen a suburb
			if ((this.cartType == 'delivery') && (this.suburbId == 0))
				this.update_div ("cartSummary_checkoutButton2",				!this.cartComplete,						message_cantCheckout + message_checkCart + message_noItems + message_chooseSuburb + '<img class="clickableImage" title="' + this.text_completeOrder +  '" src="' + this.text_checkoutImageUri + '" onClick="jsCartSummaryManager.set_display_choose_suburb (true); jsCartSummaryManager.update_summary (false, false);" />');
			// check to see if the user has reached their minimum
//			else if (!this.hasReachedMinimum)
				this.update_div ("cartSummary_checkoutButton2",				!this.cartComplete,						message_cantCheckout + message_checkCart + message_noItems + message_chooseSuburb + '<img class="clickableImage" title="' + this.text_completeOrder +  '" src="' + this.text_checkoutImageUri + '" onClick="jsCartSummaryManager.set_display_no_items (true); jsCartSummaryManager.firstContentDownload = true; jsCartSummaryManager.update_summary (false, false); jsCartSummaryManager.firstContentDownload = false;" />');
//			else
//				this.update_div ("cartSummary_checkoutButton2",				!this.cartComplete,						message_cantCheckout + message_checkCart + message_noItems + message_chooseSuburb + '<a href="' + this.url_checkout + '"><img class="clickableImage" title="' + this.text_completeOrder +  '" src="' + this.text_checkoutImageUri + '"/>RAAAAAAAAA</a>');
		}
/**/

		return true;
	},

	update_summary_with_cart_items: function (reRenderCartItems, reRenderComments) {
		if (!this.isCorporateMultiple) {
			// title
			$("cartSummary_title").innerHTML = (this.cartComplete ? this.text_yourFinalOrder : this.text_yourOrderSoFar);
			// cart items
			if (reRenderCartItems) {
				var tempHtml = '';
				tempHtml = tempHtml + '<ul class="cartItems">';
				for (var cartItemId in this.cartItems) {
					if (this.cartItems[cartItemId] != undefined)
						tempHtml = tempHtml + '<li id="cartSummary_cartItem' + cartItemId + '">' + this.cartItems[cartItemId] + '</li>';
				}
				tempHtml = tempHtml + '</ul>';
				this.update_div ("cartSummary_cartItems",	tempHtml != "",	tempHtml);
			}
		}
		if (reRenderComments) {
			this.update_div ("cartSummaryMessage_applicableGroupDeals",	this.text_applicableGroupDeals != "",	this.text_applicableGroupDeals);
			this.update_div ("cartSummaryMessage_applicableDiscounts",	this.text_applicableDiscounts != "",	this.text_applicableDiscounts);
		}
		this.update_div ("cartSummaryTotal_subTotal",				this.amount_subTotal != "",				'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_subTotal.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_subTotal.escapeHTML () + '</div>');
		this.update_div ("cartSummaryTotal_tax",					this.amount_tax != "",					'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_tax.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_tax.escapeHTML () + '</div>');
		this.update_div ("cartSummaryTotal_deliveryFee",			this.amount_deliveryFee != "",			'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + (this.amount_deliveryFee != "" ? this.amount_deliveryFee.escapeHTML () : this.amount_deliveryFeeFree.escapeHTML ()) + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_deliveryFee.escapeHTML () + '</div>');
		this.update_div ("cartSummaryTotal_deliveryTax",			this.amount_deliveryTax != "",			'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_deliveryTax.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_deliveryTax.escapeHTML () + '</div>');
		this.update_div ("cartSummaryTotal_orderTotal",				this.amount_orderTotal != "",			'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_orderTotal.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_orderTotal.escapeHTML () + '</div>');
		if (this.firstContentDownload)
			this.update_div ("cartSummaryTotal_tip",				this.text_tip != "",					this.text_tip);
		this.update_div ("cartSummaryTotal_total",					this.amount_total != "",				'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_total.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_total.escapeHTML () + '</div>');
		this.update_div ("cartSummaryMessage_minimumOrderAmount",	this.amount_minimumOrderAmount != "",	'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 65px;">' + this.amount_minimumOrderAmount.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_minimumOrderAmount.escapeHTML () + '</div>');


		var message_cantCheckout = '';
		var message_checkCart = '';
		var message_noItems = '';
		var message_chooseSuburb = '';
		if (!this.cartComplete) {
			if ((this.displayCantCheckout) && (this.text_cantCheckout))
				message_cantCheckout = '<div style="text-align: ' + this.right + '; width: 250px; padding: 0px 6px 5px 0px;">' + this.text_cantCheckout + '</div>';
			if ((this.displayCheckCart) && (this.text_checkCart))
				message_checkCart = '<div style="text-align: ' + this.right + '; width: 250px; padding: 0px 6px 5px 0px;">' + this.text_checkCart + '</div>';
			if ((this.displayNoItems) && (this.text_noItems))
				message_noItems = '<div style="text-align: ' + this.right + '; width: 250px; padding: 0px 6px 5px 0px;">' + this.text_noItems + '</div>';
			if ((this.displayChooseSuburb) && (this.text_chooseSuburb))
				message_chooseSuburb = '<div style="text-align: ' + this.right + '; width: 250px; padding: 0px 6px 5px 0px;">' + this.text_chooseSuburb + '</div>';
		}



		if (!this.isCorporateMultiple) {

			// check to see if the user has chosen a suburb
			if ((this.cartType == 'delivery') && (this.suburbId == 0))
				this.update_div ("cartSummary_checkoutButton",				!this.cartComplete,						message_cantCheckout + message_checkCart + message_noItems + message_chooseSuburb + '<img class="clickableImage" title="' + this.text_completeOrder +  '" src="' + this.text_checkoutImageUri + '" onClick="jsCartSummaryManager.set_display_choose_suburb (true); jsCartSummaryManager.update_summary (false, false);" />');
			// check to see if the user has reached their minimum
			else if (!this.hasReachedMinimum)
				this.update_div ("cartSummary_checkoutButton",				!this.cartComplete,						message_cantCheckout + message_checkCart + message_noItems + message_chooseSuburb + '<img class="clickableImage" title="' + this.text_completeOrder +  '" src="' + this.text_checkoutImageUri + '" onClick="jsCartSummaryManager.set_display_cant_check_out (true); jsCartSummaryManager.update_summary (false, false);" />');
			else
				this.update_div ("cartSummary_checkoutButton",				!this.cartComplete,						message_cantCheckout + message_checkCart + message_noItems + message_chooseSuburb + '<a href="' + this.url_checkout + '"><img class="clickableImage" title="' + this.text_completeOrder +  '" src="' + this.text_checkoutImageUri + '"/></a>');
		}


		// free delivery after $x
		if (this.isCorporateMultiple)
			this.update_div ("cartSummaryMessage_freeDeliveryAfter",	this.text_minimumOrderAmountFree != "",	'<div style="float: ' + this.right + '; text-align: ' + this.right + '; width: 55px;">' + this.amount_minimumOrderAmountFree.escapeHTML () + '</div><div style="float: ' + this.right + '; display: inline; text-align: ' + this.right + ';">' + this.text_minimumOrderAmountFree.escapeHTML () + '</div>');

		return true;
	},

	// show the content,  or hide the div altogether
	update_div: function (elementId, display, html) {
		if (display) {
			$(elementId).innerHTML = html;
			$(elementId).show ();
		}
		else
			$(elementId).hide ();
		return true;
	},

	update_tip_amounts: function (amount_tipPercent, amount_tipSpecific) {
		if ($("percentAmountDiv") != null) {
			$("percentAmountDiv").innerHTML = amount_tipPercent.escapeHTML ();
			if (amount_tipSpecific != undefined)
				$("tipAmount").value = amount_tipSpecific;
			this.focus_tip_type (undefined, true);
		}
	},

	// load this cart's values via ajax and render them
	ajax_fetch_content: function () {
		// send the ajax request to fetch the values
		var postParameters = new Object ();

		if (this.firstContentDownload)
			postParameters.firstContentDownload = "Y";
		if (this.allowEditDiscountComments)
			postParameters.allowEditDiscountComments = "Y";
		if (this.isCheckoutPage)
			postParameters.isCheckoutPage = "Y";

		gc_ajaxManager.request (
			this.uri_renderCartSummary,
			{	method: "post",
				parameters: postParameters },
			"cartSummary"
		);
		return true;
	},

	// load this cart's values via ajax and render them
	ajax_update_tip: function () {
		// send the ajax request to fetch the values
		var postParameters = new Object ();

		postParameters.action = "changeTip";
		postParameters.tipType = "percentage";
		postParameters.tipAmount = $("tipPercent").value;
		if ($("tipTypeAmount").checked) {
			postParameters.tipType = "amount";
			postParameters.tipAmount = $("tipAmount").value;
		}
		if (this.allowEditDiscountComments)
			postParameters.allowEditDiscountComments = "Y";

		gc_ajaxManager.request (
			this.uri_renderCartSummary,
			{	method: "post",
				parameters: postParameters },
			"cartSummary"
		);
		return true;
	},

	// load this cart's values via ajax and render them
	ajax_update_discount_comments: function (updatedDiscountId, newValue, fromCartSummaryId, clickedSaveButton) {

		if (newValue != null) {
			if (fromCartSummaryId) {
				if ($('discount' + updatedDiscountId + '_comment') != null)
					$('discount' + updatedDiscountId + '_comment').value = newValue;
			}
			else {
				if ($('discount' + updatedDiscountId + '_comment' + jsMenuManager.currentCartSummaryId) != null)
					$('discount' + updatedDiscountId + '_comment' + jsMenuManager.currentCartSummaryId).value = newValue;
			}
		}

		clearTimeout (this.updateDiscountCommentsTimeout);
		this.updateDiscountCommentsTimeout = setTimeout ("jsCartSummaryManager.ajax_really_update_discount_comments (" + updatedDiscountId + ", " + fromCartSummaryId + ", " + (clickedSaveButton ? 'true' : 'false') + " );", 300);
		return true;
	},

	// load this cart's values via ajax and render them
	ajax_update_discount_comments_save_button: function (updatedDiscountId, newValue, fromCartSummaryId) {
		return this.ajax_update_discount_comments (updatedDiscountId, newValue, fromCartSummaryId, true);
	},

	// load this cart's values via ajax and render them
	ajax_really_update_discount_comments: function (updatedDiscountId, fromCartSummaryId, clickedSaveButton) {

		clearTimeout (this.updateDiscountCommentsTimeout);

		// send the ajax request to store the values
		var postParameters = new Object ();
		postParameters.action = "updateDiscountComments";
		if (typeof (fromCartSummaryId) != 'undefined')
			postParameters.cartSummaryId = fromCartSummaryId;
		if (clickedSaveButton) {
			postParameters.clickedSaveButton = 'Y';
			postParameters.updatedDiscountId = updatedDiscountId;
		}

		for (var discountId in this.discountIds) {
			if ($('discount' + discountId + '_comment') != null)
				postParameters['discount' + discountId + '_comment'] = $('discount' + discountId + '_comment').value;
		}

		gc_ajaxManager.request (
			this.uri_updateDiscountComments,
			{	method: "post",
				parameters: postParameters },
			"discountComments"
		);


		var tempCartSummaryId = '';
		if (typeof (fromCartSummaryId) != 'undefined')
			tempCartSummaryId = fromCartSummaryId;

		// display the "saving" message
		if (clickedSaveButton) {
			jsMessageManager.set_place_holder ("discountCommentSaved" + updatedDiscountId + "_"  + tempCartSummaryId, "discount" + updatedDiscountId + "_comment" + tempCartSummaryId, { xSourcePoint: "left", xDestPoint: "left", xPixelOffset: -28, yPixelOffset: -10 });
			jsMessageManager.set_display_effects ("discountCommentSaved" + updatedDiscountId + "_"  + tempCartSummaryId, "Appear", { duration: 0.4 }, "DropOut", { duration: 0.5 });
			jsMessageManager.show_message ("discountCommentSaved" + updatedDiscountId + "_"  + tempCartSummaryId, "Saving");
		}

		return true;
	},

	

	// load this cart's values via ajax and render them
	ajax_really_update_discount_type_preference: function () {

		var postParameters = new Object ();
		postParameters.action = "updateDiscountTypePreference";
		postParameters.allowEditDiscountComments = "Y";

		if (($('useFirstTimeDiscountY')) && ($('useFirstTimeDiscountN'))) {
			postParameters.discountTypePreference = 'normal';
			if ($('useFirstTimeDiscountY').checked)
				postParameters.discountTypePreference = 'firstTime';
		}

		gc_ajaxManager.request (
			this.uri_renderCartSummary,
			{	method: "post",
				parameters: postParameters },
			"discountTypePreference"
		);
		return true;
	},

	// load this cart's values via ajax and render them
	ajax_update_group_deal_comments: function (updatedGroupDealId, newValue, fromCartSummaryId, clickedSaveButton) {

		if (newValue != null) {
			if (fromCartSummaryId) {
				if ($('groupDeal' + updatedGroupDealId + '_comment') != null)
					$('groupDeal' + updatedGroupDealId + '_comment').value = newValue;
			}
			else {
				if ($('groupDeal' + updatedGroupDealId + '_comment' + jsMenuManager.currentCartSummaryId) != null)
					$('groupDeal' + updatedGroupDealId + '_comment' + jsMenuManager.currentCartSummaryId).value = newValue;
			}
		}

		clearTimeout (this.updateGroupDealsCommentsTimeout);
		this.updateGroupDealsCommentsTimeout = setTimeout ("jsCartSummaryManager.ajax_really_update_group_deal_comments (\'" + updatedGroupDealId + "\', " + fromCartSummaryId + ", " + (clickedSaveButton ? 'true' : 'false') + " );", 300);
		return true;
	},

	// load this cart's values via ajax and render them
	ajax_update_group_deal_comments_save_button: function (updatedGroupDealId, newValue, fromCartSummaryId) {
		return this.ajax_update_group_deal_comments (updatedGroupDealId, newValue, fromCartSummaryId, true);
	},

	// load this cart's values via ajax and render them
	ajax_really_update_group_deal_comments: function (updatedGroupDealId, fromCartSummaryId, clickedSaveButton) {

		clearTimeout (this.updateGroupDealsCommentsTimeout);

		// send the ajax request to store the values
		var postParameters = new Object ();
		postParameters.action = "updateGroupDealComments";
		if (typeof (fromCartSummaryId) != 'undefined')
			postParameters.cartSummaryId = fromCartSummaryId;
		if (clickedSaveButton) {
			postParameters.clickedSaveButton = 'Y';
			postParameters.updatedGroupDealId = updatedGroupDealId;
		}

		for (var groupDealId in this.groupDealIds) {
			if ($('groupDeal' + groupDealId + '_comment') != null)
				postParameters['groupDeal' + groupDealId + '_comment'] = $('groupDeal' + groupDealId + '_comment').value;
		}

		gc_ajaxManager.request (
			this.uri_updateGroupDealComments,
			{	method: "post",
				parameters: postParameters },
			"groupDealComments"
		);


		var tempCartSummaryId = '';
		if (typeof (fromCartSummaryId) != 'undefined')
			tempCartSummaryId = fromCartSummaryId;

		// display the "saving" message
		if (clickedSaveButton) {
			jsMessageManager.set_place_holder ("groupDealCommentSaved" + updatedGroupDealId + "_"  + tempCartSummaryId, "discount" + updatedGroupDealId + "_comment" + tempCartSummaryId, { xSourcePoint: "left", xDestPoint: "left", xPixelOffset: -28, yPixelOffset: -10 });
			jsMessageManager.set_display_effects ("groupDealCommentSaved" + updatedGroupDealId + "_"  + tempCartSummaryId, "Appear", { duration: 0.4 }, "DropOut", { duration: 0.5 });
			jsMessageManager.show_message ("groupDealCommentSaved" + updatedGroupDealId + "_"  + tempCartSummaryId, "Saving");
		}

		return true;
	},

	// remove an item from the cart
	remove_cart_item: function (cartItemId) {
		$("cartSummary_cartItem" + cartItemId).remove ();
		this.cartItemCount--;
		this.cartItems[cartItemId] = undefined;
		// display the empty cart version if necessary
		if (this.cartItemCount <= 0) {
		// or display the empty cart version
// causes ie6 to hang when removing the last item from the cart
//			$("cartSummaryWithoutCartItems").show ();
//			$("cartSummaryWithCartItems").hide ();
		}
		// send the ajax request to fetch the values
		var postParameters = new Object ();

		postParameters.action = "removeCartItem";
		postParameters.itemId = cartItemId;
		if (this.allowEditDiscountComments)
			postParameters.allowEditDiscountComments = "Y";

		gc_ajaxManager.request (
			this.uri_renderCartSummary,
			{	method: "post",
				parameters: postParameters },
			"cartSummary" + cartItemId
		);
		return true;
	},

	// focus the relevant tip type
	focus_tip_type: function (forcePercent, dontReFetchContent) {
		if (forcePercent == undefined)
			forcePercent = $(tipTypePercentage).checked;
		if (forcePercent) {
			$("tipTypePercentage").checked = true;
			$("tipAmountDiv").hide ();
			$("percentAmountDiv").show ();
		}
		else {
			$("tipTypeAmount").checked = true;
			$("tipAmountDiv").show ();
			$("percentAmountDiv").hide ();
			$("tipPercent").selectedIndex = 0;
		}
		if (!dontReFetchContent)
			this.ajax_update_tip ();
	},







	

	submit_new_cart_type: function (cartType, suburbId, afterSubmitFoodItemId, rhs) {

		// update the current cart's details
		if (cartType == this.cartType) {
			this.store_new_cart_type (cartType, 0);


			var postParameters = new Object ();
			postParameters.action = 'changeCartType';
			postParameters.cartType = cartType;
			postParameters.suburbId = suburbId;

			// make the ajax php submit the specified food item afterwards
			if (afterSubmitFoodItemId != undefined)
				postParameters.afterSubmitFoodItemId = afterSubmitFoodItemId;
			if (rhs == true)
				postParameters.rhs = 'Y';

			gc_ajaxManager.request (
				this.uri_renderCartSummary,
				{	method: "post",
					parameters: postParameters },
				"updateCartType"
			);
		}

		// or reload the page to change the cart type
		else {
			if (cartType == 'delivery') {
				if (suburbId)
					document.location.href = '?cartType=' + cartType + '&takeawaySuburbId=' + suburbId + '#orderTakeaway';
				else
					document.location.href = '?cartType=' + cartType + '#orderTakeaway';
			}
			else
				document.location.href = '?cartType=' + cartType + '#orderTakeaway';
		}
	},

	store_new_cart_type: function (cartType, suburbId, updateSummary) {
		if (updateSummary == undefined)
			updateSummary = true;

		this.set_cart_type (cartType);
		this.set_suburb_id (suburbId);
		// if the menu manager exists (ie. the user is on a menu page),  update the cart summary popover if it's showing
		if (typeof (jsMenuManager.currentFoodItemId) != "undefined") {
			jsMenuManager.set_cart_type (cartType);
			jsMenuManager.set_suburb_id (suburbId);
		}
		// force the "choose suburb" message to show when the user checks out if need be
//		this.set_display_choose_suburb ((cartType == 'delivery') && (suburbId == 0));

//		if ((cartType != 'delivery') || (suburbId == 0))
		this.set_display_choose_suburb (false);
		if (updateSummary)
			this.update_summary (false, false);
	},

	set_cart_type: function (cartType) {
		this.cartType = cartType;
	},

	set_suburb_id: function (suburbId) {
		this.suburbId = suburbId;
		this.update_free_delivery_info ();
	},

	update_free_delivery_info: function () {
		if ((this.allowFreeDeliveryInfo) && (this.suburbId != 0) && (this.suburbId != '')) {
			var postParameters = new Object ();
			postParameters.suburbId = this.suburbId;
			gc_ajaxManager.request (
				this.uri_updateFreeDeliveryInfo,
				{	method: "post",
					parameters: postParameters },
				"updateFreeDeliveryInfo"
			);
		}
		else {
//			if ($('freeDeliveryInfo') != null)
//				$('freeDeliveryInfo').innerHTML = '';
		}
	}
}










var jsMenuManager = Class.create ();
jsMenuManager.prototype = {

	currentFoodItemId: 0,
	foodItemIds: new Object (),
	foodItemsWithChoices: new Object (),
	currentCartSummaryId: 0,
	isCurrentlyOpen: false,
	hasSpecifiedOwnTime: false,
	doesDelivery: false,
	doesPickUp: false,
	cartType: "",
	suburbId: 0,
	rhsNameSuffix: "_rhs",

	url_tickIcon: "",
	url_noticeIcon: "",
	url_deleteIcon: "",
	url_loading: "",
	url_addToCartAjax: "",
	url_conformPreOrderDetails: "",

	url_googleAnalyticsUrlForAddClick: "",
	url_googleAnalyticsUrlFoodItemAdded: "",

	toldGoogleAnalyticsAboutAddClick: false,
	toldGoogleAnalyticsAboutFoodItemAdded: false,

	text_adding: "",
	text_added: "",
	text_please_wait: "",

	messageFontSize: "20px",

	// constructor
	initialize: function (cartType, suburbId, url_tickIcon, url_noticeIcon, url_deleteIcon, url_loading, url_addToCartAjax, url_conformPreOrderDetails, url_googleAnalyticsUrlForAddClick, url_googleAnalyticsUrlFoodItemAdded) {
		this.cartType = cartType;
		this.suburbId = suburbId;
		this.url_tickIcon = url_tickIcon;
		this.url_noticeIcon = url_noticeIcon;
		this.url_deleteIcon = url_deleteIcon;
		this.url_loading = url_loading;
		this.url_addToCartAjax = url_addToCartAjax;
		this.url_conformPreOrderDetails = url_conformPreOrderDetails;
		this.url_googleAnalyticsUrlForAddClick = url_googleAnalyticsUrlForAddClick;
		this.url_googleAnalyticsUrlFoodItemAdded = url_googleAnalyticsUrlFoodItemAdded;
		return true;
	},

	// specify the text that this object is to render
	set_static_text: function (text_adding, text_added, text_please_wait) {
		this.text_adding = text_adding;
		this.text_added = text_added;
		this.text_please_wait = text_please_wait;
		return true;
	},

	set_cart_type: function (cartType) {
		this.cartType = cartType;
	},

	set_suburb_id: function (suburbId) {
		this.suburbId = suburbId;
	},

	set_is_currently_open: function (isCurrentlyOpen) {
		this.isCurrentlyOpen = isCurrentlyOpen;
	},

	set_has_specified_own_time: function (hasSpecifiedOwnTime) {
		this.hasSpecifiedOwnTime = hasSpecifiedOwnTime;
	},

	set_does_delivery: function (doesDelivery) {
		this.doesDelivery = doesDelivery;
	},

	set_does_pick_up: function (doesPickUp) {
		this.doesPickUp = doesPickUp;
	},

	submit_item: function (foodItemId, submittingChoices, rhs) {
		jsMenuManager.really_hide_current_cart_summary_popover ();
		currentNameSuffix = "";
		if ((rhs != false) && (rhs != undefined)) {
			rhs = true;
			currentNameSuffix = this.rhsNameSuffix;
		}
		else
			rhs = false;

		hasChoices = this.foodItemsWithChoices[foodItemId];

		if (rhs)
			jsMessageManager.set_place_holder ("foodItem" + foodItemId + currentNameSuffix, "foodItemAction" + foodItemId + currentNameSuffix, { xSourcePoint: "left", xDestPoint: "right", xPixelOffset: 150, yPixelOffset: -8 });
		else
			jsMessageManager.set_place_holder ("foodItem" + foodItemId + currentNameSuffix, "foodItemAction" + foodItemId + currentNameSuffix, { xSourcePoint: "right", xDestPoint: "left", xPixelOffset: 8 });
		jsMessageManager.set_display_effects ("foodItem" + foodItemId + currentNameSuffix, "Appear", { duration: 0.4 }, "DropOut", { duration: 0.5 });
		jsMessageManager.reset_messages ("foodItem" + foodItemId + currentNameSuffix);
/**
		// delivery suburb not chosen and not currently open
		if (((this.cartType == 'delivery') && (this.suburbId == 0)) && ((!this.isCurrentlyOpen) && (!this.hasSpecifiedOwnTime))) {
			this.display_choose_suburb_message (foodItemId, true, this.isCurrentlyOpen, rhs);
			return false;
		}
		// delivery suburb not chosen
		if ((this.cartType == 'delivery') && (this.suburbId == 0)) {
			this.display_choose_suburb_message (foodItemId, true, true, rhs);
			return false;
		}
		// not currently open
		else if ((!this.isCurrentlyOpen) && (!this.hasSpecifiedOwnTime)) {
			this.display_choose_suburb_message (foodItemId, false, this.isCurrentlyOpen, rhs);
			return false;
		}
/**/
		var error = false;
		var varietyId = null;
		var radios = $("tAForm" + foodItemId + currentNameSuffix).getInputs ("radio");
		if (radios.length > 0) {
			for (var count = 0; count < radios.length; count++) {
				if (radios[count].name == "varietyId") {
					if (radios[count].checked)
						varietyId = radios[count].value;
				}
			}
			if (varietyId == null) {
//				jsMessageManager.hide_message_block ('foodItemChoices' + this.currentFoodItemId);
//				jsMessageManager.hide_message_block ('foodItemChoices' + this.currentFoodItemId + this.rhsNameSuffix);
				jsOverviewManager2.hide_popover ('foodItemChoices' + this.currentFoodItemId);
				jsOverviewManager2.hide_popover ('foodItemChoices' + this.currentFoodItemId + this.rhsNameSuffix);

				jsMessageManager.add_message ("foodItem" + foodItemId + currentNameSuffix, "<div style='float: " + this.left + "; margin: 0px; padding: 0px;'><img src='" + this.url_noticeIcon + "' /></div><div style='float: " + this.left + "; padding: 0px; margin: 1px 0px 0px 10px; font-size: " + this.messageFontSize + ";'>Please select a variety to add</div>");
				error = true;
			}
		}
		else {
			var hiddenFields = $("tAForm" + foodItemId + currentNameSuffix).getInputs ("hidden");
			if (hiddenFields.length > 0) {
				for (var count = 0; count < hiddenFields.length; count++) {
					if (hiddenFields[count].name == "varietyId")
						varietyId = hiddenFields[count].value;
				}
			}
		}
		var quantity = 1;
		if ($("qty" + foodItemId + currentNameSuffix) != null) {
			quantity = $("qty" + foodItemId + currentNameSuffix).value;
			regex = /^\d+$/;
			if (!regex.test (quantity)) {
				$("qty" + foodItemId + currentNameSuffix).focus ();
//				jsMessageManager.hide_message_block ('foodItemChoices' + this.currentFoodItemId);
//				jsMessageManager.hide_message_block ('foodItemChoices' + this.currentFoodItemId + this.rhsNameSuffix);
				jsOverviewManager2.hide_popover ('foodItemChoices' + this.currentFoodItemId);
				jsOverviewManager2.hide_popover ('foodItemChoices' + this.currentFoodItemId + this.rhsNameSuffix);

				jsMessageManager.add_message ("foodItem" + foodItemId + currentNameSuffix, "<div style='float: " + this.left + "; margin: 0px; padding: 0px;'><img src='" + this.url_noticeIcon + "' /></div><div style='float: " + this.left + "; padding: 0px; margin: 1px 0px 0px 10px;'>Please specify a quantity to add</div>");
				error = true;
			}
		}
		var minAmount = 1
		var hiddenFields = $("tAForm" + foodItemId + currentNameSuffix).getInputs ("hidden");
		if (hiddenFields.length > 0) {
			for (var count = 0; count < hiddenFields.length; count++) {
				if (hiddenFields[count].name == "minAmount")
					minAmount = hiddenFields[count].value;
			}
		}

		if (quantity < minAmount) {
			this.display_not_enough_qty_message (foodItemId, minAmount, rhs);
			error = true;
		}

		if (error) {
			jsMessageManager.display_message_block ("foodItem" + foodItemId + currentNameSuffix, 3500);
			return false;
		}

		if (varietyId == null)
			return false;

		// let google know about this page view - the first time only
		if (!this.toldGoogleAnalyticsAboutAddClick) {
			register_page_view_with_google2 (this.url_googleAnalyticsUrlForAddClick);
			this.toldGoogleAnalyticsAboutAddClick = true;
		}

		if ((hasChoices) && (!submittingChoices)) {

//			jsMessageManager.hide_message_block ('foodItem' + foodItemId);
//			jsMessageManager.hide_message_block ('foodItem' + foodItemId + this.rhsNameSuffix);
//			if ((this.currentFoodItemId != foodItemId) && (this.currentFoodItemId != 0)) {
//				jsMessageManager.hide_message_block ('foodItemChoices' + this.currentFoodItemId);
//				jsMessageManager.hide_message_block ('foodItemChoices' + this.currentFoodItemId + this.rhsNameSuffix);
//			}
			this.currentFoodItemId = foodItemId;
//			jsMenuManager.disable_page ();
			var popOverHtml = '';
			popOverHtml = popOverHtml + '<div id="takeawayFoodItemPopOver' + foodItemId + currentNameSuffix + '" class="takeawayFoodItemPopOver">';
//			popOverHtml = popOverHtml + '<div style="text-align: ' + this.right + ';"><img src="' + this.url_deleteIcon + '" title="Close" onClick="jsMessageManager.hide_message_block (\'foodItemChoices' + foodItemId + currentNameSuffix + '\'); jsMenuManager.enable_page (); jsMenuManager.currentFoodItemId = 0;" class="close"></div>';
			popOverHtml = popOverHtml + '<div id="choicesContent' + foodItemId + currentNameSuffix + '"><span class="formSubtitle">' + this.text_please_wait + '</span><br /><br /><img id="pleaseWait' + foodItemId + currentNameSuffix + '" src="' + this.url_loading + '"></div>';
			popOverHtml = popOverHtml + '</div>';
//			jsMessageManager.set_place_holder ("foodItemChoices" + foodItemId + currentNameSuffix, "foodItemAction" + foodItemId + currentNameSuffix, { xSourcePoint: "right", xDestPoint: "right", xPixelOffset: -90, yPixelOffset: -10 });
//			jsMessageManager.set_display_effects ("foodItemChoices" + foodItemId + currentNameSuffix, "Appear", { duration: 0.4 }, "DropOut", { duration: 0.5 });
//			jsMessageManager.show_message ("foodItemChoices" + foodItemId + currentNameSuffix, popOverHtml);
			jsOverviewManager2.create_popover_non_ajax ("foodItemAction" + foodItemId + currentNameSuffix, "foodItemChoices" + foodItemId + currentNameSuffix, { xSourcePoint: "right", xDestPoint: "right", xPixelOffset: -90, yPixelOffset: -10 }, '450px', '', popOverHtml, 'choicesInfo');
			$("pleaseWait" + foodItemId + currentNameSuffix).src = this.url_loading;

			var postParameters = new Object ();
			postParameters.foodItemId = foodItemId;
			postParameters.varietyId = varietyId;
			postParameters.qty = quantity;
			postParameters.rhs = rhs ? "Y" : "N";
			gc_ajaxManager.request (
				this.url_addToCartAjax,
				{	method: "post",
					parameters: postParameters },
				"foodItemId" + foodItemId + currentNameSuffix
			);
		}
		else {
			if (!hasChoices)
				jsMessageManager.show_message ("foodItem" + foodItemId + currentNameSuffix, "<div style='font-size: " + this.messageFontSize + ";'>" + this.text_adding + "</div>");
			else {
				$("choicesBottom" + foodItemId + currentNameSuffix).innerHTML = "<div style='padding-top: 2px;'><div class='formSubtitle' style='padding: 0px 0px 2px 20px; float: " + this.right + ";'>" + this.text_please_wait + "</div><div class='formSubtitle' style='float: " + this.right + ";'><img id='pleaseWait" + foodItemId + currentNameSuffix + "' src='" + this.url_loading + "' title='" + this.text_please_wait + "' /></div></div>";
				$("pleaseWait" + foodItemId + currentNameSuffix).src = this.url_loading;
			}
			if ((this.currentFoodItemId != foodItemId) && (this.currentFoodItemId != 0)) {
//				jsMessageManager.hide_message_block ('foodItemChoices' + this.currentFoodItemId);
//				jsMessageManager.hide_message_block ('foodItemChoices' + this.currentFoodItemId + this.rhsNameSuffix);
				jsOverviewManager2.hide_popover ('foodItemChoices' + this.currentFoodItemId);
				jsOverviewManager2.hide_popover ('foodItemChoices' + this.currentFoodItemId + this.rhsNameSuffix);
			}

			var postParameters = new Object ();
			if (hasChoices) {
				var tempInputs = $("tAChoicesForm" + foodItemId + currentNameSuffix).serialize(true);
				for (var index in tempInputs)
					postParameters[index] = tempInputs[index];
			}
			var tempInputs = $("tAForm" + foodItemId + currentNameSuffix).serialize (true);
			for (var index in tempInputs)
				postParameters[index] = tempInputs[index];
			postParameters.foodItemId = foodItemId;
			postParameters.rhs = rhs ? "Y" : "N";
			gc_ajaxManager.request (
				this.url_addToCartAjax,
				{	method: "post",
					parameters: postParameters },
				"foodItemId" + foodItemId + currentNameSuffix
			);
		}
	},

	item_saved: function (foodItemId) {

		// let google know that a food item was added to their cart - the first time only
		if (!this.toldGoogleAnalyticsAboutFoodItemAdded) {
			register_page_view_with_google2 (this.url_googleAnalyticsUrlFoodItemAdded);
			this.toldGoogleAnalyticsAboutFoodItemAdded = true;
		}

//		jsMessageManager.hide_message_block ('foodItemChoices' + foodItemId);
//		jsMessageManager.hide_message_block ('foodItemChoices' + foodItemId + this.rhsNameSuffix);
		jsOverviewManager2.hide_popover ('foodItemChoices' + foodItemId);
		jsOverviewManager2.hide_popover ('foodItemChoices' + foodItemId + this.rhsNameSuffix);

		jsMessageManager.show_message ("foodItem" + foodItemId + currentNameSuffix, "<div style='float: " + this.left + "; margin: 0px; padding: 0px;'><img src='" + this.url_tickIcon + "' /></div><div style='float: " + this.left + "; padding: 0px; margin: 1px 0px 0px 10px; font-size: " + this.messageFontSize + ";'>" + this.text_added + "</div>", 1500);
		if (jsCartSummaryManager != undefined)
			jsCartSummaryManager.ajax_fetch_content ();
		if (this.currentFoodItemId == foodItemId) {
			this.currentFoodItemId = 0
			jsMenuManager.enable_page ();
		}
	},

	display_not_enough_qty_message: function (foodItemId, minQty, rhs) {
		var currentNameSuffix = '';
		if ((rhs != false) && (rhs != undefined))
			currentNameSuffix = this.rhsNameSuffix;

		jsMessageManager.show_message ("foodItem" + foodItemId + currentNameSuffix, "<div style='float: " + this.left + "; margin: 0px; padding: 0px;'><img src='" + this.url_noticeIcon + "' /></div><div style='float: " + this.left + "; padding: 0px; margin: 1px 0px 0px 10px; font-size: " + this.messageFontSize + ";'>Please add " + (minQty == 1 ? "at least one of these" : "at least " + minQty + " of these ") + " to your cart</div>", 3500);
	},

	display_choose_suburb_message: function (foodItemId, askForSuburb, isCurrentlyOpen, rhs) {

		var currentNameSuffix = '';
		if ((rhs != false) && (rhs != undefined))
			currentNameSuffix = this.rhsNameSuffix;

		var popOverHtml = '';
		popOverHtml = popOverHtml + '<div id="cartPreOrderDetails' + foodItemId + currentNameSuffix + '">';
//		popOverHtml = popOverHtml + '<div style="text-align: ' + this.right + ';"><img src="' + this.url_deleteIcon + '" title="Close" onClick="jsMessageManager.hide_message_block (\'foodItemChoices' + foodItemId + currentNameSuffix + '\'); jsMenuManager.enable_page (); jsMenuManager.currentFoodItemId = 0;" class="close"></div>';
		popOverHtml = popOverHtml + '<div id="cartPreOrderDetailsContent' + foodItemId + currentNameSuffix + '"><span class="formSubtitle">' + this.text_please_wait + '</span><br /><br /><img id="pleaseWait' + foodItemId + currentNameSuffix + '" src="' + this.url_loading + '"></div>';
		popOverHtml = popOverHtml + '</div>';

		jsOverviewManager2.create_popover_non_ajax ("foodItemAction" + foodItemId + currentNameSuffix, "preOrderSettings_popOver" + foodItemId + currentNameSuffix, { xSourcePoint: "right", xDestPoint: "left", xPixelOffset: -120, yPixelOffset: -10 }, '280px', ' ', popOverHtml, 'chooseCartType');
		$("pleaseWait" + foodItemId + currentNameSuffix).src = this.url_loading;

		var postParameters = new Object ();
		postParameters.foodItemId = foodItemId;
		postParameters.rhs = rhs ? "Y" : "N";
		postParameters.askForSuburb = askForSuburb ? "Y" : "N";
		postParameters.isCurrentlyOpen = isCurrentlyOpen ? "Y" : "N";
		gc_ajaxManager.request (
			this.url_conformPreOrderDetails,
			{	method: "post",
				parameters: postParameters },
			"foodItemId" + foodItemId + currentNameSuffix
		);
		return true;





/**
		var currentNameSuffix = '';
		if ((rhs != false) && (rhs != undefined))
			currentNameSuffix = this.rhsNameSuffix;

		var chooseCartTypeHtml = '';
		chooseCartTypeHtml = chooseCartTypeHtml + '<form id="tAChooseSuburb' + foodItemId + '" onsubmit="return false;">';
		var popoverTitle = '';
		if (askForSuburb) {

			popoverTitle = 'Please choose your suburb';

			chooseCartTypeHtml = chooseCartTypeHtml + '<div>';

			if (this.doesDelivery) {
				chooseCartTypeHtml = chooseCartTypeHtml + '<label for="cartType_delivery' + foodItemId + '"><input name="cartType' + foodItemId + '" class="radioButton" value="delivery" id="cartType_delivery' + foodItemId + '" type="radio"> <span style="cursor: pointer;">Delivery to</span></label> ';
				chooseCartTypeHtml = chooseCartTypeHtml + '<select id="takeawaySuburbId' + foodItemId + '" class="select" onChange="$(\'cartType_delivery' + foodItemId + '\').checked = true;">' + $('takeawaySuburbId').innerHTML + '</select>';
			}
			if ((this.doesDelivery) && (this.doesPickUp)) {
				chooseCartTypeHtml = chooseCartTypeHtml + '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;or<br />';
			}
			if (this.doesPickUp) {
				chooseCartTypeHtml = chooseCartTypeHtml + '<label for="cartType_pickUp' + foodItemId + '"><input name="cartType' + foodItemId + '" class="radioButton" value="delivery" id="cartType_pickUp' + foodItemId + '" type="radio"> <span style="cursor: pointer;">Pick up</span></label>';
			}

			chooseCartTypeHtml = chooseCartTypeHtml + '</div>';
		}

		if (!isCurrentlyOpen) {
			chooseCartTypeHtml = chooseCartTypeHtml + '<div style="margin-top: 10px;">';

			if (!askForSuburb)
				popoverTitle = 'Please select your order time';
			else
				chooseCartTypeHtml = chooseCartTypeHtml + '<div class="title">Please select your order time</div><div class="contentEnd"></div>';

			chooseCartTypeHtml = chooseCartTypeHtml + 'helo';
			chooseCartTypeHtml = chooseCartTypeHtml + '<input type="text" />';
//			alert ('rah');
			chooseCartTypeHtml = chooseCartTypeHtml + '</div>';
		}

		chooseCartTypeHtml = chooseCartTypeHtml + '</form>';
		chooseCartTypeHtml = chooseCartTypeHtml + '<script language="javascript">';
		chooseCartTypeHtml = chooseCartTypeHtml + '	$("tAChooseSuburb' + foodItemId + '").observe ("submit", function (event) {';
//		chooseCartTypeHtml = chooseCartTypeHtml + '		jsMenuManager.submit_item ('.$foodItemId.', false);';
		chooseCartTypeHtml = chooseCartTypeHtml + '		alert (\'helo\');';
		chooseCartTypeHtml = chooseCartTypeHtml + '	});';
		chooseCartTypeHtml = chooseCartTypeHtml + '</script>';



//		jsMessageManager.show_message ("foodItem" + foodItemId + currentNameSuffix, "<div style='float: " + this.left + "; margin: 0px; padding: 0px;'><img src='" + this.url_noticeIcon + "' /></div><div style='float: " + this.left + "; padding: 0px; margin: 1px 0px 0px 10px;'>Please select your suburb above<br />before adding to your cart.<br /><a href=\'#cartType\'>Jump to suburb list</a></div>", 3500);
//		var chooseCartTypeHtml = "<div style='float: " + this.left + "; margin: 0px; padding: 0px;'><img src='" + this.url_noticeIcon + "' /></div><div style='float: " + this.left + "; padding: 0px; margin: 1px 0px 0px 10px;'>Please select your suburb above<br />before adding to your cart.<br /><a href=\'#cartType\'>Jump to suburb list</a></div>";
		jsOverviewManager2.create_popover_non_ajax ("foodItemAction" + foodItemId + currentNameSuffix, "chooseCartSummary" + foodItemId + currentNameSuffix, { xSourcePoint: "right", xDestPoint: "left", xPixelOffset: 8, yPixelOffset: -10 }, '270px', popoverTitle, chooseCartTypeHtml, 'chooseCartType');

		if (askForSuburb) {
			if (this.doesDelivery)
				$('cartType_delivery' + foodItemId).checked = $('cartType_delivery').checked;
			if (this.doesPickUp)
				$('cartType_pickUp' + foodItemId).checked = $('cartType_pickUp').checked;
			$('takeawaySuburbId' + foodItemId).selectedIndex = $('takeawaySuburbId').selectedIndex;
		}
/**/
	},

	update_delivery_suburb: function (foodItemId, rhs) {
		var currentNameSuffix = '';
		if ((rhs != false) && (rhs != undefined))
			currentNameSuffix = this.rhsNameSuffix;

		if ($('cartType_delivery') != null)
			$('cartType_delivery').checked = true;
		if (foodItemId != '') {
			$('takeawaySuburbId').selectedIndex = $('takeawaySuburbId' + foodItemId).selectedIndex;
			if ($('cartType_delivery' + foodItemId) != null)
				$('cartType_delivery' + foodItemId).checked = true;
		}

		jsOverviewManager2.hide_popover ("chooseCartSummary" + foodItemId + currentNameSuffix);

		jsCartSummaryManager.submit_new_cart_type ('delivery', $('takeawaySuburbId')[$('takeawaySuburbId').selectedIndex].value, foodItemId, rhs);
		form_changed ();

		this.set_cart_type ('delivery');
		this.set_suburb_id ($('takeawaySuburbId')[$('takeawaySuburbId').selectedIndex].value);

//		if (foodItemId != '')
//			this.submit_item (foodItemId, false, rhs);
	},

	update_cart_type_to_delivery: function (foodItemId, rhs) {
		var currentNameSuffix = '';
		if ((rhs != false) && (rhs != undefined))
			currentNameSuffix = this.rhsNameSuffix;

		if ((foodItemId != '') && ($('cartType_delivery' + foodItemId) != null))
			$('cartType_delivery' + foodItemId).checked = true;


		jsCartSummaryManager.submit_new_cart_type ('delivery', $('takeawaySuburbId')[$('takeawaySuburbId').selectedIndex].value, foodItemId, rhs);
		form_changed ();

		this.set_cart_type ('delivery');
	},

	update_cart_type_to_pick_up: function (foodItemId, rhs) {
		var currentNameSuffix = '';
		if ((rhs != false) && (rhs != undefined))
			currentNameSuffix = this.rhsNameSuffix;

		if ((foodItemId != '') && ($('cartType_pickUp' + foodItemId) != null))
			$('cartType_pickUp' + foodItemId).checked = true;

		jsCartSummaryManager.submit_new_cart_type ('pickUp', 0);
		form_changed ();

		this.set_cart_type ('pickUp');
	},

	display_cart_summary_popover: function (cartSummaryId) {
//		if (this.currentCartSummaryId != cartSummaryId)
//			jsMenuManager.really_hide_current_cart_summary_popover ();
		this.currentCartSummaryId = cartSummaryId;

		var cartSummaryHtml = $("cartSummary").innerHTML;

		// alias specific ids so they're not removed from the html
		cartSummaryHtml = cartSummaryHtml.replace ('id="cartSummaryCloseWithoutCartItems"', 'id2="cartSummaryCloseWithoutCartItems"');
		cartSummaryHtml = cartSummaryHtml.replace ('id=cartSummaryCloseWithoutCartItems', 'id2="cartSummaryCloseWithoutCartItems"');	// ie
		cartSummaryHtml = cartSummaryHtml.replace ('id="cartSummaryCloseWithCartItems"', 'id2="cartSummaryCloseWithCartItems"');
		cartSummaryHtml = cartSummaryHtml.replace ('id=cartSummaryCloseWithCartItems', 'id2="cartSummaryCloseWithCartItems"');	// ie
		cartSummaryHtml = cartSummaryHtml.replace ('id=cartSummaryCloseWithCartItems', 'id2="cartSummaryCloseWithCartItems"');
		for (var count in jsCartSummaryManager.groupDealIds) {
			cartSummaryHtml = cartSummaryHtml.replace ('id="groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment"', 'id2="groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment"');
			cartSummaryHtml = cartSummaryHtml.replace ('id=groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment', 'id2="groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment"');	// ie
		}
		for (var count in jsCartSummaryManager.discountIds) {
			cartSummaryHtml = cartSummaryHtml.replace ('id="discount' + jsCartSummaryManager.discountIds[count] + '_comment"', 'id2="discount' + jsCartSummaryManager.discountIds[count] + '_comment"');
			cartSummaryHtml = cartSummaryHtml.replace ('id=discount' + jsCartSummaryManager.discountIds[count] + '_comment', 'id2="discount' + jsCartSummaryManager.discountIds[count] + '_comment"');	// ie
		}

		// remove ids from the html
		cartSummaryHtml = cartSummaryHtml.replace (/id[\s]*=[\s]*("[a-zA-Z0-9_]*"|'[a-zA-Z0-9_]*'|[a-zA-Z0-9_]*(\s))/gi, "");
		cartSummaryHtml = cartSummaryHtml.replace (/id[\s]*=[\s]*([a-zA-Z0-9_]*(\s|>))/gi, ">");

		cartSummaryHtml = cartSummaryHtml.replace ('id2="cartSummaryCloseWithoutCartItems"', 'id="cartSummaryCloseWithoutCartItems' + cartSummaryId + '"');
		cartSummaryHtml = cartSummaryHtml.replace ('id2="cartSummaryCloseWithCartItems"', 'id="cartSummaryCloseWithCartItems' + cartSummaryId + '"');
		for (var count in jsCartSummaryManager.groupDealIds) {
			cartSummaryHtml = cartSummaryHtml.replace ('id2="groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment"', 'id="groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment' + cartSummaryId + '"');	// for the group deal comment input field id
			cartSummaryHtml = cartSummaryHtml.replace ('jsCartSummaryManager.ajax_update_group_deal_comments (\'' + jsCartSummaryManager.groupDealIds[count] + '\', this.value);', 'jsCartSummaryManager.ajax_update_group_deal_comments (\'' + jsCartSummaryManager.groupDealIds[count] + '\', this.value, ' + cartSummaryId + ');');	// for the group deal comment onKeyDown
			cartSummaryHtml = cartSummaryHtml.replace ('jsCartSummaryManager.ajax_update_group_deal_comments (\'' + jsCartSummaryManager.groupDealIds[count] + '\', this.value);', 'jsCartSummaryManager.ajax_update_group_deal_comments (\'' + jsCartSummaryManager.groupDealIds[count] + '\', this.value, ' + cartSummaryId + ');');	// for the group deal comment onClick
			cartSummaryHtml = cartSummaryHtml.replace ('jsCartSummaryManager.ajax_update_group_deal_comments_save_button (\'' + jsCartSummaryManager.groupDealIds[count] + '\', null);', 'jsCartSummaryManager.ajax_update_group_deal_comments_save_button (\'' + jsCartSummaryManager.groupDealIds[count] + '\', null, ' + cartSummaryId + ');');	// for the group deal comment save button
			cartSummaryHtml = cartSummaryHtml.replace ('jsOverviewManager2.create_popover_non_ajax (\'groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment\', \'groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_info\'', 'jsOverviewManager2.create_popover_non_ajax (\'groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment' + cartSummaryId + '\', \'discount' + jsCartSummaryManager.groupDealIds[count] + '_info' + cartSummaryId + '\'');	// for the group deal info pop-over
		}
		for (var count in jsCartSummaryManager.discountIds) {
			cartSummaryHtml = cartSummaryHtml.replace ('id2="discount' + jsCartSummaryManager.discountIds[count] + '_comment"', 'id="discount' + jsCartSummaryManager.discountIds[count] + '_comment' + cartSummaryId + '"');	// for the discount comment input field id
			cartSummaryHtml = cartSummaryHtml.replace ('jsCartSummaryManager.ajax_update_discount_comments (' + jsCartSummaryManager.discountIds[count] + ', this.value);', 'jsCartSummaryManager.ajax_update_discount_comments (' + jsCartSummaryManager.discountIds[count] + ', this.value, ' + cartSummaryId + ');');	// for the discount comment onKeyDown
			cartSummaryHtml = cartSummaryHtml.replace ('jsCartSummaryManager.ajax_update_discount_comments (' + jsCartSummaryManager.discountIds[count] + ', this.value);', 'jsCartSummaryManager.ajax_update_discount_comments (' + jsCartSummaryManager.discountIds[count] + ', this.value, ' + cartSummaryId + ');');	// for the discount comment onClick
			cartSummaryHtml = cartSummaryHtml.replace ('jsCartSummaryManager.ajax_update_discount_comments_save_button (' + jsCartSummaryManager.discountIds[count] + ', null);', 'jsCartSummaryManager.ajax_update_discount_comments_save_button (' + jsCartSummaryManager.discountIds[count] + ', null, ' + cartSummaryId + ');');	// for the discount comment save button
			cartSummaryHtml = cartSummaryHtml.replace ('jsOverviewManager2.create_popover_non_ajax (\'discount' + jsCartSummaryManager.discountIds[count] + '_comment\', \'discount' + jsCartSummaryManager.discountIds[count] + '_info\'', 'jsOverviewManager2.create_popover_non_ajax (\'discount' + jsCartSummaryManager.discountIds[count] + '_comment' + cartSummaryId + '\', \'discount' + jsCartSummaryManager.discountIds[count] + '_info' + cartSummaryId + '\'');	// for the discount info pop-over
		}

		cartSummaryHtml = '<div id="cartSummaryPopover' + cartSummaryId + '" style="width: 270px;">' + cartSummaryHtml + '</div>';
///		jsMessageManager.set_place_holder ("cartSummary" + cartSummaryId, "viewCart" + cartSummaryId, { xSourcePoint: "right", xDestPoint: "left", xPixelOffset: 8, yPixelOffset: -50 });
//		jsMessageManager.set_display_effects ("cartSummary" + cartSummaryId, "Appear", { duration: 0.4 }, "DropOut", { duration: 0.5 });
//		jsMessageManager.show_message ("cartSummary" + cartSummaryId, '<div id="cartSummaryPopover' + cartSummaryId + '" style="width: 270px;">' + cartSummaryHtml + "</div>");
		jsOverviewManager2.create_popover_non_ajax ("viewCart" + cartSummaryId, "cartSummary" + cartSummaryId, { xSourcePoint: "right", xDestPoint: "left", xPixelOffset: 8, yPixelOffset: -50 }, '270px', '', cartSummaryHtml, 'cartSummary', false);
		$("cartSummaryCloseWithoutCartItems" + cartSummaryId).innerHTML = '<img src="' + this.url_deleteIcon + '" title="Close" onClick="jsMenuManager.really_hide_current_cart_summary_popover ();" class="close">';
		$("cartSummaryCloseWithCartItems" + cartSummaryId).innerHTML = '<img src="' + this.url_deleteIcon + '" title="Close" onClick="jsMenuManager.really_hide_current_cart_summary_popover ();" class="close">';

		// update the cart summary popover with the value in the main cart summary
		for (var count in jsCartSummaryManager.discountIds) {
			if ($('discount' + jsCartSummaryManager.discountIds[count] + '_comment' + cartSummaryId) != null)
				$('discount' + jsCartSummaryManager.discountIds[count] + '_comment' + cartSummaryId).value = $('discount' + jsCartSummaryManager.discountIds[count] + '_comment').value;
		}
	},

	really_hide_current_cart_summary_popover: function () {
		if (this.currentCartSummaryId != 0) {
			jsMenuManager.really_hide_cart_summary_popover (this.currentCartSummaryId);
			this.currentCartSummaryId = 0;
		}
	},

	really_hide_cart_summary_popover: function (cartSummaryId) {
//		jsMessageManager.hide_message_block ('cartSummary' + cartSummaryId);
		jsOverviewManager2.hide_popover ('cartSummary' + cartSummaryId);
	},

	update_cart_popover_content: function () {
		if (this.currentCartSummaryId != 0) {

			var cartSummaryHtml = $("cartSummary").innerHTML;

			// alias specific ids so they're not removed from the html
			cartSummaryHtml = cartSummaryHtml.replace ('id="cartSummaryCloseWithoutCartItems"', 'id2="cartSummaryCloseWithoutCartItems"');
			cartSummaryHtml = cartSummaryHtml.replace ('id=cartSummaryCloseWithoutCartItems', 'id2="cartSummaryCloseWithoutCartItems"');	// ie
			cartSummaryHtml = cartSummaryHtml.replace ('id="cartSummaryCloseWithCartItems"', 'id2="cartSummaryCloseWithCartItems"');
			cartSummaryHtml = cartSummaryHtml.replace ('id=cartSummaryCloseWithCartItems', 'id2="cartSummaryCloseWithCartItems"');	// ie
			cartSummaryHtml = cartSummaryHtml.replace ('id=cartSummaryCloseWithCartItems', 'id2="cartSummaryCloseWithCartItems"');
			for (var count in jsCartSummaryManager.groupDealIds) {
				cartSummaryHtml = cartSummaryHtml.replace ('id="groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment"', 'id2="groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment"');
				cartSummaryHtml = cartSummaryHtml.replace ('id=groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment', 'id2="groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment"');	// ie
			}
			for (var count in jsCartSummaryManager.discountIds) {
				cartSummaryHtml = cartSummaryHtml.replace ('id="discount' + jsCartSummaryManager.discountIds[count] + '_comment"', 'id2="discount' + jsCartSummaryManager.discountIds[count] + '_comment"');
				cartSummaryHtml = cartSummaryHtml.replace ('id=discount' + jsCartSummaryManager.discountIds[count] + '_comment', 'id2="discount' + jsCartSummaryManager.discountIds[count] + '_comment"');	// ie
			}

			// remove ids from the html
			cartSummaryHtml = cartSummaryHtml.replace (/id[\s]*=[\s]*("[a-zA-Z0-9_]*"|'[a-zA-Z0-9_]*'|[a-zA-Z0-9_]*(\s))/gi, "");
			cartSummaryHtml = cartSummaryHtml.replace (/id[\s]*=[\s]*([a-zA-Z0-9_]*(\s|>))/gi, ">");

			cartSummaryHtml = cartSummaryHtml.replace ('id2="cartSummaryCloseWithoutCartItems"', 'id="cartSummaryCloseWithoutCartItems' + this.currentCartSummaryId + '"');
			cartSummaryHtml = cartSummaryHtml.replace ('id2="cartSummaryCloseWithCartItems"', 'id="cartSummaryCloseWithCartItems' + this.currentCartSummaryId + '"');
			for (var count in jsCartSummaryManager.groupDealIds) {
				cartSummaryHtml = cartSummaryHtml.replace ('id2="groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment"', 'id="groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment' + this.currentCartSummaryId + '"');	// for the group deal comment input field id
				cartSummaryHtml = cartSummaryHtml.replace ('jsCartSummaryManager.ajax_update_group_deal_comments (\'' + jsCartSummaryManager.groupDealIds[count] + '\', this.value);', 'jsCartSummaryManager.ajax_update_group_deal_comments (\'' + jsCartSummaryManager.groupDealIds[count] + '\', this.value, ' + this.currentCartSummaryId + ');');	// for the group deal comment onKeyDown
				cartSummaryHtml = cartSummaryHtml.replace ('jsCartSummaryManager.ajax_update_group_deal_comments (\'' + jsCartSummaryManager.groupDealIds[count] + '\', this.value);', 'jsCartSummaryManager.ajax_update_group_deal_comments (\'' + jsCartSummaryManager.groupDealIds[count] + '\', this.value, ' + this.currentCartSummaryId + ');');	// for the group deal comment onClick
				cartSummaryHtml = cartSummaryHtml.replace ('jsCartSummaryManager.ajax_update_group_deal_comments_save_button (\'' + jsCartSummaryManager.groupDealIds[count] + '\', null);', 'jsCartSummaryManager.ajax_update_group_deal_comments_save_button (\'' + jsCartSummaryManager.groupDealIds[count] + '\', null, ' + this.currentCartSummaryId + ');');	// for the group deal comment save button
				cartSummaryHtml = cartSummaryHtml.replace ('jsOverviewManager2.create_popover_non_ajax (\'groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment\', \'groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_info\'', 'jsOverviewManager2.create_popover_non_ajax (\'groupDeal' + jsCartSummaryManager.groupDealIds[count] + '_comment' + this.currentCartSummaryId + '\', \'discount' + jsCartSummaryManager.groupDealIds[count] + '_info' + this.currentCartSummaryId + '\'');	// for the group deal info pop-over
			}
			for (var count in jsCartSummaryManager.discountIds) {
				cartSummaryHtml = cartSummaryHtml.replace ('id2="discount' + jsCartSummaryManager.discountIds[count] + '_comment"', 'id="discount' + jsCartSummaryManager.discountIds[count] + '_comment' + this.currentCartSummaryId + '"');	// for the discount comment input field id
				cartSummaryHtml = cartSummaryHtml.replace ('jsCartSummaryManager.ajax_update_discount_comments (' + jsCartSummaryManager.discountIds[count] + ', this.value);', 'jsCartSummaryManager.ajax_update_discount_comments (' + jsCartSummaryManager.discountIds[count] + ', this.value, ' + this.currentCartSummaryId + ');');	// for the discount comment onKeyDown
				cartSummaryHtml = cartSummaryHtml.replace ('jsCartSummaryManager.ajax_update_discount_comments (' + jsCartSummaryManager.discountIds[count] + ', this.value);', 'jsCartSummaryManager.ajax_update_discount_comments (' + jsCartSummaryManager.discountIds[count] + ', this.value, ' + this.currentCartSummaryId + ');');	// for the discount comment onClick
				cartSummaryHtml = cartSummaryHtml.replace ('jsCartSummaryManager.ajax_update_discount_comments_save_button (' + jsCartSummaryManager.discountIds[count] + ', null);', 'jsCartSummaryManager.ajax_update_discount_comments_save_button (' + jsCartSummaryManager.discountIds[count] + ', null, ' + this.currentCartSummaryId + ');');	// for the discount comment save button
				cartSummaryHtml = cartSummaryHtml.replace ('jsOverviewManager2.create_popover_non_ajax (\'discount' + jsCartSummaryManager.discountIds[count] + '_comment\', \'discount' + jsCartSummaryManager.discountIds[count] + '_info\'', 'jsOverviewManager2.create_popover_non_ajax (\'discount' + jsCartSummaryManager.discountIds[count] + '_comment' + this.currentCartSummaryId + '\', \'discount' + jsCartSummaryManager.discountIds[count] + '_info' + this.currentCartSummaryId + '\'');	// for the discount info pop-over
			}
			$("cartSummaryPopover" + this.currentCartSummaryId).innerHTML = cartSummaryHtml;
			$("cartSummaryCloseWithoutCartItems" + this.currentCartSummaryId).innerHTML = '<img src="' + this.url_deleteIcon + '" title="Close" onClick="jsMenuManager.really_hide_current_cart_summary_popover ()" class="close">';
			$("cartSummaryCloseWithCartItems" + this.currentCartSummaryId).innerHTML = '<img src="' + this.url_deleteIcon + '" title="Close" onClick="jsMenuManager.really_hide_current_cart_summary_popover ()" class="close">';
		}
	},

	add_food_item_id_to_list: function (foodItemId, hasChoices) {
		this.foodItemIds[foodItemId] = foodItemId;
		this.foodItemsWithChoices[foodItemId] = hasChoices;
	},

	highlight_food_items: function (selectedFoodItemIds) {
		for (var foodItemId in this.foodItemIds) {
			if ($("qty" + foodItemId) != null) {
				if (selectedFoodItemIds[foodItemId] != undefined) {
					$("qty" + foodItemId).style.fontWeight = "bold";
					$("qty" + foodItemId).style.borderWidth = "2px";
				}
				else {
					$("qty" + foodItemId).style.fontWeight = "normal";
					$("qty" + foodItemId).style.borderWidth = "1px";
				}
			}

			if ($("qty" + foodItemId + this.rhsNameSuffix) != null) {
				if (selectedFoodItemIds[foodItemId] != undefined) {
					$("qty" + foodItemId + this.rhsNameSuffix).style.fontWeight = "bold";
					$("qty" + foodItemId + this.rhsNameSuffix).style.borderWidth = "2px";
				}
				else {
					$("qty" + foodItemId + this.rhsNameSuffix).style.fontWeight = "normal";
					$("qty" + foodItemId + this.rhsNameSuffix).style.borderWidth = "1px";
				}
			}
		}
	}
}