function preview(what,maxWidth,maxHeight,outImage,defaultPic)
{
	var fileTypes=["gif","jpg","jpeg"];
	var source=what.value;
	var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
	for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
	if (i<fileTypes.length)
	{
		resizeImage(source,maxWidth,maxHeight,outImage);
	}
	else
	{
		resizeImage(defaultPic,maxWidth,maxHeight,outImage);
		if (source) alert("輸入圖檔錯誤！\n請使用圖檔且副檔名符合以下種類：\n\n"+fileTypes.join(", "));
	}
}
function resizeImage(sourceImage,maxWidth,maxHeight,outImage)
{
	globalPic=new Image();
	globalPic.src=sourceImage;
	var field=MM_findObj(outImage);
	var x=parseInt(globalPic.width);
	var y=parseInt(globalPic.height);
	if (x>maxWidth)
	{
		y*=maxWidth/x;
		x=maxWidth;
	}
	if (y>maxHeight)
	{
		x*=maxHeight/y;
		y=maxHeight;
	}
	field.style.display=(x<1 || y<1)?"none":"";
	field.src=globalPic.src;
	field.width=x;
	field.height=y;
}

