

function SetImageSize(Id, Src, Width, Height) {
    //alert(Src);
    Width  = Width  || 300;
    Height = Height || 200;
    var img = new Image();

    img.src = Src;
    var w  = img.width;
    var h  = img.height;

    var rw = (w / Width);
    var rh = (h / Height);
    var f = 1;
    if ((rw <= 1) && (rh <= 1)) {
        //
    } else if (rw > rh) {
        f = rw;
    } else {
        f = rh;
    }
    var w = w / f;
    var h = h / f;

    var e = document.getElementById(Id);
    //alert(e.src);
    e.src = Src;
    e.src = null;
    e.src = Src;
    e.style.width = w;
    e.style.height = h;
    //alert(e.id);
}
function SetImageAndName(Id, Src, Name) {
    SetImageSize(Id, Src);
    var e = document.getElementById(Name);
    e.value = GetFileName(Src);
}
function GetFileName(Path) {
    var s = new String(Path);
    var p = s.replace(/\\/g, '/').split('/');
    i = p.length-1;
    return p[i];
}