﻿function swapimage(productid, swatch, cname, cid, instanceno) {
    if (swatch != null && swatch != "") { wsZoom.updateZoom(eval("product_" + productid + "_productdisplayid"), swatch); }
    if ($('colordesc' + productid) != null) { $('colordesc' + productid).innerHTML = '&nbsp;' + cname; }
    if ($('hidcolordesc' + productid) != null) { $('hidcolordesc' + productid).innerHTML = '&nbsp;' + cname; }
//    for (n = 1; n <= 5; n++) {
//        if ($('qty' + productid + '_' + n) != null) {
//            lastinstance = n;
//        } else {
//            break;
//        }
    //    }
    lastinstance = instanceno;
    //obj = $('colors' + productid + '_' + lastinstance);
    obj = $('colors' + productid + '_' + instanceno);
    for (n = 0; n < obj.options.length; n++) {
        if (obj.options[n].value.toLowerCase() == cid.toLowerCase()) {
            obj.selectedIndex = n;
            break;
        }
    }
    getavailabilityproduct(productid, lastinstance);
}
function announcecolor(productid, colorid, colorname, instanceno) {
    if (colorid != '-99') {
        var bfound = false;
        if (swatch_available) {
            for (n = 0; n < swatch_productid.length; n++) {
                if (swatch_productid[n] == productid && swatch_colorid[n].toUpperCase() == colorid.toUpperCase()) {
                    swapimage(productid, swatch_image[n], colorname.toUpperCase(), colorid, instanceno);
                    bfound = true;
                    break;
                }
            }
            var sws = $('product_' + productid + '_swatches').getElements('div');
            sws.each(function (item) {
                item.className = (item.id.toString().toLowerCase() == "swatch_" + productid + "_" + colorid.toString().toLowerCase().replaceAll(" ", "_")) ? "over" : "normal";
            });
            
        } else if (swatch_available == false || (swatch_available == true && bfound == false)) {
            swapimage(productid, null, colorname.toUpperCase(), colorid, instanceno);
        }
    }
}

