﻿function SetDim(o, img){
    o.height = ScaleH(img,130,130);
    o.width = ScaleW(img,130,130);
}

function SetDimL(o, img){
    o.height = ScaleH(img,40,40);
    o.width = ScaleW(img,40,40);
}

function SetDimXL(o, img){
    o.height = ScaleH(img,100,100);
    o.width = ScaleW(img,100,100);
}

function ScaleH(img, width, height)
{
    var object = document.createElement("IMG");
    object.src = img;
    
    var hRatio = object.height/height;
    var wRatio = object.width/width;

    if (object.width > width && object.height > height)
    {
        var ratio = (hRatio>=wRatio ? hRatio:wRatio);
        object.width = (object.width /ratio);
        object.height = (object.height /ratio);
    }
    else
    {
        if (object.width > width)
        {
            object.width = (object.width /wRatio);
            object.height = (object.height /wRatio);
        }
        else
        {
            if (object.height > height)
            {
                object.width = (object.width /hRatio);
                object.height = (object.height /hRatio);
            }
        }
    }
    return object.height;
}

function ScaleW(img, width, height)
{
    var object = document.createElement("IMG");
    object.src = img;
    
    var hRatio = object.height/height;
    var wRatio = object.width/width;

    if (object.width > width && object.height > height)
    {
        var ratio = (hRatio>=wRatio ? hRatio:wRatio);
        object.width = (object.width /ratio);
        object.height = (object.height /ratio);
    }
    else
    {
        if (object.width > width)
        {
            object.width = (object.width /wRatio);
            object.height = (object.height /wRatio);
        }
        else
        {
            if (object.height > height)
            {
                object.width = (object.width /hRatio);
                object.height = (object.height /hRatio);
            }
        }
    }
    return object.width;
}


