﻿var  flag = false; 
 
function  DrawImage( ImgD ){  
     var  image = new  Image();  
     image.src  = ImgD.src;  
     
     if( image.width > 0  &&  image.height > 0 ){  
       flag=true;  
       if( image.width/image.height >= 125/75 ){  
         if( image.width > 125 ){      
         ImgD.width = 125;  
         ImgD.height = ( image.height*125 )/image.width;  
         }else{  
         ImgD.width = image.width;      
         ImgD.height = image.height;  
         }  
         ImgD.alt = image.width + "×" + image.height;  
         }  
       else{  
         if( image.height > 75 ){      
         ImgD.height = 75;  
         ImgD.width =( image.width*75 )/image.height;            
         }else{  
         ImgD.width = image.width;      
         ImgD.height=image.height;  
         }  
         ImgD.alt = image.width + "×" + image.height;  
         }  
       }  
} 

function AutoResizeImage(maxWidth,maxHeight,objImg){ 
    var img = new Image(); 
    img.src = objImg.src; 
    var hRatio; 
    var wRatio; 
    var Ratio = 1; 
    var w = img.width; 
    var h = img.height; 
    wRatio = maxWidth / w; 
    hRatio = maxHeight / h; 
    if (maxWidth ==0 && maxHeight==0){ 
        Ratio = 1; 
    }else if (maxWidth==0){// 
        if (hRatio<1) Ratio = hRatio; 
        }else if (maxHeight==0){ 
        if (wRatio<1) Ratio = wRatio; 
        }else if (wRatio<1 || hRatio<1){ 
        Ratio = (wRatio<=hRatio?wRatio:hRatio); 
    } 
    if (Ratio<1){ 
        w = w * Ratio; 
        h = h * Ratio; 
    } 
    objImg.height = h; 
    objImg.width = w; 
} 
