﻿// Function to find an IFRAME and set its height according to its contents
function setIframeHeight(pName, pMinHeight)
{
	var lHeight;
  var lWin = window.frames[pName]; // Works everywhere
	if (lWin)
		lHeight = documentHeight(lWin.document);
  if (!lHeight || (pMinHeight && lHeight < pMinHeight))	// Set minimum height
  {
		lHeight = pMinHeight;
	}

  var lElem = document.getElementById	// Find a function that works
		? document.getElementById(pName)
		: (document.all)
			? document.all[pName]
			: null;
  if (lElem)	// Did we get an element?
  {
    lElem.style.height = "auto";
		lElem.style.height = lHeight + "px";
  }
}

// Helper function to determine actual height of document contents
function documentHeight(pDoc)
{
	if (pDoc.height) // Find a function that works
		return pDoc.height;
	if (pDoc.body)
	{
		if (pDoc.body.scrollHeight)
			return pDoc.body.scrollHeight;
		if (pDoc.body.offsetHeight)
			return pDoc.body.offsetHeight;
	}
	return 0;
}

// Designed for calling from an onclick event
function loadIframe(pName, pUrl)
{
  if (window.frames[pName])
  {
    window.frames[pName].location = pUrl;   
    return false;
  }
  else return true;
}

// Designed for calling from an onclick event
function refreshIframe(pName)
{
  if (window.frames[pName])
  {
		var lstrUrl = window.frames[pName].location;
    window.frames[pName].location = lstrUrl;   
    return false;
  }
  else return true;
}

// Resize IFRAME from iframe "this" object
function resizeLocalIframe(pThat, pMinHeight)
{
	setIframeHeight(pThat.id, pMinHeight);
}
