﻿// JScript File

function resizeImg(which)
{
    imageObj = new Image();
    imageObj.src = which.src;
    
    if (!imageObj.complete)    
    {
        window.setTimeout(function(){resizeImg(which)},100);   
        return;      
    }
    
    var hopeWidth = which.getAttribute("HopeWidth");
    var hopeHeight = which.getAttribute("HopeHeight");
    if (hopeWidth != null && hopeWidth > 0 )
    {
        var precentWidth = imageObj.width/hopeWidth;
        var precentHeight;
        if(hopeHeight == null || hopeHeight == 0)
        {
            precentHeight = 1;    
        }
        else
        {
            precentHeight = imageObj.height/hopeHeight;
        }
        var actWidth,actHeight;
        
        if (precentWidth > 1 || precentHeight > 1 )
        {
            if (precentWidth > precentHeight)
            {
                actWidth = hopeWidth;
                actHeight = imageObj.height/precentWidth;
            }
            else
            {
                actHeight = hopeHeight;
                actWidth = imageObj.width/precentHeight;        
            }
            which.height =   actHeight;
            which.width =    actWidth;
        }
        
    }
    which.style.display = "block";
}