var maxThumbnailWidth = 140;
var thumbnailClassName = "thumbnailCategory";
function checkCategoryImageSizes(target)
{
	var el; 
	if(target == null)
	    el = document.getElementById("leftMain");
	else
	    el = document.getElementById(target);
	    
    if(el!=null)
    {
	    var arImg = el.getElementsByTagName("img");
	    for(i=0;i<arImg.length;i++)
	    {
		    if(arImg[i].className==thumbnailClassName)
		    {
			    resizeImage(arImg[i], maxThumbnailWidth);
		    }
	    }
	}
}
var maxWidth = 140;
var thumbnalClassName ="thumbnalCategory";
function checkCategoryImageSize(target)
{
	var el; 
	if(target == null)
	    el = document.getElementById("leftMain");
	else
	    el = document.getElementById(target);
	    
    if(el!=null)
    {
	    var arImg = el.getElementsByTagName("img");
	    for(i=0;i<arImg.length;i++)
	    {
		    if(arImg[i].className==thumbnalClassName)
		    {
			    resizeImage(arImg[i], maxWidth);
		    }
	    }
	}
}
var maxThumbWidth=100;
function checkCategoryImgSizes(target)
{
	var el;
	if(target == null)
	    el = document.getElementById("leftMain");
	else
	    el = document.getElementById(target);
	    
    if(el!=null)
    {
	    var arImg = el.getElementsByTagName("img");
	    for(i=0;i<arImg.length;i++)
	    {
		    if(arImg[i].className==thumbnailClassName)
		    {
			    resizeImage(arImg[i],maxThumbWidth);
		    }
	    }
	}
}
function checkProfileImageSize()
{
    var el = document.getElementById("main");
    if(el!=null)
    {
        var arImg = el.getElementsByTagName("img");
        for(i=0;i<arImg.length;i++)
        {
		    if(arImg[i].className=='supplierLogo')
		        resizeImage(arImg[i], 250);
        }
	}
}
// this function resizes while preserving aspect ratio
function resizeImage(prevImgObj, fixedWidthHeight)
{
	// create an image object
	actImg = new Image();

	// associate the Image object to the image
	actImg.src = prevImgObj.src;

	// get the file size , width and height of the image
	imgWidth = actImg.width;
	imgHeight = actImg.height;

	// to find the aspect ratio
	if ((imgWidth > fixedWidthHeight) || (imgHeight > fixedWidthHeight ) ) 
	{
		// if the width is greater than height then fix width = fixedWidthHeight
		if (imgWidth > imgHeight) {
			imgHeight = (imgHeight*fixedWidthHeight)/imgWidth;
			imgWidth = fixedWidthHeight;
		}
		// if the height is greater than width then fix height = fixedWidthHeight
		else if (imgWidth < imgHeight) {
			imgWidth = (imgWidth*fixedWidthHeight)/imgHeight;
			imgHeight = fixedWidthHeight;
		}
		// else both r equal
		else {
			imgWidth = fixedWidthHeight;
			imgHeight = fixedWidthHeight;
		}
	}

	// assign the calculated width and height to the preview image field.
	if(imgWidth==0) imgWidth = 100;
	if(imgHeight==0) imgHeight = 100;
	prevImgObj.width = imgWidth;
	prevImgObj.height = imgHeight;
	prevImgObj.style.display = "";
}
