
function DrawImage(ImgD, imgW, imgH) {
	var w=0,h=0;
	try{
		w=parseInt(imgW);
		h=parseInt(imgH);
	}catch(e){}
	if(isNaN(w)) w=0;
	if(isNaN(h)) h=0;
    var image = new Image();
    image.src = ImgD.src;
    
    if (image.width > 0 && image.height > 0) {
        if (w > 0 && h > 0) {
        	//指定高和宽
            if (image.width / image.height >= w / h) {
                if (image.width > w) {
                    ImgD.width = w;
                    ImgD.height = (image.height * w) / image.width;
				    ImgD.title="单击在新窗口显示大图片" 
					ImgD.style.cursor="pointer" 
				    ImgD.onclick=function(e){window.open(ImgD.src)} 
                } else {
                    ImgD.width = image.width;
                    ImgD.height = image.height;
                }
            } else {
                if (image.height > h) {
                    ImgD.height = h;
                    ImgD.width = (image.width * h) / image.height;
				    ImgD.title="单击在新窗口显示大图片" 
					ImgD.style.cursor="pointer" 
				    ImgD.onclick=function(e){window.open(ImgD.src)} 
                } else {
                    ImgD.width = image.width;
                    ImgD.height = image.height;
                }
            }

        } else if(w<=0 && h<=0){
        	//默认计算
            if (image.width / image.height >= 500 / 400) {
                if (image.width > 500) {
                    ImgD.width = 500;
                    ImgD.height = (image.height * 500) / image.width;
				    ImgD.title="单击在新窗口显示大图片" 
					ImgD.style.cursor="pointer" 
				    ImgD.onclick=function(e){window.open(ImgD.src)} 
                } else {
                    ImgD.width = image.width;
                    ImgD.height = image.height;
                }
            } else {
                if (image.height > 400) {
                    ImgD.height = 400;
                    ImgD.width = (image.width * 400) / image.height;
				    ImgD.title="单击在新窗口显示大图片" 
					ImgD.style.cursor="pointer" 
				    ImgD.onclick=function(e){window.open(ImgD.src)} 
                } else {
                    ImgD.width = image.width;
                    ImgD.height = image.height;
                }
            }
        }else if(w>0 & h<=0){
        	//按宽计算       	
            if (image.width > w) {
                ImgD.width = w;
                ImgD.height = (image.height * w) / image.width;
			    ImgD.title="单击在新窗口显示大图片" 
				ImgD.style.cursor="pointer" 
			    ImgD.onclick=function(e){window.open(ImgD.src)} 
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        	
        }else if(w<=0 & h>0){
        	//按高计算
            if (image.height > h) {
                ImgD.height = h;
                ImgD.width = (image.width * h) / image.height;
			    ImgD.title="单击在新窗口显示大图片" 
				ImgD.style.cursor="pointer" 
			    ImgD.onclick=function(e){window.open(ImgD.src)} 
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
}

