function AlterImageSize(imageId, imageSrc, maxWidth, maxHeight)
{
	if (document.getElementById(imageId) != null)
	{
		var img = new Image();
		
		img.src = imageSrc;
		
		var imgWidth = img.width;
		var imgHeight = img.height;
		
		if (imgWidth > maxWidth)
		{
			imgHeight = (imgHeight * maxWidth) / imgWidth;		
			imgWidth = maxWidth;
		}
		
		if (imgHeight > maxHeight)
		{
			imgWidth = (imgWidth * maxHeight) / imgHeight;
			imgHeight = maxHeight;
		}	
		img.width = imgWidth;
		img.height = imgHeight;	
		
		document.getElementById(imageId).width = img.width;
		document.getElementById(imageId).height = img.height;
	}
}

