<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
</HEAD>
<BODY>

<TABLE>
<TBODY>
	<TR>
	<TD><BUTTON id=CreateNewSession name=CreateNewSession onclick=CreateNewSession()>Create Session</BUTTON></TD>
	<TD><BUTTON id=CloseSession name=CloseSession onclick=CloseSession()>Close Session</BUTTON></TD>
	<TD><BUTTON id=DisconnectSession name=DisconnectSession onclick=DisconnectSession()>Disconnect Active Session</BUTTON></TD>
	</TR>					
</TBODY>
</TABLE>

<HR>

<TABLE>
<TBODY>
	<TR>
	<TD><BUTTON id=OpenExistingSession name=OpenExistingSession onclick=OpenExistingSession()>Open Existing Session</BUTTON></TD>
	<TD><INPUT id=existingParms name=existingParms style="HEIGHT: 22px; WIDTH: 521px"></INPUT></TD>
	</TR>					
</TBODY>
</TABLE>

<HR>

<TABLE>
<TBODY>
	<TR>
	<TD><BUTTON id=updateConnectParms name=updateConnectParms onclick=UpdateConnectParms()>Update Connect Parms</BUTTON></TD>		
	<TD><INPUT id=connectParms name=connectParms style="HEIGHT: 22px; WIDTH: 521px"></INPUT></TD>
	</TR>
</TBODY>
</TABLE>

<HR>

<TABLE>
<TR>
	<TD><INPUT id=incomingChatText name=incomingChatText height="150" style="HEIGHT: 150px; WIDTH: 275px" width="275" 
     ></INPUT></TD>
</TR>
<TR>
	<TD><INPUT id=chatText name=chatText style="WIDTH: 275px" width="275" ></INPUT></TD>
	<TD><BUTTON id=sendChatButton name=sendChatButton onclick=SendChatButtonHandler()>Send</BUTTON></TD>
</TR>
</TABLE>

<SCRIPT Language="JScript">
	var RDSHost = null;
	var RemoteDesktopSession = null;
	var ChannelManager = null;
	var ChatChannel = null;
	
	function UpdateConnectParms() {
		if (RemoteDesktopSession != null) {
			var str;
			str = RemoteDesktopSession.ConnectParms;
			connectParms.value = str;
		}
	}
	
	function CreateNewSession() {

		if (RemoteDesktopSession != null) 
		{
			alert("Must close existing session first.");
			return;
		}

		RDSHost = new ActiveXObject("RDSHost.SAFRemoteDesktopServerHost.1");
		RemoteDesktopSession = RDSHost.CreateRemoteDesktopSession(4, false,  0, "");

		var x;

		ChannelManager = RemoteDesktopSession.ChannelManager;
		ChatChannel = ChannelManager.OpenDataChannel("70");
		ChatChannel.OnChannelDataReady = function() 
				{ OnChannelDataReadyEvent(); }
		
		// Bind events.
		RemoteDesktopSession.OnConnected = function() 
				{ OnClientConnected(); }
		RemoteDesktopSession.OnDisconnected = function() 
				{ OnClientDisconnected(); }
	}

	function OpenExistingSession() {

		if (RemoteDesktopSession != null) 
		{
			alert("Must close existing session first.");
			return;
		}

		RDSHost = new ActiveXObject("RDSHost.SAFRemoteDesktopServerHost.1");
		RemoteDesktopSession = RDSHost.OpenRemoteDesktopSession(existingParms.value);
		var x;

		ChannelManager = RemoteDesktopSession.ChannelManager;
		ChatChannel = ChannelManager.OpenDataChannel("70");
		ChatChannel.OnChannelDataReady = function() 
				{ OnChannelDataReadyEvent(); }
		
		// Bind events.
		RemoteDesktopSession.OnConnected = function() 
				{ OnClientConnected(); }
		RemoteDesktopSession.OnDisconnected = function() 
				{ OnClientDisconnected(); }
	}
	
	function CloseSession() {
		if (RemoteDesktopSession != null) {
			RDSHost.CloseRemoteDesktopSession(RemoteDesktopSession);
			RemoteDesktopSession = null;
		}
	}

	function DisconnectSession() {
		if (RemoteDesktopSession != null) {
			RemoteDesktopSession.Disconnect();
		}
	}
	
	function SendChatButtonHandler() {
		if (ChatChannel != null) {
			ChatChannel.SendChannelData(chatText.value);
		}
	}	
	
	function OnChannelDataReadyEvent(channelName) {
		var str;
		str = ChatChannel.ReceiveChannelData()
		incomingChatText.value = incomingChatText.value + "\n" + str; 
	}
	
	function OnClientConnected() {
		alert("Client connected.");
	}
	
	function OnClientDisconnected() {
		alert("Client disconnected.");	
	}
	
</SCRIPT>

</BODY>
</HTML>