function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function fitImagesByWidth() {
	var i;
	var shrinkage = 0;
	var imageWidth;
	var ratio;
	for (i = 0; i < document.images.length; i++) {
		imageWidth = getCookie(document.images[i].src + "width");
		if (imageWidth == null) {
			imageWidth = document.images[i].width;
			setCookie(document.images[i].src + "width", imageWidth);
		}
		if (document.body.clientWidth > 0 && imageWidth > (document.body.clientWidth - 40)) {
			ratio = document.images[i].height/document.images[i].width;
			document.images[i].width = (document.body.clientWidth - 40);
			document.images[i].height = ratio*document.images[i].width;
			document.getElementById('resizeTable').width = document.body.clientWidth - 40;
			bAdjusted = true;
		}
	}
//	document.getElementById('resizeTable').width = document.getElementById('resizeTable').width - shrinkage;
}			
function fitImagesByHeight() {
	var j;
	var imageHeight;
	var ratio;
	for (j = 0; j < document.images.length; j++) {
		imageHeight = getCookie(document.images[j].src + "height");
		if (imageHeight == null) {
			imageHeight = document.images[j].height;
			setCookie(document.images[j].src + "height", imageHeight);
		}
		if (document.body.clientHeight > 0 
			&& imageHeight > (document.body.clientHeight - 125)
			&& document.images[j].height > (document.body.clientHeight - 125)) {
			ratio = document.images[j].width/document.images[j].height;
			document.images[j].height = (document.body.clientHeight - 125);
			document.images[j].width = ratio*document.images[j].height;
		}
	}
	document.location.reload(true);
}			

function fitImages() {
	fitImagesByWidth();
	fitImagesByHeight();
}

