var Width = "160";
var Height = "120";

function GetScaleRatio(w, h, spaceW, spaceH) {
    var ratio1 = (spaceW * 1.) / w;
    var ratio2 = (spaceH * 1.) / h;
    var ratio = (ratio1 > ratio2) ? ratio2 : ratio1;
    if (ratio > 1) ratio = 1;
    return ratio;
}

function GetWidth(w, h, spaceW, spaceH) {
    if(w == 0 || h == 0) return spaceH;
    var result = w * GetScaleRatio(w, h, spaceW, spaceH);
    if(result < 1.0) return 1;
    else return result;
}

function GetHeight(w, h, spaceW, spaceH) {
    if(w == 0 || h == 0) return spaceH;
    var result = h * GetScaleRatio(w, h, spaceW, spaceH);
    if (result < 1.0) return 1;
    else return result;
}
