
function imgResize(img, max_width, max_height)
{
	var scale_height, scale_width, width;
	var range = 0.2;
	scale_height    = max_height/img.height;
	scale_width     = max_width/img.width;
	scale           = (scale_height < scale_width)? scale_height : scale_width;
	if( Math.abs( scale-1) <= range )
	{
	    img.height = max_height;
	    img.width = max_width;
	}
	else if (scale < 1)
	{
	    height          = img.height*scale;
	    width           = img.width*scale;
	    img.height    	= Math.round(height);
	    img.width     	= Math.round(width);		
	}
	return;
}

function allImgResize(prefix)
{
	var pics = document.getElementsByTagName("IMG");
	var max_height = 0;
	var scale = 1;
	var range = 0.2;
	if (prefix=='' || prefix==null) prefix = 'img_h';
	for(i=0;i<pics.length;i++)
	{
		//alert(pics[i].className.indexOf(prefix));
	   	if( pics[i].className.indexOf(prefix)==0 ) // Æ¥Åä class='img_h123'
	   	{
	   		max_height = pics[i].className.replace(prefix,'');
			scale = max_height / pics[i].height;	
			if( Math.abs( scale-1) <= range )
			{
				pics[i].height = max_height;
				//alert(scale);
			}
			else if( scale < 1 )
		  	{
				height          = pics[i].height*scale;
				width           = pics[i].width*scale;
				pics[i].height    	= Math.round(height);
				pics[i].width     	= Math.round(width);
			}else{
			  	//do nothing
			}
			
		}
	}

}

function allImgResizeW(prefix)
{
	var pics = document.getElementsByTagName("IMG");
	var max_width = 0;
	var scale = 1;
	var range = 0.2;
	if (prefix=='' || prefix==null) prefix = 'img_w';
	for(i=0;i<pics.length;i++)
	{
		//alert(pics[i].className.indexOf(prefix));
	   	if( pics[i].className.indexOf(prefix)==0 ) // Æ¥Åä class='img_w123'
	   	{
	   		max_width = pics[i].className.replace(prefix,'');
			if(pics[i].width>max_width)
			{
				scale = max_width / pics[i].width;
				height          = pics[i].height*scale;
				width           = pics[i].width*scale;
				pics[i].height    	= Math.round(height);
				pics[i].width     	= Math.round(width);		
				
			}			
		}
	}

}
