function ScreenArea(){
     this.clientWidth = 0;//可见区域宽度
     this.clientHeight = 0;//可见区域高度
  
  //可见区域宽度
  if(document.documentElement && document.documentElement.clientWidth){
   this.clientWidth = document.documentElement.clientWidth;
  }else if(document.body && document.body.clientWidth){
   this.clientWidth = document.body.clientWidth;
  }else if(window.innerWidth){
   this.clientWidth=window.innerWidth-18;
  }

  if(document.documentElement && document.documentElement.clientHeight){
   this.clientHeight=document.documentElement.clientHeight;
  }else if(document.body && document.body.clientHeight){
   this.clientHeight=document.body.clientHeight;
  }else if(window.innerHeight){
   this.clientHeight=window.innerHeight-18;   
  }

  this.bodyWidth = document.body.clientWidth;//网页宽度
     this.bodyHeight = document.body.clientHeight;//网页高度

     this.scrollLeft = (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft); 
     this.scrollTop = (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); 
  this.scrollWidth = (document.documentElement.scrollWidth ? document.documentElement.scrollWidth : document.body.scrollWidth); 
  this.scrollHeight = (document.documentElement.scrollHeight ? document.documentElement.scrollHeight : document.body.scrollHeight);
 }

 function fit(tw,th,sw,sh){
  var temw = tw;
  var temh = th;
  var flag = 1;
  
  if(sw<=tw && sh<=th){
   temw = sw;
   temh = sh;
   flag = 0;
  }else if(sw>tw && sh<=th){   
   temw = tw;
   temh = sh*(tw/sw);
  }else if(sw<=tw && sh>th){
   temw = tw*(th/sh);
   temh = th;
  }else if(sw>tw && sh>th){   
   var dw = tw/sw;
   var dh = th/sh;
   if((dw-dh)>=0){
    temw = tw;
    temh = sh*dw;
   }else{
    temw = sw*dh;
    temh = th;
   }
  } 

  return {'width':temw,'height':temh,'flag':flag};
 }

 function showImgView(imgSrc,imgWidth,imgHeight){
  var ca = new ScreenArea();
  var viewMask = document.createElement("DIV");
  viewMask.style.cssText="position:absolute;filter:alpha(opacity=50);opacity:0.5;visibility:visible;background:#000;";
  viewMask.style.zIndex=1;
  viewMask.style.top = 0;
  viewMask.style.left = 0;
  viewMask.style.width = (ca.bodyWidth)+'px';
  viewMask.style.height = (ca.bodyHeight)+'px';
  document.body.appendChild(viewMask);


  var imgDiv = document.createElement("DIV");
  imgDiv.style.position='absolute';
  imgDiv.style.border='3px solid #333333';
  imgDiv.style.zIndex=999;
  //imgView.content=imgDiv;
  imgDiv.style.left = Math.max((ca.scrollLeft+((ca.clientWidth-imgWidth)/2)),0) + 'px'; 
  //alert("ch="+ca.clientHeight);
  imgDiv.style.top = Math.max((ca.scrollTop+((ca.clientHeight-imgHeight)/2)),0) + 'px';
  //alert(ca.clientHeight);

  var imgObj=document.createElement("img");   
  imgObj.title="单击关闭";
  imgObj.onclick=function(){
   document.body.removeChild(imgDiv);
   document.body.removeChild(viewMask);
   //imgDiv.style.display='none';
   //viewMask.style.display='none';
  }
  imgObj.src=imgSrc;
  imgDiv.appendChild(imgObj);

  //imgView.imgObj=imgObj;
  document.body.appendChild(imgDiv);
 }

 function adapt(imgObj,tw,th,isView){
  var cw = parseInt(imgObj.width);
  var ch = parseInt(imgObj.height);
  var wh = fit(tw,th,cw,ch);
  //alert('w = '+wh.width);
  //alert('h = '+wh.height);
  imgObj.width = wh.width;
  imgObj.height = wh.height;
  //alert('flag = '+wh.flag);
  if(wh.flag !=0 && isView){
   imgObj.title="单击查看大图";
   imgObj.style.cursor = 'pointer';
   imgObj.onclick = function(){
    //alert('click');
	//alert(imgObj.width+"  "+imgObj.height+"  "+ cw+"  "+ ch);
    showImgView(imgObj.src,cw,ch);
   }
  }
 }