var childWindow;
var iframeElement;
var widthTimeout;

function adjustIFrameSize() {
	if (childWindow != null) {
		adjustIFrameSize();
	}
}

function adjustIFrameSize(iframeWindow) {

	// Keep iframe objects
	if(iframeWindow) {
		childWindow = iframeWindow;
		if (document.getElementById) {
			iframeElement = document.getElementById(childWindow.name);
		}
	}

	// Compute minimum height = height of window - topNav - bottomNav
	var newHeight=400;
	if(window.innerHeight) {
		// 107: header
		// 20 : footer
		newHeight=document.documentElement.scrollHeight-107-32;
	}
	else if(document.documentElement) {
		// 107: header
		// 20 : footer
		// 4  : offset (?)
		newHeight = document.documentElement.scrollHeight-107-32-4;
	}

	// Compute optimum height
	if (childWindow.document.body.scrollHeight) {
		if (childWindow.document.body.scrollHeight > newHeight) {
			newHeight = childWindow.document.body.scrollHeight;
		}
	}
	else {
		if (iframeElement.contentDocument.documentElement.offsetHeight > newHeight) {
			newHeight = iframeElement.contentDocument.documentElement.offsetHeight;
		}
	}

	// Set new height
	if (iframeElement.style.height) {
		iframeElement.style.height = newHeight;
		iframeElement.style.width = "100%";
	}
	else {
		iframeElement.height = newHeight;
		iframeElement.width = "100%";
    }

	//clearTimeout(widthTimeout);
	//widthTimeout = setTimeout("setOptimumWidth()", 512);
}

/**
 * Compute optimum width
 * Ensure that iframe width is not smaller than the top nav bar
 * Ensure that iframe is full-sized (when larger than top nav bar)
 * Iframe must have been resized to "100%" before computing optimum width,
 * this is why this method call is delayed.
function setOptimumWidth() {

	var newWidth=0;
	if (document.body.scrollWidth) {
		newWidth=document.body.scrollWidth;
	}
	else if(document.clientWeight) {
		newWidth=document.clientWeight;
	}
	
	if (iframeElement.contentDocument && iframeElement.contentDocument.documentElement) {
		if (iframeElement.contentDocument.documentElement.offsetWidth > newWidth) {
			newWidth = iframeElement.contentDocument.documentElement.offsetWidth;
		}
	}
	else if (childWindow.document.body.scrollWidth) {
		if (childWindow.document.body.scrollWidth > newWidth) {
			newWidth = childWindow.document.body.scrollWidth;
		}
	}
	
	if(newWidth>0) {
		if (iframeElement.style.height) {
			iframeElement.style.width = newWidth;
		}
		else {
			iframeElement.width = newWidth;
		}
	}
}
 */

function checkReloadOnResize() {
    if (isns()){
	    window.captureEvents(Event.Resize)
	    window.onresize = "reload()";
	}
}