﻿//图片缩放
function Reset_ImgSize(obj, MaxW, MaxH)
{
    if (obj != null) imageObject = obj;
    var state=imageObject.readyState;
    var oldImage = new Image();
    oldImage.src = imageObject.src;
    var dW=oldImage.width; 
	var dH=oldImage.height;
    if(dW>MaxW || dH>MaxH) {
        a=dW/MaxW; 
		b=dH/MaxH;   
        if(b>a) a=b;
        dW=dW/a; 
		dH=dH/a;
    }
	else{
		dw = MaxW;
		dh = MaxH;
	}
    if(dW > 0 && dH > 0)
        imageObject.width=dW;
		imageObject.height=dH;
    if(state!='complete' || imageObject.width>MaxW || imageObject.height>MaxH) {
        setTimeout("ResizeImage(null,"+MaxW+","+MaxH+")",40); 
    }
}

//实现图片等比缩放
var flag=false;
function DrawImage(ImgD,Iwidth,Iheight){
	var image=new Image();
	var iwidth = Iwidth; //定义允许图片宽度
	var iheight = Iheight; //定义允许图片高度
	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;
				//ImgD.alt = "产品缩略图";
			}
			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;
				//ImgD.alt = "产品缩略图";
			}
   }
} 
