/******************************************************************************
* File:        winUtil.js
* 
* Description: A small function library for dealing with windows (popups,etc).
*
*/

/*****************************************************************************/
function pop( name ) 
{
	var popwin;

	popwin = window.open(filename, winname, 
		"toolbar=no,location=no,scrollbars=yes,directories=no,status=no,menubar=no,resizable=yes,height=" + h + ",width=" + w); 

	filename = "";

	popwin.focus();
}

/*****************************************************************************/
function popWin ( url, winName, attribs ) 
{	// Do a javascript popup window
	
	var popWin = window.open( url, winName, attribs );
	popWin.focus();
}

/*****************************************************************************/
function makeCenteredCoords ( theWidth, theHeight ) 
{	// Create screenX and screenY attributes for a window attribute string as 
	// used in window.open()
	
	var x = (0.5 * screen.width) - (0.5 * theWidth );
	var y = (0.5 * screen.height) - (0.5 * theHeight );	

	// Don't allow negative coordinates
	if( x < 0 ) x = 0;
	if( y < 0 ) y = 0;

	var coordsStr = "";

	if( window.screenX && window.screenY ) 
	{	// Certain netscape/mozilla versions
		coordsStr = "screenX=" + x + ",screenY=" + y;
	} 
	else
	{	// Should work w/ most other browsers
		coordsStr = "left=" + x + ",top=" + y;	
	}

	return( coordsStr );
}

/*****************************************************************************/
function popCentered( url, winName, theWidth, theHeight )
{	// Do a javascript popup window exactly in the center of the screen

	var winAttribs = 
		"width=" + theWidth + ",height=" + theHeight + "," + 
		makeCenteredCoords( theWidth, theHeight ) + 			// Get screenX and screenY
		",status=0,resizable=0";

	popWin( url, winName, winAttribs );
}

/******************************************************************************
* FUNCTIONS SPECIFIC TO THIS SITE
******************************************************************************/

/*****************************************************************************/
function popInfoFormWin( from ) 
{	// Do a javascript popup of the info request form, passing it a "from" 
	// parameter that designates the location from which the link was clicked

	// Window properties
	var winHeight = 0;
	var winWidth = 682;
	var defaultHeight = 600;
	var maxHeight = 750;
	var url = 'http://www.statenet.com/info/info.cgi?from=' + from + "&loc=" + document.location;
	var winName = 'infoForm';
	var attributeStr = "";

	if( screen.availHeight ) 
	{
		winHeight = screen.availHeight - 30;
		
		// Establish a maximum height
		if( winHeight > maxHeight ) winHeight = maxHeight;
	} 
	else if( screen.height ) 
	{
		winHeight = screen.height - 50;

		// Establish a maximum height
		if( winHeight > maxHeight ) winHeight = maxHeight;
	} 
	else 
	{
		// Screen height isn't defined, 
		// Assume user is in 800x600
		winHeight = defaultHeight;
	}

	// Construct window attribute string.
	attributeStr = 'width=' + winWidth + ',height=' + winHeight + ',screenX=0,screenY=0,left=0,top=0,scrollbars=yes,status=0';

	// alert( attributeStr );

	popWin( url, winName, attributeStr ); 
}
