// -----------------------------------------------------------------------------
//   customizable open window command

// r = resizable, s = scrollbars, t = toolbar, l = location, d = directories
// the order for rstld doesn't matter
// resizable default is yes, scrollbars,toolbar,location,directories defaults are no

// usage examples:

// openWindow('mylink.html,300,300,s,popWindowName'); -- pops a 300x300 window 
// with scrollbars named "popWindowName"

// openWindow('mylink.html'); -- pops a default size (hardwired to 640,400) 
// window to mylink.html

// openWindow('mylink.html,,,tlr'); -- pops a default size window to mylink.html 
// with tool and location bar that is NOT resizable
// NOTE: notice that in the example above there are two commas after the URL
// they're required in this case because we're adding the 'tlr' options
// commas without values will just pick up the default 640x400 values, or you 
// can change them to whatever. The rule is only the URL is required, but if you
// change a value downstream, then you need to fill in the values between the 
// URL and the value you're changing (even if it's only with a comma).

// It now centers the pop-up.
// -----------------------------------------------------------------------------

function openWindow(options) {

// URL,[width],[height],[rstld],[windowName]

	args=options.split(",");

	url = args[0];

 // default width declaration
 	if (args.length > 1 && args[1].length > 0) {
		W=args[1]; 
	} else { 
		W=740;
	}

 // default height declaration
	if (args.length > 2 && args[2].length > 0) {
		H=args[2]; 
	} else { 
		H=420; 
	}

	screenw = screen.availWidth;
	screenh = screen.availHeight;
	
// sets x,y coordinates to center window on screen
	x = "left=" + (screenw-W)/2 + ",";
	y = "top=" + (screenh-H)/2 + ",";
	
	W = "width=" + W + ",";
	H = "height=" + H + ",";
	
	if (args.length > 3) {
		prams= args[3]; 
	} else { 
		prams="";
	}

	if (args.length > 4) {
		windowname= args[4]; 
	} else { 
		windowname="";
	}

	if (prams.indexOf('l')!=-1) { loc="location=yes,"; } else { loc="location=no,"; }
	if (prams.indexOf('t')!=-1) { tbar="toolbar=yes,"; } else { tbar="toolbar=no,"; }
	if (prams.indexOf('s')!=-1) { sbars="scrollbars=yes,"; } else { sbars="scrollbars=no,"; }
	if (prams.indexOf('d')!=-1) { directories="directories=yes,"; } else { directories="directories=no,"; }
	if (prams.indexOf('r')!=-1) { resizable="resizable=yes"; } else { resizable="resizable=yes"; }
	
	str=loc+tbar+sbars+directories+W+H+x+y+resizable;

	newWindow=window.open(url,windowname,str);
	//if (newWindow !=null && newWindow.opener==null) { newWindow.opener=window; }
	
	if (window.focus) {
		newWindow.focus();
	}
}

