﻿// JScript 文件
//自动缩放图片(图片，宽度，高度)
function ReSizeImage(ImgD,iwidth,iheight)
{ 
     var Width=ImgD.width;
     var Height=ImgD.height;
     
     if(Width>0 && Height>0)
     { 
        if(Width/Height>= iwidth/iheight)
        { 
           if(Width>iwidth)
           { 
               ImgD.style.width=iwidth + "px"; 
               ImgD.style.height=(Height*iwidth)/Width + "px"; 
           }
           else
           { 
               ImgD.style.width=Width + "px"; 
               ImgD.style.height=Height + "px"; 
           } 
           ImgD.alt=Width+"×"+Height; 
        } 
        else
        { 
            if(Height>iheight)
            { 
                ImgD.style.height=iheight + "px"; 
                ImgD.style.width=(Width*iheight)/Height + "px"; 
            }
            else
            { 
                 ImgD.style.width=Width + "px"; 
                 ImgD.style.height=Height + "px"; 
            } 
            ImgD.alt=Width+"×"+Height; 
        } 
　　　　ImgD.style.cursor= "pointer"; //改变鼠标指针 
　　　　ImgD.ondblclick = function() 
　　　　{
　　　　    window.open(this.src);
　　　　} //点击打开大图片 
　　　　ImgD.title = "双击图片可在新窗口打开"; 
    }
}

//给图片加上缩放功能(显示内容)
function replaceHTML(Content)
{
    Content = Content.replace(/<IMG/gi,"<IMG onerror=\"javascript:ImageRoadError(this)\" onload=\"javascript:ReSizeImage(this,600,480)\"");
   return Content;
}

//设置图片加载失败时的显示(图象对象)
function ImageRoadError(ImageObject)
{
     var noPic= "../images/ImageRoadError.gif";
     ImageObject.src=noPic;
     var image=new Image();
     image.src= noPic;
     image.onload = function ()
     {        
        ImageObject.width= image.width;
        ImageObject.height= image.height;        
     };
}

function ReSizeImageNotChange(ImgD,iwidth,iheight)
{ 
     var image=new Image(); 
     image.src=ImgD.src; 
     if(image.width>0 && image.height>0)
     { 
        if(image.width/image.height>= iwidth/iheight)
        { 
           if(image.width>iwidth)
           { 
               ImgD.width=iwidth; 
               ImgD.height=(image.height*iwidth)/image.width; 
           }
           else
           { 
               ImgD.width=image.width; 
               ImgD.height=image.height; 
           } 
           ImgD.alt=image.width+"×"+image.height; 
        } 
        else
        { 
            if(image.height>iheight)
            { 
                ImgD.height=iheight; 
                ImgD.width=(image.width*iheight)/image.height; 
            }
            else
            { 
                 ImgD.width=image.width; 
                 ImgD.height=image.height; 
            } 
            ImgD.alt=image.width+"×"+image.height; 
        } 
    }
}