﻿var printDescription = document.getElementById('printDescription');
var fabricImage = document.getElementById('fabricImage');
var fabricDescription = document.getElementById('fabricDescription');
var discountCell = document.getElementById('discountCell');

OnEmbroidery(embroideryCellID, embroideryCheckboxID);
OnPrintSelection();

// Gallery Selection
function OnSelect(selectDescription) {

    OnTabSelection(0);

    document.forms[0].scrollIntoView();

    for (var index = 0; index < printList.length; index++) {
        if (printList.options[index].innerHTML == selectDescription) {
            printList.selectedIndex = index;
            break;
        }
    }

    OnPrintSelection();
}

// Print Selection from Combo Box
function OnPrintSelection() {

    var inventoryDetails = printList.options[printList.selectedIndex].value;

    printDescription.innerHTML = printList.options[printList.selectedIndex].innerHTML;
    fabricDescription.innerHTML = GetFabricDescription(inventoryDetails);
    fabricImage.src = GetImageFileName(inventoryDetails);

    printDetailTextBox.value = inventoryDetails;
    printDescriptionTextBox.value = printDescription.innerHTML;

    DefineAvailableQuantity();

    var discount = Discount(inventoryDetails);

    if (discount == 1) {
        discountCell.innerHTML = "<img alt='close out' style='height:28px;' src='../../Images/CloseOutLarge.png' />";
    }
    else if (discount == 2) {
        discountCell.innerHTML = "<img alt='special deal' style='height:28px;' src='../../Images/SpecialDealHats.png' />";
    }
    else if (discount == 3) {
        discountCell.innerHTML = "<img alt='limit qty sale' style='height:28px;' src='../../Images/LimitedQtyLarge.png' />";
    }
    else {
        discountCell.innerHTML = "";
    }
}

function DefineAvailableQuantity() {
    var inventoryDetails = printList.options[printList.selectedIndex].value;
    var qtyAvailable = GetAvailableQuantity(inventoryDetails);

    quantityList.options.length = 0;

    for (var qty = 1; qty <= qtyAvailable; qty++) {
        quantityList.options.add(new Option(qty));
    }
}

