
var strProductControlID = "tdProducts"; //ID of the table/table cell containing the products
var strLeadQuestionControlID = "tblROBOX"; //ID of the table/table cell containing the refinement options
var iMaxLQImageWidth = 0; //if the max width/height is set to zero, it is not taken into consideration in the calculation
var iMaxLQImageHeight = 100;
var iMaxImageWidth = 284;
var iMaxImageHeight = 284;

function getObject(strID) {
    var ie = (document.all);
    var ns4 = document.layers ? true : false;
    var dom = document.getElementById && !document.all ? true : false;

    if (dom) {
        return document.getElementById(strID);
    }
    else if (ie) {
        return document.all[strID];
    }
    else if (ns4) {
        return document.layers[strID];
    }
}


function ResizeImage(objectid, iMaxWidth, iMaxHeight) {

    var oImage = getObject(objectid);
    var imgWidth = oImage.width;
    var imgHeight = oImage.height;

    if (imgHeight > iMaxHeight && imgWidth > iMaxWidth && iMaxHeight > 0 && iMaxWidth > 0) {
        if (imgWidth / iMaxWidth > imgHeight / iMaxHeight) //i.e. the required change in width is greater than the one in height
        {
            oImage.height = imgHeight * iMaxWidth / imgWidth;
            oImage.width = iMaxWidth;
        }
        else if (imgWidth / iMaxWidth < imgHeight / iMaxHeight) {
            oImage.width = imgWidth * iMaxHeight / imgHeight;
            oImage.height = iMaxHeight;
        }
        else if (iMaxWidth < iMaxHeight) //if the ratio is the same, resize to the smaller value
        {
            oImage.height = imgHeight * iMaxWidth / imgWidth;
            oImage.width = iMaxWidth;
        }
        else {
            oImage.width = imgWidth * iMaxHeight / imgHeight;
            oImage.height = iMaxHeight;
        }
    }
    else if (imgHeight > iMaxHeight && iMaxHeight > 0 && (imgWidth <= iMaxWidth || iMaxWidth == 0)) {
        oImage.width = imgWidth * iMaxHeight / imgHeight;
        oImage.height = iMaxHeight;
    }
    else if (imgWidth > iMaxWidth && iMaxWidth > 0 && (imgHeight <= iMaxHeight || iMaxHeight == 0)) {
        oImage.height = imgHeight * iMaxWidth / imgWidth;
        oImage.width = iMaxWidth;
    }
    else {
        oImage.width = 174;
        oImage.height = 284;
    }
}

function ResizeImages() {

    try {
        for (i = 0; i < document.images.length; i++) {
            if (document.images[i].width && document.images[i].id) {
                if (SubstringExists(document.images[i].id, "Repeater")) //only resize images within repeaters
                {
                    if (SubstringExists(document.images[i].id, "lqQuestion"))
                        ResizeImage(document.images[i].id, iMaxLQImageWidth, iMaxLQImageHeight);
                    else //these should be products
                        ResizeImage(document.images[i].id, iMaxImageWidth, iMaxImageHeight);
                }
            }
        }

    }
    catch (e) {
    }
    finally {
        ToggleVisibility(strLeadQuestionControlID, true);
        ToggleVisibility(strProductControlID, true);
    }

}

function ToggleVisibility(objectid, bVisible) {
    var myObject = getObject(objectid);

    if (myObject != null) {
        if (bVisible)
            myObject.style.visibility = "visible";
        else
            myObject.style.visibility = "hidden";
    }
}
			
	

