<HTML>
<!--
Copyright (c) 2000 Microsoft Corporation
-->
<HEAD>
<meta http-equiv="MSThemeCompatible" content="Yes">
<TITLE>Remote Assistance</TITLE>
<LINK id="UI_StyleSheet" REL="stylesheet" TYPE="text/css" HREF="../../Css/rc.css">
</HEAD>
 
<SCRIPT Language="JavaScript">
	

//
// InitRAChatServer: Initiates the RA Chat Server end
//
function InitRAChatServer() 
{	
	var L_ERRACCESSDENIED_MSG	= "Directly launching this page is not allowed. ";

	if( null == parent.TraceFunctEnter )
	{
		idBody.style.visibility = "hidden";
		alert( L_ERRACCESSDENIED_MSG );
		return;
	}

	parent.TraceFunctEnter("InitRAChatServer");

	try
	{
		//
		// Get the focus on to the chat box.
		//
		chatText.click();
		chatText.select();	
	}
	catch(error)
	{
		parent.FatalError( error.description );
	}		    

	parent.TraceFunctLeave();		
	return;
}


//
// 	document.onkeydown: 
//
function document.onkeydown()
{
	if ((window.event.keyCode==8)&&(window.event.srcElement.id != "chatText"))
	{
		window.event.returnValue=false;
	}
	if ((window.event.shiftKey==false)&&(window.event.keyCode==9)&&(window.event.srcElement.id=="sendChatButton"))
	{
		parent.frames("idFrameTools").document.all("idChatimg").focus();
		window.event.returnValue=false;
	}
}

	

//
// OnEnter:
//
function OnEnter() 
{
	parent.TraceFunctEnter( "OnEnter" );

	try
	{
		if( false == parent.g_bConnected )
		{
			//
			// Not connected
			//
			parent.TraceFunctLeave();
			return;
		}

		if (window.event.keyCode == 13)
		{
			Helpee_SendChatData();
			parent.g_bNewLine = true;
			window.event.returnValue = false;
		}
	}
	catch(error)
	{
		parent.FatalError( error.description );
	}

	parent.TraceFunctLeave();
	return;
}	


//
// Helpee_SendChatData: Routine to send chat data
//
function Helpee_SendChatData() 
{
	parent.TraceFunctEnter("Helpee_SendChatData");

	try
	{
		if( false == parent.g_bConnected )
		{
			//
			// Not connected
			//
			parent.TraceFunctLeave();
			return;
		}

		if ( (parent.g_Helpee_oSAFRemoteDesktopSession != null) && ( chatText.value.length > 0))
		{
			//
			// Send the data across
			//	 
			parent.g_Helpee_oChatChannel.SendChannelData( chatText.value );

				
			//
			// Update user's chat history window
			//
			if(null != parent.g_szLocalUser)
			{
				parent.frames.idFrameChatTop.incomingChatText.value = parent.frames.idFrameChatTop.incomingChatText.value + "\n " + parent.g_szLocalUser + " says:\n   " + chatText.value;
			}
			else
			{
				parent.frames.idFrameChatTop.incomingChatText.value = parent.frames.idFrameChatTop.incomingChatText.value + parent.L_cszUserID + chatText.value;
			}
				
				
			//
			// Clear up the chat message window
			//
			chatText.value="";
			
			//Get the focus on to the chat box.
			chatText.click();
			chatText.select();

			parent.frames.idFrameChatTop.incomingChatText.doScroll("scrollbarDown");
		}
		
	}
	catch(error)
	{
		parent.FatalError( parent.L_ERRFATAL_MSG, error );
	}
	
	parent.TraceFunctLeave();
	return;
}

//
// Cut and Paste truncation code...
//
var flag = true;
function validatePaste()
{
	try
	{
		 if(flag)
		 {
			flag = false;
			var sSnapshot = clipboardData.getData("text");    
			var lpreText = chatText.innerText.length;

			if(IsActiveSelect())								// handles the case of highlighted text
			{  
				var selected = element.document.selection.createRange();
				lpreText -= selected.text.length;
			}    

			var sChop =  sSnapshot.substring( 0, chatText.Maxlength-lpreText+1);          
			clipboardData.setData("text",sChop);     
			document.execCommand("paste"); 			// calls paste method again
			event.returnValue = false;	 	                // cancels the action of the first call
			clipboardData.setData("text",sSnapshot);          // restores the clipboard                    
		}   
		else
		{ 
			flag = true;
		}
	}
	catch(error)
	{
		// Ignore this error
	}
}

function IsActiveSelect()
// returns a Boolean if there is currently something selected
{ 
	try
	{
		var selected = document.selection.createRange();
		if( selected.text.length > 0 )
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	catch(error)
	{
		// Ignore this error
	}
 }


</SCRIPT>


<BODY id="idBody" onload=InitRAChatServer() scroll=no tabindex=-1 onmouseover="">		
<Div id="ChatServerLayerBottom">
 <Table cellpadding=0 cellspacing=7 class="MaxLayout" border=0>
  <TR>
	<!--
		Chat text box
	-->
	  <TD class="Border">
				<TEXTAREA Maxlength=1024 onpaste="validatePaste();" tabindex=1 title="type new message here" class="styText ChatServerTextArea MaxLayout Overflow" align="center" id=chatText name=chatText onkeypress=OnEnter() wrap=VIRTUAL ></TEXTAREA>

	  </TD>	
	  <TD width=100px align="center">
		 <BUTTON class="MaxLayout stySubmitButton" type="submit" id=sendChatButton name=sendChatButton onclick=Helpee_SendChatData() tabindex=2 accesskey="S"> 
			<Center>
				<img src="../Common/SendChat.gif"> <BR>					
				<Span class="styText"> <u>S</u>end </Span>					
			</Center>	
		 </BUTTON> 
	 </TD>
  </TR>
 </Table> 
</div>
</BODY>
</HTML>