<%@ Control Language="c#" %>
<%@ Register TagPrefix="CS" Namespace="CommunityServer.Controls" Assembly="CommunityServer.Controls" %>
<%@ Register TagPrefix="CA" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>
<%@ Register TagPrefix="CSD" Namespace="CommunityServer.Discussions.Controls" Assembly="CommunityServer.Discussions" %>

<script language="javascript">
function resizeTreeViewPane(newPaneHeight, newPaneWidth)
{
	var listing = document.getElementById('PostTree');
	var header = document.getElementById('PostTreeHeading');
	if (listing && header)
	{
		try
		{
			listing.style.height = (newPaneHeight - parseInt(header.offsetHeight)) + 'px';
			<%=ThreadTree.ClientID%>.Render();
		}
		catch (err)
		{
		}
	}
}

var displayPaneWidth, displayPaneHeight;
function resizePostDisplayPane(newPaneHeight, newPaneWidth)
{
	displayPaneWidth = newPaneWidth;
	displayPaneHeight = newPaneHeight;

	var iframe = document.getElementById('<%=PostContainer.ClientID%>');
	if (iframe && iframe.contentWindow && iframe.contentWindow.resizePostDisplay)
		iframe.contentWindow.resizePostDisplay(newPaneWidth, newPaneHeight);
		
}

function getPostDisplayWidthHeight()
{
	return new Array(displayPaneWidth, displayPaneHeight);
}

function updateLinkTargets(doc)
{
	try
	{
		if (doc && doc.getElementsByTagName)
		{
			var re = new RegExp('^javascript', 'i');
			var elements = doc.getElementsByTagName('A');
			for(var i = 0; i < elements.length; i++)
			{
				if (!elements[i].target && !re.test(elements[i].href))
					elements[i].target = "_top";				
			}
		}
	}
	catch (err)
	{
	}
}
</script>

<style>

/* override to ensure panels can be resized to window appropriately */
#CommonBodyTable
{
	table-layout: fixed;
}

</style>

<div class="CommonBreadCrumbArea" style="margin: 0px;"><CSD:BreadCrumb ShowHome="true" runat="server" id="Breadcrumb3"/></div>
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="table-layout: fixed;">
	<tr valign="top">
		<td id="PostTreeArea" class="ForumTreeArea" width="250">
			<div style="width: 250px;">
			<div id="PostTreeHeading">
				<CS:donut runat="server" id="TooManyPostsMessage" Visible="False"><div class="ForumDisplayMessage"><asp:Literal Runat="server" ID="Literal1" /></div></CS:donut>
				<div class="ForumPostTreeHeading"><CS:ResourceControl runat="server" ResourceName="PostThreadedView_PostTreeHeading" /></div>
			</div>
			<div id="PostTree" style="overflow: hidden; width: 100%; height: 100%;">
				<CA:TreeView id="ThreadTree" 
					DragAndDropEnabled="false" 
					NodeEditingEnabled="false"
					KeyboardEnabled="true"
					CssClass="ForumPostTree" 
					NodeCssClass="ForumPostTreeNode" 
					SelectedNodeCssClass="ForumPostTreeNodeSelected" 
					HoverNodeCssClass="ForumPostTreeNodeHover"
					LineImageWidth="19" 
					LineImageHeight="20"
					DefaultImageWidth="10" 
					DefaultImageHeight="11"
					ItemSpacing="0" 
					ImagesBaseUrl="~/themes/default/images/"
					NodeLabelPadding="3"
					ParentNodeImageUrl="icon_post_show.gif" 
					ExpandedParentNodeImageUrl="icon_post_show.gif" 
					LeafNodeImageUrl="icon_post_show.gif" 
					ShowLines="true" 
					LineImagesFolderUrl="~/themes/default/images/file/lines/"
					EnableViewState="false"
					ExpandNodeOnSelect="true"
					CollapseNodeOnSelect="false"
					AutoScroll="true"
					HoverPopupEnabled="true"
					width="100%"
					height="100%"
					runat="server"  />
					
				<CA:Menu id="PostContextMenu" 
					Orientation="Vertical"
					DefaultGroupCssClass="CommonContextMenuGroup"
					DefaultItemLookID="DefaultItemLook"
					DefaultGroupItemSpacing="1"
					EnableViewState="false"
					ContextMenu="Custom"
					runat="server">
					<ItemLooks>
						<CA:ItemLook LookID="DefaultItemLook" CssClass="CommonContextMenuItem" HoverCssClass="CommonContextMenuItemHover" ExpandedCssClass="CommonContextMenuItemHover" LabelPaddingLeft="10" LabelPaddingRight="10" LabelPaddingTop="3" LabelPaddingBottom="4" />
					</ItemLooks>
				</CA:Menu>
			</div>
			</div>
		</td>
		<td width="100%" id="PostContainerArea">
			<iframe runat="server" id="PostContainer" style="width: 100%; height: 100%;" border="0" frameborder="0"></iframe>
		</td>
	</tr>
</table>

<script language="javascript">

try
{
	var iframe = document.getElementById('<%=PostContainer.ClientID%>');
	if (iframe && iframe.contentWindow && iframe.contentWindow.location != iframe.src)
		iframe.contentWindow.location = iframe.src;
}
catch (err)
{
}

setTimeout(detectInvalidIframeContent, 999);
function detectInvalidIframeContent()
{
	try
	{
		var iframe = document.getElementById('<%=PostContainer.ClientID%>');
		if (iframe && iframe.contentWindow)
		{
			var url = iframe.contentWindow.location.href;
			if (url.toLowerCase().indexOf('http://') > -1 || url.toLowerCase().indexOf('https://') > -1)
			{
				var re = new RegExp('<%=CommunityServer.Discussions.Controls.PostThreadedView.ValidPostWindowUrlPattern%>', 'i');
				if (!re.test(url))
				{
					window.top.location = url;
					return;
				}
			}
		}
	}
	catch(err)
	{
	}
	
	setTimeout(detectInvalidIframeContent, 249);
}

setTimeout(detectWindowSize, 999);
var lastHeight = -1;
var lastWidth = -1;
function detectWindowSize()
{
	if (typeof(window.innerWidth) == 'number') 
	{
		width = window.innerWidth;
		height = window.innerHeight;
	} 
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) 
	{
		width = document.documentElement.clientWidth;
		height = document.documentElement.clientHeight;
	} 
	else if (document.body && (document.body.clientWidth || document.body.clientHeight)) 
	{
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	}
		
	height -= 270;
	if (height < 250)
		height = 250;
		
	if (lastHeight != height || lastWidth != width)
	{
		lastHeight = height;
		lastWidth = width;
		
		var postContainer = document.getElementById('<%= PostContainer.ClientID %>');
		postContainer.style.height = height + 'px';
		resizePostDisplayPane(height, document.getElementById('PostContainerArea').offsetWidth);
		resizeTreeViewPane(height, document.getElementById('PostTreeArea').offsetWidth);
	}

	setTimeout(detectWindowSize, 999);
}

</script>



