/*
            Name: centerWindow.js
      Written by: Greg Jaeger (jaeger@scra.org)
         Written: 10 Aug 2000
   Last Modified:  5 Apr 2004
       Copyright: ©2000-2004 SCRA® (www.scra.org)
     Description: Open a new Window automatically centered on the users screen
	  Parameters: url - URL of the window contents (required)
	              name - name of the window 
				  width  - width of the window  (<=1 : percentage of avail width, >1 : actual width)
				  height - height of the window (<=1 : percentage of avail height, >1 : actual width)
				  toolbar, location, directories,  |
				  status,menuBar, scrollBars,      |-- optional boolean flags to show browser window items
				  resizable                        |
	 
          Usage*: centerWindow('{url}' [,'window name', width, height, toolbar, location, directories, status, menuBar, scrollBars, resizable]);
                  centerWindow('something.html');
		          centerWindow('something.html','windowName',375,325);
		          centerWindow('something.html','windowName',.75,250,0,0,0,0,0,0,0);
				  
				  * if any parameter is desired then all previous parameters are required
*/

	var win
	function centerWindow(url, name, width, height, toolbar, location, directories, status, menuBar, scrollBars, resizable) {
		name   = (name   ? name   : "newWindow");						// set default values
		width  = (width  ? width  : 600);
		height = (height ? height : 400);

		if (window.screen) {											// calculate the inner window size
			var aw = screen.availWidth  - 10;							
			var ah = screen.availHeight - 30;

			width  = ((width > 1)  ? width  : Math.abs(width * aw) );	// percentaged window dimensions
			height = ((height > 1) ? height : Math.abs(height * ah) );
			
			str = "width="    + width  + ",innerWidth="  + width;
			str += ",height=" + height + ",innerHeight=" + height;

			var xc = (aw - width) / 2;								// calculate the XY position
			var yc = (ah - height) / 2;
			str += ",left=" + xc + ",screenX=" + xc;				// add the XY position
			str += ",top="  + yc + ",screenY=" + yc;
			}
		else {
			str  = "width=700";
			str += ",height=500";
			}
		
		str += ",toolbar="     + (toolbar ? toolbar : 0)			// default window attributes
		str += ",location="    + (location ? location : 0)
		str += ",directories=" + (directories ? directories : 0)
		str += ",status="      + (status ? status : 0)
		str += ",menuBar="     + (menuBar ? menubar : 0)
		str += ",scrollBars="  + (scrollBars ? scrollBars : 1)
		str += ",resizable="   + (resizable ? resizable : 1)

		win = window.open(url, name, str);							// open the window
	}

