/// <reference path="http://wwwdev.4imprint.com/_JS/jquery/jquery-vsdoc.js" />
var selBase;
var selTrim;
var selColorDiv = "";
var txtTimer = null;
var SizingHideText = "";
var priceLabel = 'SelectedQtyPrice';
var quantityTextbox = 'txtQty';
var totalLabel = 'SelectedQtyTotal';
var arrSizes = ['S', 'M', 'L', 'XL', 'XXL', '3XL'];

$(function() {
    $('div.colordotOff').hover(function() {
        $(this).addClass('colordotOn');
    }, function() {
        $(this).removeClass('colordotOn');
    }).click(function() {
        $(selColorDiv).removeClass('colordotSel');
        selColorDiv = '#' + $(this).attr('id');
        $(this).addClass('colordotSel');
    });

    $('#disabledMessage').addClass('hide');
    $('.extrasLoadingImg').hide();
    $('#extrasResult').hide();
    $('#selectedExtras').hide();
    $('#priceTblSizeChoice').html('<table>' + $('#tblPricing').html() + '</table>');

    //    $('a.prodRelatedLinkBtn').css('opacity', 0).hover(function() {
    //        $(this).css('opacity', 1);
    //    }, function() {
    //        $(this).css('opacity', 0);
    //    });

    SizingHideText = $('a.hideUniqueColors').html();
    $('a.hideUniqueColors').click(function(e) {
        e.preventDefault();
        if ($(this).html() == 'show all colors') {
            $('.uniqueColor').show();
            $(this).html(SizingHideText);
        } else {
            $(this).html('show all colors');
            $('.uniqueColor').hide();
        }
    });

    $('#closeSizing').click(function() {
        $('.PD_SizeChoicePanel').fadeOut('fast');
        $('.PD_QuantityBtnCell input').removeAttr('disabled').css('opacity', 1);        
        return false;
    });

    $('#sizeSelectionTbl tr').each(function(i) {
        if (i > 1 && $(this).attr('id') != 'closedItemRow' && $.trim($('#SelectionQtyTotal').html()).length < 1) { $(this).hide(); }
    });

    $('#sizeSelectionTbl input').numeric().keyup(calcPrice);

    $('.colorTooltip').tooltip({
        showBody: " - ",
        fade: 250,
        positionLeft: true,
        extraClass: "mediumText"
    }).children('img').removeAttr('title');
    $('.sizingTooltip').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
    }

    calcPrice(); // does an initial price calculation in case of editing an item or the firefox reload nonsense
    $('#baseSpan').css('background-color', $('.baseSpan').css('background-color'));
    $('#trimSpan').css('background-color', $('.trimSpan').css('background-color'));

    $('.DetailsProdImg').imageFlyout({ flyoutClassName: 'mockupFlyout', closeImgClass: 'PD_SuperDetailedClose', minWidth: 700, minHeight: 420 });
    $('.PD_Mockup').imageFlyout({ flyoutClassName: 'mockupFlyout', closeImgClass: 'PD_SuperDetailedClose', minWidth: 717, minHeight: 500 });
    $('input.btnAddToCart').css('opacity', 0.3); // Add to cart button effect
    if (!$('.PD_SelectionBox').hasClass('hide')) { $('.PD_SelectionPanel').slideToggle(); };
});

function AlterSelection() {
    $('.PD_ImprintChoicePanel').fadeOut('normal', function() {
        $('.PD_QuantityChoicePanel').fadeIn();
    });
    $('.PD_SelectionPanel').slideUp();
}

function AlterSelectionSizes() {
    $('.PD_ImprintChoicePanel').fadeOut('normal', function() {
        $('.PD_QuantityChoicePanel').fadeIn();
        openSizingWindow();
    });
    $('.PD_SelectionPanel').slideUp();
}

function calcPrice() {
    var TotalQty = 0;
    $('#sizeSelectionTbl input').each(function() {
        if ($(this).val().length > 0) { TotalQty += parseInt($(this).val()); };
    });
    $('#' + quantityTextbox).html(TotalQty);
    if (TotalQty >= lowestQty) {

        var BreakNumBelow = -1;
        var BreakNumAbove = -1;
        for (var i = 0; i < arrBreak.length; i++) {
            if ((i + 1 >= arrBreak.length || arrBreak[i + 1] < 1) && TotalQty >= arrBreak[i] && arrBreak[i] > 0) {
                BreakNumBelow = i;
                BreakNumAbove = i;
            } else {
                if (TotalQty >= arrBreak[i] && TotalQty < arrBreak[i + 1]) {
                    BreakNumBelow = i;
                    BreakNumAbove = i + 1;
                }
            }
        }

        var newPrice = EstimatePrice(BreakNumBelow, TotalQty, 0);
        $('#' + priceLabel).html(currencySymbol + newPrice.toFixed(2).toString());
        $('#' + totalLabel).html(currencySymbol + (newPrice * TotalQty).toFixed(2).toString());

        // This would be where the 'you save' feature would come into play in the future
    } else {
        $('#' + priceLabel).html('');
        $('#' + totalLabel).html('');
    }
}

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.html())) || qtyBox.html() == '') {
	    alert("Please specify how many of this item you would like to order by either entering a numeric value in the size boxes you would like."); // Formerly in litNoQuantityWarning
	    return false;
	}
	else if (parseInt(qtyBox.html()) < lowestQty) {
	    alert("To order this item, you need to order a minimum quantity of " + lowestQty + ".\n Please ensure that you order at least this many, or choose a different item.");  // Formerly in litNoQuantityWarning
	    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 displaySizeLine(lineIndex) {
    $('#sizeSelectionTbl tr').eq(lineIndex + 2).show();
    $('.sizingClosedLinks').eq(lineIndex).hide();
    return false;
}

function getExtras() {
    if (checkImprints()) {

        $('.calcExtrasBtn').fadeOut('fast', function() {
            $('.extrasLoadingImg').fadeIn('fast');
        });

        var qty = $('#' + quantityTextbox).html();
        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() + "<div class='clear'></div>");
                var ExtrasTotalBox = $('#TotalWithExtras');
                ExtrasTotalBox.children('.PD_SelectionMiddlePrice').html((parseFloat($('#SelectedQtyTotal').html().replace(currencySymbol, '')) + 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 click 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().replace(currencySymbol, '')) + ExtrasTotal).toFixed(2).toString());
                ExtrasTotalBox.children('#ExtrasTotalCurrency').html(currencySymbol);
                $('#selectedExtras').slideDown('fast');
            }
        });
    }
    return false;
}

function finalizeCart() {
    $(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 finalizeCartFromSizing() { return setQuantity(); }

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 openSizingWindow() {
    if (StoreColor()) {
        if ($('.colordotSel').hasClass('uniqueColor')) {
            $('#sizeSelectionTbl tr:gt(1)').hide().children('td').children('input').val('');
            calcPrice();
            $('#unavailableRow').show();
            $('#tdSizingUnavailable span#UniqueColorName').html($('.colordotSel').children('span.ColorDesc').html());          
            $('.sizingClosedLinks').show();
        } else {
            if ($('#closedItemRow').is(':hidden')) $('#closedItemRow').show();
            $('#unavailableRow').hide();
        }
    
        $('.PD_QuantityBtnCell input').attr('disabled', 'disabled').css('opacity', 0.3);    // Disables the qty button to keep it from opening multiple windows
        $('.PD_SizeChoicePanel').fadeIn('fast').centerInClient();
    }
}

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 SetBaseTrim(baseColor, trimColor, baseName, trimName, renderBaseOnly, baseID, trimID) {
    /// <summary>Sets the color option that the user clicked on</summary>

    var baseDisplay = $('#baseSpan');
    var trimDisplay = $('#trimSpan');
    var selectedColors = $('.selColors');

    if (baseColor != "#" && trimColor != "#") {
        baseDisplay.css('background-color', baseColor);
        trimDisplay.css('background-color', trimColor);
        $('#baseSpan').css('background-color', baseColor);
        $('#trimSpan').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()) {
        resetCalcExtras();
        var Qty = $('#' + quantityTextbox).html();
        var SteppedQty = EnforceSteppingQty(Qty, steppingQty);
        if (Qty != SteppedQty) {
            // Enforce the stepping qty
            alert('The product you are ordering must be ordered in cases of ' + steppingQty + '.\n\nPlease adjust the quantities on your sizes appropriately.\n(Hint: The closest valid total quantity is ' + SteppedQty + '.)');
        } else {
            $('.selectedQty').html(Qty);
            $('#SelectionQtyPrice').html($get(priceLabel).innerHTML.replace(currencySymbol, ''));
            $('#SelectionQtyTotal').html($get(totalLabel).innerHTML.replace(currencySymbol, ''));

            // Load up sizes here
            var sizeDescs = $('.sizeLineDesc');  // labels
            var sizeInputs = $('#sizeSelectionTbl input');
            
            var selectedSizes = '';

            for (var j = 0; j < sizeDescs.length; j++) {
                var LineSizes = "";
                var inputIndex = j * arrSizes.length;
                for (var i = 0; i < arrSizes.length; i++) {
                    if (inputIndex < sizeInputs.length) {
                        if ($.trim(sizeInputs.eq(inputIndex).val()).length > 0) {
                            LineSizes += (arrSizes[i] + ': ' + $.trim(sizeInputs.eq(inputIndex).val()) + '&nbsp;&nbsp;&nbsp;');
                        }
                    }
                    inputIndex++;
                }
                if (LineSizes.length > 0) {
                    var SizeLbl = $.trim(sizeDescs.eq(j).html())
                    SizeLbl = SizeLbl.length > 0 ? ("<div class='underline'>" + SizeLbl + "</div>") : '';
                    selectedSizes += "<div>" + SizeLbl + LineSizes + "</div>";
                }
            }

            $('.PD_SelectionSizes').html(selectedSizes);
            
            $('.PD_SizeChoicePanel').fadeOut('fast');
            $('.PD_QuantityBtnCell input').removeAttr('disabled').css('opacity', 1);
            $('.PD_SelectionPanel').slideDown();
            $('.PD_SelectionBox').removeClass('hide').fadeIn();
            $('.PD_QuantityChoicePanel').fadeOut('normal', function() {
                $('.PD_ImprintChoicePanel').fadeIn();
            });
        }
    }
    return 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 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 (lowestQty <= quantity) {
        if (firstDigit != null) {
            var newPrice = EstimatePrice(firstDigit, quantity, qty);
            $('#' + priceLabel).html(currencySymbol + newPrice.toFixed(2).toString());
            $('#' + totalLabel).html(currencySymbol + (newPrice * quantity).toFixed(2).toString());
            $('#' + quantityTextbox).html(quantity);
        }
    }
}









