﻿function shrinkImage(id, maxWidth, maxHeight) {
    if (!document.getElementById) return;

    img = document.getElementById(id);
    if (!img) return;

    var imgWidth = img.width;
    var imgHeight = img.height;

    var maxW = (maxWidth > 0) ? maxWidth : imgWidth;
    var maxH = (maxHeight > 0) ? maxHeight : imgHeight;

    var widthRate = imgWidth / maxW;
    var heightRate = imgHeight / maxH;

    if (widthRate <= 1 && heightRate <= 1) return;

    if (widthRate > 1 && heightRate > 1) {
        if (widthRate > heightRate) {
            img.width = maxW;
            img.height = Math.floor(imgHeight / widthRate);
        } else {
            img.width = Math.floor(imgWidth / heightRate);
            img.height = maxH;
        }
    } else if (widthRate > 1 && heightRate <= 1) {
        img.width = maxW;
        img.height = Math.floor(imgHeight / widthRate);
    } else if (widthRate <= 1 && heightRate > 1) {
        img.width = Math.floor(imgWidth / heightRate);
        img.height = maxH;
    }
}



function selectMenu(idxGroup, idxMenu, menuCount) {

    if (!document.getElementById) return;
    for (i = 0; i <= menuCount - 1; i++) {
        pageID = idxGroup + "_" + i;
        if (!document.getElementById("body" + pageID)) continue;
        if (pageID == idxGroup + "_" + idxMenu) {
            document.getElementById("menu" + pageID).className = "categorymenuitemselected";
            document.getElementById("body" + pageID).style.display = "block";
            document.getElementById("tr" + pageID).style.background = "#067070";
            document.getElementById("categorymenuarrowicon" + pageID).style.background = "#067070";
            document.getElementById("categorymenuarrowiconImage" + pageID).style.display = "inline";
            document.getElementById("categorymenuarrowiconImage" + pageID).className = "";
            if (document.getElementById("hfTab"))
            document.getElementById("hfTab").value = idxMenu;
        } else {
            document.getElementById("menu" + pageID).className = "categorymenuitem";
            document.getElementById("body" + pageID).style.display = "none";
            document.getElementById("tr" + pageID).style.background = "#E1EBEC";
            document.getElementById("categorymenuarrowicon" + pageID).style.background = "#E1EBEC";
            document.getElementById("categorymenuarrowiconImage" + pageID).className = "displaynone";
        }
        document.getElementById("body" + pageID).style.borderBottom = "none";
    }
}

