﻿
function autoSizeImg(Contents,offsetWidth,offsetHeight,vlmiddle){ 
var o=Contents.getElementsByTagName("img"); 
var cwidth= window.getComputedStyle?window.getComputedStyle(Contents,null).width:Contents.currentStyle["width"]; 
var cheight=window.getComputedStyle?window.getComputedStyle(Contents,null).height:Contents.currentStyle["height"]; 
var ncwidth=parseInt(cwidth); 
var ncheight=parseInt(cheight); 
for(var i=0;i<o.length;i++){ 
var img=o[i]; 
var iw=img.width; 
var ih=img.height; 
if(img.width>ncwidth){ 
var nw=ncwidth-offsetWidth; 
img.width=nw 
img.height=(nw*ih)/iw; 
}else if(img.width<ncwidth&&img.height>ncheight){ 
var nh=ncheight-offsetHeight; 
img.height=ncheight; 
img.width=(ncheight*iw)/ih; 
} 
if(img.height>ncheight&&img.width<ncwidth){ 
var hh=ncheight-offsetHeight; 
img.height=ncheight; 
img.width=(ncheight*iw)/ih; 
} 
if(vlmiddle)img.style.marginTop=((ncheight-img.height)/2)+"px";} 
} 

