﻿function scaleSize(obj, maxWidth, maxHeight, refresh) {
    var tempImg = new Image();
    tempImg.src = obj.src;
    var iWidth = tempImg.width;
    var iHeight = tempImg.height;
    tempImg.style.visibility = "hidden";
    if (refresh || iWidth == 0 || iHeight == 0) {
        originalImage = new Image();
        originalImage.src = tempImg.src;
        iWidth = originalImage.width;
        iHeight = originalImage.height;
    }
    sizeRatioW = maxWidth / iWidth;
    sizeRatioH = maxHeight / iHeight;

    if (sizeRatioW > sizeRatioH) {
        sizeRatio = sizeRatioH;
    } else {
        sizeRatio = sizeRatioW;
    }

    newWidth = iWidth * sizeRatio;
    newHeight = iHeight * sizeRatio;
    
    //RESIZE IMAGE
    obj.style.width = newWidth + 'px';
    obj.style.height = newHeight + 'px';
    obj.style.visibility = "visible";
}
