﻿// JScript File
var FOR_PURCHASE = 1
var FOR_QUOTE = 2
var FOR_QUOTE_AND_PURCHASE = 4

//Function to do totals on matrix order form
function GetTotal(txtQtyID, txtTotalID, Price) {
    try {
        var Quantity = document.getElementById(txtQtyID).value;
        var Total = parseInt(Quantity,10) * parseFloat(Price);

        //If the amount is greater than zero, display in matrix.
        if (Quantity != 0 && Price != 0 && !isNaN(Total)) {
            document.getElementById(txtTotalID).value = "$" + Total.toFixed(2);
        }
        else {
            if (isNaN(Total) && document.getElementById(txtQtyID).value != "") {
                alert("'" + Quantity + "' is not a valid quantity.");
                document.getElementById(txtQtyID).value = "";
            }
            document.getElementById(txtTotalID).value = "";
        }
    } catch (ex) {alert('Error in GetTotal: ' + ex.message); }
}

function qtyField() {
    this.fieldID = "";
    this.minQty = 0;
    this.Property1 = "";
    this.Property2 = "";
    this.getValue = function() {
        try {
            return document.getElementById(this.fieldID).value;
        } catch (ex) { alert('Error in getting quantity: ' + ex.message); }
    }
    this.checkMin = function() {
        try{
        var curVal = document.getElementById(this.fieldID).value;
        if (isNaN(curVal) || curVal == '') {
            alert("The quantity specified for the " + this.Property1 + " / " + this.Property2 + " option is not valid");
            return false;
        } else if (curVal < this.minQty) {
            alert("The " + this.Property1 + " / " + this.Property2 + " option requires a minimum quantity of " + this.minQty)
            document.getElementById(this.fieldID).value = this.minQty;
            return false
        }
        } catch (ex) { alert('Error in checking minimum quantity: ' + ex.message); }
        return true;
    }
}

function getQtyField(id, min, prop1, prop2) {
    var fieldVal = new qtyField();
    fieldVal.fieldID = id; fieldVal.minQty = min; fieldVal.Property1 = prop1; fieldVal.Property2 = prop2;
    return fieldVal;
}

function OrderFormMinQty(hdnQtyID, qtyFields){
    try{
        var MinQty = document.getElementById(hdnQtyID).value;
        MinQty = (MinQty == '') ? 0 : MinQty;
        var total = 0;
        var fieldMinFailed = false;
        if(qtyFields.length != null){
            for (i = 0; i < qtyFields.length; i++) {
                var fieldVal = qtyFields[i].getValue(); 
                if(fieldVal != '' && !isNaN(fieldVal)){
                    total += parseInt(fieldVal, 10);
                    if (!qtyFields[i].checkMin()) {fieldMinFailed = true;}
                }
            }
            if(total < MinQty)
                alert("This product requires a total quantity of " + MinQty + ".")
        }                       
        if(total < 1)
            alert("Please select at least one product.")
    }catch(e){alert('Error in minimum quantity check: ' + e.message)}
    return (total >= MinQty && total > 0 && !fieldMinFailed);
}

//object to control the functionality of a matrix child within the selectors
function SelectorMatrixProduct() {
    this.Property1Value = null;
    this.Property2Value = null;
    this.ProductID = null;
    this.QtyAvailable = 0;
    this.listPrice = 0;
    this.hasSamples = false;
    this.priceTableID = null;
    this.minimumQty = null;
    this.forceReload = false;
    this.hasFreeSamples = false;
    this.isParent = false;
    this.allowPurchase = true;
    this.allowQuote = false;
    this.allowInstantQuote = false;
    this.showAvailable = false;
    this.isExpired = false;
}


//Object to control the functionality of the matrix
function SelectorMatrix() {
    
    //fields
    this.matrixChildren = new Array();
    this.sampleButtons = null;
    this.selector1ID = null;
    this.selector1 = null;
    this.selector2ID = null;
    this.selector2 = null;
    this.selectedChildID = null;
    this.selectedChildField = null;
    
    //internal properties
    this.allowNone = false;
    this.selectedIndex = 0;
    this.selectedProperty1 = '';
    this.selectedProperty2 = '';

    //availability
    this.showAvailQty = false;
    this.visibleQuantityID = null;
    this.visibleQuantityField = null;
    this.hiddenQuantityID = null;
    this.hiddenQuantityField = null;
    this.MinQtyID = null;
    this.MinQtyField = null;
    this.MaxQtyID = null;
    this.MaxQtyField = null;
    this.ExpiredID = null;
    this.ExpiredField = null;

    //buttons...
    this.getSampleID = null;
    this.getSampleButton = null;
    this.surveySampleID = null;
    this.surveySampleButton = null;
    
    this.addToCartID = null;
    this.addToCartButton = null;
    this.surveyAddToCartID = null;
    this.surveyAddToCartButton = null;
    
    this.requestQuoteID = null;
    this.requestQuoteButton = null;
    this.surveyRequestQuoteID = null;
    this.surveyRequestQuoteButton = null;

    this.instantQuoteID = null;
    this.instantQuoteButton = null;

    //sets up a new selector object
    this.createNew = function(pbAllowNone, psSelector1ID, psSelector2ID, psSelectedID) {
        this.allowNone = pbAllowNone
        this.selector1ID = psSelector1ID;
        this.selector2ID = psSelector2ID;
        this.selectedChildID = psSelectedID;
    }
    //sets up the quantity fields
    this.setQuantityFields = function(pbShowAvailQty, psDispAvailQtyID, psHdnQtyID, psDispMinQtyID, psMaxQtyID, psExpiredID) {
        this.showAvailQty = pbShowAvailQty;
        this.visibleQuantityID = psDispAvailQtyID;
        this.hiddenQuantityID = psHdnQtyID;
        this.MinQtyID = psDispMinQtyID;
        this.MaxQtyID = psMaxQtyID;
        this.ExpiredID = psExpiredID;
    }
    //sets up the buttons on the form
    this.setButtons = function(psSampleID, psSurvSampleID, psAddID, psSurvAddID, psQuoteID, psSurvQuoteID, psInstantQuoteID) {
        this.getSampleID = psSampleID;
        this.surveySampleID = psSurvSampleID;
        this.addToCartID = psAddID;
        this.instantQuoteID = psInstantQuoteID;
        
        this.surveyAddToCartID = psSurvAddID;
        this.requestQuoteID = psQuoteID;
        this.surveyRequestQuoteID = psSurvQuoteID;
    }
    //loops through a given array of IDs (for buttons) and returns an array of object references
    this.getButtonArrayElements = function(parrIDs) {
        try {
            if (typeof parrIDs == 'undefined') { return []; }
            var arrButtons = new Array();
            var intXLoop = 0
            for (intXLoop = 0; intXLoop < parrIDs.length; intXLoop++) {            
                arrButtons[intXLoop] = document.getElementById(parrIDs[intXLoop]);
            }
            return arrButtons;
        } catch (ex) { alert('Error in getButtonArrayElements: ' + ex.message);}
    }
    //loops through an array of buttons and disables them
    this.setButtonArrayEnabled = function(parrButtons, pbolEnable) {
        try {
            var intXLoop = 0;
            if (typeof parrButtons == 'undefined') { return 0; }
            for (intXLoop = 0; intXLoop < parrButtons.length; intXLoop++)
                if(typeof parrButtons[intXLoop] != 'undefined' && parrButtons[intXLoop] !== null)
                    parrButtons[intXLoop].disabled = !pbolEnable;
        } catch (ex) { alert('Error in SetButtonArrayEnabled: ' + ex.message); }
    }
    //loops through an array of buttons and sets whether or not they are hidden
    this.setButtonArrayVisibility = function(parrButtons, pbolShow) {
        try {
            var intXLoop = 0;
            if (typeof parrButtons == 'undefined') { return 0; }
            for (intXLoop = 0; intXLoop < parrButtons.length; intXLoop++) {
                if (parrButtons[intXLoop]) {
                    parrButtons[intXLoop].style.display = (pbolShow ? '' : 'none');
                }
            }
        } catch (ex) { alert('Error in setting button visibility: ' + ex.message); }
    }
    
    //checks to see if a reference to the button has been stored and if not get it
    this.checkButtons = function() {
        if (!this.getSampleButton) { this.getSampleButton = this.getButtonArrayElements(this.getSampleID) };       
        if (!this.surveySampleButton) { this.surveySampleButton = document.getElementById(this.surveySampleID) };
        if (!this.addToCartButton) { this.addToCartButton = this.getButtonArrayElements(this.addToCartID); }
        if (!this.surveyAddToCartButton) { this.surveyAddToCartButton = document.getElementById(this.surveyAddToCartID); }
        if (!this.requestQuoteButton) { this.requestQuoteButton = this.getButtonArrayElements(this.requestQuoteID); }
        if (!this.surveyRequestQuoteButton) { this.surveyRequestQuoteButton = document.getElementById(this.surveyRequestQuoteID); }
        if (!this.instantQuoteButton) { this.instantQuoteButton = this.getButtonArrayElements(this.instantQuoteID); }
    }

    //sets up the sample buttons
    this.setSampleButtons = function(psSampleURL, psFreeURL, psSampleText, psFreeText) {
        try {
            this.sampleButtons = new ButtonDefinition()
            this.sampleButtons.init(psSampleURL, psFreeURL, psSampleText, psFreeText);
        } catch (ex) { alert('Error in Sample Button config:' + ex.message); }
    }

    //adds a matrix child to the selector controller
    this.addChild = function(psProperty1Val, psProperty2Val, plProductID, plQtyAvail, pdListPrice, pbHasSamples, psPriceTableID, plMinQty,
        pbForceReload, pbAllowPurchase, pbAllowQuote, pbAllowInstantQuote, pbHasFreeSamples, pbIsParent, pbShowAvail, pbHasExpired) {
        var idx = this.matrixChildren.length;
        this.matrixChildren[idx] = new SelectorMatrixProduct()
        this.matrixChildren[idx].Property1Value = psProperty1Val;
        this.matrixChildren[idx].Property2Value = psProperty2Val;
        this.matrixChildren[idx].ProductID = plProductID;
        this.matrixChildren[idx].QtyAvailable = plQtyAvail;
        this.matrixChildren[idx].listPrice = pdListPrice;
        this.matrixChildren[idx].hasSamples = pbHasSamples;
        this.matrixChildren[idx].priceTableID = psPriceTableID;
        this.matrixChildren[idx].minimumQty = (plMinQty > 0) ? plMinQty : 1;
        this.matrixChildren[idx].forceReload = pbForceReload;
        this.matrixChildren[idx].allowPurchase = pbAllowPurchase;
        this.matrixChildren[idx].allowQuote = pbAllowQuote;
        this.matrixChildren[idx].allowInstantQuote = pbAllowInstantQuote;
        this.matrixChildren[idx].hasFreeSamples = pbHasFreeSamples;
        this.matrixChildren[idx].isParent = pbIsParent;
        this.matrixChildren[idx].showAvailable = pbShowAvail;
        this.matrixChildren[idx].hasExpired = pbHasExpired;
    }
    
    //handles the event when the 1st selector is changed
    this.select1Changed = function() {
        try {
            var isSelected = false;
            var intCount = 0;

            if (!this.selector1) { this.selector1 = document.getElementById(this.selector1ID); }
            if (!this.selector2) { this.selector2 = document.getElementById(this.selector2ID); }
            if (!this.selectedChildField) { this.selectedChildField = document.getElementById(this.selectedChildID); }

            //undisable all dropdown lists
            this.selector1.disabled = false;
            this.selector2.disabled = false;

            //empty the dependent dropdown of all options
            for (intCount = this.selector2.options.length; intCount >= 0; intCount--)
                this.selector2.options[intCount] = null;

            //add the matching options -- if selector 1 is '', pull the parent, which is now an item.
            for (intCount = 0; intCount < this.matrixChildren.length; intCount++) {
                if ((this.matrixChildren[intCount].Property1Value == this.selector1.value) 
                    || (this.matrixChildren[intCount].isParent && this.selector1.value == '')) {
                    myEle = CreateOption(this.matrixChildren[intCount].Property2Value, this.matrixChildren[intCount].ProductID)

                    //set hidden value field
                    if (!isSelected) {
                        myEle.setAttribute("selected", "true")
                        this.selectedChildField.value = this.matrixChildren[intCount].ProductID;
                        isSelected = true;
                        this.selectedIndex = intCount;
                        this.selectedProperty1 = this.matrixChildren[intCount].Property1Value;
                        this.selectedProperty2 = this.matrixChildren[intCount].Property2Value;
                    }

                    //Add element
                    this.selector2.appendChild(myEle);
                }
            }

            //update the selection actions...
            this.setSelectedChild();
        } catch (ex) { alert('Select 1 Error: ' + ex.message); }
    }
    
    //updates the rest of the page display after the matrix child is selected
    this.setSelectedChild = function() {
        try {
            if (!this.selector1) { this.selector1 = document.getElementById(this.selector1ID); }
            if (!this.selectedChildField) { this.selectedChildField = document.getElementById(this.selectedChildID); }

            //set the quantity fields
            if (!this.visibleQuantityField) { this.visibleQuantityField = document.getElementById(this.visibleQuantityID); }
            if (!this.hiddenQuantityField) { this.hiddenQuantityField = document.getElementById(this.hiddenQuantityID); }
            if (!this.MinQtyField) { this.MinQtyField = document.getElementById(this.MinQtyID); }
            if (!this.MaxQtyField) { this.MaxQtyField = document.getElementById(this.MaxQtyID); }
            if (!this.ExpiredField) { this.ExpiredField = document.getElementById(this.ExpiredID); }

            //set the buttons
            this.checkButtons()

            //if the selected child requires a reload, lock down the buttons and reload the page
            //handle reload if required
            if (this.matrixChildren[this.selectedIndex].forceReload) {
                //lock all buttons
                try {
                    if (this.addToCartButton) { this.setButtonArrayEnabled(this.addToCartButton, false); }
                    if (this.surveyAddToCartButton) { this.surveyAddToCartButton.disabled = true; }
                    if (this.requestQuoteButton) { this.setButtonArrayEnabled(this.requestQuoteButton, false); }
                    if (this.instantQuoteButton) { this.setButtonArrayEnabled(this.instantQuoteButton, false); }
                    if (this.surveyRequestQuoteButton) { this.surveyRequestQuoteButton.disabled = true; }
                    if (this.getSampleButton) { this.setButtonArrayEnabled(this.getSampleButton, false); }
                    if (this.surveySampleButton) { this.surveySampleButton.disabled = true; }
                } catch (ex) { alert('Error in lock buttons: ' + ex.message); }
                __doPostBack(this.selector2.getAttribute('name'), 'MatrixChildChanged_' + this.selector2.value);
            }

            //set quantity fields
            try {
                //if displaying onhand qty...
                if (this.matrixChildren[this.selectedIndex].showAvailable && this.visibleQuantityField) {
                    this.visibleQuantityField.value = this.matrixChildren[this.selectedIndex].QtyAvailable;
                    this.visibleQuantityField.parentNode.parentNode.style.display = '';
                } else if (this.visibleQuantityField) {
                    this.visibleQuantityField.parentNode.parentNode.style.display = 'none';
                }
                if (this.MaxQtyField) {this.MaxQtyField.value = this.matrixChildren[this.selectedIndex].QtyAvailable}
                if (this.ExpiredField) {this.ExpiredField.value = this.matrixChildren[this.selectedIndex].hasExpired; }
                                
                //if the min qty field is visible, show min.
                if (this.MinQtyField) {
                    this.MinQtyField.value = this.matrixChildren[this.selectedIndex].minimumQty;
                }
                //if there is nothing wrong with the hidden min to be validated against on add, fill that.                
                if (this.hiddenQuantityField) {
                    this.hiddenQuantityField.value = this.matrixChildren[this.selectedIndex].minimumQty;
                }
            } catch (err) { alert('Error in setting quantities: ' + err.message); }

            //hide all existing pricing...
            try {
                for (var intCount = 0; intCount < this.matrixChildren.length; intCount++)
                    document.getElementById(this.matrixChildren[intCount].priceTableID).style.display = 'none';
                //show the selected child's price chunk
                document.getElementById(this.matrixChildren[this.selectedIndex].priceTableID).style.display = '';
            } catch (ex) {
                alert("Error in resetting displayed price: " + ex.message);
            }

            //pick up the button behavior...
            //Update the Request Sample button(s) as appropriate
            try {
                if (this.matrixChildren[this.selectedIndex].hasSamples) {
                    if (this.getSampleButton) {this.setButtonArrayVisibility(this.getSampleButton, true); }
                    if (this.surveySampleButton) { this.surveySampleButton.style.display = '' };
                    //set the text/image of the buttons...
                    if (this.matrixChildren[this.selectedIndex].hasFreeSamples) {
                        this.sampleButtons.setFreeButton(this.getSampleButton)
                        this.sampleButtons.setFreeButton(this.surveySampleButton)
                    } else {
                        this.sampleButtons.setRegularButton(this.getSampleButton)
                        this.sampleButtons.setRegularButton(this.surveySampleButton)
                    }
                } else {
                    if (this.getSampleButton) { this.setButtonArrayVisibility(this.getSampleButton, false) }
                    if (this.surveySampleButton) { this.surveySampleButton.style.display = 'none' };
                }
            } catch (ex) { alert('Error in setSampleButton: ' + ex.message); }

            //Update the Add to Cart button(s) as appropriate
            try {
                if (this.matrixChildren[this.selectedIndex].allowPurchase) {
                    if (this.addToCartButton) { this.setButtonArrayVisibility(this.addToCartButton, true); }
                    if (this.surveyAddToCartButton) { this.surveyAddToCartButton.style.display = ''; }
                } else {
                    if (this.addToCartButton) { this.setButtonArrayVisibility(this.addToCartButton, false); }
                    if (this.surveyAddToCartButton) { this.surveyAddToCartButton.style.display = 'none'; }
                }
            } catch (ex) { alert('Error in setAddButton: ' + ex.message); }

            //update teh Request Quote button(s) as approprite
            try {
                if (this.matrixChildren[this.selectedIndex].allowQuote) {
                    if (this.requestQuoteButton) { this.setButtonArrayVisibility(this.requestQuoteButton, true) }
                    if (this.surveyRequestQuoteButton) { this.surveyRequestQuoteButton.style.display = ''; }
                } else {
                    if (this.requestQuoteButton) { this.setButtonArrayVisibility(this.requestQuoteButton, false); }
                    if (this.surveyRequestQuoteButton) { this.surveyRequestQuoteButton.style.display = 'none'; }
                }
            } catch (ex) { alert('Error in setQuoteButton: ' + ex.message); }
            
            if (this.matrixChildren[this.selectedIndex].allowInstantQuote) {
                if (this.instantQuoteButton) { this.setButtonArrayVisibility(this.instantQuoteButton, true); }
            } else {
                if (this.instantQuoteButton) { this.setButtonArrayVisibility(this.instantQuoteButton, false); }
            }
        } catch (ex) { alert('Error in SetSelectedChild: ' + ex.message); }
    }


    //handles the event when the 2nd selector is changed
    this.select2Changed = function() {
        if (!this.selector1) { this.selector1 = document.getElementById(this.selector1ID); }
        if (!this.selectedChildField) { this.selectedChildField = document.getElementById(this.selectedChildID); }
        //rip through all of the possible matrix children and find the one whose ID matches the selected value for the dropdown
        if (!this.selector2) { this.selector2 = document.getElementById(this.selector2ID); }
        for (var intCount = 0; intCount < this.matrixChildren.length; intCount++) {
            if (this.matrixChildren[intCount].ProductID == this.selector2.value) {
                this.selectedChildField.value = this.matrixChildren[intCount].ProductID;
                this.selectedIndex = intCount;
                this.selectedProperty1 = this.matrixChildren[intCount].Property1Value;
                this.selectedProperty2 = this.matrixChildren[intCount].Property2Value;
            }
        }
        //set up the page for the new selected matrix child...
        this.setSelectedChild();
    }
    
}






function CreateOption(text, value) {
    var retVal = document.createElement("option");
    retVal.setAttribute("value", value);
    var txt = document.createTextNode(text);
    retVal.appendChild(txt);
    return retVal;
}


//defines a sample button
function ButtonDefinition(){
    this.regImg = null;
    this.freeImg = null;
    this.regText = null;
    this.freeText = null;
    
    this.isOK = function () {return typeof(this.regImg) != 'nothing' && typeof(this.freeImg) != 'nothing' && this.regText != '' && this.freeText != ''}    
    this.init = function (regSrc, freeSrc, regTxt, freeTxt) {
        this.regImg = new Image;
        this.regImg.src = regSrc;
        this.freeImg = new Image;
        this.freeImg.src = freeSrc;
        this.regText = regTxt;
        this.freeText = freeTxt;
    }
    this.setFreeButton = function(poButton) {
        try {
            if (poButton) {
                if (poButton.length) {
                    var intXLoop = 0;
                    for (intXLoop = 0; intXLoop < poButton.length; intXLoop++)
                        if (poButton[intXLoop]) {
                            poButton[intXLoop].src = this.freeImg.src;
                            poButton[intXLoop].setAttribute("alt", this.freeText);}
                } else {
                    poButton.src = this.freeImg.src;
                    poButton.setAttribute("alt", this.freeText);
                }
            }
        } catch (ex) { alert('Error in setFreeButton: ' + ex.message) }
    }
    this.setRegularButton = function(poButton) {
        try {
            if (poButton) {
                if (poButton.length) {
                    var intXLoop = 0
                    for (intXLoop = 0; intXLoop < poButton.length; intXLoop++) 
                        if(poButton[intXLoop]){
                            poButton[intXLoop].src = this.regImg.src;
                            poButton[intXLoop].setAttribute("alt", this.regText);}
                } else {
                    poButton.src = this.regImg.src;
                    poButton.setAttribute("alt", this.regText);
                }
            }
        } catch (ex) { alert('Error in setRegularButton: ' + ex.message) }
    }
}

//Object for Price Levels in order form
function PriceLevel(){
    this.lowerBound = 0
    this.upperBound = 0
    this.price = 0
}

//Creates a new price level object so that it can be added in one tidy line.
function GenerateLevel(intLowerBound, intUpperBound, dblPrice){
    var newLevel = new PriceLevel();
    newLevel.lowerBound = intLowerBound;
    newLevel.upperBound = intUpperBound;
    newLevel.price = dblPrice;
    return newLevel;
}

//Object to wrap an entire set of pricelevels
function PriceLevels(){
    this.productID = 0
    this.arrLevels = new Array();
    this.addLevel = pl_AddLevel;
    this.getPrice = pl_GetPrice;
}

//Member function for the Price Levels object.
//Adds a price level to the array inside the Price Levels object
function pl_AddLevel(PriceLevel){
    this.arrLevels[this.arrLevels.length] = PriceLevel
}

//Member function of the Price Levels object.
//Looks up a price from the Price Levels based on the quantity.
function pl_GetPrice(qty){
    try{
        var intLvlCount=0;
        if(this.arrLevels.length > 0){
            if(qty < this.arrLevels[0].lowerBound)
                return this.arrLevels[0].price
            for(intLvlCount=0;intLvlCount<this.arrLevels.length;intLvlCount++){
                if(this.arrLevels[intLvlCount].lowerBound <= qty && (isNaN(this.arrLevels[intLvlCount].upperBound) || this.arrLevels[intLvlCount].upperBound >= qty))
                    return this.arrLevels[intLvlCount].price
            }
            return this.arrLevels[this.arrLevels.length-1].price
        }else{
            return 0;
        }
    }catch(e){
        alert(e.message);
    }
    //Failure state; return nothing
    return 0;
}

//swaps out the order forms for the hybrid style
function hybridSwap(selVal, arrTables){
    try{
        var i=0;
        var reClean = /[^A-Za-z0-9]/g;
        for(i=0;i<arrTables.length;i++){
            var tblIdParts = arrTables[i].split("_");
            if(tblIdParts[tblIdParts.length -1] == selVal.replace(reClean,""))
                document.getElementById(arrTables[i]).style.display = '';
            else
                document.getElementById(arrTables[i]).style.display = 'none';                
        }
    }catch(err){alert(err.message);}
}

//Verifies that a product has been selected from the matrix property dropdowns
function verifyMatrixSelected(Property1ID, Property2ID, LabelID) {
    var bolProdSelected = true;
    try {
        var Property1Selector = $('#' + Property1ID);
        var Property2Selector = $('#' + Property2ID);
        var lblDisplay = $('#' + LabelID);
        var errMsg = ""
        
        if (Property1Selector.val() == '') {
            var PropertyName = Property1Selector.parent().prev().children('span').html()
            errMsg = PropertyName + '<br />'
            bolProdSelected = false;
        }
        if (Property2Selector.val() == '') {
            var PropertyName = Property2Selector.parent().prev().children('span').html()
            errMsg = errMsg + PropertyName + '<br />'
            bolProdSelected =false
        }

        if (!bolProdSelected) {
            lblDisplay.html(errMsg)
            var pnlPop = lblDisplay.parent()
            pnlPop.dialog({ modal: true, resizable: false });

            lblDisplay.next().bind('click', function(evt) {
                $(evt.target).parent().parent().dialog('destroy');
            })                       
        }
    } catch (err) {alert(err.message);}
    return bolProdSelected;
}
