// Window functions
// http://www.dithered.com/javascript/window/index.html
// code by Chris Nott (chris@dithered.com)
// rewrite 28,Oct,2002 (shige@works-sup.com)(http://www.works-sup.com)

/*******************************************************************************
	Popup Window openers
*******************************************************************************/

var winReference = null;

function openWindow(name, width, height, x, y, url, scrollbars, resizable, status, toolbar, location, directories, menubar) {

	// set properties
	var scrollbars  = ((scrollbars)  ? scrollbars  : 'yes');
	var resizable   = ((resizable)   ? resizable   : 'yes');
	var status      = ((status)      ? status      : 'yes');
	var toolbar     = ((toolbar)     ? toolbar     : 'no' );
	var location    = ((location)    ? location    : 'no' );
	var directories = ((directories) ? directories : 'no' );
	var menubar     = ((menubar)     ? menubar     : 'no' );
	var properties  = "scrollbars="+scrollbars+",resizable="+resizable+",status="+status+",toolbar="+toolbar+",location="+location+",directories="+directories+",menubar="+menubar;


	// set MAX size
	if ((String(width ).toLowerCase() == "max") && (String(height).toLowerCase() == "max")) {properties += ",fullscreen=yes"; x = 0; y = 0;}
	if ((String(width ).toLowerCase() == "max") && (screen)) width  = screen.width  - 10;
	if ((String(height).toLowerCase() == "max") && (screen)) height = screen.height - 30;


	// set CENTER position
	if ((String(x).toLowerCase() == "center") && (screen)) x = (screen.availWidth  - width ) / 2;
	if ((String(y).toLowerCase() == "center") && (screen)) y = (screen.availHeight - height) / 2;


	// set 0,0 position
	if (x == 0) properties += ",screenX=0,left=0";
	if (y == 0) properties += ",screenY=0,top=0";


	// the size of a window is adjusted
	var agent = navigator.userAgent.toLowerCase();
	if (agent.indexOf("mac") != -1) {
		if (agent.indexOf("msie 4") != -1)                        {             height +=  2; }
		if (agent.indexOf("msie 4") != -1 && scrollbars == "yes") { width -= 16;height -=  1; }
		if (agent.indexOf("msie 5") != -1 && scrollbars == "yes") { width -= 16;height -= 16; }
	}
	if (agent.indexOf("windows") != -1) {
		if (agent.indexOf("msie 5") != -1 && scrollbars == "yes") { width += 16;              }
		if (agent.indexOf("msie 6") != -1 && scrollbars == "yes") { width += 16;              }
	}


	// open window
	properties += ((width) ? ',width='   + width : '') + ((height) ? ',height='  + height : '');
	properties += ((x)     ? ',screenX=' + x     : '') + ((y)      ? ',screenY=' + y      : '');
	properties += ((x)     ? ',left='    + x     : '') + ((y)      ? ',top='     + y      : '');

	winReference = window.open(((url) ? url : ''), name, properties);


	// ie doesn't like giving focus immediately
	// (to new window in 4.5 on mac; to existing ones in 5 on pc)
	setTimeout('if (winReference && !winReference.closed) winReference.focus()', 250);
	return winReference;

}
