// JavaScript Document

function changeImg(mypic)
{ 
 var xw=600; 
 var xl=510; 

 var width = mypic.width; 
 var height = mypic.height; 
 
 if (width > xw ) mypic.width = xw; 
 if (height > xl ) mypic.height = xl; 
} 



function DrawImage(ImgD,iwidth)
{
 var image=new Image();
 image.src=ImgD.src;
 if(image.width>0 && image.height>0)
 {
  if(image.width>iwidth)
  {  
   ImgD.width=iwidth;
   ImgD.height=(image.height*iwidth)/image.width;
  }
 }
 ImgD.style.display = "block";
} 


//图片自适应大小   
 //id为img控件的id   
//width与height为img父控件的宽高——即img的最大宽高   
 //示例：<img id="dd" src="ee.jpg" onload="imgFit(''dd'',100,200)" />"   

 function imgFit(id,width,height)   
 {   
     var imageArr=document.getElementById(id);   
     if(imageArr.offsetWidth>width || imageArr.offsetHeight>height)   
     {   
       imageRate1=parseInt(imageArr.offsetWidth)/width;   
       imageRate2=parseInt(imageArr.offsetHeight)/height;   
        if(imageRate2>imageRate1)   
           imageArr.style.height = imageArr.offsetHeight/imageRate2+"px";   
        else  
           imageArr.style.width = imageArr.offsetWidth/imageRate1 +"px";   
    }   

 }    
 
function img_resize(controlID,MaxWidth,MaxHeight)
{
	
    var imageArr=document.getElementById(controlID);
    var imageRate=imageArr.offsetWidth/imageArr.offsetHeight;    
    
    if(imageArr.offsetWidth>MaxWidth)
    {
        imageArr.style.width=MaxWidth+"px";
        imageArr.style.Height=MaxWidth/imageRate+"px";
    }
    
    if(imageArr.offsetHeight>MaxHeight)
    {
        imageArr.style.width=MaxHeight*imageRate + "px";
        imageArr.style.Height = MaxHeight+"px";
    }

}
