// JavaScript Document

//function f(n){return document.getElementById(n);}

var flag=false; 

function DrawImage(ImgD,w,h){ 

var image=new Image(); 

var iwidth = w;  //定义允许图片宽度 

var iheight = h;  //定义允许图片高度 

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.style.width=iwidth+"px";

   ImgD.style.height=(image.height*iwidth)/image.width+"px";

   var pgh=iheight - (image.height*iwidth)/image.width; 
   setHeight(ImgD,pgh);
   }else{ 

   ImgD.style.width=image.width+"px";

   ImgD.style.height=image.height+"px";
   
   var pgw=iwidth - image.width;
   var pgh=iheight - image.height;
   setWidth(ImgD,pgw);
   setHeight(ImgD,pgh);
   } 

  // ImgD.alt=image.width+"×"+image.height; 

   } 

else{ 

  if(image.height>iheight){   

   ImgD.style.height=iheight+"px";

   ImgD.style.width=(image.width*iheight)/image.height+"px";

   var pgw=iwidth - (image.width*iheight)/image.height;
   setWidth(ImgD,pgw);
   }else{ 

   ImgD.style.width=image.width+"px";
   ImgD.style.height=image.height+"px";
   var pgw=iwidth - image.width;
   var pgh=iheight - image.height;
   setWidth(ImgD,pgw);
   setHeight(ImgD,pgh);
   } 

   //ImgD.alt=image.width+"×"+image.height; 

   } 

} 

} 

function setWidth(ts,w)
{
	    if(w.toString().indexOf("."))w=parseInt(w.toFixed(0));// + 1;
		var iw=parseInt(w)/2;
		iw=iw.toFixed(0);
		var w_1=iw;
		var w_2=iw;
	    ts.style.paddingLeft=w_1+"px";
	    ts.style.paddingRight=w_2+"px";
}

function setHeight(ts,h)
{
	    if(h.toString().indexOf("."))h=parseInt(h.toFixed(0));// + 1;
		var ih=parseInt(h)/2;
		ih=ih.toFixed(0);
		var h_1=ih;
		var h_2=ih;
		ts.style.paddingTop=h_1+"px";
		ts.style.paddingBottom=h_2+"px";
}

