/*
 Copyright (C) 2000-2001  e.magination network, llc.  All Rights Reserved.
   Feel free to reuse or modify this code,
   provided this header remains in tact.
   http://www.emagination.com
   jibba jabba strikes again.
   
   5/31/2001 positioning for smaller resolutions fixed
   5/11/2001 AOL issue
*/

/*
features available:
	channelmode
	directories
	fullscreen
	location
	menubar
	resizable
	scrollbars
	status
	titlebar
	toolbar
*/

function openNewWindow(URL, windowName, intWidth, intHeight, featuresRequested) {

	var _isNS = (navigator.appName=="Netscape");
	var _isIE = (navigator.appName=="Microsoft Internet Explorer");
	//AOL detection (bug: returns false if used in first AOL browser window.)
	var _isAOL = (navigator.userAgent.indexOf("AOL ") >= 0);

	//default values
	if (!featuresRequested) featuresRequested = '';
	
	//declare
	var aryFeatureName = new Array(
		'channelmode',
		'directories',
		'fullscreen',
		'location',
		'menubar',
		'resizable',
		'scrollbars',
		'status',
		'titlebar',
		'toolbar'
	);
	var aryFeature = new Array();
	
	//default all features to 0 (no)
	for (var i in aryFeatureName) {
		aryFeature[aryFeatureName[i]] = 0;
	}

	//get array of features requested
	var aryFeaturesRequested = featuresRequested.split(',');
	//set any features requested to 1 (yes)
	for (var i in aryFeaturesRequested) {
		if (aryFeature[aryFeaturesRequested[i].replace(/ /g,'')] == 0) {//'no' means key exists
			aryFeature[aryFeaturesRequested[i].replace(/ /g,'')] = 1;
		}
	}

	//find browser dimensions
	var offsetWidth, offsetHeight;
	if (_isNS) {//ns
		offsetWidth = window.offsetWidth;
		offsetHeight = window.offsetHeight;
	}
	else if (_isIE) {//ie
		//need to account for all the bars and estimate size.
		offsetWidth = document.body.offsetWidth;
		offsetHeight = document.body.offsetHeight+180;
	}

	//determine width and height if undefined
	if (!intWidth) intWidth=offsetWidth;
	if (!intHeight) intHeight=offsetHeight;

	//construct feature string
	var strPopUpFeatures = '';
	
	var centerLeft = Math.ceil((screen.availWidth-intWidth-20)/2);
	var centerTop = Math.ceil((screen.availHeight-intHeight-20)/2);
	centerLeft = Math.max(0, centerLeft);
	centerTop = Math.max(0, centerTop);
	if (!_isAOL) {//AOL bug, document is moved rather than window
		strPopUpFeatures += 'left=' + centerLeft + ',';
		strPopUpFeatures += 'top=' + centerTop + ',';
	}

	if (intWidth) strPopUpFeatures += 'width=' + intWidth + ',';
	if (intHeight) strPopUpFeatures += 'height=' + intHeight + ',';
	for (var strFeature in aryFeature) {
		strPopUpFeatures += strFeature + '=' + aryFeature[strFeature] + ',';
	}
	//remove last comma
	strPopUpFeatures = strPopUpFeatures.replace(/\,$/,'');

	//open pop-up login
	var objWindow = window.open(URL, windowName, strPopUpFeatures);
	
	with (objWindow) {         
		//fix AOL bug: document actually moves right/down in the window, so move back.
		if (_isAOL) {
			moveTo(0,0);
		}

		//give focus to pop-up
		focus();
	
		//resize for chromeless browser window
		if (aryFeature['fullscreen'] == 1) {
			resizeTo(intWidth, intHeight);
			moveTo(centerLeft, centerTop);
		}
	}//with

	return objWindow;

}//openNewWindow

