// Copyright (c) 2002 TOBE Hitoshi. All rights reserved.
function doOpenExtWin_top( params) {
	var obj;
	var aFileName, aWinName, aOptions;
	var aOSType, aBrowserType, aVersion;
	var aAgent = window.navigator.userAgent.toLowerCase();
	var aAppName = window.navigator.appName.toLowerCase();
	var aAppVer = window.navigator.appVersion.toLowerCase();
	var aStart, aEnd;
	
	if( aAgent.indexOf( 'mac') >= 0) {
		aOSType = 'mac';
	} else if( aAgent.indexOf( 'win') >=0) {
		aOSType = 'win';
	} else {
		aOSType = '';
	}

	if( aAppName.indexOf( 'netscape') >= 0) {
		aBrowserType = 'nn';
	} else if( aAppName.indexOf( 'microsoft') >= 0) {
		aBrowserType = 'ie';
	} else {
		aBrowserType = '';
	}

	if( aBrowserType == 'nn') {
		aAppVer = window.navigator.appVersion;
		aEnd = aAppVer.indexOf( ' ', 0);
		aVersion = eval( aAppVer.substring( 0, aEnd));
		if( aVersion >= 5) {
			aVersion++;
		}
	} else if( aBrowserType == 'ie') {
		aAppVer = window.navigator.userAgent;
		aStart = aAppVer.indexOf( 'MSIE ', 0) + 5;
		aEnd = aAppVer.indexOf( ';', aStart);
		aVersion = eval( aAppVer.substring( aStart, aEnd));
	} else {
		aVersion = 0;
	}

	aFileName = params[ 'file_name'];
	if( params[ 'win_name'] == null) {
		aWinName = '';
	} else {
		aWinName = params[ 'win_name'];
	}
	
	aOptions = get_open_ext_win_options( params, aOSType, aBrowserType, aVersion);
	
	obj = window.open( aFileName, aWinName, aOptions);

	//window.open( aFileName, aWinName, aOptions);


	if( params[ 'focus'] == 1) {
		obj.focus();
	}

	return obj;

}

function get_open_ext_win_options( params, aOSType, aBrowserType, aVersion) {
	var aOptions = '';

	aOptions += get_open_ext_win_option_str( params, 'width', aOSType, aBrowserType, aVersion) + ',';
	aOptions += get_open_ext_win_option_str( params, 'height', aOSType, aBrowserType, aVersion) + ',';
	aOptions += get_open_ext_win_option_str( params, 'loc_left', aOSType, aBrowserType, aVersion) + ',';
	aOptions += get_open_ext_win_option_str( params, 'loc_top', aOSType, aBrowserType, aVersion) + ',';
	aOptions += get_open_ext_win_option_str( params, 'scrollbars', aOSType, aBrowserType, aVersion) + ',';
	aOptions += get_open_ext_win_option_str( params, 'resizable', aOSType, aBrowserType, aVersion) + ',';
	aOptions += get_open_ext_win_option_str( params, 'status', aOSType, aBrowserType, aVersion) + ',';
	aOptions += get_open_ext_win_option_str( params, 'location', aOSType, aBrowserType, aVersion) + ',';
	aOptions += get_open_ext_win_option_str( params, 'toolbar', aOSType, aBrowserType, aVersion) + ',';
	aOptions += get_open_ext_win_option_str( params, 'directories', aOSType, aBrowserType, aVersion) + ',';
	aOptions += get_open_ext_win_option_str( params, 'menubar', aOSType, aBrowserType, aVersion) + ',';
	aOptions += get_open_ext_win_option_str( params, 'titlebar', aOSType, aBrowserType, aVersion);
	
	return aOptions;
}

function get_open_ext_win_option_str( params, aID, aOSType, aBrowserType, aVersion) {
	var aLocalID;
	var aOptName;
	
	aBrowserType = ( aBrowserType == '') ? 'ie' : aBrowserType;
	if( aBrowserType == 'nn') {
		if( aVersion < 6) {
			aBrowserType = 'nn4';
		} else {
			aBrowserType = 'nn6';
		}
	}
	
	if( aID == 'loc_left') {
		aOptName = ( aBrowserType == 'ie') ? 'left' : 'screenX';
	} else if( aID == 'loc_top') {
		aOptName = ( aBrowserType == 'ie') ? 'top' : 'screenY';
	} else {
		aOptName = aID;
	}

	if( aID == 'width' || aID == 'height') {
		aLocalID = aID + '_' + aOSType + '_' + aBrowserType;
	} else {
		aLocalID = aID;
	}

	if( aID == 'width' || aID == 'height' || aID == 'loc_left' || aID == 'loc_top') {
		if( params[ aLocalID] == null || params[ aLocalID] == 0) {
			return '';
		} else {
			return aOptName + '=' + params[ aLocalID];
		}
	} else {
		if( params[ aLocalID] == null || params[ aLocalID] == 0) {
			return aOptName + '=no';
		} else {
			return aOptName + '=yes';
		}
	}
}

