var maxHeight = 100;  	//height to resize large imaes to
var maxWidth = 100; 	//width to resize large images to
var fileTypes = ["jpg","jpeg"];   //valid file types
var outImage = "previewField";			//the id of the preview image tag
var defaultPic = "asset\images\spacer.gif";
function preview(what)
{
	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;
	globalPic = new Image();
	if(i<fileTypes.length)
	{
	 	globalPic.src = source;
	}
	else
	{
		globalPic.src = defaultPic;
		alert("THAT IS NOT A VALID IMAGE"); //Please load an image with an extension of one of the following:\n\n+fileTypes.join(","))
	}
	setTimeout("applyChanges()",200);
}

var globalPic;
function applyChanges()
{
	var field = document.getElementById(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;
}