var productArray = new Array();
var styleDropdownArray = new Array();
var sizeDropdownArray = new Array();
var colorDropdownArray = new Array();
var metalFinishDropdownArray = new Array();
var gemStoneDropdownArray = new Array();
var lengthDropdownArray = new Array();
var crystalDropdownArray = new Array();
var letterDropdownArray = new Array();

var templateProductAttributeSwatchHex = new Ext.Template(
    '<div style="clear:none; float:left; margin-right: 5px; min-height:20px;">',
    '<div class="productCatalog-swatchBorder" name="{systemRef}" id="swatchTable{systemRef}" style="background-color: {location}; cursor: pointer; height:15px; width: 52px;" title="{description}" onclick="{functionName}(\'{systemRef}\', this)"></div>',
    '</div>'
    );

var templateProductAttributeSwatchImg = new Ext.Template(
    '<div style="clear:none; float:left; margin-right: 5px; min-height:20px;">',
    '<div class="productCatalog-swatchBorder" name="{systemRef}" id="swatchTable{systemRef}" >',
    '<a href="javascript:{functionName}(\'{systemRef}\', this)">',
    '{location}',
    '</a>',
    '</div>',
    '</div>'
    );

function ProductGroupProduct(productId, productGroupId, sku, styleSystemRef, styleDescription, styleLocation, sizeSystemRef, sizeDescription, sizeLocation, colorSystemRef, colorDescription, colorLocation, unitPrice, unitPriceBV, retailPrice, retailPriceBV, consultantUnitPrice, consultantUnitPriceBV, consultantRetailPrice, consultantRetailPriceBV, unitOfMeasure, isProductAvailable, isProductTempUnavailable, isProductBackorder, isProductLimitedAvailable, estimatedAvailabilityDate, allowBackorder, name, currencyCode, wishListPrice, metalFinishSystemRef, metalFinishDescription, metalFinishLocation, gemStoneSystemRef, gemStoneDescription, gemStoneLocation, lengthSystemRef, lengthDescription, lengthLocation, crystalSystemRef, crystalDescription, crystalLocation, letterSystemRef, letterDescription, letterLocation, productImages) {
    this.productId = productId;
    this.productGroupId = productGroupId;
    this.sku = sku;
    this.styleSystemRef = styleSystemRef;
    this.styleDescription = styleDescription;
    this.styleLocation = styleLocation;
    this.sizeSystemRef = sizeSystemRef;
    this.sizeDescription = sizeDescription;
    this.sizeLocation = sizeLocation;
    this.colorSystemRef = colorSystemRef;
    this.colorDescription = colorDescription;
    this.colorLocation = colorLocation;
    this.unitPrice = unitPrice;
    this.unitPriceBV = unitPriceBV;
    this.retailPrice = retailPrice;
    this.retailPriceBV = retailPriceBV;
    this.consultantUnitPrice = consultantUnitPrice;
    this.consultantUnitPriceBV = consultantUnitPriceBV;
    this.consultantRetailPrice = consultantRetailPrice;
    this.consultantRetailPriceBV = consultantRetailPriceBV;
    this.unitOfMeasure = unitOfMeasure;
    this.isProductAvailable = isProductAvailable;
    this.isProductTempUnavailable = isProductTempUnavailable;
    this.isProductBackorder = isProductBackorder;
    this.isProductLimitedAvailable = isProductLimitedAvailable;
    this.estimatedAvailabilityDate = estimatedAvailabilityDate;
    this.allowBackorder = allowBackorder;
    this.name = name;
    this.currencyCode = currencyCode;
    this.wishListPrice = wishListPrice;
    this.metalFinishSystemRef = metalFinishSystemRef;
    this.metalFinishDescription = metalFinishDescription;
    this.metalFinishLocation = metalFinishLocation;
    this.gemStoneSystemRef = gemStoneSystemRef;
    this.gemStoneDescription = gemStoneDescription;
    this.gemStoneLocation = gemStoneLocation;
    this.lengthSystemRef = lengthSystemRef;
    this.lengthDescription = lengthDescription;
    this.lengthLocation = lengthLocation;
    this.crystalSystemRef = crystalSystemRef;
    this.crystalDescription = crystalDescription;
    this.crystalLocation = crystalLocation;
    this.letterSystemRef = letterSystemRef;
    this.letterDescription = letterDescription;
    this.letterLocation = letterLocation;
    this.productImages = productImages;
}

function DropDownInfo(id, description) {
    this.id = id;
    this.description = description;
}

function Swatch(systemRef, description, imageLocation) {
    this.systemRef = systemRef;
    this.description = description;
    this.imageLocation = imageLocation;
}

function getSelectedProductAttribute(attributeTypeName) {
    if (document.forms["qtyForm"].elements["product" + attributeTypeName] === undefined) {
        return "";
    }
    if (document.forms["qtyForm"].elements["product" + attributeTypeName].options.length <= 0) {
        return "";
    }
    if (document.forms["qtyForm"].elements["product" + attributeTypeName].selectedIndex < 0) {
        document.forms["qtyForm"].elements["product" + attributeTypeName].selectedIndex = 0;
    }
    return DomUtils.getSelectListValue("qtyForm", "product" + attributeTypeName);
}

function buildChoices(attributeType) {
    if (document.forms["qtyForm"].elements["product" + attributeType] === undefined) {
        return;
    }

    var attributeType1stLowCase = attributeType.substr(0, 1).toLowerCase() + attributeType.substr(1);
    var attributeDropdownArray = window[attributeType1stLowCase + "DropdownArray"];

    var selectedStyle = getSelectedProductAttribute("Style");
    var selectedSize = getSelectedProductAttribute("Size");
    var selectedColor = getSelectedProductAttribute("Color");
    var selectedMetalFinish = getSelectedProductAttribute("MetalFinish");
    var selectedGemStone = getSelectedProductAttribute("GemStone");
    var selectedLength = getSelectedProductAttribute("Length");
    var selectedCrystal = getSelectedProductAttribute("Crystal");
    var selectedLetter = getSelectedProductAttribute("Letter");

    var indexSize = document.forms["qtyForm"].elements["product" + attributeType].options.length;

    for (var i = indexSize - 1; i >= 0; i = i - 1) {
        var optionChild = document.forms["qtyForm"].elements["product" + attributeType].options[i];
        document.forms["qtyForm"].elements["product" + attributeType].removeChild(optionChild);
    }

    for (var idxDropDown = 0; idxDropDown < attributeDropdownArray.length; idxDropDown = idxDropDown + 1) {

        var dropDown = attributeDropdownArray[idxDropDown];

        for (var idxProducts = 0; idxProducts < productArray.length; idxProducts = idxProducts + 1) {

            var product = productArray[idxProducts];

            var foundProduct = true;
            if (attributeType === "Style") {
                foundProduct = foundProduct && (product.styleSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.styleSystemRef === selectedStyle);
            }
            if (attributeType === "Color") {
                foundProduct = foundProduct && (product.colorSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.colorSystemRef === selectedColor);
            }
            if (attributeType === "Size") {
                foundProduct = foundProduct && (product.sizeSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.sizeSystemRef === selectedSize);
            }
            if (attributeType === "MetalFinish") {
                foundProduct = foundProduct && (product.metalFinishSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.metalFinishSystemRef === selectedMetalFinish);
            }
            if (attributeType === "GemStone") {
                foundProduct = foundProduct && (product.gemStoneSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.gemStoneSystemRef === selectedGemStone);
            }
            if (attributeType === "Length") {
                foundProduct = foundProduct && (product.lengthSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.lengthSystemRef === selectedLength);
            }
            if (attributeType === "Crystal") {
                foundProduct = foundProduct && (product.crystalSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.crystalSystemRef === selectedCrystal);
            }
            if (attributeType === "Letter") {
                foundProduct = foundProduct && (product.letterSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.letterSystemRef === selectedLetter);
            }

            if (foundProduct) {

                var option = document.createElement('OPTION');
                option.value = dropDown.id;
                option.innerHTML = dropDown.description;

                document.forms["qtyForm"].elements["product" + attributeType].appendChild(option);

                var selectedAttribute = eval("selected" + attributeType);
//                if (product[attributeType1stLowCase + "SystemRef"] === selectedAttribute || idxDropDown == 0) {
                if (product[attributeType1stLowCase + "SystemRef"] === selectedAttribute) {
                    option.selected = true;
                }

                break;
            }
        }
    }

    //if (jQuery("select[name='product" + attributeType + "']").selectpicker) {
    //    jQuery("select[name='product" + attributeType + "']").selectpicker("render");
    //}
}


function buildSwatches(attributeType) {

    if (document.forms["qtyForm"].elements["product" + attributeType] == 'undefined') {
        return;
    }

    if (document.getElementById("productCatalog-divSwatches" + attributeType) == null) {
        return;
    }

    document.getElementById("productCatalog-divSwatches" + attributeType).style.visibility = "hidden";

    var attributeType1stLowCase = attributeType.substr(0, 1).toLowerCase() + attributeType.substr(1);
    var attributeDropdownArray = window[attributeType1stLowCase + "DropdownArray"];

    var selectedStyle = getSelectedProductAttribute("Style");
    var selectedSize = getSelectedProductAttribute("Size");
    var selectedColor = getSelectedProductAttribute("Color");
    var selectedMetalFinish = getSelectedProductAttribute("MetalFinish");
    var selectedGemStone = getSelectedProductAttribute("GemStone");
    var selectedLength = getSelectedProductAttribute("Length");
    var selectedCrystal = getSelectedProductAttribute("Crystal");
    var selectedLetter = getSelectedProductAttribute("Letter");

    var html = '';

    var productID;
    var swatchesArray = new Array();
    for (var i = 0; i < attributeDropdownArray.length; i = i + 1) {
        var dropDown = attributeDropdownArray[i];

        for (var idxProducts = 0; idxProducts < productArray.length; idxProducts = idxProducts + 1) {
            var product = productArray[idxProducts];

            var foundProduct = true;
            if (attributeType === "Style") {
                foundProduct = foundProduct && (product.styleSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.styleSystemRef === selectedStyle);
            }
            if (attributeType === "Color") {
                foundProduct = foundProduct && (product.colorSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.colorSystemRef === selectedColor);
            }
            if (attributeType === "Size") {
                foundProduct = foundProduct && (product.sizeSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.sizeSystemRef === selectedSize);
            }
            if (attributeType === "MetalFinish") {
                foundProduct = foundProduct && (product.metalFinishSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.metalFinishSystemRef === selectedMetalFinish);
            }
            if (attributeType === "GemStone") {
                foundProduct = foundProduct && (product.gemStoneSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.gemStoneSystemRef === selectedGemStone);
            }
            if (attributeType === "Length") {
                foundProduct = foundProduct && (product.lengthSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.lengthSystemRef === selectedLength);
            }
            if (attributeType === "Crystal") {
                foundProduct = foundProduct && (product.crystalSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.crystalSystemRef === selectedCrystal);
            }
            if (attributeType === "Letter") {
                foundProduct = foundProduct && (product.letterSystemRef === dropDown.id);
            } else {
                foundProduct = foundProduct && (product.letterSystemRef === selectedLetter);
            }

            if (foundProduct) {

                if (!StringUtils.isEmpty(product[attributeType1stLowCase + "Location"])) {
                    swatchesArray[swatchesArray.length] = new Swatch(product[attributeType1stLowCase + "SystemRef"],
                        product[attributeType1stLowCase + "Description"],
                        product[attributeType1stLowCase + "Location"]);
                }
            }
        }
    }

    var idxSwatch = 0;
    while (idxSwatch < swatchesArray.length) {
        if (swatchesArray[idxSwatch].imageLocation.indexOf("#") == 0) {
            html += templateProductAttributeSwatchHex.applyTemplate({systemRef: swatchesArray[idxSwatch].systemRef, description: swatchesArray[idxSwatch].description, location: swatchesArray[idxSwatch].imageLocation, functionName: "onSelect" + attributeType + "Swatch"});
        } else {
            html += templateProductAttributeSwatchImg.applyTemplate({systemRef: swatchesArray[idxSwatch].systemRef, description: swatchesArray[idxSwatch].description, location: swatchesArray[idxSwatch].imageLocation, functionName: "onSelect" + attributeType + "Swatch"});
        }
        idxSwatch = idxSwatch + 1;
    }

    if (swatchesArray.length > 0) {
        document.getElementById("productCatalog-divSwatches" + attributeType).innerHTML = html;
        document.getElementById("productCatalog-divSwatches" + attributeType).style.visibility = "visible";
    }
}

function buildStyleSwatches() {
    buildSwatches("Style");
}

function buildSizeChoices() {
    buildChoices("Size");
}

function buildSizeSwatches() {
    buildSwatches("Size");
}

function buildColorChoices() {
    buildChoices("Color");
}

function buildColorSwatches() {
    buildSwatches("Color");
}

function buildMetalFinishChoices() {
    buildChoices("MetalFinish");
}

function buildMetalFinishSwatches() {
    buildSwatches("MetalFinish");
}

function buildGemStoneChoices() {
    buildChoices("GemStone");
}

function buildGemStoneSwatches() {
    buildSwatches("GemStone");
}

function buildLengthChoices() {
    buildChoices("Length");
}

function buildLengthSwatches() {
    buildSwatches("Length");
}

function buildCrystalChoices() {
    buildChoices("Crystal");
}

function buildCrystalSwatches() {
    buildSwatches("Crystal");
}

function buildLetterChoices() {
    buildChoices("Letter");
}

function buildLetterSwatches() {
    buildSwatches("Letter");
}

function onSelectStyleSwatch(systemRef, anchorObj) {
    document.forms["qtyForm"].elements["productStyle"].value = systemRef;
    onAttributeChange();
}

function onSelectSizeSwatch(systemRef, anchorObj) {
    document.forms["qtyForm"].elements["productSize"].value = systemRef;
    onAttributeChange();
}

function onSelectColorSwatch(systemRef, anchorObj) {
    document.forms["qtyForm"].elements["productColor"].value = systemRef;
    onAttributeChange();
}

function onSelectMetalFinishSwatch(systemRef, anchorObj) {
    document.forms["qtyForm"].elements["productMetalFinish"].value = systemRef;
    onAttributeChange();
}

function onSelectGemStoneSwatch(systemRef, anchorObj) {
    document.forms["qtyForm"].elements["productGemStone"].value = systemRef;
    onAttributeChange();
}

function onSelectLengthSwatch(systemRef, anchorObj) {
    document.forms["qtyForm"].elements["productLength"].value = systemRef;
    onAttributeChange();
}

function onSelectCrystalSwatch(systemRef, anchorObj) {
    document.forms["qtyForm"].elements["productCrystal"].value = systemRef;
    onAttributeChange();
}

function onSelectLetterSwatch(systemRef, anchorObj) {
    document.forms["qtyForm"].elements["productLetter"].value = systemRef;
    onAttributeChange();
}

function setAttributesFromProductId(productId) {

    for (var idxProducts = 0; idxProducts < productArray.length; idxProducts = idxProducts + 1) {
        var product = productArray[idxProducts];
        if (product.productId === productId) {

            if (document.forms["qtyForm"].elements["productStyle"] != undefined) {
                onSelectStyleSwatch(product.styleSystemRef);
            }

            if (document.forms["qtyForm"].elements["productSize"] != undefined) {
                onSelectSizeSwatch(product.sizeSystemRef);
            }

            if (document.forms["qtyForm"].elements["productColor"] != undefined) {
                onSelectColorSwatch(product.colorSystemRef);
            }

            if (document.forms["qtyForm"].elements["productMetalFinish"] != undefined) {
                onSelectMetalFinishSwatch(product.metalFinishSystemRef);
            }

            if (document.forms["qtyForm"].elements["productGemStone"] != undefined) {
                onSelectGemStoneSwatch(product.gemStoneSystemRef);
            }

            if (document.forms["qtyForm"].elements["productLength"] != undefined) {
                onSelectLengthSwatch(product.lengthSystemRef);
            }

            if (document.forms["qtyForm"].elements["productCrystal"] != undefined) {
                onSelectCrystalSwatch(product.crystalSystemRef);
            }

            if (document.forms["qtyForm"].elements["productLetter"] != undefined) {
                onSelectLetterSwatch(product.letterSystemRef);
            }

            break;
        }
    }
}

function setAttributesFromSku(sku) {

    for (var idxProducts = 0; idxProducts < productArray.length; idxProducts = idxProducts + 1) {
        var product = productArray[idxProducts];
        if (product.sku === sku) {

            if (document.forms["qtyForm"].elements["productStyle"] != undefined) {
                onSelectStyleSwatch(product.styleSystemRef);
            }

            if (document.forms["qtyForm"].elements["productSize"] != undefined) {
                onSelectSizeSwatch(product.sizeSystemRef);
            }

            if (document.forms["qtyForm"].elements["productColor"] != undefined) {
                onSelectColorSwatch(product.colorSystemRef);
            }

            if (document.forms["qtyForm"].elements["productMetalFinish"] != undefined) {
                onSelectMetalFinishSwatch(product.metalFinishSystemRef);
            }

            if (document.forms["qtyForm"].elements["productGemStone"] != undefined) {
                onSelectGemStoneSwatch(product.gemStoneSystemRef);
            }

            if (document.forms["qtyForm"].elements["productLength"] != undefined) {
                onSelectLengthSwatch(product.lengthSystemRef);
            }

            if (document.forms["qtyForm"].elements["productCrystal"] != undefined) {
                onSelectCrystalSwatch(product.crystalSystemRef);
            }

            if (document.forms["qtyForm"].elements["productLetter"] != undefined) {
                onSelectLetterSwatch(product.letterSystemRef);
            }

            break;
        }
    }

}

function setSelectedProductInformation() {

    var selectedStyle = getSelectedProductAttribute("Style");
    var selectedSize = getSelectedProductAttribute("Size");
    var selectedColor = getSelectedProductAttribute("Color");
    var selectedMetalFinish = getSelectedProductAttribute("MetalFinish");
    var selectedGemStone = getSelectedProductAttribute("GemStone");
    var selectedLength = getSelectedProductAttribute("Length");
    var selectedCrystal = getSelectedProductAttribute("Crystal");
    var selectedLetter = getSelectedProductAttribute("Letter");

    var product = getSelectedProduct();

    if (document.getElementById("swatchTable" + selectedColor) != undefined) {
        document.getElementById("swatchTable" + selectedColor).className = "productCatalog-swatchBorderSelected";
    }

    if (document.getElementById("swatchTable" + selectedStyle) != undefined) {
        document.getElementById("swatchTable" + selectedStyle).className = "productCatalog-swatchBorderSelected";
    }

    if (document.getElementById("swatchTable" + selectedSize) != undefined) {
        document.getElementById("swatchTable" + selectedSize).className = "productCatalog-swatchBorderSelected";
    }

    if (document.getElementById("swatchTable" + selectedMetalFinish) != undefined) {
        document.getElementById("swatchTable" + selectedMetalFinish).className = "productCatalog-swatchBorderSelected";
    }

    if (document.getElementById("swatchTable" + selectedGemStone) != undefined) {
        document.getElementById("swatchTable" + selectedGemStone).className = "productCatalog-swatchBorderSelected";
    }

    if (document.getElementById("swatchTable" + selectedLength) != undefined) {
        document.getElementById("swatchTable" + selectedLength).className = "productCatalog-swatchBorderSelected";
    }

    if (document.getElementById("swatchTable" + selectedCrystal) != undefined) {
        document.getElementById("swatchTable" + selectedCrystal).className = "productCatalog-swatchBorderSelected";
    }

    if (document.getElementById("swatchTable" + selectedLetter) != undefined) {
        document.getElementById("swatchTable" + selectedLetter).className = "productCatalog-swatchBorderSelected";
    }

    document.forms["qtyForm"].elements["itemSku"].value = product.sku;

    if (document.getElementById("selectedItemSku")) {
        document.getElementById("selectedItemSku").innerHTML = product.sku;
    }

    if (document.getElementById("divUnitPrice")) {
        document.getElementById("divUnitPrice").innerHTML = NumberUtils.formatCurrency(product.unitPrice);
    }

    if (document.getElementById("divMeasure")) {
        document.getElementById("divMeasure").innerHTML = product.unitOfMeasure;
    }

    if (document.getElementById("divRetailPrice")) {

        document.getElementById("divRetailPrice").innerHTML = NumberUtils.formatCurrency(product.retailPrice);

        if (document.getElementById("divUnitPrice")) {
            if (Number.parseFloat(product.unitPrice) < Number.parseFloat(product.retailPrice)) {
                document.getElementById("divRetailPrice").style.visibility = "visible";
                document.getElementById("divRetailPrice").style.display = "inline";
                document.getElementById("divUnitPrice").className = "sale_price";
            } else {
                document.getElementById("divRetailPrice").style.visibility = "hidden";
                document.getElementById("divRetailPrice").style.display = "none";
                document.getElementById("divUnitPrice").className = "";
            }
        }

    }


    if (document.getElementById("divConsultantUnitPrice")) {
        document.getElementById("divConsultantUnitPrice").innerHTML = NumberUtils.formatCurrency(product.consultantUnitPrice);
    }

    if (document.getElementById("divConsultantRetailPrice") != null) {

        document.getElementById("divConsultantRetailPrice").innerHTML = NumberUtils.formatCurrency(product.consultantRetailPrice);

        if (document.getElementById("divConsultantUnitPrice")) {
            if (Number.parseFloat(product.consultantUnitPrice) < Number.parseFloat(product.consultantRetailPrice)) {
                document.getElementById("divConsultantRetailPrice").style.visibility = "visible";
                document.getElementById("divConsultantRetailPrice").style.display = "block";
            } else {
                document.getElementById("divConsultantRetailPrice").style.visibility = "hidden";
                document.getElementById("divConsultantRetailPrice").style.display = "none";
            }
        }

    }

    if (document.getElementById("divBusinessVolume") != null) {
        document.getElementById("divBusinessVolume").innerHTML = parseInt(product.unitPriceBV);
    }

    if (document.getElementById("divAddToOrder") != null) {
        if (product.isProductAvailable) {
            document.getElementById("divAddToOrder").style.visibility = "visible";
            document.getElementById("divAddToOrder").style.display = "block";
        } else {
            document.getElementById("divAddToOrder").style.visibility = "hidden";
            document.getElementById("divAddToOrder").style.display = "none";
        }

        if (product.isProductTempUnavailable) {
            document.getElementById("divItemTemporarilyUnavailable").style.visibility = "visible";
            document.getElementById("divItemTemporarilyUnavailable").style.display = "block";
        } else {
            document.getElementById("divItemTemporarilyUnavailable").style.visibility = "hidden";
            document.getElementById("divItemTemporarilyUnavailable").style.display = "none";
        }
    }

    if (window.setImage) {
        setImage();
    }
}

function getSelectedProduct() {

    var selectedStyle = getSelectedProductAttribute("Style");
    var selectedSize = getSelectedProductAttribute("Size");
    var selectedColor = getSelectedProductAttribute("Color");
    var selectedMetalFinish = getSelectedProductAttribute("MetalFinish");
    var selectedGemStone = getSelectedProductAttribute("GemStone");
    var selectedLength = getSelectedProductAttribute("Length");
    var selectedCrystal = getSelectedProductAttribute("Crystal");
    var selectedLetter = getSelectedProductAttribute("Letter");

    for (var idxProducts = 0; idxProducts < productArray.length; idxProducts = idxProducts + 1) {
        var product = productArray[idxProducts];
        if (product.styleSystemRef === selectedStyle) {
            if (product.sizeSystemRef === selectedSize) {
                if (product.colorSystemRef === selectedColor) {
                    if (product.metalFinishSystemRef === selectedMetalFinish) {
                        if (product.gemStoneSystemRef === selectedGemStone) {
                            if (product.lengthSystemRef === selectedLength) {
                                if (product.crystalSystemRef === selectedCrystal) {
                                    if (product.letterSystemRef === selectedLetter) {
                                        return product;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return "";
}

function setSelectedItemSku() {
    var objSelectedProduct = getSelectedProduct();

    if (document.getElementById("selectedItemSku")) {
        document.getElementById("selectedItemSku").innerHTML = objSelectedProduct.sku;
    }
}


function buildAllChoicesAndWatches() {
    buildStyleSwatches();
    buildColorChoices();
    buildColorSwatches();
    buildSizeChoices();
    buildSizeSwatches();
    buildMetalFinishChoices();
    buildMetalFinishSwatches();
    buildGemStoneChoices();
    buildGemStoneSwatches();
    buildLengthChoices();
    buildLengthSwatches();
    buildCrystalChoices();
    buildCrystalSwatches();
    buildLetterChoices();
    buildLetterSwatches();
}


function onAttributeChange() {
    buildAllChoicesAndWatches();
    setSelectedProductInformation();
    var selectedProduct = getSelectedProduct();

    var objAddToCart = jQuery(".addToCart");
    if (objAddToCart.length === 1) {
        objAddToCart.attr("data-reference", selectedProduct.sku);
        objAddToCart.attr("data-description", selectedProduct.name);
    }

    var objAddToCartCustomerMonthlySpecial = jQuery(".addToCartCustomerMonthlySpecial");
    if (objAddToCartCustomerMonthlySpecial.length === 1) {
        objAddToCartCustomerMonthlySpecial.attr("data-reference", selectedProduct.sku);
        objAddToCartCustomerMonthlySpecial.attr("data-description", selectedProduct.name);
    }
}