// this script resizes the avatar so that it fits into the login box
function resize(className, maxWidth, maxHeight) {
    var s = document.getElementsByTagName("img");
    for (var i=0; i<s.length; i++) {
        if (s[i].className==className) {
            doResize(s[i],maxWidth, maxHeight);
        }
    }
}

function doResize(imageTag, maxWidth, maxHeight) {
    var image = new Image();
    image.src = imageTag.src;
    if (image.width <= 0) {
        image.width = 1;
    }

    if (image.height <= 0) {
        image.height = 1;
    }

    if ( (image.height > maxHeight) || (image.width > maxWidth) ) {
        if (image.height > image.width) {
            image.width = Math.ceil(image.width / image.height * maxHeight);
            image.height = maxHeight;
        } else {
            image.height = Math.ceil(image.height / image.width * maxWidth);
            image.width = maxWidth;
        }
    }
    imageTag.width = image.width;
    imageTag.height = image.height;
}