/*
* 用 formatImage(图片所在容器，最大宽度，最大高度) 来设置指定容器里的所有图片规格
* 用法：<script laguage="javascript" src="这个js文件路径"></script>
*      在引用文件的头部<head></head>里加上这个函数就行了 
*    如：<script type="text/javascript" defer="defer">formatImage("ctl00_CMain_ProductList",134,134);</script>  
* 程序开发：梁锦斌 2009-03-27
*/

function formatImage(container,width,height)
{
    var imgs = document.getElementById(container.toString()).getElementsByTagName("img");
    for (j=0; j < imgs.length; j++)
    {
        var img = new Image();
        img.src = imgs[j].src;
        
        if(img.width>0 && img.height>0)
	    { 
		    flag=true; 
		    if(img.width/img.height>= width/height)
		    { 
		        if(img.width > width)
		        { 
			        imgs[j].style.width = width; 
			        imgs[j].style.height = (img.height*width)/img.width; 
		        }
		        else
		        { 
		            imgs[j].style.width=img.width; 
		            imgs[j].style.height=img.height; 
		        } 
	            //ImgD.alt=image.width+"x"+image.height; //测试结果用
	        } 
	        else
	        { 
		        if(img.height > height)
		        { 
		            imgs[j].style.height=height; 
		            imgs[j].style.width=(img.width*height)/img.height; 
		        }
		        else
		        { 
		            imgs[j].style.width=img.width; 
		            imgs[j].style.height=img.height; 
		        } 
            }
	    } 
    }
}

