/// <reference path="http://wwwdev.4imprint.com/_JS/jquery/jquery-vsdoc.js" />
var selBase;
var selTrim;
var selColorDiv = "";
var txtTimer = null;

$(function() {
    $('div.colordotOff').hover(function() {
        $(this).addClass('colordotOn');
    }, function() {
        $(this).removeClass('colordotOn');
    }).click(function() {
        $(selColorDiv).removeClass('colordotSel');
        selColorDiv = '#' + $(this).attr('id');
        $(this).addClass('colordotSel');
    });

    HighlightColumn('.PriceCol1', 1);
    HighlightColumn('.PriceCol2', 2);
    HighlightColumn('.PriceCol3', 3);
    HighlightColumn('.PriceCol4', 4);
    HighlightColumn('.PriceCol5', 5);
    HighlightColumn('.PriceCol6', 6);
    HighlightColumn('.PriceCol7', 7);
    HighlightColumn('.PriceCol8', 8);

    $('#disabledMessage').hide();
    $('.extrasLoadingImg').hide();
    $('#extrasResult').hide();
    $('#selectedExtras').hide();
    
    $('a.prodRelatedLinkBtn').css("opacity", 0).hover(function() {
        $(this).css("opacity", 1);
    }, function() {
        $(this).css("opacity", 0);
    });

    $('.colorTooltip').tooltip({
        showBody: " - ",
        fade: 250,
        positionLeft: true,
        extraClass: "mediumText"
    }).children('img').removeAttr('title');
    $('.qtyTooltip').tooltip({
        showBody: " - ",
        fade: 250,
        positionLeft: true,
        extraClass: "mediumText"
    }).children('img').removeAttr('title');
    $('.imprintTooltip').tooltip({
        showBody: " - ",
        fade: 250,
        positionLeft: true,
        extraClass: "mediumText"
    }).children('img').removeAttr('title');

    if ($('#' + possibleImprintLocs).val().length < 1 || !CheckImprintColors()) {
        $('input.btnAddToCart').css('opacity', 0.3); // Add to cart button effect
    }

    $('.DetailsProdImg').imageFlyout({ flyoutClassName: 'mockupFlyout', closeImgClass: 'PD_SuperDetailedClose', minWidth: 700, minHeight: 420 });
    $('.PD_Mockup').imageFlyout({ flyoutClassName: 'mockupFlyout', closeImgClass: 'PD_SuperDetailedClose', minWidth: 717, minHeight: 500 });
    if (!$('.PD_SelectionBox').hasClass('hide')) { $('.PD_SelectionPanel').slideToggle(); };
});

function pageLoad(sender, e) {
    var slider = $find('sliderExtBehav');
    if(slider) slider.add_valueChanged(onSlideEnd);
}

function AlterSelection() {
    $('.PD_ImprintChoicePanel').fadeOut('normal', function() {
        $('.PD_QuantityChoicePanel').fadeIn();
    });
    $('.PD_SelectionPanel').slideUp();
}

function checkImprints() {
    if ($('#' + possibleImprintLocs).val().length == 0) {
        alert('Please select a location with at least one color selection.'); // Formerly in litNoImprintChoices
        return false;
    } else {
        if (CheckImprintColors()) {
            return true;
        } else {
            alert('You have a location selected but no colors - please select at least one color for each chosen location or uncheck any unwanted locations (Please note: one location is the minimum requirement).'); // Formerly in litNoImprintColor
            return false;
        }
    }
}

function CheckImprintColors() {
    var ImpLocs = $('#' + possibleImprintLocs);
    var arrImprintsChecked = new Array();
    if (ImpLocs.val().lastIndexOf(',') < 0) {
        arrImprintsChecked.push(ImpLocs.val());
    } else {
        arrImprintsChecked = ImpLocs.val().split(',');
    }

    for (var i = 0; i < arrImprintsChecked.length; i++) {
        var chkID = arrImprintsChecked[i];
        //var isExclusive = (chkID.substring(0, (chkID.length - 11))) + 'inputImpLoc';
        var inputID = (chkID.substring(0, (chkID.length - 11))) + 'inputImpLoc';

        if ($('#' + chkID).attr('checked') == true) {
            if ($('#' + inputID).val().length == 0) {
                return false;
            }
        }
    }
    return true;
}

function checkQty() {
    qtyBox = $('#' + quantityTextbox);
	if ((!IsNumeric(qtyBox.val())) || qtyBox.val() == '') {
	    alert("Please specify how many of this item you would like to order by either entering a numeric value in the quantity field or clicking one of the quantity fields above the price."); // Formerly in litNoQuantityWarning
	    qtyBox.val('');
	    qtyBox.focus();
	    return false;
	}
	else if (parseInt(qtyBox.val()) < parseInt($('#' + lowestQtyHidden).val())) {
	    alert("To order this item, you need to order a minimum quantity of " + $('#' + lowestQtyHidden).val() + ".\n Please ensure that you order at least this many, or choose a different item."); // Formerly in litNoQuantityWarning
	    qtyBox.focus();
	    return false;
	}
	else { return true; }
}

function DeleteImprintColor(hiddenInput, parentID, indexToDelete) {
    resetCalcExtras();
    ImprintColorInput = $('#' + hiddenInput);
    if (ImprintColorInput.val().endsWith("|")) {
        ImprintColorInput.val(ImprintColorInput.val().substring(0, ImprintColorInput.val().length - 1));
    }

    if (ImprintColorInput.val().length > 0) {
        var arrColors = ImprintColorInput.val().split('|');
        if (indexToDelete < arrColors.length) {
            var arrNewColors = new Array();
            var counter = 0;

            if ($('#' + parentID + PadDigits(arrColors.length, 2) + '_spnImpColor').length > 0) {
                $('#' + parentID + PadDigits(arrColors.length, 2) + '_spnImpColor').removeClass("PD_ImprintColorChoiceBox_On");
                $('#' + parentID + PadDigits((arrColors.length - 1), 2) + '_spnImpColor').addClass("PD_ImprintColorChoiceBox_On");
            }

            for (var i = 0; i < arrColors.length; ) {
                if (counter >= indexToDelete) {
                    // Change the background color to the value of the next item
                    if ($('#' + (parentID + PadDigits((counter + 1), 2) + '_spnImpColor')).length > 0) {
                        $('#' + (parentID + PadDigits(counter, 2) + '_spnImpColor')).css('background-color', $('#' + (parentID + PadDigits((counter + 1), 2) + '_spnImpColor')).css('background-color'));
                    } else {
                        $('#' + (parentID + PadDigits(counter, 2) + '_spnImpColor')).css('background-color', "White");
                    }
                }
                if (counter != indexToDelete) {
                    arrNewColors.push(arrColors.shift());
                } else {
                    arrColors.shift();
                }
                counter++;
            }

            ImprintColorInput.val(arrNewColors.join('|'));
        }
    }
}

function getExtras() {
    if(checkImprints()) {
        
        $('.calcExtrasBtn').fadeOut('fast', function() {
            $('.extrasLoadingImg').fadeIn('fast');
        });        
        
        var qty = $('#' + quantityTextbox).val();
        var ImpLocs = $('#' + possibleImprintLocs);
        var arrImprintsChecked = new Array();        
        
        arrImprintsChecked = ImpLocs.val().split(',');
        var imprintData = '';

        for (var i = 0; i < arrImprintsChecked.length; i++) {
            var chkID = arrImprintsChecked[i];
            var inputID = (chkID.substring(0, (chkID.length - 11))) + 'inputImpLoc';
            var inputImpLocID = (chkID.substring(0, (chkID.length - 11))) + 'inputImpLocIDs';
            imprintData += $('#' + inputImpLocID).val() + "-" + $('#' + inputID).val() + "_";
        }
        
        var requestData = {
            "ID": prodID,
            "Qty": qty,
            "Imps": imprintData
        };
        $.ajax({
            type: "POST",
            url: "/cart/ajaxextrascalculator.aspx",
            data: requestData,
            dataType: "html",
            timeout: 15000,
            success: function(data) {
                $('#extrasResult').html(data + "<div class='clear'></div>");
                $('.extrasLoadingImg').fadeOut('fast', function() {
                    $('#extrasResult').slideDown('fast');
                });                                
                
                var ExtraTemplate = $('#selectedExtrasBox').children('.selectedExtraLine').eq(0);
                var ExtrasTotal = 0.00;
                var Extras = $(document.createElement("div")).attr('id', 'ExtraDummy');
                $('#extrasResult').children('.extraDetailsLine').each(function() {
                    var NewExtra = ExtraTemplate.clone(false);
                    var LineTotal;
                    var LinePrice;
                    var LineQty;
                    $(this).children('div.extraDetailsNumCol').each(function(e) {
                        switch (e) {
                            case 0:
                                LineQty = $(this).html();
                                break;
                            case 1:
                                LinePrice = $(this).html();
                                break;
                            case 2:
                                LineTotal = $(this).html();
                                break;
                        }
                    });
                    ExtrasTotal += parseFloat(LineTotal.replace(currencySymbol, '')); 
                    NewExtra.children('.selectionExtraDesc').html($(this).children('div.extraDetailsDescCol').html());
                    if (LinePrice == '' || LineQty == '') {
                        NewExtra.children('.selectionExtraQtyPrice').html('');
                    } else {
                        NewExtra.children('.selectionExtraQtyPrice').html(LineQty + ' x ' + LinePrice);
                    }
                    NewExtra.children('.PD_SelectionMiddlePrice').html(LineTotal.replace(currencySymbol, ''));
                    NewExtra.appendTo(Extras);
                });
                $('#selectedExtrasBox').html(Extras.html());
                var ExtrasTotalBox = $('#TotalWithExtras');
                ExtrasTotalBox.children('.PD_SelectionMiddlePrice').html((parseFloat($('#SelectedQtyTotal').html()) + ExtrasTotal).toFixed(2).toString());
                ExtrasTotalBox.children('#ExtrasTotalCurrency').html(currencySymbol);
                $('#selectedExtras').slideDown('fast');
            },
            error: function() {
                $('.extrasLoadingImg').fadeOut('fast');
                $('#extrasResult')
                .html('Sorry, an error occurred. Please <a href="#" onclick="return getExtras();">click here</a> to try again. You can also view the imprint charges in your cart by clicking the Add to Cart button below.')
                .slideDown('fast');
                var ExtraTemplate = $('#selectedExtrasBox').children('.selectedExtraLine').eq(0);
                var ExtrasTotal = 0.00;
                ExtraTemplate.children('.selectionExtraDesc').html($('#extrasResult').html());
                ExtraTemplate.children('.selectionExtraQtyPrice').html('');
                ExtraTemplate.children('.PD_SelectionMiddlePrice').html(ExtrasTotal.toString());
                var ExtrasTotalBox = $('#TotalWithExtras');
                ExtrasTotalBox.children('.PD_SelectionMiddlePrice').html((parseFloat($('#SelectedQtyTotal').html()) + ExtrasTotal).toFixed(2).toString());
                ExtrasTotalBox.children('#ExtrasTotalCurrency').html(currencySymbol);
                $('#selectedExtras').slideDown('fast');
            }
        });
    }
    return false;
}

function finalizeCart(sender) {
    $(sender).attr("disabled", "disabled");    
    var impResult = checkImprints();
    if (impResult == false) {
        $(sender).removeAttr("disabled");
        return false;
    } else {
	$('form').css("cursor", "wait");
    	$('input.btnAddToCart').css("cursor", "wait");
        __doPostBack(sender.name, '');  // calls the asp.net postback routine
    }
}

function HighlightColumn(classname, colNum) {
    $(classname).hover(function() {
        $(classname).addClass('priceColOn');
    }, function() {
        $(classname).removeClass('priceColOn');
    }).click(function() {
        SelectQty(colNum);
    }).children('a').addClass('underline');
}

function IsNumeric(strString) {
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;


    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

function onSlideEnd(sender, e) {
    UpdatePrice(sender.get_element().value);
}

function PadDigits(n, totalDigits) {
    n = n.toString();
    var pd = '';
    if (totalDigits > n.length) {
        for (i = 0; i < (totalDigits - n.length); i++) {
            pd += '0';
        }
    }
    return pd + n.toString();
}

function resetCalcExtras() {
    $('.extrasLoadingImg').hide();
    $('#extrasResult').slideUp('fast', function(){
        $('.calcExtrasBtn').fadeIn();
    });
    $('#selectedExtras').slideUp('fast');
}

function RemoveAllImprintColors(hiddenInput, parentID) {
    resetCalcExtras();
    ImprintColorInput = $('#' + hiddenInput);
    if (ImprintColorInput.val().endsWith("|")) {
        ImprintColorInput.val(ImprintColorInput.val().substring(0, ImprintColorInput.val().length - 1));
    }

    if (ImprintColorInput.val().length > 0) {
        var arrColors = ImprintColorInput.val().split('|');

        for (var i = 0; i < arrColors.length; i++) {
            var currentSelectionBox = $('#' + (parentID + PadDigits(i, 2) + '_spnImpColor'));
            currentSelectionBox.css('background-color', 'White');
            if (i == 0) {
                currentSelectionBox.addClass("PD_ImprintColorChoiceBox_On");
            } else {
                currentSelectionBox.removeClass("PD_ImprintColorChoiceBox_On");
            }
        }

        if ($('#' + parentID + PadDigits(arrColors.length, 2) + '_spnImpColor')) {
            $('#' + parentID + PadDigits(arrColors.length, 2) + '_spnImpColor').addClass("PD_ImprintColorChoiceBox");
        }
    }

    ImprintColorInput.val("");
}

function SaveImprintColor(hiddenInput, colorID, hex, parentID, divNeedMoreColors, MaxImprintColors) {
    resetCalcExtras();
    if(parseFloat($('input.btnAddToCart').css('opacity')) < 1) {$('input.btnAddToCart').fadeTo('fast', 1.0);}; // Add to cart button effect
    ImprintColorInput = $('#' + hiddenInput);
    var MoreColorsLabel = $('#' + divNeedMoreColors);
    if (MaxImprintColors > 1) {
        if (MoreColorsLabel.css('display') == 'none') {
            if (ImprintColorInput.val().length > 0) {
                var arrTempImpColors = ImprintColorInput.val().split('|');
                if (ImprintColorInput.val().endsWith("|")) {
                    arrTempImpColors.pop();
                    ImprintColorInput.val(ImprintColorInput.val().substring(0, ImprintColorInput.val().length - 1));
                }

                if ($get(parentID + '01_spnImpColor').style.display == "inline") {
                    if ($get(parentID + PadDigits(arrTempImpColors.length, 2) + '_spnImpColor')) {
                        ImprintColorInput.val(ImprintColorInput.val() + "|" + colorID + "|");
                    } else {
                        // the last imprint color option has been reached, so change the last value to the new color
                        arrTempImpColors.pop();
                        arrTempImpColors.push(colorID);
                        ImprintColorInput.val(arrTempImpColors.join('|') + "|");
                    }
                    MoreColorsLabel.addClass('hide');
                } else {
                    ImprintColorInput.val(colorID + "|");
                    MoreColorsLabel.css("visibility", "visible");
                }
            } else {
                ImprintColorInput.val(colorID + "|");
                MoreColorsLabel.css("visibility", "visible");
            }
        } else {
            ImprintColorInput.val(colorID + "|");
            MoreColorsLabel.css("visibility", "visible");
        }
    } else {
        ImprintColorInput.val(colorID + "|");
    }
    var arrImprintCols = ImprintColorInput.val().split('|');
    arrImprintCols.pop();

    var boxToColor = $('#' + parentID + PadDigits((arrImprintCols.length - 1), 2) + '_spnImpColor');
    if ($('#' + parentID + PadDigits(arrImprintCols.length, 2) + '_spnImpColor')) {
        $('#' + parentID + PadDigits(arrImprintCols.length, 2) + '_spnImpColor').addClass("PD_ImprintColorChoiceBox_On");
        boxToColor.removeClass('PD_ImprintColorChoiceBox_On'); 
    }
    boxToColor.css('background-color', hex);
    if (recolorAvailable) {
        if (selBase == null || selTrim == null) {
            var arrColorVals = $get(colorsInput).value.split('/');
            selBase = arrColorVals[0];
            selTrim = arrColorVals[1];
        }
        $('.DetailsProdImg img').attr('src', 'http://secure.4imprint.com/images/recoloredimage.ashx?ID=' + prodID + '&CA=' + catAlias + '&base=' + selBase + '&trim=' + selTrim + '&imp=' + colorID);
    }
}

function SelectQty(columnId) {
    /// <summary>Changes the quantity to the value of the price break that the user clicked on</summary>
    /// <param name="columnId">Column index in the price break table</param>
    if (arrBreak[columnId] > 0) {
        $('#' + quantityTextbox).val(arrBreak[columnId]);
        SetSlider(arrBreak[columnId]);
    }
}

function SetBaseTrim(baseColor, trimColor, baseName, trimName, renderBaseOnly, baseID, trimID) {
    /// <summary>Changes the quantity to the value of the price break that the user clicked on</summary>
    /// <param name="columnId">Column index in the price break table</param>

    var baseDisplay = $('#baseSpan');
    var trimDisplay = $('#trimSpan');
    var selectedColors = $('.selColors');

    if (baseColor != "#" && trimColor != "#") {
        baseDisplay.css('background-color', baseColor);
        trimDisplay.css('background-color', trimColor);

        //display selected color names
        if (baseName == trimName || renderBaseOnly == 'true') {
            selectedColors.html(baseName);
        }
        else {
            selectedColors.html(baseName + ' : ' + trimName);
        }
    }
    else {
        if (baseColor != "#") {
            baseDisplay.css('background-color', baseColor);
        }
        else {
            baseDisplay.css('background-color', '#f8f8f8');
        }

        if (trimColor != "#") {
            trimDisplay.css('background-color', trimColor);
        }
        else {
            trimDisplay.css('background-color', '#f8f8f8');
        }


        //this item doesn't have a product color 
        // still must show a visual cue that item has been choosen
        if (baseName == trimName || renderBaseOnly == 'true') {
            selectedColors.html(baseName);
        }
        else {
            selectedColors.html(baseName + ' : ' + trimName);
        }
    }
    selBase = baseID;
    selTrim = trimID;
    SetOptColor();
}

function SetOptColor() {
    /// <summary>Sets the user's color selection, and if available, recolors the product image with those colors</summary>
    if (selBase != "" && selTrim != "") {
        document.getElementById(colorsInput).value = selBase + "/" + selTrim;
    }
    else {
        document.getElementById(colorsInput).value = "";
    }

    if (recolorAvailable) {
        if (selTrim != "")
        { $('.DetailsProdImg img').attr('src', 'http://secure.4imprint.com/images/recoloredimage.ashx?ID=' + prodID + '&CA=' + catAlias + '&base=' + selBase + '&trim=' + selTrim); }
    }
}

function setQuantity() {
    if (checkQty() && StoreColor()) {
        resetCalcExtras();
        $('.selectedQty').html($('#' + quantityTextbox).val());
        $('#SelectedQtyPrice').html($get(priceLabel).innerHTML.replace(currencySymbol, ''));
        $('#SelectedQtyTotal').html($get(totalLabel).innerHTML.replace(currencySymbol, ''));

        $('.PD_SelectionPanel').slideDown();
        $('.PD_SelectionBox').removeClass('hide').fadeIn();
        $('.PD_QuantityChoicePanel').fadeOut('normal', function() {
            $('.PD_ImprintChoicePanel').fadeIn();
        });
    }
}

function SetSlider(qty) {
    // Setting the animation pending property to true and then calling calcValue triggers the slider animation
    // that moves the slider from it's old position to the new one. The _animationPending property is then
    // set to false internally in calcValue when the animation completes.
    var slider = $find('sliderExtBehav');
    slider._animationPending = true;
    slider._isUpdatingInternal = true;
    var prevValue = slider._value;
    slider._calcValue(SetSlideQty(qty));
    if (prevValue == slider._value) { UpdatePrice(prevValue.toString()); }
    slider._isUpdatingInternal = false;
}

function StoreColor() {
    if ($('#' + colorsInput).val() == '') {
        alert("Please select a color option from the list provided."); // Formerly in litNoColorWarning
	    return false;
	} else {
	    $('.spnSelectionColors').html($('.selColors').html());
	    $('.SelectionBaseColor').css('background-color', $('#baseSpan').css('background-color'));
	    $('.SelectionTrimColor').css('background-color', $('#trimSpan').css('background-color'));
        return true;
    }
}

function TextUpdateSlider(qty) {
    if (txtTimer != null) {
        clearTimeout(txtTimer);
    }
    txtTimer = setTimeout("TextUpdateSliderFinish('" + qty + "')", 500);
}

function TextUpdateSliderFinish(qty) {
    if (IsNumeric(qty)) {
        qty = parseInt(qty);
        
        var SlideQty = qty;
        if (parseInt($('#' + lowestQtyHidden).val()) <= qty) {
            for (var i = arrBreak.length - 1; i > 0; i--) {
                if (arrBreak[i] > 0) {
		    // If the qty is greater than the end of the slider, need to set the value to slide to to the last break.
                    if (qty > arrBreak[i]) {
                        SlideQty = arrBreak[i];
                        qty = EnforceSteppingQty(qty, steppingQty);
                    }
                    break; 
                }
            }
            SetSlider(SlideQty);

            // The slider doesn't deal in qtys, just percentages, so sometimes it will adjust the qty when it does
            // its percentage calculation if the user typed a qty. This will reset it to the user entered value.
            var qtyTxtbox = $('#' + quantityTextbox);
            if (qty > SlideQty) {
                qtyTxtbox.val(qty);
                var price = parseFloat($('#' + priceLabel).html().substring(1));    // Trims the currency symbol
                $('#' + totalLabel).html(currencySymbol + (price * qty).toFixed(2).toString());
            } else {
                if (parseInt(qtyTxtbox.val()) != qty) {
                    if (EnforceSteppingQty(qty, steppingQty) == qty) {
                        qtyTxtbox.val(qty);
                        var price = parseFloat($get(priceLabel).innerHTML.substring(1));    // Trims the currency symbol
                        $('#' + totalLabel).html(currencySymbol + (price * qty).toFixed(2).toString());
                    }
                }
            }
            qtyTxtbox.select();
        }
    }
}

function ToggleImpLocation(chkClicked, IsExclusive) {
    resetCalcExtras();
    var chkBox = $('#' + chkClicked);
    var ImpLocs = $('#' + possibleImprintLocs);
    var IsExcl = $('#' + IsExclusive);
    var arrImpLocs = new Array();
    if (ImpLocs.val().length > 0) {
        if (ImpLocs.val().lastIndexOf(',') > -1) {
            arrImpLocs = ImpLocs.val().split(',');
        } else {
            arrImpLocs.push(ImpLocs.val());
        }
    }
    if (chkBox.attr('checked') == true) {
        if (IsExcl.val() == 'True' && arrImpLocs.length > 0) {
            alert('The location you are trying to add cannot be used with any other imprint locations. Please uncheck any other locations to continue with this location.'); // formerly in ImprintAddExclusiveLocError
        } else {
            for (var i = 0; i < arrImpLocs.length; i++) {
                var ParentPath = arrImpLocs[i].substring(0, (arrImpLocs[i].length - 11));
                var ExistingExclusive = ParentPath + 'inputIsExcl';
                if ($('#' + ExistingExclusive).val() == 'True') {
                    var LocationText = "'" + $get(arrImpLocs[i]).nextSibling.innerHTML + "'";
                    alert('The ' + LocationText + ' that is currently selected cannot be used with any other imprint locations. Please remove the check from the box next to it if you would like to use a different location.'); // formerly in ImprintAddOtherLocToExclusiveLocError
                }
            }
        }
        arrImpLocs.push(chkClicked);
        ImpLocs.val(arrImpLocs.join(','));
    } else {
        var arrNewLocs = new Array();
        for (var i = 0; i < arrImpLocs.length; i++) {
            if (arrImpLocs[i] != chkClicked) { arrNewLocs.push(arrImpLocs[i]); }
        }

        if (arrNewLocs.length == 0) {
            ImpLocs.val("");
        } else {
            ImpLocs.val(arrNewLocs.join(','));
        }
    }
    chkBox.parent().siblings(".PD_ImprintLocationPanel").slideToggle();
}

function UnlockMoreColors(divNeedMoreColors, parentID, MaxImprintColors) {
    /// <summary>Called after clicking the more colors button, this displays the boxes after the first for additional color entries</summary>
    /// <param name="divNeedMoreColors">Div containing the more colors button</param>
    /// <param name="parentID">ID of the container element that holds the color boxes</param>
    /// <param name="MaxImprintColors">Maximum number of imprint colors</param>
    for (var i = 1; i < MaxImprintColors; i++) {
        if ($('#' + (parentID + PadDigits(i, 2) + '_spnImpColor'))) {
            $('#' + (parentID + PadDigits(i, 2) + '_spnImpColor')).css('display', 'inline');
            $('#' + (parentID + PadDigits(i, 2) + '_lblImpColorNo')).css('display', 'inline');
            $('#' + (parentID + PadDigits(i, 2) + '_imgClose')).css('display', 'inline');
        }
    }
    $('#' + divNeedMoreColors).addClass('hide');
}

function UpdatePrice(qty) {
    var firstDigit = GetBreakSegment(qty);
    var quantity = GetSlideQty(firstDigit, qty);
    if (parseInt($get(lowestQtyHidden).value) <= quantity) {
        if (firstDigit != null) {
            var newPrice = EstimatePrice(firstDigit, quantity, qty);
            var startPrice = arrPrice[1]; // pricing always starts at index 1
            $('#' + priceLabel).html(currencySymbol + newPrice.toFixed(2).toString());
            $('#' + totalLabel).html(currencySymbol + (newPrice * quantity).toFixed(2).toString());
            $('#' + quantityTextbox).val(quantity);
            if(newPrice.toFixed(2) >= startPrice.toFixed(2)) {
                if($('div#YouSaveBox').css('visibility') == 'visible') {$('div#YouSaveBox').css('visibility', 'hidden');}
                //$('div#divYouSave').html('');
            } else {
                if($('div#YouSaveBox').css('visibility') == 'hidden') {$('div#YouSaveBox').css('visibility', 'visible');}
                $('div#divYouSave').html(currencySymbol + ((startPrice * quantity) - (newPrice * quantity)).toFixed(2).toString());
            }
        }
    }
}