﻿var flag = false;
function DrawImage(ImgD) {
    var image = new Image();
    var _w = 396; var _h = 393;
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        flag = true;
        if (image.width / image.height >= _w / _h) {
            if (image.width > _w) {
                ImgD.width = _w;
                ImgD.height = (image.height * _w) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > _h) {
                ImgD.height = _h;
                ImgD.width = (image.width * _h) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
} 