﻿function ImageOnLoad(obj,smaxwidth,smaxheight)
{

	var tmp,index,imageid
	var sheight,swidth
	var iheight,iwidth,imaxheight,imaxwidth	
	
	imageid = obj.id	

	
	sheight = document.all(imageid).height.toString();		
	index = sheight.lastIndexOf("px");			
	if(index != "-1")	
		sheight = sheight.substring(0,index);
	iheight = new Number(sheight);
	
	
	swidth = document.all(imageid).width.toString();		
	index = swidth.lastIndexOf("px");			
	if(index != "-1")	
		swidth = swidth.substring(0,index);	
	iwidth = new Number(swidth);
		
		
	index = smaxheight.lastIndexOf("px");		
	if(index != "-1")	
		smaxheight = smaxheight.substring(0,index);	
	imaxheight = new Number(smaxheight);
	
		
	index = smaxwidth.lastIndexOf("px");		
	if(index != "-1")	
		smaxwidth = smaxwidth.substring(0,index);
	imaxwidth = new Number(smaxwidth);	
	
	if((imaxheight != -1) && (imaxwidth != -1))
	{
		if(	iwidth / iheight > imaxwidth / imaxheight)
			imaxheight = -1;
		else
			imaxwidth = -1;
	}
	
	if(imaxheight == -1)
	{
//	alert(swidth+"_____"+smaxwidth);
		if(iwidth < imaxwidth)
			document.all(imageid).style.width = swidth;
		else
			document.all(imageid).style.width = smaxwidth;		
	}
	
	if(imaxwidth == -1)
	{
	//alert(sheight+"_____"+smaxheight);
		if(iheight < imaxheight)
			document.all(imageid).style.height = sheight;
		else
			document.all(imageid).style.height = smaxheight;		
	}
	
	
	
	//alert(sheight+"_____"+smaxheight);
	
		
			
	
}