/*
	By Tim S. Van Haren at CC Communications, Inc.
	
	- Adapted from the inline Javascript from DNN's IFrame.vb file
	- Moved the inline JS to this separate file
	- Added JQuery functionality to this script and to the IFrame.vb file
*/

function autoIframe(frameId, moreSpace)
{
	try
	{
		resizeFrameHeight(frameId, moreSpace);		
		resizeFrameWidth(frameId);
	}
	catch (err)
	{
		//alert(err.message);
	}
}

function resizeFrameHeight(frameId, moreSpace)
{
	//var frame = document.getElementById(frameId);
	//var innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
	//var objToResize = (frame.style) ? frame.style : frame;
	
	//objToResize.height =  innerDoc.body.scrollHeight + moreSpace;
	
	var iframe = jQuery('#' + frameId);
	var contents = iframe.contents();
		
	var bodyTag = jQuery('body', contents)[0];
	var htmlTag = jQuery('html', contents)[0];
	
	var bodyHeight = bodyTag.scrollHeight;
	var htmlHeight = htmlTag.scrollHeight;
	
	var docHeight;
	
	if (bodyHeight > htmlHeight)
	{
		docHeight = htmlHeight;	
	}
	else
	{
		docHeight = bodyHeight;	
	}	
	
	var newHeight = docHeight + moreSpace + 20;
	
	//alert(docHeight + " -> " + newHeight);
	
	iframe.attr('height', newHeight); 
}

function resizeFrameWidth(frameId)
{
	var iframe = jQuery('#' + frameId);
	var contents = iframe.contents();
	var htmlTag = jQuery('html', contents)[0];
	var docWidth = htmlTag.scrollWidth;
	
	var resizeWidth = jQuery('#resizeWidth', contents).val();
	var defaultWidth = jQuery('#defaultWidth', contents).val();
	
	if (resizeWidth == 'true')
	{
		iframe.attr('width', docWidth); 
	}
	else
	{
		iframe.attr('width', defaultWidth); 
	}
}