function openPopup(url, name, width, height, stringOfOptions) {
	if (width == 0) {
		width = screen.availWidth;
	}
	if (height == 0) {
		height = screen.availHeight;
	}
	if (stringOfOptions == "") {
		stringOfOptions = "scrollbars=yes,resizable=yes,location=no,status=no";
	}
	w = window.open(url,name,"width=" + width + ",height=" + height + "," + stringOfOptions);
	w.focus();
} 

function writeImgTag(img, imgWidth, imgHeight, title, configUrl) {
   width     = screen.availWidth - 30;
   height    = screen.availHeight - 88;
   maxWidth  = getMaxImgWidth(imgWidth, imgHeight, width, height);
   maxHeight = getMaxImgHeight(imgWidth, imgHeight, width, height);
   document.write('<a href="' + configUrl + '"><img src="' + img + '" alt="' + title + '" title="' + title + '" width="' + maxWidth + '" height="' + maxHeight + '" style="margin-top: ' + parseInt(((height - maxHeight) / 2 + 3)) + 'px; border: 1px solid #fff;" /></a>');
   return;
} 

function getMaxImgWidth(imgWidth, imgHeight, width, height) {
   if (width > imgWidth && height > imgHeight) {
      return imgWidth;
   } else if (width > imgWidth && height <= imgHeight) {
      return parseInt(imgWidth * (height / imgHeight));
   } else if (width <= imgWidth && height > imgHeight) {
      return parseInt(imgWidth * (width / imgWidth));
   } else {
      // if (width <= imgWidth && height <= imgHeight) 
      factor = width / imgWidth;
      if (imgHeight * factor > height) {
         factor = height / imgHeight;
      }
      return parseInt(imgWidth * factor);
   }
} 

function getMaxImgHeight(imgWidth, imgHeight, width, height) {
   if (width > imgWidth && height > imgHeight) {
      return imgHeight;
   } else if (width > imgWidth && height <= imgHeight) {
      return parseInt(imgHeight * (height / imgHeight));
   } else if (width <= imgWidth && height > imgHeight) {
      return parseInt(imgHeight * (height / imgHeight));
   } else {
      // if (width <= imgWidth && height <= imgHeight) 
      factor = width / imgWidth;
      if (imgHeight * factor > height) {
         factor = height / imgHeight;
      }
      return parseInt(imgHeight * factor);
   }
} 
