
function setcolortext(name, productid) {
    $('activecolor_' + productid).innerHTML = "<font class='RedText'><strong>" + name + "</strong></font>";
}

function erasecolor(productid) {
    $('activecolor_' + productid).innerHTML = "Roll Over Color";
}

function doublearraysort(arr1, arr2) {
    var minval, minidx, temp1, temp2, i, j, bcontinue;
    if (arr1.length > 0 && arr2.length > 0 && arr1.length == arr2.length) {
        for (j = 0; j < arr1.length; j++) {
            minval = arr1[j];
            minidx = j;
            for (i = j; i < arr1.length; i++) {
                if (arr1[i] < minval) {
                    minval = arr1[i];
                    minidx = i;
                }
            }
            temp1 = arr1[minidx];
            temp2 = arr2[minidx];
            arr1[minidx] = arr1[j];
            arr2[minidx] = arr2[j];
            arr1[j] = temp1;
            arr2[j] = temp2;
        }
    }
}

function getminmax(productid, min, max) {
    min = -1;
    max = -1;
    for (i = 0; i < po_prices.length; i++) {
        if (po_productid[i] == productid && po_availabilityflag[i] == 1) {
            if (parseFloat(po_prices[i]) > parseFloat(max) || max == -1) {
                max = parseFloat(po_prices[i]);
            }
            if (parseFloat(po_prices[i]) < parseFloat(min) || min == -1) {
                min = parseFloat(po_prices[i]);
            }
        }
    }
    output = "$" + min;
    if (max != min) {
        output += " - $" + max;
    }
    output += " </strong>"; //+eval("product"+productid+"_qtymsg");
    return output;
}

function removechar(instr, character) {
    while (instr.indexOf(character) != -1) {
        instr = instr.replace(character, "");
    }
    return instr;
}

function setuparrays() {
    //: Setup ProductID Arrays
    for (j = 0; j <= productids.length - 1; j++) {
        scolorids = "";
        scolornames = "";
        ssizeids = "";
        ssizenames = "";
        for (k = 0; k <= po_productid.length - 1; k++) {
            if (po_productid[k] == productids[j] && po_availabilityflag[k] == 1) {
                if (scolorids.indexOf("'" + po_colorids[k] + "'") == -1) {
                    scolorids += "'" + po_colorids[k] + "',";
                    scolornames += po_colornames[k] + ",";
                }
                if (ssizeids.indexOf("'" + po_sizeids[k] + "'") == -1) {
                    ssizeids += "'" + po_sizeids[k] + "',";
                    ssizenames += po_sizenames[k] + ",";
                }
            }
        }
        ssizeids = removechar(ssizeids, "'");
        scolorids = removechar(scolorids, "'");
        if (ssizeids.substring(ssizeids.length - 1, ssizeids.length) == ",") {
            ssizeids = ssizeids.substring(0, ssizeids.length - 1);
            ssizenames = ssizenames.substring(0, ssizenames.length - 1);
        }
        if (scolorids.substring(scolorids.length - 1, scolorids.length) == ",") {
            scolorids = scolorids.substring(0, scolorids.length - 1);
            scolornames = scolornames.substring(0, scolornames.length - 1);
        }
        if (ssizeids.length == 0) {
            eval("sizeids_" + productids[j] + "=new Array();");
        } else {
            eval("sizeids_" + productids[j] + "=ssizeids.split(',');");
        }
        if (ssizenames.length == 0) {
            eval("sizenames_" + productids[j] + "=new Array();");
        } else {
            eval("sizenames_" + productids[j] + "=ssizenames.split(',');");
        }
        if (scolorids.length == 0) {
            eval("colorids_" + productids[j] + "=new Array();");
        } else {
            eval("colorids_" + productids[j] + "=scolorids.split(',');");
        }
        if (scolornames.length == 0) {
            eval("colornames_" + productids[j] + "=new Array();");
        } else {
            eval("colornames_" + productids[j] + "=scolornames.split(',');");
        }

        //: Sort colornames,colorids
        doublearraysort(eval("colornames_" + productids[j]), eval("colorids_" + productids[j]));

        //: Set ranges
        var srange = "";
        //if ( eval("sizeids_"+productids[j]+"[0]") != null && eval("sizeids_"+productids[j]+"["+Number(eval("sizeids_"+productids[j]+".length")-1)+"]") != null && Number( eval("sizeids_"+productids[j]+".length")-1 ) != 0 ) 
        //	srange+="Sizes "+eval("sizeids_"+productids[j]+"[0]")+"-"+eval("sizeids_"+productids[j]+"["+Number(eval("sizeids_"+productids[j]+".length")-1)+"]")+ "&nbsp;&nbsp;";					
        var min = 0;
        var max = 0;
        srange += getminmax(productids[j], min, max);
        $('pPrice' + productids[j]).innerHTML = srange;
        //srange+="<br /><br /><img src='"+root+"/assets/icons/right_arrow.gif' border='0' align='absmiddle'>&nbsp;<a href=\"javascript:popup('/popups/sizes.aspx','sizeinfo',600,400,'no','yes','no','yes','no');\">Size Information</a></font></font><br /><br />";
        //$('range'+productids[j]).innerHTML = srange;			
    }
    return true;
}

function getprice(optionprice, productid, qty, pricegroup, indexNo) {
    if (typeof (indexNo) == "undefined")
        indexNo = -1;
    if (qty == "-99") {
        qty = 1;
    }
    numproducts = eval("product" + productid + "_initialcartqty");
    numproducts = numproducts + eval("pricegroup_" + pricegroup);

    //: Get # selected for SAME product or other products in price group
    for (m = 0; m <= productids.length - 1; m++) {
        if (productids[m] == productid || eval("product_" + productids[m] + "_pricegroup") == eval("product_" + productid + "_pricegroup")) {
            for (i = 1; i <= 5; i++) {
                if ($("qty" + productids[m] + "_" + i) != null) {
                    //: Check to see if selected
                    if (
									($("colors" + productids[m] + "_" + i) == null || $("colors" + productids[m] + "_" + i + ".value") != "-99")
									&& ($("sizes" + productids[m] + "_" + i) == null || $("sizes" + productids[m] + "_" + i + ".value") != "-99")
									&& ($("qty" + productids[m] + "_" + i + ".value") != "-99")
								) {
                        numproducts = numproducts + Number($("qty" + productids[m] + "_" + i + ".value"));
                    }
                } else {
                    //: That was last Element
                    break;
                }
            }
        }
    }



    //: Check Product Level Discounts
    x = eval("product" + productid + "_discounts.length");
    if (numproducts > qty) {
        if (numproducts - 1 > x - 1) {
            discvalue = eval("product" + productid + "_discounts[" + (x - 1) + "]");
        } else {
            discvalue = eval("product" + productid + "_discounts[" + (numproducts - 1) + "]");
        }
    } else {
        discvalue = eval("product" + productid + "_discounts[" + (qty - 1) + "]");
    }

    //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
    //: Check Option Discounts to see if price break is greater
    if (typeof (po_discounts) != "undefined") {
        x = po_discounts[indexNo].length;
        if (numproducts > qty) {
            if (numproducts - 1 > x - 1) {
                optiondiscvalue = po_discounts[indexNo][x - 1]; 			//eval("product"+productid+"_discounts["+(x-1)+"]");
            } else {
                optiondiscvalue = po_discounts[indexNo][numproducts - 1]; 	//eval("product"+productid+"_discounts["+(numproducts-1)+"]");
            }
        } else {
            optiondiscvalue = po_discounts[indexNo][qty - 1]; 					//eval("product"+productid+"_discounts["+(qty-1)+"]");
        }

        //: Take lowest of price break vs. option price break
        //if (parseFloat(optiondiscvalue) < parseFloat(discvalue)) 
        discvalue = optiondiscvalue;
    }
    //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


    //: check to see if option is on sale and less than qty disc
    if (parseFloat(optionprice) < parseFloat(discvalue)) {
        return optionprice;
    } else {
        return discvalue;
    }
}

function checkqtyselection(productid, instanceno) {
    bsizeselected = true;
    bcolorselected = true;
    bsizeavail = false;
    bcoloravail = false;
    if ($('sizes' + productid + '_' + instanceno) != null) {
        bsizeavail = true;
        if ($('sizes' + productid + '_' + instanceno).value.toString() == "-99") {
            bsizeselected = false;
        }
    } else {
        bsizeselected = false;
    }
    if ($('colors' + productid + '_' + instanceno) != null) {
        bcoloravail = true;
        if ($('colors' + productid + '_' + instanceno).value.toString() == "-99") {
            bcolorselected = false;
        }
    } else {
        bcolorselected = false;
    }
    if ((!(bsizeselected) && bsizeavail) || (!(bcolorselected) && bcoloravail)) {
        $('qty' + productid + '_' + instanceno).selectedIndex = 0;
        $('sku' + productid + '_' + instanceno).value = 0;
        if (bsizeavail && bcoloravail) {
            wsModalAlert(null, "Please select a Size & Color first.");
        } else if (bsizeavail) {
            wsModalAlert(null, "Please select a Size first.");
        } else if (bcoloravail) {
            wsModalAlert(null, "Please select a Color first.");
        }
        return false;
    } else {
        return true;
    }
}

function pcase(instring) {
    var strReturn_Value = "";
    var iTemp = instring.length;
    var start = 1;
    if (iTemp == 0) {
        return "";
    }
    var UcaseNext = false;
    strReturn_Value += instring.charAt(0).toUpperCase();

    if ((instring.charCodeAt(0) == 120) && (instring.charCodeAt(1) == 120)) {
        strReturn_Value += instring.charAt(1).toUpperCase();
        start = 2;
    }
    for (var iCounter = start; iCounter < iTemp; iCounter++) {
        if (UcaseNext == true) {
            strReturn_Value += instring.charAt(iCounter).toUpperCase();
        }
        else {
            strReturn_Value += instring.charAt(iCounter).toLowerCase();
        }

        var iChar = instring.charCodeAt(iCounter);
        if (iChar == 32 || iChar == 45 || iChar == 47) {
            UcaseNext = true;
        }
        else {
            UcaseNext = false;
        }
    }
    return strReturn_Value;
}

function injectddl(spanprefix, productnumber, instanceno, productid, bsetmoreproducts) {
    colorsempty = false;
    sizesempty = false;
    bonesize = false;
    bonecolor = false;

    if (bsetmoreproducts == true) { bsetmoreproducts = 1; }

    var sHTML = '';
    //sHTML += '<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" class=\"displayProductsDDL\">';
    //	sHTML += '<tr>';

    //: Size DDL
    x = eval('sizeids_' + productid);
    y = eval('sizenames_' + productid);
    if (x.length == 0 && y.length == 0) {
        sizesempty = true;
    } else {



        sHTML += '<td nowrap>';
        sHTML += '<select style=\"display:none;\" class=\"medium\" id=\"sizes' + productid + '_' + instanceno + '\" name=\"sizes' + productid + '_' + instanceno + '\" onkeyup=\"getavailabilityproduct(' + productid + ', ' + instanceno + ');\" onchange=\"getavailabilityproduct(' + productid + ', ' + instanceno + ')\">\n';
        sHTML += '<option value=\"-99\">Size</option>\n';
        for (k = 0; k <= x.length - 1; k++) {
            sHTML += '<option value=\"' + x[k] + '\"';
            if (x.length - 1 == 0) {
                //: only one element
                bonesize = true;
                sHTML += ' selected ';
            }
            if (y[k].length > 3)
                sHTML += '>' + pcase(y[k]) + '</option>\n';
            else
                sHTML += '>' + y[k].toUpperCase() + '</option>\n';
        }
        sHTML += '</select>';
        //sHTML += '</td>';

        //: size Boxes



        sBoxes = "";
        $('size_boxes_header_' + productid + '_' + instanceno).innerHTML = "<div style=\"clear:both !important; float:none; border-color: Transparent !important;\"><span style=\"font-weight:bold;\">Select Size:</span>&nbsp;<span id=\"sizedesc" + productid + "\" class=\"pSizeDesc\">&nbsp;</span><span id=\"hidsizedesc" + productid + "\" style=\"display:none;\"></span>&nbsp;&nbsp;&nbsp;-&nbsp;Click to select size</div>";
        for (k = 0; k <= x.length - 1; k++) {
            sBoxes += "<div id='size_boxes_" + productid + "_" + instanceno + "_" + x[k].toString().toLowerCase().replaceAll(" ", "_") + "' class='normal' onmouseover=\"$('sizedesc" + productid + "').innerHTML='&nbsp; " + y[k].toUpperCase() + "'\"; onmouseout=\"$('sizedesc" + productid + "').innerHTML=$('hidsizedesc" + productid + "').innerHTML;\" onclick=\"javascript:setSize(" + productid + "," + instanceno + ",'" + x[k] + "'); javascript:$('hidsizedesc" + productid + "').innerHTML=$('sizedesc" + productid + "').innerHTML;\">" + y[k].toUpperCase() + "</div>";
        }
        $('size_boxes_' + productid + '_' + instanceno).innerHTML = sBoxes;
    }

    //: Color DDL
    x = eval('colorids_' + productid);
    y = eval('colornames_' + productid);
    if (x.length == 0 && y.length == 0) {
        colorsempty = true;
    } else {


        //sHTML += '<td nowrap>';

        sHTML += '<select style=\"display:none;\" class=\"medium\" id=\"colors' + productid + '_' + instanceno + '\" name=\"colors' + productid + '_' + instanceno + '\" onkeyup=\"getavailabilityproduct(' + productid + ', ' + instanceno + ');if (typeof(announcecolor)!=\'undefined\') { announcecolor(' + productid + ',this.value,this.options[this.selectedIndex].text,' + instanceno + '); } \" onchange=\"getavailabilityproduct(' + productid + ', ' + instanceno + ');if (typeof(announcecolor)!=\'undefined\') { announcecolor(' + productid + ',this.value,this.options[this.selectedIndex].text, ' + instanceno + '); } \">\n';
        sHTML += '<option value=\"-99\">Color</option>\n';
        for (k = 0; k <= x.length - 1; k++) {
            sHTML += '<option value=\"' + x[k] + '\"';
            if (x.length - 1 == 0) {
                //: only one element
                sHTML += ' selected ';
                bonecolor = true;
            }
            sHTML += '>' + pcase(y[k]) + '</option>\n';
        }
        sHTML += '</select>';
        //sHTML += '</td>';
    }

    $(spanprefix + productnumber + '_1').innerHTML = sHTML;

    //: Quantity DDL

    //sHTML += '<td align=\"left\" nowrap>';

    sHTML = "";
    sHTML += '<strong>Select Quantity:</strong> &nbsp;<select id=\"qty' + productid + '_' + instanceno + '\" style=\"padding-top:0px;\" name=\"qty' + productid + '_' + instanceno + '\" onkeyup=\"checkqtyselection(' + productid + ', ' + instanceno + ');getavailabilityproduct(' + productid + ', ' + instanceno + ',1);\" onchange=\"checkqtyselection(' + productid + ', ' + instanceno + ');getavailabilityproduct(' + productid + ', ' + instanceno + ',1);\">\n';
    sHTML += '<option value=\"-99\">Qty</option>\n';
    for (k = 1; k <= 10; k++) {
        sHTML += '<option value=\"' + (k) + '\">' + (k) + '</option>\n';
    }
    sHTML += '</select>';


    //: Sku Hidden Field		
    //sHTML += '</td><td width=\"100%\">';
    //: Availability

    sHTML += '&nbsp;&nbsp;<span style=\"padding-top:7px;\" id=\"availability' + productid + '_' + instanceno + '\" name=\"availability' + productid + '_' + instanceno + '\" class=\"medium\"></span>\n';
    sHTML += '<input type=\"hidden\" id=\"sku' + productid + '_' + instanceno + '\" name=\"sku' + productid + '_' + instanceno + '\" value=\"0\" >';
    sHTML += '<input type=\"hidden\" id=\"productdisplayid' + productid + '_' + instanceno + '\" name=\"productdisplayid' + productid + '_' + instanceno + '\" value=\"' + eval("product_" + productid + "_productdisplayid") + '\" >';
    //sHTML += '</td></tr></table>';		

    $(spanprefix + productnumber + '_' + instanceno + '_qty').innerHTML = sHTML;


    if (bsetmoreproducts == 1 && (!(bonecolor && bonesize))) {
        setmoreproducts();
    }

    /*if ( parseFloat(instanceno) > parseFloat(1) ) {
    //: Set Size
    if ( $('sizes'+productid+'_'+instanceno) != null ) {
    $('sizes'+productid+'_'+instanceno).selectedIndex = $('sizes'+productid+'_'+Number(instanceno-1)).selectedIndex;
    }
    }*/

}

function setSize(productid, instanceno, sizeID) {
    var szs = $('size_boxes_' + productid + '_' + instanceno).getElements('div');
    szs.each(function (item) {
        item.className = (item.id.toString().toLowerCase() == "size_boxes_" + productid + "_" + instanceno + "_" + sizeID.toString().toLowerCase().replaceAll(" ", "_")) ? "over" : "normal";
    });
    if ($('sizes' + productid + '_' + instanceno) != null) {
        $('sizes' + productid + '_' + instanceno).value = sizeID;
    }
    getavailabilityproduct(productid, instanceno);
}


function getindexof(pid, cid, sid) {
    output = -1;
    var stest = "";
    for (z = 0; z <= po_productid.length - 1; z++) {
        if (po_productid[z] == pid && (po_colorids[z] == cid || cid == '') && (po_sizeids[z] == sid || sid == '')) {
            output = z;
            break;
        }
    }
    return output;
}

function getavailability(productid, instanceno, fromqty, originstance, donotset) {
    if (donotset == null) {
        donotset = false;
    }

    //: If qty is selected then set qty back to 'qty' if there is not 
    //: both of the required criteria
    bsizeselected = true;
    bcolorselected = true;
    bsizeavail = false;
    bcoloravail = false;

    if ($('sizes' + productid + '_' + instanceno) != null) {
        bsizeavail = true;
        if ($('sizes' + productid + '_' + instanceno).value == "-99") {
            bsizeselected = false;
        }
    } else {
        bsizeselected = false;
    }
    if ($('colors' + productid + '_' + instanceno) != null) {
        bcoloravail = true;
        if ($('colors' + productid + '_' + instanceno).value == "-99") {
            bcolorselected = false;
        }
    } else {
        bcolorselected = false;
    }

    if (((!(bsizeselected) && bsizeavail) || (!(bcolorselected) && bcoloravail)) && $('qty' + productid + '_' + instanceno).selectedIndex != 0) {
        $('qty' + productid + '_' + instanceno).selectedIndex = 0;
        $('sku' + productid + '_' + instanceno).value = 0;
    }

    indexno = "";
    if ($('qty' + productid + '_' + instanceno) != null) {

        if ($('availability' + productid + '_' + instanceno) != null) {
            if ($('colors' + productid + '_' + instanceno) != null) {
                var colorvalue = $('colors' + productid + '_' + instanceno).value;
            } else {
                var colorvalue = "";
            }
            if ($('sizes' + productid + '_' + instanceno) != null) {
                var sizevalue = $('sizes' + productid + '_' + instanceno).value;
            } else {
                var sizevalue = "";
            }
            indexno = getindexof(productid, colorvalue, sizevalue);

            if (output == -1 && (($('colors' + productid + '_' + instanceno) == null || colorvalue != "-99") && ($('sizes' + productid + '_' + instanceno) == null || sizevalue != "-99"))) {
                $('availability' + productid + '_' + instanceno).innerHTML = "<span class='errorControl' style='font-weight:bold;'>Not Available</span>";
                $('qty' + productid + '_' + instanceno).value = "-99";
                $('sku' + productid + '_' + instanceno).value = 0;
            } else if (indexno == -1) {
                //: Not Found
                $('availability' + productid + '_' + instanceno).innerHTML = ""
                $('sku' + productid + '_' + instanceno).value = 0;
            } else {
                //: Found					
                //: Set qty to 1 if currently 0

                if (!donotset) {
                    if ((fromqty != true) && (po_availabilityflag[indexno] == 1) && ($('qty' + productid + '_' + instanceno).value == "-99")) {
                        if (originstance == null || originstance == instanceno) {
                            $('qty' + productid + '_' + instanceno).value = 1;
                        }
                    } else if ((fromqty == true) && $('qty' + productid + '_' + instanceno).value.toString() == "-99") {
                        //: If from qty ddl and set to 0, leave at 0 and wipe out availability
                        $('availability' + productid + '_' + instanceno).innerHTML = "";
                        $('sku' + productid + '_' + instanceno).value = 0;
                    }
                }

                if (po_availabilityflag[indexno] != 1) { //&& $('qty'+productid+'_'+instanceno).value.toString() != "-99") {
                    $('availability' + productid + '_' + instanceno).innerHTML = po_availability[indexno];
                    $('sku' + productid + '_' + instanceno).value = "0";
                    $('qty' + productid + '_' + instanceno).value = "-99";
                } else if ($('qty' + productid + '_' + instanceno).value.toString() != "-99") {
                    //: Ets Added Index No
                    $('availability' + productid + '_' + instanceno).innerHTML = po_availability[indexno] + "<span class='small' style='color:#333333'>&nbsp;$" + getprice(po_prices[indexno], productid, $('qty' + productid + '_' + instanceno).value, po_pricegroup[indexno], indexno) + " ea.</span>";
                    $('sku' + productid + '_' + instanceno).value = po_skus[indexno];
                }
            }
        }
    }
}

function getavailabilityproduct(productid, instanceno, fromqty) {

    getavailability(productid, instanceno, fromqty, instanceno);
    for (n = 1; n <= 5; n++) {
        if ($('qty' + productid + '_' + n) != null) {
            if (n != instanceno) {
                getavailability(productid, n, false, instanceno);
            }
        } else {
            break;
        }
    }

    //: Check other products in the same pricegroup
    for (pcnt = 0; pcnt <= productids.length - 1; pcnt++) {
        if (productids[pcnt] != productid && eval("product_" + productids[pcnt] + "_pricegroup") == eval("product_" + productid + "_pricegroup")) {
            for (n = 1; n <= 5; n++) {
                if ($('qty' + productids[pcnt] + '_' + n) != null) {
                    getavailability(productids[pcnt], n, false, instanceno, true);
                    //alert('getavailability('+productids[pcnt]+','+n+',false,'+instanceno+');');			
                } else {
                    break;
                }
            }
        }
    }

    return true;
}

function injectinitial() {
    setuparrays();
    for (j = 0; j <= productids.length - 1; j++) {
        injectddl('ddl', Number(j + 1), Number(j + 1), productids[j], 0);
    }
    setmoreproducts();
}

function setmoreproducts() {
    for (m = 0; m <= productids.length - 1; m++) {
        bonecolor = false;
        bonesize = false;
        bcoloravail = true;
        bsizeavail = true;
        lastinstance = 6;
        for (l = 1; l <= 5; l++) {
            if ($('qty' + productids[m] + '_' + l) != null) {
                //: Element Exists
                lastinstance = l;
            } else {
                //: That was last Element
                break;
            }
        }

        if (($('sizes' + productids[m] + '_' + lastinstance) != null || $('colors' + productids[m] + '_' + lastinstance) != null) && Number(lastinstance + 1) < 6) {
            //: make sure there is more than one item on sizes or colors
            if ($('sizes' + productids[m] + '_' + lastinstance) != null) {
                if ($('sizes' + productids[m] + '_' + lastinstance).options.length < 3) {
                    bonesize = true;
                }
            } else {
                bsizeavail = false;
            }

            if ($('colors' + productids[m] + '_' + lastinstance) != null) {
                if ($('colors' + productids[m] + '_' + lastinstance).options.length < 3) {
                    bonecolor = true;
                }
            } else {
                bcoloravail = false;
            }

            bsetmore = false;
            selectmoremessage = "Select Multiple Sizes/Colors";
            if (bsizeavail && bcoloravail) {
                if (!bonesize && !bonecolor) {
                    bsetmore = true;
                    selectmoremessage = "Select Multiple Sizes/Colors";
                } else if (!bonesize && bonecolor) {
                    bsetmore = true;
                    selectmoremessage = "Select Multiple Sizes";
                } else if (bonesize && !bonecolor) {
                    bsetmore = true;
                    selectmoremessage = "Select Multiple Colors";
                }
            } else if (bsizeavail && !bcoloravail) {
                if (!(bonesize)) {
                    bsetmore = true;
                    selectmoremessage = "Select Multiple Sizes";
                }
            } else if (!bsizeavail && bcoloravail) {
                if (!(bonecolor)) {
                    bsetmore = true;
                    selectmoremessage = "Select Multiple Colors";
                }
            }

            if (bsetmore && 1 == 0) {
                $('ddl' + Number(m + 1) + '_' + Number(lastinstance + 1)).innerHTML = "&nbsp;<font class='bluetext'><font class='small' style='font-weight:normal'><a href='javascript:injectddl(\"ddl\"," + Number(m + 1) + "," + Number(lastinstance + 1) + "," + productids[m] + ",1);'>" + selectmoremessage + " ></a></font></font>";
            }
        }
    }
}

function getAddToCartPostMode() {
    if (typeof (addtocart_postmode) == "undefined") {
        return ("default");
    } else {
        return (addtocart_postmode.toString());
    }
}

function addtocart(dest, addtocart_mode) {
    if (typeof (dest) == "undefined") dest = defaultdestination;
    if (typeof (addtocart_mode) == "undefined") addtocart_mode = getAddToCartPostMode();
    numproducts = 0;
    spost = "";
    for (m = 0; m <= productids.length - 1; m++) {
        //for (l=1; l<=5; l++) {
        if ($('qty' + productids[m] + '_' + Number(m + 1)) != null) {

            //: Element Exists
            lastinstance = m;
            //: Check to see if selected
            if (($('colors' + productids[m] + '_' + Number(m + 1)) == null || $('colors' + productids[m] + '_' + Number(m + 1)).value != "-99") && ($('sizes' + productids[m] + '_' + Number(m + 1)) == null || $('sizes' + productids[m] + '_' + Number(m + 1)).value != "-99") && $('qty' + productids[m] + '_' + Number(m + 1)).value != "-99" && $('sku' + productids[m] + '_' + Number(m + 1)).value != "0") {
                numproducts = numproducts + 1;
                spost += "&productsku" + numproducts + "=" + escape($('sku' + productids[m] + '_' + Number(m + 1)).value) + "&productqty" + numproducts + "=" + escape($('qty' + productids[m] + '_' + Number(m + 1)).value) + "&productdisplayid" + numproducts + "=" + escape($('productdisplayid' + productids[m] + '_' + Number(m + 1)).value);

                if (addtocart_mode == "dynamic" || addtocart_mode == "modalDynamic") {
                    spost += "&branch" + numproducts + "=" + escape(eval("product_" + productids[m] + "_branch"));
                }
            }
        } else {
            //: That was last Element
            break;
        }
        //}
    }

    if (numproducts == 0) {
        wsModalAlert(null, "Please select an item/qty first.");
    } else {
        if (productdisplayid != 0 && addtocart_mode == "default") {
            spost = dest + "?source=" + escape(source) + "&productdisplayid=" + productdisplayid + "&BRANCH=" + branch + "&numformitems=" + numproducts + spost;
            location.href = root + spost;

        } else if (addtocart_mode == "modal") {
            serrorpost = "/addtocart.aspx" + "?source=" + escape(source) + "&addtocart_mode=" + escape(addtocart_mode) + "&productdisplayid=" + productdisplayid + "&BRANCH=" + branch + "&numformitems=" + numproducts + spost;
            spost = dest + "?source=" + escape(source) + "&addtocart_mode=" + escape(addtocart_mode) + "&productdisplayid=" + productdisplayid + "&BRANCH=" + branch + "&numformitems=" + numproducts + spost;
            try {
                wsModal(root + spost, "This item has been added to your bag", "450");
            } catch (e) {
                location.href = root + serrorpost;
            }

        } else if (addtocart_mode == "modalDynamic") {
            serrorpost = dest + "?source=" + escape(source) + "&addtocart_mode=" + escape(addtocart_mode) + "&numformitems=" + numproducts + spost;
            spost = dest + "?source=" + escape(source) + "&addtocart_mode=" + escape(addtocart_mode) + "&numformitems=" + numproducts + spost;
            try {
                wsModal(root + spost, "This item has been added to your bag", "450");
            } catch (e) {
                location.href = root + serrorpost;
            }

        } else if (productdisplaygroupid != null) {
            spost = dest + "?source=" + escape(source) + "&productdisplaygroupid=" + productdisplaygroupid + "&BRANCH=" + branch + "&numformitems=" + numproducts + spost;
            location.href = root + spost;
        }

    }
}

function setcolor(obj, val) {
    obj.value = val;
}


function newSearch() {
    wsZoom.altImages.length = 0;
    wsZoom.instances.length = 0;
    productids = new Array();
    productskus = new Array();
    po_productid = new Array();
    po_skus = new Array();
    po_colorids = new Array();
    po_colornames = new Array();
    po_sizeids = new Array();
    po_sizenames = new Array();
    po_prices = new Array();
    po_discounts = new Array();
    po_pricegroup = new Array();
    po_availabilityflag = new Array();
}
