function autoSizeImg(Contents,offsetWidth,offsetHeight,vlmiddle){
	if ( Contents ) {
	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);
	if ( ncwidth==NaN || ncheight==NaN ) {
		alert(ncwidth + "," + ncheight);
		return;
	}
	for(var i=0;i<o.length;i++){
		var img=o[i];
		var iw=img.width;
		var ih=img.height;
		var newiw = iw;
		var newih = ih;
		if ( iw==0 || ih==0 ) continue;
		if(iw>ncwidth-offsetWidth){
			var nw=ncwidth-offsetWidth;
			newiw = nw;
			newih = (nw * ih) / iw;
		}
		
		iw = newiw;
		ih = newih;
		
		if(iw<=ncwidth-offsetWidth && ih>ncheight-offsetHeight){
			var nh=ncheight-offsetHeight;
			newih=nh;
			newiw=(nh*iw)/ih;
		}
		
		if (vlmiddle) {
			img.style.marginTop= ((ncheight-newih)/2)+"px";
			img.style.marginLeft = ((ncwidth-newiw)/2) + "px";
		}
		img.style.visibility = 'visible';
		img.style.width = newiw + 'px';
		img.style.height = newih + 'px';
		Contents.style.paddingTop = '0px';
		Contents.style.paddingLeft = '0px';
	}
	}
}
