/*=============================================================================
  File     : EPDemoFrames.js
  Created  : 20/7/2004 19:45:35
  Author   : Sergey Steinvil
  Project  : Olive FileCabinet
  Contents : Scripts for activating application frames and 
=============================================================================
(C) Copyright 2000-2003  Olive Software Inc.  All Rights Reserved.
=============================================================================*/

var g_arrTabImages	= new Array("imgTabHome", "imgTabLibrary", "imgTabViewer", "imgTabSearchRes");
var g_arrTabFrames	= new Array("EP_HomeFrame", "EP_LibraryFrame", "EP_ViewerFrame", "EP_SearchResFrame");
var g_iActiveTab	= initialFrame;
var g_sFrameSetName = "EP_ContentFrame"; // name of the frame that contains application pages
function viewInitialTab()
{
	var ActiveTabName = g_arrTabImages[initialFrame];
	getObj(ActiveTabName).style.display = "block";
}

function onPageActivated(iPage)
{
	ActivateTab(iPage, true);
} // onPageActivated()

/******************************************************************************
 * Function : GetIFrameDocument()
 * Overview : Retrieves document object of HTML displayed inside IFRAME
******************************************************************************/
function GetIFrameDocument(oIFrame)
{
	if (!oIFrame)
		return null;
	var oDoc = (oIFrame.contentWindow || oIFrame.contentDocument);
	if (oDoc && oDoc.document)
		oDoc = oDoc.document;
	return oDoc;
} // GetIFrameDocument()

/******************************************************************************
 * Function : ActivateTab()
 * Overview : Switches to the tab specified by index
******************************************************************************/
function ActivateTab(iTabIndex, bIgnoreEmptyContent)
{
	if (g_iActiveTab == iTabIndex)
		return false;

	// Retrieve previous and next page IFRAME elements
	var tabPrevImg = getObj(g_arrTabImages[g_iActiveTab]);
	var tabNextImg = getObj(g_arrTabImages[iTabIndex]);
	var oContentFrame = eval("window.top.EP_ContentFrame");
	var tabPrevFrame = oContentFrame.getObj(g_arrTabFrames[g_iActiveTab]);
	var tabNextFrame = oContentFrame.getObj(g_arrTabFrames[iTabIndex]);
	
	// Check whether some HTML is loaded in the new (target) IFRAME
	if (!bIgnoreEmptyContent)
	{
		var oNextDoc = GetIFrameDocument(tabNextFrame);
		if (!oNextDoc || 
			!oNextDoc.location ||
			oNextDoc.location.href == "" ||
			oNextDoc.location.href == "about:blank")
		{
			alert("No data is available");
			return false;
		}
	}

/*
	var oFlashObj = co("divFlashReader");
	if (oFlashObj)
	{
		if(iTabIndex == 2)
		{
			oFlashObj.FlashContainerShow();
		}
		else
		{
			oFlashObj.FlashContainerHide();
		}
	}
*/

	// Switch tab:

	// Update visiblity of the IFRAME elements:
	if (tabPrevFrame)
	{
		// Settings size to zero causes NS7.2 (Windows) to work incorrectly 
		// when leaving viewer page.  
		// Workaround - set IFRAME size to one pixel
		tabPrevFrame.style.width = "1px";
		tabPrevFrame.style.height = "1px";
		tabPrevFrame.style.zIndex = 100;
	}
	else
		alert("Cannot retrieve currently active page frame");

	if (tabNextFrame)
	{
		tabNextFrame.style.width = "100%";
		tabNextFrame.style.height = "97%";
		tabNextFrame.style.zIndex = 1;
	}
	else
		alert("Cannot retrieve next page frame");

	g_iActiveTab = iTabIndex;

	// Update visiblity of the tab images:
	if (tabPrevImg)
		tabPrevImg.style.display = "none";
	if (tabNextImg)
		tabNextImg.style.display = "block";
	return true;
} // ActivateTab()

/******************************************************************************
 * Function : ShowHome()
 * Overview : Switches to the "Home" pane
******************************************************************************/
function ShowHome()
{
	ActivateTab(0);
} // ShowHome()

/******************************************************************************
 * Function : ShowLibrary()
 * Overview : Switches to the "Library" pane
******************************************************************************/
function ShowLibrary()
{
	ActivateTab(1);
} // ShowLibrary()

/******************************************************************************
 * Function : ShowViewer()
 * Overview : Switches to the "Viewer" pane
******************************************************************************/
function ShowViewer()
{
	ActivateTab(2);
} // ShowViewer()

/******************************************************************************
 * Function : ShowSearchRes()
 * Overview : Switches to the "Search Results" pane
******************************************************************************/
function ShowSearchRes()
{
	ActivateTab(3);
} // ShowSearchRes()
