
// should be called by every toplevel frameset to enable client side
// timeouts
// @param timeoutUrl  url to display when the timeout happens
// @param customerid if the user has logged in to a custom config
// @param timeout in minutes
var cst;
function setClientSideTimeout(timeoutUrl, custId, timeout)
{
    if (cst)
    {
        clearTimeout(cst);
    }
    cst = setTimeout("clientSideTimeout('" + timeoutUrl + "','" + custId + "');", timeout*60*1000);
}

function clearClientSideTimeout()
{
    clearTimeout(cst);
}

// called when the user does nothing for a few minutes.  timeoutUrl must be URL encoded
// else a new webspirs session will be created when cookies are disabled
function clientSideTimeout(timeoutUrl, custId)
{
    // No longer include the customerid parameter in the URL as this is
    // determined from the UIState.startQuertString in the timeout page
    parent.ws_topFrame.location=timeoutUrl;
}

// Store the Webspsirs 5 popup windows as members of the top-level frameset
// Database guide window
var guideWindow;
// Important Message/Message of the day window
var impmsgWindow;
// Table of contents window
var tocWindow;
// Link popup window (listing full text and see also links) 
var linkWindow;
// Database Title Screen
var titleWindow;
// The window to show links that may be owned by a third party
var externalLinkWindow;
// The window to show hotlinks (e.g. from PsycLit or current Contents)
var hotlinkWindow;
// The about Webspirs 5 window
var aboutWindow;

//Functions to show the popup windows.  Urls must be passed in from the individual
// calling pages as the URL must be encoded by the calling page, not the top frame.
// This is because the session id associated with the top frame gets confused after
// logging out and in again with cookies disabled.

// Open a pop-up window with the database guide information
function showGuideWindow(dbGuideWindowUrl)
{
    if ( !guideWindow || guideWindow.closed )
    {
        guideWindow=window.open(dbGuideWindowUrl, "guide", "scrollbars,status,resizable,width=600,height=350");
    }
    guideWindow.focus();
}

//function to show Message of the Day in the message popup window
function showMsgOfDay(msgOfTheDayUrl)	
{
	if (!impmsgWindow || impmsgWindow.closed)
	{
		var impmsgprops = "height=450,width=600,location=no,directories=no,location=no,menubar=no,status=no,toolbar=no,resizable=no,left=100,top=100,dependent=true";
		impmsgWindow = window.open(msgOfTheDayUrl, "serverMessageWindow", impmsgprops);
	}
	impmsgWindow.focus();
}

//function to show Important Message in the message popup window
function showImpMsg(importantMessageUrl)	
{
	if (!impmsgWindow || impmsgWindow.closed)
	{
		var impmsgprops = "height=450,width=600,location=no,directories=no,location=no,menubar=no,status=no,toolbar=no,resizable=no,left=100,top=100,dependent=true";
		impmsgWindow = window.open(importantMessageUrl, "messageOfTheDayWindow", impmsgprops);
	}
	impmsgWindow.focus();
}

// Bring the TOC popup window to the front
function focusTocWindow()
{
	if (tocWindow && !tocWindow.closed)
	{
		tocWindow.focus();
	}
}

function showTocWindow(tocWindowUrl)
{
	if (!tocWindow || tocWindow.closed)
	{
    	tocWindow = window.open(tocWindowUrl,'TableOfContents','height=500,width=700,location=no,directories=no,menubar=no,status=no,toolbar=no,resizable=yes,left=100,top=100,screenX=100,screenY=100');
        tocWindow.opener = window;
	}
	else
	{
    	tocWindow.location.href = tocWindowUrl;
	}        
    tocWindow.focus();
}

function showWs5LinkPopup(linkWindowUrl)
{
    if (!linkWindow || linkWindow.closed)
    {
        linkWindow = window.open(linkWindowUrl,'ws5Links','height=450,width=600,resizable=yes,left=100,top=100,screenX=100,screenY=100,scrollbars=yes');
    }
    else
    {
        linkWindow.location.href = linkWindowUrl;
    }
    linkWindow.focus(); 
}

// Show window for cross-references (as in Psyclit, Current contents)
function showHotLink(link)
{
    hotlinkWindow = window.open(link,'hotLink','height=450,width=600,location=no,directories=no,menubar=no,status=no,toolbar=no,resizable=yes,left=100,top=100,screenX=100,screenY=100');
    hotlinkWindow.focus(); 
}

// Open a window to show third party data
function openLink(link)
{
    externalLinkWindow = window.open(link, 'externalLink');
    
    // Cannot set focus to a window showing content from another domain in IE4
    // as this generates a Javascript 'Access is denied' error
    if (navigator.userAgent.indexOf("MSIE 4") == -1)
    {
        externalLinkWindow.focus();
    }
}

// open a link from a select item
function ol (sel)
{
    if (sel.selectedIndex != 0)top.openLink(sel.options[sel.selectedIndex].value)
}


// Show the databse title screen
function getTitleScreen(titleScreenUrl)
{
    if ( !titleWindow || titleWindow.closed )
    {
       titleWindow=window.open(titleScreenUrl,"titleScreen","scrollbars,status,resizable,width=600,height=350");
    }
    else
    {
        titleWindow.location.href = titleScreenUrl;
    }
    titleWindow.focus();
}

//function to show About Webspirs 5 window
function showAboutWindow(aboutUrl)	
{
	if (!aboutWindow || aboutWindow.closed)
	{
		aboutWindow = window.open(aboutUrl, "aboutWindow","height=450,width=600,location=no,directories=no,location=no,menubar=no,status=no,toolbar=no,resizable=no,left=100,top=100");
	}
	aboutWindow.focus();
}

// Close all database specific popup windows
function closeDbSpecificWindows()
{
    closePopupWindow(titleWindow);
    closePopupWindow(guideWindow);
    closePopupWindow(tocWindow);
    closePopupWindow(linkWindow);
    closePopupWindow(hotlinkWindow);
}

// Close the database title screen popup
function closeTitleScreen()
{
    closePopupWindow(titleWindow);
}

// Close the TOC window
function closeTocWindow()
{
    closePopupWindow(tocWindow);
}

// Close the supplied popup window
function closePopupWindow(popupWindow)
{
    if (popupWindow && !popupWindow.closed)
    {
        popupWindow.close();
    }
    
}

// Close all popup windows
function closeAllPopupWindows()
{
    closeDbSpecificWindows();
    closePopupWindow(impmsgWindow);
    closePopupWindow(aboutWindow);
    closePopupWindow(top.helpWin);
    closePopupWindow(top.howdoi_popup);
}

function isEnter(evt)   
{
    return evt.which ? evt.which == 13 : evt.keyCode == 13;
}
function isTab(evt)
{
    return evt.which ? evt.which == 9 : evt.keyCode == 9;
}

