/** 
  <summary>
    Main Function:  calculation quote detail(shopping cart)
    Created Date:   08/17/2009
    Created By:     YW
    Modified Date: [MM/DD/YYYY]
    Modified By: [Your initial]
    Reason for Modifying: [Your comment]
*/
 
    function PopUpShipMethodInfo(shipMethodTypeCode)
    {
        var processResult = shipMethodTypeCode.split(SERVICE_DIV);  
        if (processResult && processResult.length >=2)
        {            
            PopupMessage(processResult[0], processResult[1], null, null);  
        }   
    }    
        
    // calculate shipping result
    function CalculateShippingResult(QuoteID, submitting)
    {
        OrderService.CalculateShippingResult(QuoteID, isWebSalesLogIn, submitting, ProcessShippingResult, ServiceErrorHandler);
    }
    
    function SelectShippingPopup(selectedShipMethod)
    {   
        if (quoteIDHiddenFieldID && $get(quoteIDHiddenFieldID).value != "")
        {
            if (itemTaxResultHiddenFieldID && itemTaxResultHiddenFieldID != "" && $get(itemTaxResultHiddenFieldID))
            {
                OrderService.SelectShipMethod($get(quoteIDHiddenFieldID).value, selectedShipMethod, ProcessSelectShipMethod, ServiceErrorHandler);
            }
            else
            {
                OrderService.GetSelectShipMethodCost($get(quoteIDHiddenFieldID).value, selectedShipMethod, ProcessSelectShipMethodCost, ServiceErrorHandler);
            }
        }
    }
    
    function ProcessSelectShipMethodCost(result)
    {      
        var processResult = result.split(SERVICE_DIV);

        if (processResult == null || !totalShipCostLabelID)
        {
            return;
        }
      
        totalDeliveryCost = parseFloat(processResult[0]);
        
        if (totalDeliveryCost >= 0)
        {
            DisplayPriceLable(totalShipCostLabelID, totalDeliveryCost, false, false);
        }
        else
        {
            $get(totalShipCostLabelID).innerHTML = "$?.??";     
        }
        
        if (processResult.length >= 2 && processResult[1] != "") 
        {
            var holidayArr = processResult[1].split("!*-");
            if (holidayArr == null || holidayArr.length < 2) 
            {
                PopupMessage("PaperMart Holiday Schedule", processResult[1], null, null);
            }
            else 
            {
                PopupMessage(holidayArr[1], holidayArr[0], null, null);
            }
        }             
    }
    
    function ProcessSelectShipMethod(result)
    {    
        var processResult = result.split(SERVICE_DIV);             
        if (processResult == null || processResult.length < 2)
        {
            CloseLoadingImage(); 
            return;
        }       
        
        if (updateShippingImageButtonID && $get(updateShippingImageButtonID))
        {
            $get(updateShippingImageButtonID).disabled = false;
        }
        
        // holiday string
        if (processResult.length >= 3 && processResult[2] != "")
        {
            //TM 010810: Now the string has header of Popup header too
		    var holidayArr = processResult[2].split("!*-");
		    if (holidayArr == null || holidayArr.length < 2) {
		        PopupMessage("PaperMart Holiday Schedule", processResult[2], null, null);
		    }
		    else 
		    {
		        PopupMessage(holidayArr[1], holidayArr[0], null, null);
            }
        }
        
        var isChanged = (processResult[0].toString().toLowerCase() == "true");
        
        if (isChanged)
        {
            $get(itemTaxResultHiddenFieldID).value = processResult[1];
            ShowSummary();
        }       
    }
    
    // ProcessShippingResult
    function ProcessShippingResult(result)
    {        
        var shipResultList = result.split(SERVICE_DIV);
        if (shipResultList.length < 3 )
        {
            var popUpStr;
            if (shipResultList.length == 2)
            {
                popUpStr = shipResultList[0];
                
                // clear address
                if (shipResultList[1].toString().toLowerCase() == "true" && 
                    addressInCartLabelID && $get(addressInCartLabelID) &&
                    editAddressLinkButtonID && $get(editAddressLinkButtonID) &&
                    reCalculateShipImageButtonID && $get(reCalculateShipImageButtonID) &&
                    calculateShipImageButtonID && $get(calculateShipImageButtonID))
                {                    
                    $get(addressInCartLabelID).innerHTML = '';
                    $get(editAddressLinkButtonID).style.display = 'none';
                    $get(reCalculateShipImageButtonID).style.display = 'none';
                    $get(calculateShipImageButtonID).style.display = 'block';                    
                }
            }
            else
            {
                popUpStr = result;
            }
            PopupMessage("Cannot Calculate Shipping", popUpStr, null, null);
            ShowSummary();     
            CloseLoadingImage(); 
            
            return;
        }
        if (shippingOptionTableAreaID && $get(shippingOptionTableAreaID))
        {
            $get(shippingOptionTableAreaID).innerHTML = shipResultList[0];
        }
        
        if (shipOptionPopupBehaviorID && shipOptionPopupBehaviorID != "" &&
            shipOptionPanelID && shipOptionPanelID != "" )
        {
            $find(shipOptionPopupBehaviorID).show();
            $get(shipOptionPanelID).style.display = 'block';
            $get(shipOptionPanelID).style.width = '800px';
            
        } 
        
        if (showShippingOptionLinkButtonID && $get(showShippingOptionLinkButtonID ))
        {
            // selected values
            isMultitpleShipResult = (shipResultList[1].toString().toLowerCase() == "true");
            
            if (isMultitpleShipResult)
            {
                $get(showShippingOptionLinkButtonID ).style.display = 'block';
            }
            else
            {
                $get(showShippingOptionLinkButtonID ).style.display = 'none';
            }
        }
        
        if (reCalculateShipImageButtonID && $get(reCalculateShipImageButtonID) &&
            calculateShipImageButtonID && $get(calculateShipImageButtonID))
        {
            $get(reCalculateShipImageButtonID).style.display = 'none';
            $get(calculateShipImageButtonID).style.display = 'block';
        }
          
        var selectedShipMethod = shipResultList[2];
        var selectedShipMethodRadio = selectedShipMethod + "shipMethodRadioButton";
        if (selectedShipMethodRadio && $get(selectedShipMethodRadio))
        {
            $get(selectedShipMethodRadio).checked = true;    
        
            if (updateShippingImageButtonID && $get(updateShippingImageButtonID))
            {
                $get(updateShippingImageButtonID).disabled = false;
            }
        
            // holiday string
            if (shipResultList.length >= 4 && shipResultList[3] != "")
            {
                //TM 010810: Now the string has header of Popup header too
		        var holidayArr = shipResultList[3].split("!*-");
		        if (holidayArr == null || holidayArr.length < 2) {
		            PopupMessage("PaperMart Holiday Schedule", shipResultList[3], null, null);
		        }
		        else 
		        {
		            PopupMessage(holidayArr[1], holidayArr[0], null, null);
                }
            }
        }
        else
        {
            if (selectedShipMethod == "SHMRK" && updateShippingImageButtonID && $get(updateShippingImageButtonID))
            {
                $get(updateShippingImageButtonID).disabled = false;
            }
        }

        CheckExpandExpedite(selectedShipMethod);
        
        ShowSummary();          
        CloseLoadingImage(); 
    }

    // clear promotion from quote    
    function ClearPromoCode()
    {        
        $get(promotionResultHiddenFieldID).value = "";
        $get(promoCodeTextBoxID).value = "";
        OrderService.ClearPromotionCode(RecalculateQuoteAndShowTotal, ServiceErrorHandler);
    }
    
    function RecalculateQuoteAndShowTotal()
    {
        OrderService.GetQuote($get(quoteIDHiddenFieldID).value, false, false, ProcessRecalculateQuoteAndShowTotal, ServiceErrorHandler); 
    }
    
    function ProcessRecalculateQuoteAndShowTotal(result) 
    {
        if (result.toString().length > 0) 
        {
            var resultList = result.split(SERVICE_DIV);
            if (resultList.length < 3 )
            {
                CloseLoadingImage(); 
                return;
            }
            $get(promotionResultHiddenFieldID).value = resultList[1];   
            $get(itemTaxResultHiddenFieldID).value = resultList[2];           
        }
        ShowSummary();
    }
    
    // calculate    
    function ValidatePromoCode()
    {
        if (promoCodeTextBoxID && $get(promoCodeTextBoxID))
        {
            OrderService.CheckPromotionCode($get(quoteIDHiddenFieldID).value, $get(promoCodeTextBoxID).value, ProcessPromoCode);
        }
        return false;
    }
    
    function ProcessPromoCode(result)
    {                  
        if (result.toString().toLowerCase() == "true")
        {  
            RecalculateQuoteAndShowTotal();
        }
        else
        {         
            OrderService.ClearPromotionCode();   
            CloseLoadingImage();    
            PopupMessage("PR#", result, null, null);
        }
    }
    
    // show summary
    function ShowSummary()
    {             
        if (!quoteIDHiddenFieldID || !$get(quoteIDHiddenFieldID) || 
            !$get(quoteIDHiddenFieldID).value || $get(quoteIDHiddenFieldID).value == "")
        {
            ShowEmptyCart();
            return;
        }   
               
        if ($get("aboutShoppingCartArea"))
        {
            $get("aboutShoppingCartArea").style.display = 'block'; 
        }
        
        if (ItemTableHeaderID && $get(ItemTableHeaderID))
        {
            $get(ItemTableHeaderID).style.visibility = "visible";
        }
        
        if (cartSummaryTableRowID && $get(cartSummaryTableRowID))
        {
            $get(cartSummaryTableRowID).style.display = 'block'; 
        }
        
        if (starCustomerSavingsTableID && $get(starCustomerSavingsTableID))
        {
            $get(starCustomerSavingsTableID).style.display = 'block'; 
        } 
        
        if (toAddItemAreaID && $get(toAddItemAreaID))
        {
            $get(toAddItemAreaID).style.display = 'none'; 
        }
        
        if (checkOutButtonAreaID && $get(checkOutButtonAreaID))
        {
            $get(checkOutButtonAreaID).style.display = 'block'; 
        }
        
        if (smallPkgFeeTableID && smallPkgFeeDescLabelID && smallPkgFeeAmtLabelID && 
            accountFeeTableID && accountFeeDescLabelID && accountFeeAmtLabelID &&
            packFeeTableID && packFeeDescLabelID && packFeeAmtLabelID &&
            $get(smallPkgFeeTableID) && $get(smallPkgFeeDescLabelID) && $get(smallPkgFeeAmtLabelID) &&
            $get(accountFeeTableID) && $get(accountFeeDescLabelID) && $get(accountFeeAmtLabelID) &&
            $get(packFeeTableID) && $get(packFeeDescLabelID) && $get(packFeeAmtLabelID))   
        {
            $get(smallPkgFeeTableID).style.display = 'none'; 
            $get(accountFeeTableID).style.display = 'none';     
            $get(packFeeTableID).style.display = 'none';     
        }
        else
        {   // no need to show total info
            UpdateCartHeader();
            CloseLoadingImage();    
            return;
        }
        
        if (freeShipInfoTableID && $get(freeShipInfoTableID))
        {
            $get(freeShipInfoTableID).style.display = 'none'; 
        }
        
        if (freeShippingSpanID && $get(freeShippingSpanID))
        {
            $get(freeShippingSpanID).style.display = 'none'; 
        }
        if (qualifyFreeShipSpanID && $get(qualifyFreeShipSpanID))
        {
            $get(qualifyFreeShipSpanID).style.display = 'none'; 
        }
        if (freightInfoSpanID && $get(freightInfoSpanID))
        {
            $get(freightInfoSpanID).style.display = 'none';     
        }         
        
        // get subtotal
        subtotalAmount = 0;
        if (subTotalAmountHiddenFieldID && $get(subTotalAmountHiddenFieldID) && $get(subTotalAmountHiddenFieldID).value != "")
        {
            subtotalAmount = parseFloat($get(subTotalAmountHiddenFieldID).value);            
            DisplayPriceLable(subtotalLabelID, subtotalAmount, false, false);
        }
        
        // discount amount
        discountAmount = 0;
        if (discounteAmountHiddenFieldID && $get(discounteAmountHiddenFieldID) && $get(discounteAmountHiddenFieldID).value != "")
        {
            discountAmount = parseFloat($get(discounteAmountHiddenFieldID).value);
                        
            $get(starCustomerSavingsTableID).style.display = "none";
            $get(discountTotalTableID).style.display = "none";
            if (discountAmount > 0)
            {
                if (isStarCustomer.toString().toLowerCase() == "true")
                {
                    $get(starCustomerSavingsTableID).style.display = "block";
                    DisplayPriceLable(starCustomerSavingsLabelID, discountAmount, false, false);
                }
                else
                {
                    $get(discountTotalTableID).style.display = "block";
                    DisplayPriceLable(starSavingTotalLabelID, discountAmount, false, false);
                }
            }
        }
        
        // promo code
        discountedSubtotalAmount = subtotalAmount;       
        var afterPromoSubTotalAmount = discountedSubtotalAmount;
        $get(promoTableID).style.display = 'none';
        $get(clearPromoCodeTableRowID).style.display = 'none'; 
        $get(enterPromoCodeTableRowID).style.display = 'block'; 
        if (promotionResultHiddenFieldID && $get(promotionResultHiddenFieldID) && $get(promotionResultHiddenFieldID).value != "")
        {
            var promotionResult = eval("(" + $get(promotionResultHiddenFieldID).value + ")");
            
            if (promotionResult && promotionResult.PromotionAmount && promotionResult.Promotion)
            {
                var discountAmt = promotionResult.PromotionAmount;
                if (discountAmt > 0)
                { 
                    $get(promoTableID).style.display = 'block';
                    $get(clearPromoCodeTableRowID).style.display = 'block'; 
                    $get(enterPromoCodeTableRowID).style.display = 'none'; 
                    $get(promoCodeLabelID).innerHTML = promotionResult.Promotion.PromotionDesc; 
                    $get(promoDescLableID).innerHTML = promotionResult.Promotion.PromotionDesc;
                    
                    afterPromoSubTotalAmount = Math.round(subtotalAmount * 100) / 100 - Math.round(discountAmt * 100) / 100;
                    if (promotionResult.DiscountOnOrder.toString().toLowerCase() != "true")
                    {
                        discountedSubtotalAmount = afterPromoSubTotalAmount;
                    }
                    
                    DisplayPriceLable(promoAmountLableID, discountAmt, false, true);
                    DisplayPriceLable(discountedSubtotalLabelID, afterPromoSubTotalAmount, false, false);       
                }         
            }
        }
        
        // tax rate
        taxRate = 0;
        taxTotal = 0;
        if ($get(taxLabelID))
        {
            $get(taxLabelID).innerHTML = "Tax:";
        }
        if (itemTaxResultHiddenFieldID && $get(itemTaxResultHiddenFieldID) && $get(itemTaxResultHiddenFieldID).value != "")
        {
            var itemTaxResult =  eval("(" + $get(itemTaxResultHiddenFieldID).value + ")");
            if (itemTaxResult)
            {
                taxRate = itemTaxResult.TaxRate;
                taxTotal = itemTaxResult.TaxAmount;
                
                if ($get(taxLabelID))
                {
                    $get(taxLabelID).innerHTML = itemTaxResult.Town.City + " tax " +  taxRate + "%:";
                }
            }
        }
        
        // shipping
        
        if (freightTotalLabelID && $get(freightTotalLabelID))
        {
            $get(freightTotalLabelID).style.display = 'none'; 
        }
        if (shipCostDescriptionLabelID && $get(shipCostDescriptionLabelID))
        {
            $get(shipCostDescriptionLabelID).innerHTML = "Total Shipping:&nbsp;";
        }            
        if (totalShipCostLabelID && $get(totalShipCostLabelID) != null)
        {
            $get(totalShipCostLabelID).innerHTML = "$?.??";
        }
        if (totalCostLabelID && $get(totalCostLabelID))
        {
            $get(totalCostLabelID).innerHTML = "$?.??";
        }
                        
        OrderService.CalculateQuoteTotal($get(quoteIDHiddenFieldID).value, isWebSalesLogIn, discountedSubtotalAmount, afterPromoSubTotalAmount, taxTotal, taxRate, ProcessFinalTotal, ServiceErrorHandler);        
    }

    // calculate fee   
    /*
        return string format: 
     *      0   IsFinal (True : False)
     *      1   IsFreight True : False)
     *      2   IsOurTruck (True : False)
     *      
     *      3   SelectShipMethod 
     *      4   ShipCost 
     *      5   DropShipCost 
     *      6   MimAmountToFreeShip
     *      
     *      7   SmallPackagingFeeDescription
     *      8   SmallPackagingFeeCost
     *      
     *      9   AccountFeeDescription
     *      10  AccountFee
     *      
     *      11  TaxTotal
     *      
     *      12  FinalTotal
     *      
     *      13  Cart string
     *      
     *      14  WareHouse shipping desc
     *      15  Has Drop ship Items
     *      16  routeCode
     *      
     *      17  ShipResultCalculated
     *      
     *      18   packFeeDescription
     *      19   packFeeCost
     *      20  isFreeShipping
     *      21  WillCallTime
     *      22  isCustomWarehouse
     */
    function ProcessFinalTotal(result)
    {    
        var processFeeResult = result.split(SERVICE_DIV);
        
        mimAmountToFreeShip = 300;
        if (processFeeResult == null || processFeeResult.length < 20)
        {
            ShowEmptyCart();
            return;
        }       
                        
        if (cartSummaryTableRowID && $get(cartSummaryTableRowID))
        {
            $get(cartSummaryTableRowID).style.display = 'block'; 
        }
        
        // shipping cost
        var isFinal = (processFeeResult[0].toString().toLowerCase() == "true");
        var isFreight = (processFeeResult[1].toString().toLowerCase() == "true");
        var isOurTruck = (processFeeResult[2].toString().toLowerCase() == "true");
        //TM 07/28/11: Added new flag, isFreeShipStr (isLocal)
        var isFreeShipStr = (processFeeResult[20].toString()== "1")
        //TM 102411: Added new flag, is CustomWarehouse
        var isCustom = (processFeeResult[22].toString() == "1")
        
        totalDeliveryCost = 0;
        warehouseDeliveryCost = parseFloat(processFeeResult[4]);
        dropShipDeliveryCost = parseFloat(processFeeResult[5]);
        totalDeliveryCost = warehouseDeliveryCost + dropShipDeliveryCost;
        var selectedShipMethod = processFeeResult[3];
        var shipResultCalculated = (processFeeResult[17].toString().toLowerCase() == "true");
        
        if (!shipResultCalculated)
        {
            if (showShippingOptionLinkButtonID && $get(showShippingOptionLinkButtonID))
            {
                $get(showShippingOptionLinkButtonID ).style.display = 'none';
            }
        }
        
        // minimun order
        if (processFeeResult[6] != "")
        {
            mimAmountToFreeShip = parseFloat(processFeeResult[6]);
        }
        
        var wareHouseShipDesc = processFeeResult[14];
        var hasDropShip = (processFeeResult[15].toString().toLowerCase() == "true");
                    
        // ship not final
        if (!isFinal || totalDeliveryCost < 0)
        {
            if (isFreight)
            {
                if (freeShipInfoTableID && $get(freeShipInfoTableID) && 
                    freightInfoSpanID && $get(freightInfoSpanID))
                {
                    $get(freeShipInfoTableID).style.display = 'block'; 
                    $get(freightInfoSpanID).style.display = 'block';    
                }
                 
                if (freightTotalLabelID && $get(freightTotalLabelID))
                {
                   $get(freightTotalLabelID).style.display = 'block'; 
                }
                
            }
                    
                if (normalShippingSpanID && $get(normalShippingSpanID) && 
                    dropShipSpanID && $get(dropShipSpanID) && 
                    normalShippingDescLabelID && $get(normalShippingDescLabelID) && 
                    normalShippingCostLabelID && $get(normalShippingCostLabelID) && 
                    dropShippingCostLabelID && $get(dropShippingCostLabelID))
                {
                    if (wareHouseShipDesc != "")
                    {
                        $get(normalShippingSpanID).style.display = 'block'; 
                        $get(normalShippingDescLabelID).innerHTML = wareHouseShipDesc;  
                        $get(normalShippingCostLabelID).innerHTML = "$?.??";
                    }
                    else
                    {
                        $get(normalShippingSpanID).style.display = 'none'; 
                    }
                    
                    if (hasDropShip)
                    {
                        $get(dropShipSpanID).style.display = 'block'; 
                        if (dropShipDeliveryCost > 0)
                        {
                            DisplayPriceLable(dropShippingCostLabelID, dropShipDeliveryCost, false, false);
                        }
                        else
                        {
                            $get(dropShippingCostLabelID).innerHTML = "$?.??";
                        }
                    }
                    else
                    {
                        $get(dropShipSpanID).style.display = 'none'; 
                    }
                }
                
                //tab control
                //AssignValueToHidden('Shipping', 'true');
//            else 
//            {   //tab control
//                //AssignValueToHidden('Shipping', '');
//                
//            } 
            DisplayPriceLable(taxAmtLabelID, taxTotal, false, false);
            
            // uncheck will call check box
            if (isWebSalesLogIn && willCallCheckBoxID && $get(willCallCheckBoxID) && $get(willCallCheckBoxID).checked)
            {
                $get(willCallCheckBoxID).checked = false;
                EnableWebSalesWillCallSelect(false);
            }
        }
        else 
        {   //tab control
            //AssignValueToHidden('Shipping', 'true');            

            if (freightTotalLabelID && $get(freightTotalLabelID))
            {
                $get(freightTotalLabelID).style.display = 'none'; 
            }
            
            //if will Call, show PM Address
            if (PMAddressSpanID && $get(PMAddressSpanID))
            {
                if (selectedShipMethod == "WLLCL")
                {
                    $get(PMAddressSpanID).style.display = 'block';
                }
                else
                {
                    $get(PMAddressSpanID).style.display = 'none';
                }
            }
            
            // for local delivery , we show free shipping info
            // TM 07/27/11: Also if isFreeShipStr(isLocal)
            // TM 10/24/11: Don't show if it's custom
            if (((isOurTruck) || (isFreeShipStr)) && (!isCustom))
            {           
                // check free shipping
                if (mimAmountToFreeShip > 0 && freeShipInfoTableID && 
                    freeShipInfoTableID  && freeShippingSpanID && qualifyFreeShipSpanID )
                {
                    if (mimAmountToFreeShip > discountedSubtotalAmount)
                    {
                        // show dollar-away free shipping info
                        // TM 07/27/11: Changed to as long as it's less than $300
                        if (dollarAwayLabelID && $get(dollarAwayLabelID) && warehouseDeliveryCost > 0 &&
                            discountedSubtotalAmount < mimAmountToFreeShip)
                        {
                            $get(freeShipInfoTableID).style.display = 'block'; 
                            $get(freeShippingSpanID).style.display = 'block'; 
                            $get(qualifyFreeShipSpanID).style.display = 'none'; 
                            if ($get(freightInfoSpanID))
                            {
                                $get(freightInfoSpanID).style.display = 'none';     
                            }   
                                    
                            DisplayPriceLable(dollarAwayLabelID, parseFloat(mimAmountToFreeShip) - (parseFloat(discountedSubtotalAmount) - parseFloat("0.01")), false, false);
                        }
                    }                    
                    else 
                    {
                        // qualify for free shipping
                        if (warehouseDeliveryCost == 0 && dropShipDeliveryCost <= 0)
                        {
                            $get(freeShipInfoTableID).style.display = 'block'; 
                            $get(freeShippingSpanID).style.display = 'none'; 
                            $get(qualifyFreeShipSpanID).style.display = 'block'; 
                            if ($get(freightInfoSpanID))
                            {
                                $get(freightInfoSpanID).style.display = 'none';     
                            }   
                        }
                    }
                } 
            }      
            
            if (normalShippingSpanID && $get(normalShippingSpanID) && 
                dropShipSpanID && $get(dropShipSpanID) && 
                normalShippingDescLabelID && $get(normalShippingDescLabelID) && 
                routeCodeLabelID && $get(routeCodeLabelID) && 
                normalShippingCostLabelID && $get(normalShippingCostLabelID) && 
                dropShippingCostLabelID && $get(dropShippingCostLabelID))
            {
                var routeCode = processFeeResult[21] ? "Will call pick up time: " + processFeeResult[21] : processFeeResult[16]; 
                
                if (wareHouseShipDesc != "")
                {
                    $get(normalShippingSpanID).style.display = 'block'; 
                    $get(normalShippingDescLabelID).innerHTML = wareHouseShipDesc;
                    $get(routeCodeLabelID).innerHTML = routeCode;
            
                    if (warehouseDeliveryCost >= 0)
                    {
                        DisplayPriceLable(normalShippingCostLabelID, warehouseDeliveryCost, false, false);
                    }
                    else
                    {
                        $get(normalShippingCostLabelID).innerHTML = "$?.??";
                    }
                }
                else
                {
                    $get(normalShippingSpanID).style.display = 'none'; 
                }
                
                if (hasDropShip)
                {
                    $get(dropShipSpanID).style.display = 'block'; 
                    if (dropShipDeliveryCost >= 0)
                    {
                        DisplayPriceLable(dropShippingCostLabelID, dropShipDeliveryCost, false, false);
                    }
                    else
                    {
                        $get(dropShippingCostLabelID).innerHTML = "$?.??";
                    }
                }
                else
                {
                    $get(dropShipSpanID).style.display = 'none'; 
                }
            }
            
            // shipping desc
            if (shipCostDescriptionLabelID && $get(shipCostDescriptionLabelID))
            {
                // is out truck delivery
                if (isOurTruck && dropShipDeliveryCost == 0 && selectedShipMethod == "ORTRK")
                {
                    $get(shipCostDescriptionLabelID).innerHTML = "Paper Mart Delivery Truck:";
                }
                else
                {
                    $get(shipCostDescriptionLabelID).innerHTML = "Total Shipping:";
                }
            }  
            
            if (totalShipCostLabelID)
            {
                DisplayPriceLable(totalShipCostLabelID, totalDeliveryCost, false, false);
            }     
            
            // show order total
            finalTotal = parseFloat(processFeeResult[12])
            DisplayPriceLable(totalCostLabelID, finalTotal, true, false);            
        }     
            
        // small package fee
        if (processFeeResult[7] != "" && processFeeResult[8] != "" && processFeeResult[8] != "0")
        {
            var smallPkgFee = parseFloat(processFeeResult[8]);
                
            if (smallPkgFee > 0)
            {
                $get(smallPkgFeeTableID).style.display = 'block'; 
                    
                $get(smallPkgFeeDescLabelID).innerHTML = (processFeeResult[7]);
                DisplayPriceLable(smallPkgFeeAmtLabelID, smallPkgFee, false, false);
            }
        } 
            
        // customer account fee
        if (processFeeResult[9] != "" && processFeeResult[10] != "" && processFeeResult[10] != "0")
        {
            var accountFee = parseFloat(processFeeResult[10]);
                
            if (accountFee > 0)
            {
                $get(accountFeeTableID).style.display = 'block'; 
                    
                $get(accountFeeDescLabelID).innerHTML = processFeeResult[9];
                DisplayPriceLable(accountFeeAmtLabelID, accountFee, false, false);
            }
        }   
            
        // canada package fee
        if (processFeeResult[18] != "" && processFeeResult[19] != "" && processFeeResult[19] != "0")
        {
            var packFee = parseFloat(processFeeResult[19]);
                
            if (packFee > 0)
            {
                $get(packFeeTableID).style.display = 'block'; 
                    
                $get(packFeeDescLabelID).innerHTML = (processFeeResult[18]);
                DisplayPriceLable(packFeeAmtLabelID, packFee, false, false);
            }
        }        
            
        // tax total
        if (processFeeResult[11] != "" && processFeeResult[11] != "0")
        {
            taxTotal = parseFloat(processFeeResult[11]);
            DisplayPriceLable(taxAmtLabelID, taxTotal, false, false);
        }
        else
        {
            DisplayPriceLable(taxAmtLabelID, taxTotal, false, false);
        }
        
        var cartHeaderStr = processFeeResult[13];
        if (cartHeaderStr && cartHeaderStr != "")
        {
            ShowCartHeader(cartHeaderStr);
        }
        CloseLoadingImage();    
    }
    
    // show empty cart
    function ShowEmptyCart()
    {
        if (ItemTableHeaderID && $get(ItemTableHeaderID))
        {
            var table = $get(ItemTableHeaderID); 
            var rows = table.getElementsByTagName("tr");   
            while (table.rows.length > 1)
            {  
                table.deleteRow(table.rows.length - 1);
            }
            $get(ItemTableHeaderID).style.visibility = "hidden";
        }
        if (cartSummaryTableRowID && $get(cartSummaryTableRowID))
        {
            $get(cartSummaryTableRowID).style.display = 'none'; 
        }
        if (enterPromoCodeTableRowID && $get(enterPromoCodeTableRowID))
        {
            $get(enterPromoCodeTableRowID).style.display = 'none'; 
        }
        if (clearPromoCodeTableRowID && $get(clearPromoCodeTableRowID))
        {
            $get(clearPromoCodeTableRowID).style.display = 'none'; 
        }
        if (starCustomerSavingsTableID && $get(starCustomerSavingsTableID))
        {
            $get(starCustomerSavingsTableID).style.display = 'none'; 
        }          
        
        if ($get("aboutShoppingCartArea") && isWebSalesLogIn == "True")
        {
            $get("aboutShoppingCartArea").style.display = 'none';
        }
        
        if (isWebSalesLogIn != "True" && toAddItemAreaID && $get(toAddItemAreaID))
        {
            $get(toAddItemAreaID).style.display = 'block'; 
        }
        
        if (checkOutButtonAreaID && $get(checkOutButtonAreaID))
        {
            $get(checkOutButtonAreaID).style.display = 'none'; 
        }

        //tab control
        AssignValueToHidden('CartItem', 'false');
        //move control
        SetNavigationVisibility("hidden");
        UpdateCartHeader(); 
        
        CloseLoadingImage();    
    }

// display price label
function DisplayPriceLable(LabelID, Price, Bold, Negitive)
{
    if (!$get(LabelID))
    {
        return;
    }

    var priceStr = (Math.round(Price * 100) / 100).toString();
    var priceStr = Price.toString().replace(/\$|\,/g,'');
    if(isNaN(priceStr)) {
        priceStr = "0";
    }
    sign = (priceStr == (priceStr = Math.abs(priceStr)));
    priceStr = Math.floor(priceStr*100+0.50000000001);
    cents = priceStr%100;
    priceStr = Math.floor(priceStr/100).toString();
    if(cents<10)
        cents = "0" + cents;
    for (var i = 0; i < Math.floor((priceStr.length-(1+i))/3); i++) {
        priceStr = priceStr.substring(0,priceStr.length-(4*i+3)) + ',' + priceStr.substring(priceStr.length-(4*i+3));
    }
    priceStr = (((sign)?'':'-') + '$' + priceStr + '.' + cents);
  
    if (Negitive)
    {
        priceStr = "- " + priceStr;
    }
    
    if (Bold)
    {
        $get(LabelID).innerHTML = "<b>" + priceStr + "</b>";
    }
    else
    {
        $get(LabelID).innerHTML = priceStr;
    }
}

function ShowWillCallTimesDropDown(control, deliveryType)
{ 
    if(deliveryType == "WLLCL")
    {   
        // only credit card users can select will call time, or Open_Account, but diff msg
        // Always allow willcall pickup now
        /*if($("*[id$='orderShippingIsNotCreditCardInput']").val() == "true" || $("input[id$='paybyCODCheckBox']:checked").length) 
        {
            //PopupMessage("Order pre-pull", "Your items will be pre-pulled only if your account is in good standing", null, null);
            
            if($("*[id$='orderShippingIsOpenAccount']").val() == "true")
            {
                PopupMessage("Order pre-pull", "Order (Items) will be pre-pulled for accounts in good standing", null, null);
                // Will call select is non-empty.  Display will call select and hide the others.
                $("select[id$='WillCallTimesDropDownList']").each(  function () 
                                                                { 
                                                                    if ($(this).children().size() == 0)
                                                                    { 
                                                                        $(this).parent().css("display", "none"); 
                                                                    }
                                                                    else 
                                                                    {
                                                                        $(this).parent().css("display", "block");
                                                                    }
                                                                });
            }
            else
            {
            
                $("*[id$='TimesSelectDiv']").css("display", "none");
                PopupMessage("Order pre-pull", "We can save you time on your pick up.<br /><br />Have your items pre-pulled and waiting for you if you pay by credit card.", null, null);
            
            }
        }
        else
        {*/
            // Will call select is non-empty.  Display will call select and hide the others.
            $("select[id$='WillCallTimesDropDownList']").each(  function () 
                                                                { 
                                                                    if ($(this).children().size() == 0)
                                                                    { 
                                                                        $(this).parent().css("display", "none"); 
                                                                    }
                                                                    else 
                                                                    {
                                                                        $(this).parent().css("display", "block");
                                                                    }
                                                                });
        //}
    }
    else
    {            
        $("*[id$='TimesSelectDiv']").css("display", "none");            
    }
}

function WillCallTimesResponse(result)
{
    var willCallSelectSpan = $get("WLLCLTimesSelectDiv");    
    if (willCallSelectSpan)
    {
        willCallSelectSpan.innerHTML = 'Select a will call pick up time:&nbsp' + result;
    }
}

function SetWillCallTime(controlId)
{
    var $selectControl = $("#" + controlId);
    
    var willCallTime = $("#" + controlId + " option:selected").index();
    OrderService.SetWillCallTime(!willCallTime ? null : $selectControl.children("option:selected").val(), SetWillCallTimeCallback);
}

function SetWillCallTimeCallback(response)
{
    var willCallCheckBox = $("input[id$='willCallCheckBox']");
    if(response)
    {
        EnableWebSalesWillCallSelect(true);
        $("select[id$='willCallTimesWebSalesDropDownList']").val(response);
        
              
        if (isWebSalesLogIn && $("input[id$='willCallCheckBox']").length)
        {
            $("input[id$='willCallCheckBox']").prop("checked", true);
        }
        
        if(routeCodeLabelID)
        {
            $("#" + routeCodeLabelID).html("Will call pick up time: " + response);        
        }
    }
    else
    {
        $("input[id$='willCallCheckBox']").prop("checked", false);
        EnableWebSalesWillCallSelect(false);
    }
}


function ValidateWillCallTimeSelected()
{
    var result = true;
    // Return true if will call radio is not checked or COD checkbox is checked
    if(!$("input[id='WLLCLshipMethodRadioButton']:checked").length || $("input[id$='paybyCODCheckBox']:checked").length)
    {
        CloseShippingOption();
        return false;
    }
    else
    {
        if (!$("*[id$='orderShippingIsNotCreditCardInput']").val())
        {
            $("select[id$='WillCallTimesDropDownList']").each(  function () 
                                                                { 
                                                                    if ($(this).children().size() > 0)
                                                                    { 
                                                                        if($(this).find("option:selected").index() == 0)
                                                                        {
                                                                            result = false;
                                                                            $(this).addClass("DisableGoogleFillRequire");
                                                                            $("div[id='WLLCLInvalidWillCallSelectMessage']").css("display", "block");
                                                                        }
                                                                        else
                                                                        {
                                                                            $(this).removeClass("DisableGoogleFillRequire");
                                                                            $("div[id='WLLCLInvalidWillCallSelectMessage']").css("display", "none");
                                                                        }
                                                                    }
                                                                });
        }
        
                                                            
    }
    if(result)
    {
        CloseShippingOption();
        //PopLoadingImage();
        
        if (!$("*[id$='orderShippingIsNotCreditCardInput']").val())
            EnableWebSalesWillCallSelect(true);
            
    }
    return false;
}

function ResetWillCall()
{
    OrderService.SetWillCallTime(null);
}

function EnableWebSalesWillCallSelect(enable)
{
    if((!enable))
    {
        $("select[id$='willCallTimesWebSalesDropDownList']").css("color", "LightGray").prop({"selectedIndex": 0
                                                                                                });
        $("select[id$='willCallTimesWebSalesDropDownList']").attr('disabled', true);
        OrderService.SetWillCallTime(null);
    }
    else
    {
        $("select[id$='willCallTimesWebSalesDropDownList']").prop('disabled', false);
        $("select[id$='willCallTimesWebSalesDropDownList']").css("color", "Navy");
        
        $("div[id$='webSalesWillCallTimesLabelDiv']").css("color", "#505050");

    }
}


