/***************************************************************************
 * displayAjaxMessage()                                                  *
 *                                                                         *
 * input: title - the string to set the title of the dialog to             *
 *        msg - the message to put in the dialog                           *
 *        dialogId - the id of the dialog to display                       *
 *        formid - the formid of the form on the page                      *
 *        itemid - the itemid of the item in the form                      *
 *        actionid - the actionid of the action in the form                *
 *                                                                         *
 * output: none                                                            *
 *                                                                         *
 * description: Opens the appropriate dialog window and sets all values.   *
 *                                                                         *
 ***************************************************************************/
function displayAjaxMessage(title, msg, dialogId, formid, itemid, actionid) {
	
	var dialogTxt;
	var dialogMsg;
	var dialogDiv;
    var frameId;
	
	var objTitle;
	var objMsg;
	var objDiv;

	if (dialogId == null || dialogId == "") {
		dialogId = "1";
	}
	
    frameId = "productWarningFrame" + dialogId;
	dialogDiv = "uiBlockDialog" + dialogId;
	dialogTxt = "productWarningTitle" + dialogId;
	dialogMsg = "productWarningMessage" + dialogId;
	dialogId = "productWarning" + dialogId;
			
	title = title.toLowerCase();
	
	objDiv = document.getElementById(dialogDiv);
	objTitle = document.getElementById(dialogTxt);
	objMsg = document.getElementById(dialogMsg);
	
	if (objTitle && objMsg && dialogDiv) {
	
		objTitle.innerHTML = title;
		
		objMsg.innerHTML = msg;

		objDiv.setAttribute("formid", formid);
	    objDiv.setAttribute("itemid", itemid);
	    objDiv.setAttribute("actionid", actionid);
		
	    showPopup(frameId, dialogId, -1, false);
		
	}
			
	//Clear objects
	objDiv = null;
	objMsg = null;
	objTitle = null;
	
	return;
} //displayAjaxMessage()

function showGiftCardAmountFields(cardOrdinalNumber, amt, rem) {
	hideGiftCardMsg(cardOrdinalNumber);
	var tableCell = $("#cards table input#giftCardNum" + cardOrdinalNumber).parent("td");
	if (tableCell) {
		if ($(tableCell).children("img")) $(tableCell).children("img").remove(); // hide()
	}
	if (amt != null) $("#cards table #giftCardNum" + cardOrdinalNumber + "Amt").html(amt);
	if (rem != null) $("#cards table #giftCardNum" + cardOrdinalNumber + "AmtRem").html(rem);
	var row = $("#cards table #giftCardAmtRow" + cardOrdinalNumber); 
	if (row) row.removeClass("no-show");
}

function hideGiftCardAmountFields(cardOrdinalNumber) {
	$("#cards table #giftCardNum" + cardOrdinalNumber + "Amt").html('');
	$("#cards table #giftCardNum" + cardOrdinalNumber + "AmtRem").html('');
	var row = $("#cards table #giftCardAmtRow" + cardOrdinalNumber);
	if (row) row.addClass("no-show");
}

function showGiftCardMsg(cardOrdinalNumber, errorMsg) {
	hideGiftCardAmountFields(cardOrdinalNumber);
	var tableCell = $("#cards table input#giftCardNum" + cardOrdinalNumber).parent("td");
	if (tableCell) {
		if ($(tableCell).children("img")) $(tableCell).children("img").remove(); // hide()
	}
	$("#cards table #giftCardNum" + cardOrdinalNumber + "Error").html(errorMsg);
	var row = $("#cards table #giftCardMsgRow" + cardOrdinalNumber);
	if (row) row.removeClass("no-show");
}

function hideGiftCardMsg(cardOrdinalNumber) {
	$("#cards table #giftCardNum" + cardOrdinalNumber + "Error").html('');
	var row = $("#cards table #giftCardMsgRow" + cardOrdinalNumber);
	if (row) row.addClass("no-show");
}

function updateGiftCardUI(xml, balanceInfoFieldName, cardOrdinalNumber) {
  var giftCardNumber = $("giftCardNumber" + cardOrdinalNumber,xml).text();
  var gcBalance = $("gcBalance" + cardOrdinalNumber,xml).text();
  var gcBalanceRemaining = $("gcBalanceRemaining" + cardOrdinalNumber,xml).text();
  var paymentRemaining = $("paymentRemaining" + cardOrdinalNumber,xml).text();
  var gcAmountApplied = $("gcAmountApplied" + cardOrdinalNumber,xml).text();
  var giftCardsAllowed = $("giftCardsAllowed",xml).text();
  var paymentRemainingZero = $("paymentRemainingZero",xml).text();
  var status = $("status",xml).text();
  var statusText = $("statusText",xml).text();
  var orderIsPriced = $("OrderIsPriced",xml).text();
  var giftCardsAllowedInt = parseInt(giftCardsAllowed);
  var cardNumOnPage = balanceInfoFieldName.substring("giftCardNum".length, "giftCardNum".length+1);
  if (statusText == '0') {
    if($OLO("payment-remaining-h5")) $OLO("payment-remaining-h5").style.display = "block";
    if($OLO("no-payment-remaining-h5")) $OLO("no-payment-remaining-h5").style.display = "none";
    if($OLO("pay-by-cash")) document.getElementById('pay-by-cash').style.display = dispState;
    if($OLO("pay-by-check")) document.getElementById('pay-by-check').style.display = dispState;
    if($OLO("pay-by-credit")) document.getElementById('pay-by-credit').style.display = dispState;
    if($OLO("ccDeatilsTable")) document.getElementById('ccDeatilsTable').style.display = dispState;
    //if($OLO(balanceInfoFieldName)) $OLO(balanceInfoFieldName).style.color = "black";
    //if($OLO(balanceInfoFieldName)) $OLO(balanceInfoFieldName).innerHTML = "$" + gcAmountApplied;
    //if($OLO(balanceInfoFieldName + "Rem")) $OLO(balanceInfoFieldName + "Rem").style.color = "black";
    //if($OLO(balanceInfoFieldName + "Rem")) $OLO(balanceInfoFieldName + "Rem").innerHTML = "$" + gcBalanceRemaining;
    showGiftCardAmountFields(cardNumOnPage, "$" + gcAmountApplied, "$" + gcBalanceRemaining);
    if($OLO(balanceInfoFieldName + "HIDDEN")) $OLO(balanceInfoFieldName + "HIDDEN").value = "$" + gcBalance;
    if($OLO(balanceInfoFieldName + "RemHIDDEN")) $OLO(balanceInfoFieldName + "RemHIDDEN").value = "$" + gcBalanceRemaining;
    if($OLO(balanceInfoFieldName + "Applied")) $OLO(balanceInfoFieldName + "Applied").value = gcAmountApplied;
    if($OLO("paymentRemaining")) $OLO("paymentRemaining").innerHTML = paymentRemaining;
    if($OLO("paymentRemainingHIDDEN")) $OLO("paymentRemainingHIDDEN").value = paymentRemaining;
    if (paymentRemainingZero == 'Y') {
      if($OLO("payment-remaining-h5")) $OLO("payment-remaining-h5").style.display = "none";
      if($OLO("no-payment-remaining-h5")) $OLO("no-payment-remaining-h5").style.display = "block";
      if($OLO("payby-label")) document.getElementById('payby-label').style.display = "none";
      if($OLO("pay-by-cash")) document.getElementById('pay-by-cash').style.display = "none";
      if($OLO("pay-by-check")) document.getElementById('pay-by-check').style.display = "none";
      if($OLO("pay-by-credit")) document.getElementById('pay-by-credit').style.display = "none";
      if($OLO("ccDeatilsTable")) document.getElementById('ccDeatilsTable').style.display = "none";
    }
  } else {
    //if($OLO(balanceInfoFieldName)) $OLO(balanceInfoFieldName).style.color = "red";
    //if($OLO(balanceInfoFieldName)) $OLO(balanceInfoFieldName).innerHTML = statusText;
	showGiftCardMsg(cardNumOnPage, statusText);
    if (status == '-7' || status == '-8') {
      if($OLO(balanceInfoFieldName.substring(0, 12) + "PreviousValue")) 
         $OLO(balanceInfoFieldName.substring(0, 12) + "PreviousValue").value = giftCardNumber;
    } else {
      if($OLO(balanceInfoFieldName.substring(0, 12) + "PreviousValue")) 
         $OLO(balanceInfoFieldName.substring(0, 12) + "PreviousValue").value = "";
    }
  }
  var enablePricing = true;
  for (i=1; i <= giftCardsAllowedInt; i = i + 1) {
    if($OLO('giftCardNum' + i + 'Error')) {
      if ($OLO('giftCardNum' + i + 'Error').innerHTML == 'Retrieving Balance...') {
        enablePricing = false;
      }
    }
  }
  if (enablePricing && orderIsPriced == 'Y') {
    if($OLO('pricingEnabled:placeOrdeLink')) $OLO('pricingEnabled:placeOrdeLink').style.display = "block";
    if($OLO('placeOrdeLinkP')) $OLO('placeOrdeLinkP').style.display = "block";
    if($OLO('placeOrdeLinkDIS')) $OLO('placeOrdeLinkDIS').style.display = "none";
    if (document.getElementById('placeOrderDisabledByGiftCards')) {
        document.getElementById('placeOrderDisabledByGiftCards').value = '';
    }
  }
}

function ajaxGetGiftCardBalance(giftCardNumber, giftCardPIN, balanceInfoFieldName, useSameCardAgain, recaptcha_challenge_field, recaptcha_response_field) {
    $.post("/olo/servlet/ajax_servlet",{
      cmd: "gcBalance"
      , balanceInfoFieldName: balanceInfoFieldName
      , giftCardNumber: giftCardNumber
      , giftCardPIN: giftCardPIN
      , useSameCardAgain: useSameCardAgain
      , recaptcha_challenge_field: recaptcha_challenge_field
      , recaptcha_response_field: recaptcha_response_field
    },function(xml){
      updateGiftCardUI(xml, balanceInfoFieldName, "");
    });
}

function ajaxInvalidateSession() {
    $.post("/olo/servlet/ajax_servlet",{
      cmd: "invalidateSession"
    },function(xml){
    });
}

function ajaxPriceOrder(formName, getFreeDeliveryOffer, usePriceOrder, useCouponPicker) {
	var origFormName = formName;
    var formName = formName + ":";

	if (typeof(useCouponPicker) == 'undefined' || useCouponPicker == null) {
		useCouponPicker = "N";
	}	
	if (typeof(usePriceOrder) == 'undefined' || usePriceOrder == null) {
		usePriceOrder = "N";
	}

	var runPriceOrder = (usePriceOrder == "Y");
	var runCouponPicker = (useCouponPicker == "Y");

	if (runPriceOrder) {
	    if($OLO("order-total")) $OLO("order-total").style.display = "block";
	    if($OLO(formName + "order_pricing_info_subtotal")) $OLO(formName + "order_pricing_info_subtotal").innerHTML = '';
	    if($OLO("order_pricing_info_text")) $OLO("order_pricing_info_text").innerHTML = "Calculating...";
	    if($OLO("order_pricing_wait_text")) $OLO("order_pricing_wait_text").innerHTML = "Calculating price...";
	    if($OLO("serviceTimeD")) $OLO("serviceTimeD").innerHTML = "(Calculating service time...)";
	    if($OLO("serviceTimeP")) $OLO("serviceTimeP").innerHTML = "(Calculating service time...)";
	}

    $.post("/olo/servlet/ajax_servlet",{
      cmd: "priceOrder"
      , formName: formName
      , getFreeDeliveryOffer: getFreeDeliveryOffer
      , runCouponPicker: useCouponPicker
      , runPriceOrder: usePriceOrder
    },function(xml){
    	if (runPriceOrder) {
	      var status = $("status",xml).text();
	      var statusText = $("statusText",xml).text();
	      if (status == '0') {
	        var productCount = $("productCount",xml).text();
	        var productPrices = new Array();
	        var productDiscountMessages = new Array();
	        for (var i = 0; i < productCount; i++) {
	          productPrices[i] = $("product" + i + "price",xml).text(); 
	          productDiscountMessages[i] = $("product" + i + "discountMessage",xml).text(); 
	        }
	        for (var i = 0; i < productCount; i++) {
	          if (productPrices[i] != 'x') {
	            if($OLO(formName + "summaryItemsTable:" + i + ":pricedAt")) $OLO(formName + "summaryItemsTable:" + i + ":pricedAt").innerHTML = productPrices[i];
	            if($OLO("placeOrderProduct:" + i + ":pricedAt")) $OLO("placeOrderProduct:" + i + ":pricedAt").innerHTML = productPrices[i];
	          }
	          if (productDiscountMessages[i] == 'x') {
	              if($OLO(i + ":discount2")) $OLO(i + ":discount2").innerHTML = "";
	              if($OLO(formName + "summaryItemsTable:" + i + ":discount1")) $OLO(formName + "summaryItemsTable:" + i + ":discount1").innerHTML = "";
	              if($OLO(formName + "summaryItemsTable:" + i + ":discount2")) $OLO(formName + "summaryItemsTable:" + i + ":discount2").innerHTML = "";
	              if($OLO(formName + "summaryItemsTable:" + i + ":discount3")) $OLO(formName + "summaryItemsTable:" + i + ":discount3").innerHTML = "";
	          }
	        }
	        var subtotal = $("subtotal",xml).text();
	        var tax = $("tax",xml).text();
	        var delivery = $("delivery",xml).text();
	        var deliveryLabel = $("deliveryLabel",xml).text();
	        var total = $("total",xml).text();
	        var serviceTime = $("serviceTime",xml).text();
	        var showYouGot30 = $("showYouGot30",xml).text();
	        if (showYouGot30 == 'bloque') showYouGot30 = 'block';
	        var pointsEarned = $("pointsEarned",xml).text();
	        var totalPoints = $("totalPoints",xml).text();
	        var freeDeliveryTresholdPassed = $("FreeDeliveryTresholdPassed",xml).text();
	        var showFreeDeliveryOffer = $("ShowFreeDeliveryOffer",xml).text();
	        var showCrossSellOfferOffer = $("ShowCrossSellOfferOffer",xml).text();
	        var showFreeProductOffer = $("ShowFreeProductOffer",xml).text();
	        var showFreeProductOfferInfo = $("ShowFreeProductOfferInfo",xml).text();
	        var showFreeProductOfferWarning = $("ShowFreeProductOfferWarning",xml).text();
	        var freeProductOfferWarning = $("FreeProductOfferWarning",xml).text();
	        
	        var fDOTitle = $("FDOTitle",xml).text();
	        var fDOText = $("FDOText",xml).text();
	        var fDOImage = $("FDOImage",xml).text();
	        var fDOMessage = $("FDOMessage",xml).text();
	        var fDOSubtotal = $("FDOSubtotal",xml).text();
	
	        if($OLO(formName + "order_pricing_info_subtotal")) $OLO(formName + "order_pricing_info_subtotal").innerHTML =   subtotal;
	        if($OLO(formName + "order_pricing_info_tax"))      $OLO(formName + "order_pricing_info_tax").innerHTML =        tax;
	        if($OLO(formName + "order_pricing_info_delivery")) $OLO(formName + "order_pricing_info_delivery").innerHTML =   delivery;
	        if($OLO(formName + "order_pricing_info_delivery_label")) $OLO(formName + "order_pricing_info_delivery_label").innerHTML =   deliveryLabel;
	        if($OLO(formName + "order_pricing_info_total"))    $OLO(formName + "order_pricing_info_total").innerHTML = total;
	        if($OLO("paymentRemaining")) $OLO("paymentRemaining").innerHTML = total;
	        if($OLO("paymentRemainingHIDDEN")) $OLO("paymentRemainingHIDDEN").value = total;
	        if($OLO("balanceUpdate")) $OLO("balanceUpdate").innerHTML = total;
	        if($OLO(formName + "loyalty_points_earned")) $OLO(formName + "loyalty_points_earned").innerHTML =   pointsEarned;
	        if($OLO(formName + "loyalty_total_points")) $OLO(formName + "loyalty_total_points").innerHTML =   totalPoints;
	        if($OLO("you-got-30-banner")) $OLO("you-got-30-banner").style.display = showYouGot30;
	        if($OLO("serviceTimeD")) $OLO("serviceTimeD").innerHTML = serviceTime;
	        if($OLO("serviceTimeP")) $OLO("serviceTimeP").innerHTML = serviceTime;
	        if($OLO("order_pricing_info_text")) $OLO("order_pricing_info_text").innerHTML = "";
	        if($OLO("order_pricing_wait_text")) $OLO("order_pricing_wait_text").innerHTML = "";
	        if($OLO("order_pricing_info_na")) $OLO("order_pricing_info_na").style.display = "none";
	        if($OLO("order_pricing_info_na6")) $OLO("order_pricing_info_na6").style.display = "none";
	        if($OLO("pricingEnabled:placeOrdeLink")) $OLO("pricingEnabled:placeOrdeLink").style.display = "block";
	        if($OLO("placeOrdeLinkP")) $OLO("placeOrdeLinkP").style.display = "block";
	        if($OLO("placeOrdeLinkDIS")) $OLO("placeOrdeLinkDIS").style.display = "none";
	        if (document.getElementById('placeOrderDisabledByGiftCards')) {
	            document.getElementById('placeOrderDisabledByGiftCards').value = '';
	        }
	
	        if($OLO("you_got_free_delivery")) {
	          $OLO("you_got_free_delivery").style.display = "none";
	          if (freeDeliveryTresholdPassed == 'Y') {
	            $OLO("you_got_free_delivery").style.display = "";
	          }
	        }
	        if($OLO("you_can_get_free_delivery")) {
	          $OLO("you_can_get_free_delivery").style.display = "none";
	          if (freeDeliveryTresholdPassed == 'N') {
	            $OLO("you_can_get_free_delivery").style.display = "";
	          }
	        }
	        
	        if(showFreeProductOffer == 'Y') {
            	if($OLO("freeProductOfferFlag")) $OLO("freeProductOfferFlag").value = "Y";        
            	if($OLO("freeProductOfferInfoFlag")) $OLO("freeProductOfferInfoFlag").value = "N";        
            	if($OLO("freeProductOfferWarnFlag")) $OLO("freeProductOfferWarnFlag").value = "N";        
	        	if($OLO("fdt-offer-text")) $OLO("fdt-offer-text").innerHTML = fDOText;
	            if($OLO("cross-sell")) $OLO("cross-sell").src = fDOImage;        
	            if($OLO("fdNO")) $OLO("fdNO").style.display = "";
	            if($OLO("fdNOWarn")) $OLO("fdNOWarn").style.display = "none";
	            if($OLO("fdt-offer-text")) $OLO("fdt-offer-text").style.display = "";
	            if($OLO("fdt-offer-text-WARN")) $OLO("fdt-offer-text-WARN").style.display = "none";
	            if($OLO("fdoOffer")) $OLO("fdoOffer").value = "OFFER";        
            	if(!$OLO("upsell-popup") || $OLO("upsell-popup").style.display == "none") {        
				    showPopup('crosssell-popup-frame', 'crosssell-popup', 5);
            	} else {
	            	if($OLO("ShowFreeProductOffer")) $OLO("ShowFreeProductOffer").value = "Y";        
            	}
			}
	        
		    if(showFreeProductOfferInfo == 'Y') {
            	if($OLO("freeProductOfferFlag")) $OLO("freeProductOfferFlag").value = "N";        
            	if($OLO("freeProductOfferInfoFlag")) $OLO("freeProductOfferInfoFlag").value = "Y";        
            	if($OLO("freeProductOfferWarnFlag")) $OLO("freeProductOfferWarnFlag").value = "N";        
	            if($OLO("fdNO")) $OLO("fdNO").style.display = "";
	            if($OLO("fdNOWarn")) $OLO("fdNOWarn").style.display = "none";
	            if($OLO("fdt-offer-text")) $OLO("fdt-offer-text").style.display = "";
	            if($OLO("fdt-offer-text-WARN")) $OLO("fdt-offer-text-WARN").style.display = "none";
	            if($OLO("fdoOffer")) $OLO("fdoOffer").value = "INFO";        
            	if(!$OLO("upsell-popup") || $OLO("upsell-popup").style.display == "none") {        
				   	showPopup('crosssell-popup-frame', 'crosssell-popup', 5);
            	} else {
	            	if($OLO("ShowFreeProductOffer")) $OLO("ShowFreeProductOffer").value = "Y";        
            	}
			}
		    
		    if(showFreeProductOfferWarning == 'Y') {
            	if($OLO("freeProductOfferFlag")) $OLO("freeProductOfferFlag").value = "N";        
            	if($OLO("freeProductOfferInfoFlag")) $OLO("freeProductOfferInfoFlag").value = "N";        
            	if($OLO("freeProductOfferWarnFlag")) $OLO("freeProductOfferWarnFlag").value = "Y";        
            	if($OLO("freeProductOfferFlag")) $OLO("freeProductOfferFlag").value = "N";        
	            if($OLO("fdNO")) $OLO("fdNO").style.display = "none";
	            if($OLO("fdNOWarn")) $OLO("fdNOWarn").style.display = "";
	            if($OLO("fdt-offer-text")) $OLO("fdt-offer-text").style.display = "none";
	            if($OLO("fdt-offer-text-WARN")) $OLO("fdt-offer-text-WARN").style.display = "";
	            if($OLO("fdoOffer")) $OLO("fdoOffer").value = "WARN";        
            	if(!$OLO("upsell-popup") || $OLO("upsell-popup").style.display == "none") {        
				    showPopup('crosssell-popup-frame', 'crosssell-popup', 5);
            	} else {
	            	if($OLO("ShowFreeProductOffer")) $OLO("ShowFreeProductOffer").value = "Y";        
            	}
		    }
		    
	        if(getFreeDeliveryOffer == 'Y') {
	          if(showFreeDeliveryOffer == 'Y') {
            	if($OLO("freeDeliveryFlag")) $OLO("freeDeliveryFlag").value = "Y";        
            	if(!$OLO("stjude-div") || $OLO("stjude-div").style.display != '') {        
            		if($OLO("free-delivery-h2")) $OLO("free-delivery-h2").innerHTML = "No-Fee Delivery";
	          	}
	            if($OLO("fdt-offer-text")) $OLO("fdt-offer-text").innerHTML = fDOText;
	            if($OLO("free-delivery-copy")) $OLO("free-delivery-copy").innerHTML = fDOMessage;
	            if($OLO("free-delivery-copy-subtotal")) $OLO("free-delivery-copy-subtotal").innerHTML = fDOSubtotal;
	            if($OLO("free-delivery-copy")) $OLO("free-delivery-copy").style.display = "";
	            if($OLO("free-delivery-copy-div")) $OLO("free-delivery-copy-div").style.display = "";
            	if($OLO("btn-no-img")) $OLO("btn-no-img").setAttribute("style","float:left");
            	if($OLO("btn-no-img")) $OLO("btn-no-img").style.styleFloat = "left";
	            if (fDOImage != '') {
	              if($OLO("crosssell-popup")) $OLO("crosssell-popup").style.height = "";        
	              if($OLO("crosssell-graphic")) $OLO("crosssell-graphic").style.display = "";        
	              if($OLO("cross-sell")) $OLO("cross-sell").src = fDOImage;        
	            } else {
	              if($OLO("crosssell-popup")) $OLO("crosssell-popup").style.height = "150px";        
	            }
	            if($OLO("pricingEnabled:btn-else")) $OLO("pricingEnabled:btn-else").style.display = "";        
	            //if($OLO("free-delivery-padding")) $OLO("free-delivery-padding").style.display = "none";        
	            showPopup('crosssell-popup-frame', 'crosssell-popup', 5);
	          }
	          if(showCrossSellOfferOffer == 'Y') {
	        	showPopup('crosssell-popup-frame', 'crosssell-popup', 5);
	          	freeDeliveryTracking('View', 'View Offer');
	          }
	        }
	
	      } else if (status == '6') {
	        if($OLO("order_pricing_info_text")) $OLO("order_pricing_info_text").innerHTML = "";
	        if($OLO("order_pricing_info_na")) $OLO("order_pricing_info_na").style.display = "none";
	        if($OLO("order_pricing_info_na6")) $OLO("order_pricing_info_na6").style.display = "";
	        if($OLO("order_pricing_wait_text")) $OLO("order_pricing_wait_text").innerHTML = '';
	        if($OLO("you-got-30-banner")) $OLO("you-got-30-banner").style.display = 'none';
	        if($OLO("serviceTimeD")) $OLO("serviceTimeD").innerHTML = '';
	        if($OLO("serviceTimeP")) $OLO("serviceTimeP").innerHTML = '';
	      } else if (status == '-1') {
	        if($OLO("order_pricing_info_text")) $OLO("order_pricing_info_text").innerHTML = "";
	        if($OLO("order_pricing_info_na")) $OLO("order_pricing_info_na").style.display = "";
	        if($OLO("order_pricing_wait_text")) $OLO("order_pricing_wait_text").innerHTML = '';
	        if($OLO("you-got-30-banner")) $OLO("you-got-30-banner").style.display = 'none';
	        if($OLO("serviceTimeD")) $OLO("serviceTimeD").innerHTML = '';
	        if($OLO("serviceTimeP")) $OLO("serviceTimeP").innerHTML = '';
	      } else {
	        if($OLO("order_pricing_info_text")) $OLO("order_pricing_info_text").innerHTML = statusText;
	        if($OLO("order_pricing_wait_text")) $OLO("order_pricing_wait_text").innerHTML = '';
	        if($OLO("you-got-30-banner")) $OLO("you-got-30-banner").style.display = 'none';
	        if($OLO("serviceTimeD")) $OLO("serviceTimeD").innerHTML = '';
	        if($OLO("serviceTimeP")) $OLO("serviceTimeP").innerHTML = '';
	      }
	      if (status == '0' || status == '6' || status == '-1') {
	        var giftCardsFound = $("giftCardsFound",xml).text();
	        var giftCardsFoundInt = parseInt(giftCardsFound);
	        for (i=1; i <= giftCardsFoundInt; i = i + 1) {
	          updateGiftCardUI(xml, 'giftCardNum' + i + 'Amt', i);
	        }
	      }
	  }
      
      if (runCouponPicker) {
      	parseCouponPickerResponse(xml, origFormName);
      }	
      
    });
}

function parseCouponPickerResponse(xml, formName) {
		var origFormName = formName;
	    var formName = formName + ":";
        var bestFitCouponCount = $("bestFitCouponCount",xml).text();
        var couponCodes = new Array();
        var couponDescs = new Array();
        var couponPrices = new Array();
        var couponUpsells = new Array();
        for (var i = 0; i < bestFitCouponCount; i++) {
          couponCodes[i] = $("bestFitCoupon" + i + "Code",xml).text(); 
        }
        for (var i = 0; i < bestFitCouponCount; i++) {
          couponDescs[i] = $("bestFitCoupon" + i + "Desc",xml).text(); 
        }
        for (var i = 0; i < bestFitCouponCount; i++) {
          couponPrices[i] = $("bestFitCoupon" + i + "Price",xml).text(); 
        }
        for (var i = 0; i < bestFitCouponCount; i++) {
        	couponUpsells[i] = $("bestFitCoupon" + i + "Upsell",xml).text(); 
        }        
        var couponPickerHeader = document.getElementById('couponPickerHeader');
    	var pickerTable = document.getElementById(formName + 'couponPickerTable');
    	var newRow;
    	var newCell;
    	var newLink;
    	
    	var pickerDisplay = "block";
    	var googleCategory ="Best Fit Coupon";

		var couponCodeVar = "couponCode";
		var extraFormInfo = "";
		var eventCode = "javascript:checkChanged(this);";
		var googleLabel = "Regular Offer ";

    	
    	if (origFormName == "pricingEnabled") {
			pickerDisplay = "inline";
	    	googleCategory ="Best Fit Coupon Checkout";
			couponCodeVar = "userCouponCode";
			extraFormInfo = "document.forms['pricingEnabled']['goTo'].value='null';";
			eventCode = "";
		}

    	
    	if (pickerTable) {
    		while (pickerTable.childNodes.length > 0) {
				pickerTable.removeChild(pickerTable.childNodes[0]);
			}
			
						
			var onClickText = "";
			
        	for (var i = 0; i < bestFitCouponCount; i++) {
    			googleLabel = "Regular Offer " + i;

        		if (couponUpsells[i] == "1") {
        			googleLabel = "Upsell Offer 1";
        		}
        		
        		onClickText = "myEventTracker('" + googleCategory + "', 'Click', '" + googleLabel + "');document.forms['" + origFormName + "']['" + formName + "_idcl'].value='" + formName + "addCouponLink';document.forms['" + origFormName + "']['" + couponCodeVar + "'].value='" + couponCodes[i] + "'; " + extraFormInfo + " document.forms['" + origFormName + "'].submit(); return false;";
        	
				newRow = document.createElement("tr");
				pickerTable.appendChild(newRow);
				
				newCell = document.createElement("td");
				newCell.innerHTML = (i+1) + ".";
				newRow.appendChild(newCell);
				
				newCell = document.createElement("td");
				newCell.innerHTML += "<!-- mp_trans_disable_start -->";
				newRow.appendChild(newCell);
				
				newLink = document.createElement("a");
				newLink.id = formName + "couponPickerCoupon" + (i+1);
				newLink.innerHTML = couponDescs[i] + " " + couponPrices[i];
				newLink.href = "#";
                newLink.setAttribute("onkeydown", eventCode);
                newLink.setAttribute("onmouseup", eventCode);
                newLink.setAttribute("onclick", onClickText);
				newLink.innerHTML += "";
				newCell.appendChild(newLink);
				newCell.innerHTML += "";
				
				newLink = document.createElement("a");
				newLink.id = formName + "couponPickerCouponAdd" + (i+1);
				newLink.className = "add-coupon-picker";
				newLink.innerHTML = "Add Coupon";
                newLink.setAttribute("onkeydown", eventCode);
                newLink.setAttribute("onmouseup", eventCode);
                newLink.setAttribute("onclick", onClickText);
				newLink.innerHTML += "";
				newCell.appendChild(newLink);
				newCell.innerHTML += "";
				newCell.innerHTML += "<!-- mp_trans_disable_end -->";
			}

        }

    	if (couponPickerHeader && bestFitCouponCount > 0) {
			$("#couponPickerHeader").css("display",pickerDisplay);
			$("#couponPickerHeader").parent().css("display",pickerDisplay);
			myEventTracker(googleCategory, "View", "View Best Fit offer");

        	$(document).ready(function(){	  	
        		/* 
        			HOVER CODE FOR COUPON CHOOSER
        			This code is needed for IE6. For other browsers CSS selector
        			li:hover is used.
        		*/
        		$("#order-summary-coupon-picker-list tr").hover(function() {
        				$(this).addClass("over");
        			}, function() {
        				$(this).removeClass("over");			
        			});
        	});
        }
    	
}

function ajaxSurvey(answer, surveyId) {
    var surveyId = surveyId + ":";
    $.post("/olo/servlet/ajax_servlet",{
      cmd: "survey"
      , formName: surveyId
      , message: answer
    },function(xml){
    });
}

function ajaxcanAcceptOrders(thisStoreCanAcceptOrders, alertUser, server, port) {
  return true;
  /*
  var goAhead = false;
  if (thisStoreCanAcceptOrders == 'X') {
    goAhead = true;
  }
  if (thisStoreCanAcceptOrders == 'N' && alertUser == 'Y') {
    window.location.href = "http://" + server + ":" + port + "/olo/faces/common/storeNotReachable.jsp";
  }

  if (goAhead) {
    $.post("/olo/servlet/ajax_servlet",{
      cmd: "canAcceptOrders"
    },function(xml){
      var status = xml.documentElement.getElementsByTagName("status")[0].firstChild.nodeValue;
      var statusText = xml.documentElement.getElementsByTagName("statusText")[0].firstChild.nodeValue;
      if (status == '-1' && alertUser == 'Y') {
        window.location.href = "http://" + server + ":" + port + "/olo/faces/common/storeNotReachable.jsp";
      }
    });
  }
  */
}
