// 图片相关函数 for Client Browser
// 作　　者： 苏州 dolfen@163.com
// 新建日期： 2006-06
// 修改日期： 2006-11-28


//自动调整图片大小，超过限制则自动按比例缩小。
//例子：
// <IMG onload="imgAutoSize(this,50,50)">  限定显示 宽度 和 高度。
// <IMG onload="imgAutoSize(this,50,-1)">  限定显示 宽度，不限 高度。
// <IMG onload="imgAutoSize(this,50,50,1)">  限制 宽度 和 高度，当图片尺寸大于限定显示尺寸时，自动添加超链接。
function imgAutoSize(ImgObject,MaxWidth,MaxHeight)
{
	//if(ImgObject.height>maxSize||ImgObject.width>maxSize)ImgObject.style.zoom=maxSize/(ImgObject.height>ImgObject.width?ImgObject.height:ImgObject.width);
	
	// 获取第4个参数（可选参数），0:[默认]不添加链接，1:当图片有缩小时自动添加超链接。
	var ShowLink= arguments.length>3 ? arguments[3] : 0;

	var obj;
	if(typeof(ImgObject)=="string")
	{
		if(ImgObject.Indexof(".")<0) obj=document.getElementById(ImgObject);
		else obj=eval(ImgObject);	
	}
	else if(typeof(ImgObject)=="object")
	{
		obj=ImgObject;
	}
	else return;

	var img=new Image();
	img.src=obj.src;	
	//alert(obj);
	var rate;
    if (img.width>MaxWidth && MaxWidth>=0)
    {
        rate=MaxWidth/img.width;
        obj.height=img.height*rate;
        obj.width=MaxWidth;
		ShowLink++;
    }
    if (img.height>MaxHeight && MaxHeight>=0)
    {
        rate=MaxHeight/img.height;
        obj.width=img.width*rate;
        obj.height=MaxHeight;
		ShowLink++;
    }
	if(ShowLink>1)
	{
		var oNewNode = document.createElement("a");
		oNewNode.href=obj.src;
		oNewNode.target="_blank";
		oNewNode.title="图片已缩小，点击查看原图";
		obj.applyElement(oNewNode);
	}
}

//在指定ImgObject显示图片，并且自动调整图片大小
// ImgObject： 显示对象 或者 对象ID
//例子：
//  <a id="lnk01" href="#"><IMG id="img01" alt="" src="" align=right></a>
//  <INPUT type="file" id="UploadFile1" runat="server"
//         onpropertychange="if(event.propertyName=='value'){imgShow(img01,100,100,this.value);}">
//  <INPUT type="file" id="UploadFile2" runat="server"
//         onpropertychange="if(event.propertyName=='value'){imgShow('img01',100,100,this.value);}">
//  <INPUT type="file" id="UploadFile3" runat="server"
//         onpropertychange="if(event.propertyName=='value'){imgShow('lnk01.childNodes[0]',100,100,this.value);}">
function imgShow(ImgObject,MaxWidth,MaxHeight,ImgSrc)
{
	//alert(ImgObject);
	//alert(ImgSrc);
	var o;
	if(typeof(ImgObject)=="string")
	{
		//alert("string "+ImgObject.indexOf("."));
		if(ImgObject.indexOf(".")<0) o=document.getElementById(ImgObject);
		else o=eval(ImgObject); //alert(eval(ImgObject)); //
	}
	else if(typeof(ImgObject)=="object")
	{
		//alert("object");
		o=ImgObject;
	}
	else return;
	//var o=document.getElementById(ImgObject);
	o.src=ImgSrc;

	var img=new Image();
	img.src=ImgSrc;
	var rate;
    if (img.width>MaxWidth)
    {
        rate=MaxWidth/img.width;
        o.height=img.height*rate;
        o.width=MaxWidth;
    }
    if (img.height>MaxHeight)
    {
        rate=MaxHeight/img.height;
        o.width=img.width*rate;
        o.height=MaxHeight;
    }
	
	//setTimeout("imgAutoSize('"+ImgObject+"',"+MaxWidth+","+MaxHeight+");alert('[string] "+ImgObject+","+MaxWidth+","+MaxHeight+"');",500);
}




