﻿function proDownImage(ImgD,proMaxWidth,proMaxHeight){
     try
     {
          var image=new Image();
          image.src=ImgD.src;      
          if(image.width>0 && image.height>0)
          {
                var rate = (proMaxWidth/image.width < proMaxHeight/image.height)?proMaxWidth/image.width:proMaxHeight/image.height;
                var w=image.width*rate;
                var h=image.height*rate;
                
                if(rate <= 1)
                {   
                    ImgD.width = image.width*rate;
                    ImgD.height =image.height*rate;
                }
                else if(rate!=0)
                {
                    ImgD.width = image.width*rate;
                    ImgD.height =image.height*rate;
                }
                
                if(proMaxWidth-w>0)
                {
                
                    //ImgD.style.marginLeft=""+((proMaxWidth-w)/2)+"px";
                }
                else if(proMaxHeight-h>0)
                {
                    //alert("fuck!");
                    ImgD.style.marginTop=""+((proMaxHeight-h)/2)+"px";
                    
                }
          }
      }
      catch(Error){}      
}
