// make sure popwin initilizes (see onlaod.js)
if (initialize) { initialize.popwin = true }

// popwin object used to store global variables and functions for popup windows
var popwin = new Object();

// popDefault popup
popwin.popDefault = new Object();
popwin.popDefault.w = 608;
popwin.popDefault.h = 566;

popwin.popSmall = new Object();
popwin.popSmall.w = 306;
popwin.popSmall.h = 296;

popwin.popZoom = new Object();
popwin.popZoom.w = 670;
popwin.popZoom.h = 670;

/**
* This function detects links that need to pop new windows and makes that happen.
*/
popwin.ini = function()
{
	// if the "did you lose your work" link is available, pop it
	var nav0_work = document.getElementById( 'nav0_work' );
	if (nav0_work)
	{
		nav0_work.className = 'popWindow';
		nav0_work.onclick = popwin.pop;
	}
	
	var pageContent = document.getElementById( 'pageContent' );
	
	if (!pageContent) { return false; }
	
	var cA = pageContent.getElementsByTagName( 'A' );
	var oA;
	var iA = 0;
	var nA = cA.length;

	if ( nA > 0 )
	{
		for ( iA ; iA < nA ; iA++ )
		{
			oA = cA[iA];

			// if these links have newWindow or popWindow, attach onclick event to them that pops the window
			if ( oA.className && ( oA.className.indexOf('newWindow')>-1 || oA.className.indexOf('popWindow')>-1 ) )
			{
				oA.onclick = popwin.pop;
			}
		}
	}
}

/**
* This function opens the link in a new window.
*/
popwin.pop = function()
{
	// store URL in variable
	var sURL = this.href;

	if (this.className.indexOf('newWindow') > -1 )
	{
		window.open(this.href);
		return false;
	}

	var popWinW = popwin.popDefault.w;
	var popWinH = popwin.popDefault.h;
	var popWinScrollbars = '1';

	if (this.className.indexOf('popWindowSmall') > -1 )
	{
		popWinW = popwin.popSmall.w;
		popWinH = popwin.popSmall.h;
		popWinScrollbars = '1';
	}
	else if (this.className.indexOf('popWindowZoom') > -1 )
	{
		popWinW = popwin.popZoom.w;
		popWinH = popwin.popZoom.h;
		popWinScrollbars = '0';
	}

	// combine and store popup parameters
	var sPopParams = 'height='+popWinH+',width='+popWinW+',scrollbars='+popWinScrollbars+',status=0,location=0,resizable=0,menubar=0';	

	if (this.className.indexOf('popWindowSmall') > -1 )
	{
		// open the popup window
		popwin.winSmall = window.open(sURL,'popwinPopSmall',sPopParams);

		// bring the popup window into the foreground, if it's behind the main window
		if (window.focus) {popwin.winSmall.focus()}
	}
	else if (this.className.indexOf('popWindowZoom') > -1 )
	{
		// open the popup window
		popwin.winZoom = window.open(sURL,'popwinPopZoom',sPopParams);

		// bring the popup window into the foreground, if it's behind the main window
		if (window.focus) {popwin.winZoom.focus()}
	}
	else
	{
		// open the popup window
		popwin.win = window.open(sURL,'popwinPop',sPopParams);

		// bring the popup window into the foreground, if it's behind the main window
		if (window.focus) {popwin.win.focus()}
	}

	// prevent main window from refreshing with url from link
	return false;
}