var firstTime = true;
var timerID = 0;
var heights;
var widths;

//------------- ADD HANDLERS -----------------------------------------------
addEventHandlers();

function onLoadHandler()
{
	timerID = setTimeout('doResize()', 100);
}

function onResizeHandler()
{
	doResize();
}

// -------------------------------------------------------------------------
function doResize()
{	
	if (firstTime)
	{
		clearTimeout(timerID);
		firstTime = false;
		// Initialize arrays
		heights = [numberOfResizers];
		widths = [numberOfResizers];		
		// Add resizer iframes.
		addIframes();		
	}	
	
	var height = 0;
	var width = 0;
	var iframeResizerURL;
	for (i = 1; i<=numberOfResizers; i++)
	{
		var iframe = document.getElementById('HiddenIframe'+i);
		if (iframe.contentDocument && document.body.offsetHeight) // FFox
		{
			height = document.body.offsetHeight;
		}
		else // Others
		{
			height = document.body.scrollHeight;
		}
		width = document.body.scrollWidth;
		
		iframeResizerURL = eval('iframeResizerURL' + i);		
		
		// Uncomment the following line if you don't want the next alert on IE:
		//		----Security Information----------------------------------X--
		//		|This page contains both secure and nonsecure items" alert.	|
		//		|		Do you want to display the nonsecure items?			|
		//		|				[Yes]	[No]	[More info]					|
		//		-------------------------------------------------------------
		// WARNING: This will prevent the autoresize to work when the Association site is NON-Secure and the current ISGweb page is secure.
		
		//if (isSecureURL(location.href) && !isSecureURL(iframeResizerURL)) continue;

		var containerWidth = (document.documentElement.clientWidth != 0) ? document.documentElement.clientWidth : document.body.clientWidth;		
		if (containerWidth != widths[i])
		{
			if (!widths[i]) // If the value of the array is undefined, it will eventually get the "width" variable value.
			{
				widths[i] = width;
			}
			else
			{
				widths[i] = containerWidth;
			}
			iframe.src = iframeResizerURL +'?height='+height+'&width='+width;
		}
	}	
}

// -------------------------------------------------------------------------
function doForceResize()
{	
	var height = 0;
	var width = 0;
	for (i = 1; i<=numberOfResizers; i++)
	{
		var iframe = document.getElementById('HiddenIframe'+i);
		if (iframe.contentDocument && document.body.offsetHeight) // FFox
		{
			height = document.body.offsetHeight;
		}
		else // Others
		{
			height = document.body.scrollHeight;
		}
		width = document.body.scrollWidth;

		var containerWidth = (document.documentElement.clientWidth != 0) ? document.documentElement.clientWidth : document.body.clientWidth;		
		widths[i] = containerWidth;
		iframe.src = eval('iframeResizerURL' + i) +'?height='+height+'&width='+width;		
	}
}

// Add iFrames dinamically to the page -------------------------------------
function addIframes() 
{
	var iframeString = '';	
	for (i = 1; i<=numberOfResizers; i++)
	{
		var ifr = document.createElement('IFRAME');
		ifr.id = 'HiddenIframe' + i;
		ifr.width = 1;
		ifr.height = 1;
		ifr.style.position = 'absolute';
		ifr.style.top = '0px'; 
		ifr.style.left = '0px';
		ifr.src = '';
		ifr.style.visibility = 'hidden';
		document.body.appendChild(ifr);
	}
}

// Add  -------------------------------------
function isSecureURL(url) 
{
	return (url.substring(0,5) == 'https');
}


// Add handlers ------------------------------------------------------------
function addEventHandlers()
{
	if (window.addEventListener)
	{
		window.addEventListener("resize", onResizeHandler, false);
		window.addEventListener("load", onLoadHandler, false)
	}
	else if (window.attachEvent)
	{
		window.attachEvent("onresize", onResizeHandler);
		window.attachEvent("onload", onLoadHandler, false)
	}
	else
	{
		window.onResize = onResizeHandler
		window.onLoad = onLoadHandler
	}
}

// Remove handlers ---------------------------------------------------------
function removeEventHandlers()
{
	if (window.addEventListener)
	{
		window.removeEventListener("resize", onResizeHandler, false)
		window.removeEventListener("load", onLoadHandler, false)
	}
	else if (window.attachEvent)
	{
		window.detachEvent("onresize", onResizeHandler);
		window.detachEvent("onload", onLoadHandler);
	}
	else
	{
		window.onResize = null;
		window.onLoad = null;
	}
}

