
var CUSTOMIZED_PRODUCT = true; // FLAG TO INDICATE THE PRODUCT SCREEN HOLDS A CUSTOMIZED PRODUCT

// MFP n ap 11/04/2008 - Changed IDs Against What I See In DB  
var STOCK_VINYL_ID = 1;
var STOCK_FABRIC_ID = 2;
var CUSTOM_VINYL_ID = 3;
var CUSTOM_FABRIC_ID = 4;


// --------------------------------------------------------------------------------

function SetUniqueRadioButton(nameregex, current) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            if (re.test(elm.name)) {
                elm.checked = false;
            }

        }
    }
    current.checked = true;
}


// --------------------------------------------------------------------------------

function SetHiddenFieldColorChoice(dropDownClientId, colorChoiceId) {
    var dropDown = $('#' + dropDownClientId);
    var hiddenColorChoiceField = $('#' + HiddenFieldColorChoiceArray[colorChoiceId]);
    hiddenColorChoiceField[0].value = dropDown[0].value;
}

// --------------------------------------------------------------------------------


function StandardExceptionRoutine(radioButtonControlId) {
    $('#' + radioButtonControlId).attr('checked', false);
    //$('#' + radioButtonControlId).parents('.selectioncontainer').hide();
    $('#' + radioButtonControlId).attr('disabled', 'disabled');
    $('#' + radioButtonControlId).parents('.selectioncontainer').addClass('preprod-disabled-text');
    $('#' + radioButtonControlId).parents('.selectioncontainer').children().attr('disabled', 'disabled');
}

// --------------------------------------------------------------------------------

function ShowAColorChoicePanel(colorChoicePanel) {
    // Enable DropDown
    colorChoicePanel.show();
    var dropDown = colorChoicePanel.find('select');
    dropDown.attr('disabled', '');

    colorChoicePanel.removeClass('preprod-disabled');
}


// --------------------------------------------------------------------------------

function HideAColorChoicePanel(colorChoicePanel, HiddenFieldColorChoiceArrayIndex) {
    // Clear DropDown
    var dropDown = colorChoicePanel.find('select');
    dropDown[0].value = 0;
    dropDown.attr('disabled', 'disabled');

    // Clear Div And IMG
    var divColorSelectionPreview = colorChoicePanel.find('.color-select');
    divColorSelectionPreview.css('background-color', 'white');
    divColorSelectionPreview.css('background-image', '');


    // Hide The Panel
    //colorChoicePanel.hide();
    colorChoicePanel.addClass('preprod-disabled');


    // Clear The Value Of The Hidden Field Cooresponding To This Color Choice
    HiddenFieldColorChoiceArray[HiddenFieldColorChoiceArrayIndex].value = '';

}


// --------------------------------------------------------------------------------


function SetColorChoicePanelVisibilities() {
    var colorCountSelected = -1;

    $('.preprod-colors :radio').each(
        function () {
            if ($(this).parents('.selectioncontainer').is(':visible') && this.checked) {
                colorCountSelected = parseInt($(this).parent().parent().children('.colorCount').text());
            }
        });

    if ((typeof colorCountSelected) == "undefined" || colorCountSelected == null) {
        colorCountSelected = -1;
    }

    cidx = 0;
    $.each($('.colorgroup'), function () {
        cidx++;

        if (cidx > colorCountSelected) {
            HideAColorChoicePanel($(this), cidx - 1);
        }
        else {
            //$(this).show();
            ShowAColorChoicePanel($(this));
        }
    });
}


// --------------------------------------------------------------------------------

function SetColorChoiceDropdownLists() {
    var colorTypeSelected = -1;

    // MFP 10/30/2008 - Changed Order Of Radio Buttons Against What I See In DB  
    // Figure Out Which Color Type Is Selected And Hold A Value Between 1 And 4 To Indicate Color Type
    // Globals :
    //var STOCK_FABRIC_ID = 1;
    //var STOCK_VINYL_ID = 2;
    //var CUSTOM_FABRIC_ID = 3;
    //var CUSTOM_VINYL_ID = 4;   

    cidx = 0;
    $.each($('#ColorTypes :radio'), function () {
        cidx++;

        if ($(this).attr('checked')) {
            if ($(this).attr('value') == 'RadioButtonStockFabric') {
                colorTypeSelected = STOCK_FABRIC_ID;
            }
            else if ($(this).attr('value') == 'RadioButtonStockVinyl') {
                colorTypeSelected = STOCK_VINYL_ID;
            }
            else if ($(this).attr('value') == 'RadioButtonCustomFabric') {
                colorTypeSelected = CUSTOM_FABRIC_ID;
            }
            else if ($(this).attr('value') == 'RadioButtonCustomVinyl') {
                colorTypeSelected = CUSTOM_VINYL_ID;
            }
        }
    });

    // Build Options List From Each Color Of Type = colorTypeSelected
    if (typeof (FabricList) != 'undefined') {
        var options = '<option value="0">Select Color</option>';
        var valueForOption;
        for (var i = 0; i < FabricList.length; i++) {
            if (FabricList[i].fabrictypeField == colorTypeSelected) {
                options += '<option value="' + FabricList[i].idField + '">' + FabricList[i].nameField + '</option>';
            }
        }
    }
    $('.colorgroup select').empty();
    $('.colorgroup select').append(options);

}

// --------------------------------------------------------------------------------

function ClearHiddenColorChoices() {
    // Clear All divColorSelectionPreviews and HiddenFieldColorChoiceArray memebers
    var cidx = -1
    $.each($('.color-select'), function () {
        cidx++;

        $(this).css('background-color', 'white');
        $(this).css('background-image', '');

        var hiddenColorChoiceField = $('#' + HiddenFieldColorChoiceArray[cidx]);
        hiddenColorChoiceField[0].value = "";

    });
}

// --------------------------------------------------------------------------------

function ColorSelected(dropDown, desiredColor) {
    if (dropDown != null) {
        var divColorSelectionPreview = dropDown.parents('.colorgroup').find('.color-select');

        if (desiredColor == null) { // If Desired Color Is Null - Get It From The DropDown           
            var optionTag = null;
            try {
                optionTag = dropDown.find('option:selected');
            }
            catch (e) {
            }
            desiredColor = optionTag.val();
        }


        // Find Color Object In Fabric List - The DropDown Value Holds The idField For The Desired Color
        var colorObject = null;
        $.each(FabricList, function () {

            //if ( $(this)[0].idField == dropDown[0].value )
            if (this.idField == desiredColor) {
                colorObject = this; // Match Found
            }
        });


        if (colorObject == null) // No Match Found
        {
            // Clear Div And IMG
            divColorSelectionPreview.css('background-color', 'white');
            divColorSelectionPreview.css('background-image', '');

        }
        else {
            if (colorObject.isRGBField) {
                // Set Background Color Of Div
                divColorSelectionPreview.css('background-color', colorObject.rgbHexValueField);
                divColorSelectionPreview.css('background-image', '');
            }
            else {
                // Set Image Path For IMG     
                divColorSelectionPreview.css('background-color', 'white');

                // MFP 07/30/2008 - WE DO NOT USE THE imageFileNameField field in Db
                // Instead we use a hash like FabColimgNN.jpg where NN is the Id of the Fabric            
                //divColorSelectionPreview.css('background-image', 'url(/images/FabricColorImages/' + colorObject.imageFileNameField + ')' );             

                divColorSelectionPreview.css('background-image', 'url(/images/FabricColorImages/FabColimg' + colorObject.idField + '.jpg)');

            }
        }

    }
}


// --------------------------------------------------------------------------------



