﻿
function DrawImage(ImgD, maxWidth, maxHeight)
{
	var image=new Image();
	var iwidth = maxWidth; //定义允许图片宽度
	var iheight = maxHeight; //定义允许图片高度
	image.src=ImgD.src;
	if(image.width>0 && image.height>0)
	{
		flag=true;
		if(image.width/image.height>= iwidth/iheight)
		{
			if(image.width>iwidth)
			{ 
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
			}
			else
			{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height;
		}
		else
		{
			if(image.height>iheight)
			{
				ImgD.height=iheight;
				ImgD.width=(image.width*iheight)/image.height; 
			}
			else{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
			ImgD.alt=image.width+"×"+image.height;
		}
	}
}	


//去掉字串左边的空格
function lTrim(str)
{
	if (str.charAt(0) == " ")
	{
	//如果字串左边第一个字符为空格
	str = str.slice(1);//将空格从字串中去掉
	//这一句也可改成 str = str.substring(1, str.length);
	str = lTrim(str); //递归调用
	}
	return str;
}

//去掉字串右边的空格
function rTrim(str)
{
	var iLength;
	iLength = str.length;
	if (str.charAt(iLength - 1) == " ")
	{
	//如果字串右边第一个字符为空格
	str = str.slice(0, iLength - 1);//将空格从字串中去掉
	//这一句也可改成 str = str.substring(0, iLength - 1);
	str = rTrim(str); //递归调用
	}
	return str;
}
//去掉字串两边的空格
function trim(str)
{
	return lTrim(rTrim(str));
}
