﻿//图片缩放
function DownImage(ImgD,MaxWidth,MaxHeight,alignX,alignY)
{
	alignX=alignX||1;
	alignY=alignY||1;
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0)
	{
		var rate = (MaxWidth/image.width < MaxHeight/image.height)?MaxWidth/image.width:MaxHeight/image.height;
		var wid=0;
		var hid=0;
		if(rate <= 1)
		{
			wid=ImgD.width=image.width*rate;
			hid=ImgD.height=image.height*rate;
		}
		else
		{
			wid=ImgD.width=image.width;
			hid=ImgD.height=image.height;
		}
		if(alignX==1)
		{
			var ii=(MaxWidth-wid)/2;
			ImgD.style.marginLeft=ImgD.style.marginRight=ii+"px";
		}
		if(alignY==1)
		{
			var ii=(MaxHeight-hid)/2;
			ImgD.style.marginTop=ImgD.style.marginBottom=ii+"px";
		}
    }
    //fixPNG(ImgD);
}


function correctPNG()  
{ 
for(var i=0; i<document.images.length; i++) 
{ 
  var img = document.images[i] 
  var imgName = img.src.toUpperCase() 
  if (imgName.substring(imgName.length-3, imgName.length) == "PNG") 
  { 
   var imgID = (img.id) ? "id='" + img.id + "' " : "" 
   var imgClass = (img.className) ? "class='" + img.className + "' " : "" 
   var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' " 
   var imgStyle = "display:inline-block;" + img.style.cssText  
   if (img.align == "left") imgStyle = "float:left;" + imgStyle 
   if (img.align == "right") imgStyle = "float:right;" + imgStyle 
   if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle   
   var strNewHTML = "<span " + imgID + imgClass + imgTitle 
   + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 
  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
   + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"  
   img.outerHTML = strNewHTML 
   i = i-1 
  } 
} 
} 
window.attachEvent("onload", correctPNG); 


function winopen(url,target,width,height) 
{ 
    ContentWindow=window.open(url,target,"toolbar=no,width="+width+",height="+height+",directories=no,status=no,scrollbars=no,resize=no,menubar=no"); 
} 
