<?xjs
	load('webInit.ssjs');
	var f = new File(file_cfgname(system.ctrl_dir, 'services.ini'));
	if(f.open("r")) {
		var fspIni = f.iniGetObject('FlashPolicy');
		var wssIni = f.iniGetObject('WebSocket');
		f.close();
	}
	if(fspIni === undefined || fspIni === null) {
		var embed = false;
		var fspPort = 843;
	} else {
		var embed = true;
		var fspPort = fspIni.Port;
	}
	if(wssIni === undefined || wssIni === null) {
		var htmlterm = false;
	} else {
		var htmlterm = true;
		var wssPort = wssIni.Port;
	}
	f = new File(file_cfgname(system.ctrl_dir, 'sbbs.ini'));
	if(f.open("r")) {
		var sbbsIni = f.iniGetObject("BBS");
		f.close();
		var rloginPort = sbbsIni.RLoginPort;
		var telnetPort = sbbsIni.TelnetPort;
	} else {
		var rloginPort = 513;
		var telnetPort = 23;
	}
?>

<html>

<head>
<link rel="stylesheet" type="text/css" href="../style/style.css" />
<script type="text/javascript">
var ClientVars = {
	AlertDialogX : 0,
	AlertDialogY : 0,
	AutoConnect : 0,
	BitsPerSecond : 115200,
	CodePage : "437",
	ConnectButtonX : 0,
	ConnectButtonY : 0,
	ConnectAnsi : "http://<?xjs write(http_request.host); ?>:<?xjs write(webIni.HTTPPort); ?>/<?xjs write(webIni.appendURL); ?>/ftelnet/ftelnet-resources/connectansi.txt",
	Enter : "\r",
	FontWidth : 9,
	FontHeight : 16,
	LocalEcho : 0,
	RIP : 0,
	RIPIconPath : "/ripicon",
	RLogin : 0,
	RLoginHostName : "<?xjs write(http_request.host); ?>",
	RLoginPort : <?xjs write(rloginPort); ?>,
	RLoginClientUserName : "",
	RLoginServerUserName : "",
	RLoginTerminalType : "",
	ScreenColumns : 80,
	ScreenRows : 25,
	SendOnConnect : "",
	ServerName : "<?xjs write(system.name); ?>",
	SocketPolicyPort : <?xjs write(fspPort); ?>,
	TelnetHostName : "<?xjs write(http_request.host.replace(/\:\d*/g, "")); ?>",
	TelnetPort : <?xjs write(telnetPort); ?>,
	VirtualKeyboardWidth : 1,
	VT : 0,
	WebSocketHostName : "<?xjs write(http_request.host); ?>",
	WebSocketPort : 1123
};
</script>
<script type="text/javascript" src="./ClientFuncs.js"></script>
<script type="text/javascript" src="./swfobject.js"></script>
<script type="text/javascript" src="./HtmlTerm.compiled.js"></script>
<script type="text/javascript" src="./HtmlTerm.font2.js"></script>
<script type="text/javascript" src="./HtmlTerm.fontamiga.js"></script>
<script type="text/javascript" src="./HtmlTerm.fontatari.js"></script>
</head>

<body class="background">
<p style="text-align: center;">
<div id="ClientContainer"></div>
</p>
<script type="text/javascript">
	var embed = <?xjs write(embed); ?>;
	var htmlterm = <?xjs write(htmlterm); ?>;
	if(embed) {
		swfobject.embedSWF(
			"fTelnet.swf",
			"ClientContainer",
			"100%",
			"100%",
			"10.2.0",
			"playerProductInstall.swf",
			ClientVars,
			{
				allowfullscreen: "true",
				allowscriptaccess: "sameDomain",
				bgcolor: "#ffffff", quality: "high"
			},
			{
				align: "middle",
				id: "fTelnet",
				name: "fTelnet",
				swliveconnect: "true"
			},
			function (callbackObj) {
				if(!callbackObj.success)
					embed = false;
			}
		);
	}
	if(!embed && !htmlterm || (htmlterm && !HtmlTerm.Init("ClientContainer", ClientVars)))
		document.getElementById('ClientContainer').innerHTML = "Could not load fTelnet or HTMLTerm.";
</script>
</body>

</html>