﻿function sideNavigation_SelectedChanged(id, count) {
    if (!document.getElementById) return;
    for (i = 1; i <= count; i++) {
        if (i == id) {
            document.getElementById("sidenavigation" + i).className = "sidenavigationselected";
        }
        else {
            document.getElementById("sidenavigation" + i).className = "";
        }
    }
}

function pullDownMenu_OnChange(pullDownID) {
    if (!document.getElementById) return;

    var pullDown = document.getElementById(pullDownID);
    if (!pullDown || pullDown.selectedIndex < 0) return;

    var value = pullDown.options[pullDown.selectedIndex].value;
    if (!value || value == "") return;

    window.location.href = value;
}

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;
    }
}
