
function avatarLoaded(img, maxSize)
{    
    var result = imageForceSize(img, maxSize);    
    img.style.visibility = "visible";
    
    return result;
}

function avatarLoadedProfile(img, maxSize)
{    
    var result = imageMaxSize(img, maxSize);    
    img.style.visibility = "visible";
    
    return result;
}

function groupEmblemLoaded(img, maxSize)
{    
    var result = imageForceSize(img, maxSize);    
    img.style.visibility = "visible";
    
    return result;
}

function photoAlbumPictureLoaded(img, maxSize)
{    
    var result = imageForceSize(img, maxSize);    
    img.style.visibility = "visible";
    
    return result;
}

function albumPhotoLoaded(img, maxSize)
{    
    var result = imageForceSize(img, maxSize);    
    img.style.visibility = "visible";
    
    return result;
}

function imageForceSize(img, maxSize)
{
    if (null == img)
        return false;
    if (maxSize <= 0)
        return false;

    if (img.width > img.height)
    {
        img.width = parseInt(maxSize);
        img.height = parseInt(parseFloat(img.height) * parseFloat(maxSize) / parseFloat(img.width));
    }
    else
    {
        img.height = parseInt(maxSize);
        img.width = parseInt(parseFloat(img.width) * parseFloat(maxSize) / parseFloat(img.height));
    }

    return true;
}

function imageForceSize2(img, maxSize)
{
    if (null == img)
        return false;
    if (maxSize <= 0)
        return false;

    if (img.width > img.height)
    {
        img.width = parseInt(maxSize);
        img.height = parseInt(parseFloat(img.height) * parseFloat(maxSize) / parseFloat(img.width));
    }
    else
    {
        img.height = parseInt(maxSize);
        img.width = parseInt(parseFloat(img.width) * parseFloat(maxSize) / parseFloat(img.height));
    }

    img.style.visibility = "visible";

    return true;
}

function imageForceWidth(img, maxSize)
{
    if (null == img)
        return false;
    if (maxSize <= 0)
        return false;

    img.width = parseInt(maxSize);
    img.height = parseInt(parseFloat(img.height) * parseFloat(maxSize) / parseFloat(img.width));
        
    return true;
}

function imageMaxSize(img, maxSize)
{
    if (null == img)
        return false;
    if (maxSize <= 0)
        return false;

    if ((img.width <= maxSize) && (img.height <= maxSize))
        return true;
    if ((0 == img.width) || (0 == img.height))
        return true;
        
    iNewWidth = img.width;
    iNewHeight = img.height;
        
    if ( img.width > img.height )
    {
        iNewWidth = parseInt(maxSize);
        iNewHeight = parseInt(parseFloat(img.height) * parseFloat(maxSize) / parseFloat(img.width));
    }
    else
    {
        iNewHeight = parseInt(maxSize);
        iNewWidth = parseInt(parseFloat(img.width) * parseFloat(maxSize) / parseFloat(img.height));
    }
    
    img.width = iNewWidth;
    img.height = iNewHeight;
        
    return true;
}

function showImage(img)
{
    img.style.visibility = "visible";
}
