
var prdSelArr = new Array();

function prdSel(pProductId, isMainProduct) {
    this.productId = pProductId;
    this.prodSelector = new ProdSelector();
    this.prodList = new Array();
    this.sizeList = new Array();
    this.colorList = new Array();
    this.isMainProduct = isMainProduct;


    this.addProduct = function (pPrd) {
        this.prodList.push(pPrd);
        this.addColor(pPrd.colorCode, pPrd.colorName);
    }

    this.addSize = function (pSize) {
        this.sizeList.push(pSize);
    }

    this.addColor = function (pColorCode, pColorName) {
        if (!this.containsColorCode(pColorCode)) {
            this.colorList.push(new Color(pColorCode, pColorName));
        }
    }

    this.containsColorCode = function (pColorCode) {
        for (var i = 0; i < this.colorList.length; i++) {
            if (this.colorList[i].colorCode == pColorCode) {
                return true;
            }
        }
        return false;
    }

    this.getColorName = function (pColorCode) {
        if (pColorCode != null) {
            for (var i = 0; i < this.colorList.length; i++) {
                if (this.colorList[i].colorCode == pColorCode) {
                    return this.colorList[i].colorName;
                }
            }
        }
        return null;
    }

    this.initialize = function () {
        this.prodSelector.initialize(this.prodList, this.sizeList, "");
    }

    this.setSelectedColorCode = function (pSelectedColor) {
        if (isEmpty(pSelectedColor)) {
            this.prodSelector.mSelectedColorCode = this.prodSelector.mAvailableColorCodes[0];
            this.prodSelector.initializeAvailableSizes(this.prodSelector.mSelectedColorCode, this.prodSelector.mSelectedSizeType);
            this.prodSelector.initializeDefaultSelectedSize();
        }
        else {
            this.prodSelector.mSelectedColorCode = pSelectedColor;
            this.prodSelector.initializeAvailableSizes(this.prodSelector.mSelectedColorCode, this.prodSelector.mSelectedSizeType);
            this.prodSelector.initializeDefaultSelectedSize();

        }
    }

    this.setSelectedSizeType = function (pSelectedSizeType) {
        this.prodSelector.mSelectedSizeType = pSelectedSizeType;
        this.prodSelector.initializeAvailableColors(this.prodSelector.mSelectedSizeType);
        this.prodSelector.initializeDefaultSelectedColor();
        this.prodSelector.initializeAvailableSizes(this.prodSelector.mSelectedColorCode, this.prodSelector.mSelectedSizeType);
        this.prodSelector.initializeDefaultSelectedSize();

    }

    this.setSelectedSizeName = function (pSelectedSizeName) {
        this.prodSelector.mSelectedSizeName = pSelectedSizeName;

    }

    this.repopulateSizeTypes = function () {
        for (var i = 0; i < this.prodSelector.mAvailableSizeTypes.length; i++) {

            if (this.prodSelector.mAvailableSizeTypes[i] != "") {
                if (this.prodSelector.mAvailableSizeTypes[i] == this.prodSelector.mSelectedSizeType) {
                    if (getElement("sizetype" + this.productId + this.prodSelector.mAvailableSizeTypes[i]) != null) {
                        getElement("sizetype" + this.productId + this.prodSelector.mAvailableSizeTypes[i]).className = "active";
                    }

                } else {
                    if (getElement("sizetype" + this.productId + this.prodSelector.mAvailableSizeTypes[i]) != null) {
                        getElement("sizetype" + this.productId + this.prodSelector.mAvailableSizeTypes[i]).className = "";
                    }
                }
            }
        }
    }


    this.repopulateSizes = function (isMainProduct) {
        var modifiedProductId = this.productId;
        if (isMainProduct != null & isMainProduct == "true") {
            modifiedProductId = "l" + this.productId;
        }

        for (var i = 0; i < this.prodSelector.mAllSizes.length; i++) {
            var currentPrd = this.prodSelector.getProd(this.prodSelector.mAllSizes[i]);
            if (getElement("size" + modifiedProductId + this.prodSelector.mAllSizes[i]) != null) {
                if (this.prodSelector.isAvailableSize(this.prodSelector.mAllSizes[i]) && currentPrd != null) {
                    if (this.prodSelector.mAllSizes[i] == this.prodSelector.mSelectedSizeName) {
                        ////Added new visibility parameter for  Rose. If "true" then hide.
                        getElement("size" + modifiedProductId + this.prodSelector.mAllSizes[i]).innerHTML = "<a class=\"sizeButton selectedSizeButton\" href=\"javascript:putSelectedSize(\'" + (i + 1) + "\',\'" + this.productId + "\',\'" + replaceAll(this.prodSelector.mAllSizes[i]) + "\',\'" + isMainProduct + "\',\'" + "true" + "\')\">" + this.prodSelector.mAllSizes[i] + "</a>";
                    }
                    else if (currentPrd.availabilityStatus == this.prodSelector.AVAILABILITY_STATUS_DISCONTINUED || currentPrd.availabilityStatus == this.prodSelector.STATUS_OUT_OF_STOCK) {
                        getElement("size" + modifiedProductId + this.prodSelector.mAllSizes[i]).innerHTML = "<span class=\"sizeButton notavailableSizeButton\">" + this.prodSelector.mAllSizes[i] + "</span>";
                    }
                    else {
                        ////Added new visibility parameter for  Rose. If "true" then hide.
                        getElement("size" + modifiedProductId + this.prodSelector.mAllSizes[i]).innerHTML = "<a class=\"sizeButton availableSizeButton\" href=\"javascript:putSelectedSize(\'" + (i + 1) + "\',\'" + this.productId + "\',\'" + replaceAll(this.prodSelector.mAllSizes[i]) + "\',\'" + isMainProduct + "\',\'" + "true" + "\')\">" + this.prodSelector.mAllSizes[i] + "</a>";

                    }
                }
                else {
                    getElement("size" + modifiedProductId + this.prodSelector.mAllSizes[i]).innerHTML = "";
                }
            }
        }
    }


    function HideDivGeneral(object, val) {
        document.getElementById("ListDiv").style.visibility = val;
    }


    function replaceAll(oldStr) {
        var findStr = "'";
        var repStr = "\\'";

        var srchNdx = 0;
        var newStr = "";
        while (oldStr.indexOf(findStr, srchNdx) != -1) {
            newStr += oldStr.substring(srchNdx, oldStr.indexOf(findStr, srchNdx));
            newStr += repStr;
            srchNdx = (oldStr.indexOf(findStr, srchNdx) + findStr.length);
        }
        newStr += oldStr.substring(srchNdx, oldStr.length);
        return newStr;
    }

    this.repopulateAll = function (isMainProduct) {
        var modifiedProductId = this.productId;
        if (isMainProduct != null & isMainProduct == "true") {
            modifiedProductId = "l" + this.productId;
        }

        this.repopulateSizeTypes();

        this.repopulateSizes(isMainProduct);
        var colorName = this.getColorName(this.prodSelector.mSelectedColorCode);
        if (colorName != null) {
            if (getElement(modifiedProductId + "selectedColor") != null) {
                getElement(modifiedProductId + "selectedColor").innerHTML = colorName;
            }
            if (getElement("ContentPlaceHolder1_" + modifiedProductId + "selectedColor") != null) {
                getElement("ContentPlaceHolder1_" + modifiedProductId + "selectedColor").innerHTML = colorName;
            }

            if (getElement(this.productId + "selColor") != null) {
                getElement(this.productId + "selColor").innerHTML = colorName;
            }
        }
        else {
            if (getElement(modifiedProductId + "selectedColor") != null) {
                getElement(modifiedProductId + "selectedColor").innerHTML = "";
            }
            if (getElement("ContentPlaceHolder1_" + modifiedProductId + "selectedColor") != null) {
                getElement("ContentPlaceHolder1_" + modifiedProductId + "selectedColor").innerHTML = "";
                //getElement("ctl00_ContentPlaceHolder1_" + modifiedProductId + "selectedColor").innerHTML = colorName.toUpperCase();
            }

            if (getElement(this.productId + "selColor") != null) {
                getElement(this.productId + "selColor").innerHTML = "";
            }
        }

        if (this.prodSelector.mSelectedSizeName != null) {
            if (getElement(this.productId + "selectedSize") != null) {
                getElement(this.productId + "selectedSize").innerHTML = ReplaceIfNeeded(this.prodSelector.mSelectedSizeName);
            }

            if (getElement("ContentPlaceHolder1_" + this.productId + "selectedSize") != null) {
                getElement("ContentPlaceHolder1_" + this.productId + "selectedSize").innerHTML = ReplaceIfNeeded(this.prodSelector.mSelectedSizeName);
            }

            if (getElement(this.productId + "selSize")) {
                getElement(this.productId + "selSize").innerHTML = "SIZE" + " " + this.prodSelector.mSelectedSizeName;
            }
        } else {
            if (getElement(this.productId + "selectedSize") != null) {
                getElement(this.productId + "selectedSize").innerHTML = "No Size Selected";
            }

            if (getElement("ContentPlaceHolder1_" + this.productId + "selectedSize") != null) {
                getElement("ContentPlaceHolder1_" + this.productId + "selectedSize").innerHTML = "No Size Selected";
            }

            if (getElement(this.productId + "selSize")) {
                getElement(this.productId + "selSize").innerHTML = "No Size Selected";
            }
        }


        if (getElement(this.productId + "selType") != null) {
            if (this.prodSelector.mSelectedSizeType != null) {
                if (this.prodSelector.mSelectedSizeName != null) {
                    if (this.prodSelector.mAvailableSizeTypes.length > 1) {
                        getElement(this.productId + "selType").innerHTML = "," + " " + this.prodSelector.mSelectedSizeType;

                    }
                    else if (this.prodSelector.mAvailableSizeTypes.length == 1) {
                        if (this.prodSelector.mSelectedSizeType == "regular") {
                            getElement(this.productId + "selType").innerHTML = "";
                        }
                        else {
                            getElement(this.productId + "selType").innerHTML = "," + " " + this.prodSelector.mSelectedSizeType;
                        }
                    }
                    else {
                        getElement(this.productId + "selType").innerHTML = "";
                    }
                }
                else {
                    getElement(this.productId + "selType").innerHTML = "";
                }
            } else {

                getElement(this.productId + "selType").innerHTML = "";
            }
        }

        if (this.prodSelector.getSelectedProd() != null
			&& (getElement(this.productId + "selectBox") == null
				|| getElement(this.productId + "selectBox").checked)) {

            var selectedSku = this.prodSelector.getSelectedProd();

        }
    }
}

function getPrdSel(pProductId, createNew, pIsLeaderProduct) {
    for (var i = 0; i < prdSelArr.length; i++) {
        if (prdSelArr[i].productId == pProductId && prdSelArr[i].isMainProduct == pIsLeaderProduct) {
            return prdSelArr[i];
        }
    }

    if (createNew) {
        prdSelArr.push(new prdSel(pProductId, pIsLeaderProduct));
        return prdSelArr[prdSelArr.length - 1];
    } else {

        return null;
    }

}

function addProduct(pProductId, prd, pIsLeaderProduct) {
    var prdSel = getPrdSel(pProductId, true, pIsLeaderProduct);
    prdSel.addProduct(prd);
}

function addSize(pProductId, size, pIsLeaderProduct) {
    var prdSel = getPrdSel(pProductId, true, pIsLeaderProduct);
    prdSel.addSize(size);
}

function initializeProduct(productId, colorCode, pIsLeaderProduct) {
    var prdSel = getPrdSel(productId, true, pIsLeaderProduct);
    prdSel.prodSelector.mSelectedColorCode = colorCode;
    prdSel.initialize();
}

function loadSelSize(imgElem, pProductId, pColorCode, prodImg, pPrdId, pColorName, isMainProduct) {
    if (getElement("ProductSizes") != null && getElement("ProductSizes").length == 2) {
        getElement("ProductSizes").selectedIndex = 1;
    }
}

function putSelColor(imgElem, pProductId, pColorCode, prodImg, pPrdId, pColorName, isMainProduct) {
    var prdSel = getPrdSel(pProductId, false, isMainProduct);
    g_color = prodImg;

    var prImage = document.images['ProductImage'];
    if (prImage != null) {
        document.images['ProductImage'].src = "/store/productimages/regular/" + aColor[prodImg];
    } else {
        document.images['ContentPlaceHolder1_ProductImage'].src = "/store/productimages/regular/" + aColor[prodImg];
    }

    reload_sizes();

    var pc = document.getElementById("ProductColors");
    if (pc != null) {
        document.getElementById("ProductColors").selectedIndex = prodImg;
    } else {
        document.getElementById("ContentPlaceHolder1_ProductColors").selectedIndex = prodImg;
    }

    change_upc();
    change_extragroup();
    change_unitcost();
    change_previouscost();
    change_costspans();
    change_zoom(aColor[prodImg], "/store/productimages/regular/", "/store/productimages/details/");
    change_stockalert();


    var quicklookzoom = getElementByID_Master("ZoomImage");

    if (quicklookzoom != null) {
        try {
            var img = aColor[prodImg];
            img = "/store/productimages/details/" + img.replace(".jpg", "_z.jpg");
            quicklookzoom.href = img;
        }
        catch (err) { }
    }

    try { setElem("AddToCartMessage", ""); }
    catch (err) { }

    if (prdSel != null) {
        prdSel.setSelectedColorCode(pColorCode);
        initializeAllProducts(isMainProduct);

    }
    changeColor(pProductId, pColorCode, prodImg, pPrdId, pColorName, isMainProduct);
    imgClicked(imgElem.id, imgElem);
}

function setSelectedType(pProductId, pSizeType, isMainProduct) {
    var prdSel = getPrdSel(pProductId, false, isMainProduct);
    if (prdSel != null) {
        prdSel.setSelectedSizeType(pSizeType);
        initializeAllProducts(isMainProduct);
    }
}

function putSelectedSize(pInd, pProductId, pSizeName, isMainProduct, closeWindow) {


    var ps = document.getElementById("ProductSizes");

    if (ps != null) {
        ps = document.getElementById("ProductSizes");
    } else {
        ps = document.getElementById("ContentPlaceHolder1_ProductSizes");
    }

    for (var i = 0; i <= ps.length - 1; i = i + 1) {
        var ddlText = ps.options[i].text;
        if (ddlText == pSizeName) {
            ps.selectedIndex = i;
            change_size(pInd)
            break;
        }

    }

    change_stockalert();
    var prdSel = getPrdSel(pProductId, false, isMainProduct);

    if (prdSel != null) {
        prdSel.setSelectedSizeName(pSizeName);
        initializeAllProducts(isMainProduct);
    }

    try {
        setElem("AddToCartMessage", "");
    } catch (err) { }


    /*Taryn Rose visibility code change Start*/
    var productSizeHolder = document.getElementById("SizeSubMenuDiv");
    if ((closeWindow != null) && (productSizeHolder != null) && (closeWindow == "true")) {
        productSizeHolder.style.visibility = "hidden";
        productSizeHolder.style.backgroundColor = "#000000";
        var SelectSizeListItem = document.getElementById('SelectSizeListItem');
        if (SelectSizeListItem != null) {
            SelectSizeListItem.style.backgroundColor = "#000000";
        }
    }
    else if (productSizeHolder != null) {
        productSizeHolder.style.visibility = "visible";
    }


}

/*Taryn Rose visibility code change End*/
//Show Div
function ShowSizeSubMenuDiv() {
    obj = document.getElementById('SizeSubMenuDiv');
    if (obj != null) {
        obj.style.visibility = 'visible';
        var SelectSizeListItem = document.getElementById('SelectSizeListItem');
        if (SelectSizeListItem != null) {
            SelectSizeListItem.style.backgroundColor = "#000000";
        }
    }
}



function setSelectedSizeForShopBySize(pProductId, pSizeName, pSizeName1, isMainProduct) {
    var prdSel = getPrdSel(pProductId, false, isMainProduct);
    if (prdSel != null) {
        if (prdSel.prodSelector.isAvailableSize(pSizeName)) {
            prdSel.setSelectedSizeName(pSizeName);
            initializeAllProducts(isMainProduct);
        }
        else if (prdSel.prodSelector.isAvailableSize(pSizeName1)) {
            prdSel.setSelectedSizeName(pSizeName1);
            initializeAllProducts(isMainProduct);
        }
        else { }
    }
}

function initializeAllProducts(isMainProduct) {
    var prdSelected = false;
    var sizeSelect = false;
    var boxSelected = false;
    var checkBox = true;

    for (var i = 0; i < prdSelArr.length; i++) {
        prdSelArr[i].repopulateAll(isMainProduct);

        if (prdSelArr[i].prodSelector.getSelectedProd() != null) {
            if (getElement(prdSelArr[i].productId + "selectBox") != null) {
                if (getElement(prdSelArr[i].productId + "selectBox").checked) {
                    prdSelected = true;
                }
            } else {
                sizeSelect = true;
                prdSelected = true;
            }
        } else {
            if (getElement(prdSelArr[i].productId + "selectBox") != null) {
                if (getElement(prdSelArr[i].productId + "selectBox").checked) {
                    boxSelected = true;
                    checkBox = false;
                }
            } else {
                sizeSelect = true;
            }
        }
    }

}

function ProdSelector() {

    this.STATUS_IN_STOCK = 1;
    this.STATUS_OUT_OF_STOCK = 0;

    this.contextPath = "";
    this.prds = null;
    this.mSelectedColorCode = null;
    this.mSelectedSizeType = null;
    this.mSelectedSizeName = null;
    this.mAvailableColorCodes = null;
    this.mAvailableSizeTypes = null;
    this.mAvailableSizes = null;
    this.mAllSizes = null;

    this.initialize = function (prodList, sizeList, path) {
        this.prds = prodList;
        this.mAllSizes = sizeList;
        this.contextPath = path;

        this.initializeAvailableSizeTypes();
        this.initializeDefaultSelectedSizeType();
        this.initializeAvailableColors(this.mSelectedSizeType);
        this.initializeDefaultSelectedColor();
        this.initializeAvailableSizes(this.mSelectedColorCode,
				this.mSelectedSizeType);
        this.initializeDefaultSelectedSize();
    }


    this.initializeAvailableSizeTypes = function () {
        this.mAvailableSizeTypes = new Array();
        var index = 0;
        for (var i = 0; i < this.prds.length; i++) {
            var currentPrd = this.prds[i];
            if (this.mAvailableSizeTypes, this.prds[i].type != "" && !contains(this.mAvailableSizeTypes, this.prds[i].type)) {
                this.mAvailableSizeTypes[index] = this.prds[i].type;
                index++;
            }
        }
        this.mAvailableSizeTypes.sort();
        this.sortSizeTypes(this.mAvailableSizeTypes);
    }

    this.sortSizeTypes = function (array) {
        if (contains(array, "regular") && contains(array, "petite")) {
            var temp = array[0];
            array[0] = array[1];
            array[1] = temp;
        }
    }

    this.initializeDefaultSelectedSizeType = function () {

        if (isEmpty(this.mSelectedSizeType)) {
            this.mSelectedSizeType = this.mAvailableSizeTypes[0];
        } else {
            var currentSelectedSizeTypeIsAvaiable = false;
            for (var i = 0; i < this.mAvailableSizeTypes.length; i++) {
                var sizeType = this.mAvailableSizeTypes[i];
                if (sizeType == this.mSelectedSizeType) {
                    currentSelectedSizeTypeIsAvaiable = true;
                    break;
                }
            }
            if (!currentSelectedSizeTypeIsAvaiable) {
                this.mSelectedSizeType = this.mAvailableSizeTypes[0];
            }
        }
    }

    this.initializeAvailableColors = function (pSizeType) {

        this.mAvailableColorCodes = new Array();
        var index = 0;
        for (var i = 0; i < this.prds.length; i++) {
            var currentPrd = this.prds[i];
            //if (currentPrd.type == pSizeType) {
            if (this.mAvailableColorCodes, currentPrd.colorCode != "" && !contains(this.mAvailableColorCodes, currentPrd.colorCode)) {
                this.mAvailableColorCodes[index] = currentPrd.colorCode;
                index++;
            }
            //}
        }
    }

    this.initializeDefaultSelectedColor = function () {

        if (isEmpty(this.mSelectedColorCode)) {
            this.mSelectedColorCode = this.mAvailableColorCodes[0];
        } else {
            var selectedColorIsPresentInAvailableColors = false;

            for (var i = 0; i < this.mAvailableColorCodes.length; i++) {
                var color = this.mAvailableColorCodes[i];
                if (color == this.mSelectedColorCode) {
                    selectedColorIsPresentInAvailableColors = true;
                    break;
                }
            }
            if (!selectedColorIsPresentInAvailableColors) {

                this.mSelectedColorCode = this.mAvailableColorCodes[0];
            }
        }
    }

    this.initializeAvailableSizes = function (pSelectedColor, pSelectedSizeType) {

        this.mAvailableSizes = new Array();
        var index = 0;

        for (var i = 0; i < this.prds.length; i++) {
            var currentPrd = this.prds[i];
            //if ((currentPrd.type == pSelectedSizeType) && (currentPrd.colorCode == pSelectedColor)) {
            if (this.mAvailableSizes, currentPrd.sizeName != "" && !contains(this.mAvailableSizes, currentPrd.sizeName)) {
                this.mAvailableSizes[index] = currentPrd.sizeName;
                index++;
            }
            //}
        }

    }

    this.initializeDefaultSelectedSize = function () {
        availableSizesinSizeType = new Array();
        for (var i = 0; i < this.mAvailableSizes.length; i++) {
            var sizeName1 = this.mAvailableSizes[i];
            if (this.getProd(this.mAvailableSizes[i]) != null && (this.getProd(this.mAvailableSizes[i]).availabilityStatus == this.STATUS_IN_STOCK || this.getProd(this.mAvailableSizes[i]).availabilityStatus == this.AVAILABILITY_STATUS_BACKORDERABLE)) {
                if (getElement("DisableOneSizeSelection") == null || (getElement("DisableOneSizeSelection") != null && getElement("DisableOneSizeSelection").value != 1)) {
                    availableSizesinSizeType.push(sizeName1);
                }
            }
        }

        if (availableSizesinSizeType.length == 1) {
            this.mSelectedSizeName = availableSizesinSizeType[0];


        }
        else {
            for (var i = 0; i < this.mAvailableSizes.length; i++) {
                var sizeName = this.mAvailableSizes[i];
                if (sizeName == this.mSelectedSizeName) {
                    if (this.getProd(this.mAvailableSizes[i]) != null && (this.getProd(this.mAvailableSizes[i]).availabilityStatus == this.STATUS_IN_STOCK || this.getProd(this.mAvailableSizes[i]).availabilityStatus == this.AVAILABILITY_STATUS_BACKORDERABLE)) {
                        return;
                    }
                }
            }
            this.mSelectedSizeName = null;


        }
    }

    this.getSelectedProd = function () {
        for (var i = 0; i < this.prds.length; i++) {
            var prd = this.prds[i];
            if (prd.colorCode != '' && prd.sizeName != '') {
                if ((prd.colorCode == this.mSelectedColorCode)
					&& (prd.sizeName == this.mSelectedSizeName)
						&& (prd.type == this.mSelectedSizeType)) {
                    return prd;
                }
            } else if (prd.colorCode == '' && prd.sizeName != '') {
                if ((prd.sizeName == this.mSelectedSizeName)
						&& (prd.type == this.mSelectedSizeType)) {
                    return prd;
                }
            } else if (prd.colorCode != '' && prd.sizeName == '') {
                if (prd.colorCode == this.mSelectedColorCode) {
                    return prd;
                }
            } else {
                return prd;
            }
        }
        return null;
    }

    this.getProd = function (pSizeName) {

        for (var i = 0; i < this.prds.length; i++) {
            var prd = this.prds[i];
            if (this.mSelectedColorCode != null) {
                if ((prd.colorCode == this.mSelectedColorCode)
					&& (prd.sizeName == pSizeName)
						&& (prd.type == this.mSelectedSizeType)) {

                    return prd;
                }
            } else {
                if ((prd.sizeName == pSizeName)
						&& (prd.type == this.mSelectedSizeType)) {

                    return prd;
                }
            }
        }
        return null;
    }

    this.getColorName = function (pColorCode) {
        for (var i = 0; i < this.prds.length; i++) {
            var prd = this.prds[i];
            if (prd.colorCode == pColorCode) {
                return prd.colorName;
            }
        }
        return null;
    }

    this.isAvailableSize = function (pSizeName) {
        for (var i = 0; i < this.mAvailableSizes.length; i++) {
            if (this.mAvailableSizes[i] == pSizeName) {
                return true;
            }
        }
        return false;
    }
}

function Prd(pPrdId, pSizeName, pType, pColorCode, pColorName, pAvailabilityStatus, pAvailabilityDate, pImagePath) {
    this.prdId = pPrdId;
    this.sizeName = pSizeName;
    this.type = pType;
    this.colorCode = pColorCode;
    this.colorName = pColorName;
    this.availabilityStatus = pAvailabilityStatus;
    this.availabilityDate = pAvailabilityDate;
    this.imagePath = pImagePath;
}

function isEmpty(pValue) {
    if ((pValue == null) || (trim(pValue) == "")) {
        return true;
    } else {
        return false;
    }
}
function trim(str) {
    return str.replace(/^\s*|\s*$/g, "");
}

function contains(array, value) {
    for (var i = 0; i < array.length; i++) {
        if (array[i] == value) {
            return true;
        }
    }
    return false;
}

function getElement(elementId) {
    return document.all ? document.all[elementId] : document.getElementById(elementId);
}

function imgClicked(imgId, imgElem) {
    var end = imgId.lastIndexOf("_");
    imgId = imgId.substring(0, end);
    if (end != -1) {
        unselectAll_iterator(imgId);
    }
    else {
        unselectAll(imgId);
    }

    imgElem.name = "selected";
    imgElem.className = "selected";
}

function changeColor(id, pColorCode, prodImg, prdId, pColorName, isMainProduct, pSizeName) {
    var uniqueId = id;

    if (pSizeName != null) {
        uniqueId = pSizeName;
    }

    if (isMainProduct != null & isMainProduct == "true") {
        uniqueId = "l" + uniqueId;
    }
    if (prdId != null && prdId != "") {
        getElement(uniqueId + "catalogRefIds").value = prdId;
        getElement(uniqueId + "qty").name = prdId;
    }

    if (document["frm" + uniqueId] != null) {
        document["frm" + uniqueId].color.value = pColorCode;
    }
    if (getElement(uniqueId + "selectedColor") != null && pColorName != null) {
        getElement(uniqueId + "selectedColor").innerHTML = pColorName;
    }


    if (isMainProduct != null & isMainProduct == "true") { } else {
        changeImage("img" + uniqueId, prodImg);
    }
}

function changeImage(imageHandle, prodImg) {
    if (prodImg != null && document[imageHandle] != null) {
        document[imageHandle].src = prodImg;
    }
}

function imgMouseOver(imgElem, color) {

    imgElem.className = "mouseOver";
}

function imgMouseOut(imgElem, color) {
    if (imgElem.name == "selected") {
        imgElem.className = "selected";
    } else {
        imgElem.className = "unselected";
    }
}
function unselectAll_iterator(elementId) {
    var i = 0;
    while (!isNull(document.getElementById(elementId + "_" + i))) {
        var elem = document.getElementById(elementId + "_" + i)
        if (elem.name == "selected" || elem.className == "selected") {
            elem.name = "";
            elem.className = "unselected";
        }
        i++;
    }
}

function isNull(elem) {
    if (elem == null) return true;
    return false;
}
function unselectAll(elementId) {
    if (document.all) {
        var length = document.all(elementId).length;
        for (var i = 0; i < length; i++) {
            var elem = document.all(elementId, i);
            if (elem.name == "selected") {
                elem.name = "";
                elem.className = "unselected";
            }
        }
    } else {
        var length = document.getElementById(elementId).length;
        for (var i = 0; i < length; i++) {
            var elem = document.getElementById(elementId, i);
            if (elem.name = "selected") {
                elem.name = "";
                elem.className = "unselected";
            }
        }
    }
}

var scrptFunArr = new Array();

function addScriptFunction(pProductId, pSizeName, pProductColor, pProdImg, pPrdId, pColorName) {
    scrptFunArr.push(new scrptF(pProductId, pSizeName, pProductColor, pProdImg, pPrdId, pColorName));
}

function callscriptfunctions() {
    for (var i = 0; i < scrptFunArr.length; i++) {
        changeColor(scrptFunArr[i].productId, scrptFunArr[i].productColor, scrptFunArr[i].prodImg, scrptFunArr[i].prdId, scrptFunArr[i].colorName, '', scrptFunArr[i].sizeName);
    }
}

function scrptF(productId, pSizeName, pProductColor, pProdImg, pPrdId, pColorName) {
    this.productId = productId;
    this.sizeName = pSizeName;
    this.productColor = pProductColor;
    this.prodImg = pProdImg;
    this.prdId = pPrdId;
    this.colorName = pColorName;
}


function getElement(elementId) {
    return document.all ? document.all[elementId] : document.getElementById(elementId);
}

function View(pViewName, pViewURL) {
    this.viewName = pViewName;
    this.viewURL = pViewURL;
}

function Color(pColorCode, pColorName, pProductImageURL) {
    this.colorCode = pColorCode;
    this.colorName = pColorName;
    this.productImageURL = pProductImageURL;
    this.viewList = new Array();

    this.addView = function (pViewName, pViewURL) {
        this.viewList.push(new View(pViewName, pViewURL));
    }
}

var colorList = new Array();

function addColor(pColorCode, pColorName, pProductImageURL) {
    colorList.push(new Color(pColorCode, pColorName, pProductImageURL));
}

function getColor(pColorCode) {
    for (var i = 0; i < colorList.length; i++) {
        if (colorList[i].colorCode == pColorCode) {
            return colorList[i];
        }
    }
    return null;
}

function ReplaceIfNeeded(pSizeName) {

    if (typeof (ReplaceIfNeededFlag) == 'undefined') {

        var sizes = new Array();
        sizes[0] = "PETITE";
        sizes[1] = "SMALL";
        sizes[2] = "MEDIUM";
        sizes[3] = "LARGE";
        sizes[4] = "PETITE/SMALL";
        sizes[5] = "MEDIUM/LARGE";

        for (var i = 0; i < sizes.length; i++) {
            if (pSizeName == 'P')
                return sizes[0];
            if (pSizeName == 'S')
                return sizes[1];
            if (pSizeName == 'M')
                return sizes[2];
            if (pSizeName == 'L')
                return sizes[3];
            if (pSizeName == 'P/S')
                return sizes[4];
            if (pSizeName == 'M/L')
                return sizes[5];

            else
                return pSizeName;
        }
    } else
        return pSizeName;
}
  
