<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ChatIEMessages.aspx.vb" Inherits="ChattyWays.ChatIEMessages" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
	<HEAD>
		<title>Chat Messages</title>
		<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
		<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
		<meta content="JavaScript" name="vs_defaultClientScript">
		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
		<LINK href="../includes/stylesheets/ChatStyle.css" rel="stylesheet">
		<!--
		'=======================================================================================
		'AUTHOR                  : David Silverlight
		'
		'CLAIM TO FAME      : Head Geek at XMLPitstop.com and CoFounder of NonProfitWays.com
		'
		'EMAIL                      : HeadGeek@XMLPitstop.com
		'
		'SHAMELESS PLUG  :Yes I am a consultant who is always looking for cool projects.
		'
		'PHONE                    : (561) 212-5707  Coconut Grove, Florida
		'
		'COPYWRIGHT		: This demo is not copywrighted so feel free to use it however it may help you.  Credit is always appreciated,
		'                                  but not required.  I created it simply for the learning experience. If you have any suggestions on areas that 
		'                                  can be improved upon, please feel free to email me.  All credit for enhancements will be given to 
		'                                  those who suggest them.  Enjoy.
		'=======================================================================================
	-->
	</HEAD>
	<BODY id="divBody" style="DISPLAY: block" bottomMargin="0" bgColor="white" leftMargin="0" topMargin="0" onload="doStartTimeOut();" rightMargin="0" onunload="doOnUnload();">
		<OBJECT id="MSXML3" style="DISPLAY: none" codeBase="msxml3.cab#version=8,20,8730,1" type="application/x-oleobject" data="data:application/x-oleobject;base64,EQ/Z9nOc0xGzLgDAT5kLtA==" classid="clsid:f5078f32-c551-11d3-89b9-0000f81fe221">
			<!-- The below object tag enables the automatic distribuion of the MSXML 3.0 
parser. MSXML 3.0 or above is required to support the DOM objects 		used in this 
chat application.  The MSXML 3.0 parser is included with the XP OS and also with 
IE6 and will not be installed if it already exists on 		your system.  In order 
to distribute the object, the MSXML 3.0 .cab file must reside in your virtual 
folder (or subfolder) of the web app		that will distribute the object. The .cab 
file is available from the Microsoft site.  The following explains each 
attribute of the object:				id			- Identifies the object. This attribute is 
optional and can be used for documentation purposes.		classid		- Unique ID that 
identifies the object. This attribute is mandatory and cannot be changed.
		codebase	- Specifies the path for the msxml3 .cab file and the version number. 
For example, if the msxml3 .cab file is located in 					the Objects folder of 
your website's root directory, the codebase can be changed to: 
codebase="Objects/msxml3.cab#version=8,20,8730,1"					NOTE: The version number 
can be changed if you want users to download a different version of MSXML 3.0. 
This example specifies the					MSXML 3.0 SP2.		type		- Specifies the type of 
object. This attribute cannot be changed.		style		- Specifies that the object is 
not displayed on the Web page. This attribute should not be changed.	-->
		</OBJECT>
		<form id="Form1" method="post" runat="server">
			<div style="DISPLAY: block; WIDTH: 100%; POSITION: absolute; TOP: 0px; HEIGHT: 5%; BACKGROUND-COLOR: lightblue">
				<table cellpadding="0" cellspacing="0" style="WIDTH: 100%; HEIGHT: 100%" border="0">
					<tr style="HEIGHT: 20px" bgColor="#afeeee">
						<td style="DISPLAY: block;FONT-SIZE: 14pt;WIDTH: 120px;COLOR: white;FONT-FAMILY: arial;HEIGHT: 20px;BACKGROUND-COLOR: darkblue"><span>Current 
								Chat:</span></td>
						<td><asp:textbox id="txtCurrentChatDesc" style="DISPLAY: block;FONT-SIZE: 14pt;COLOR: darkblue;FONT-FAMILY: arial" runat="server" Width="350" Height="30"></asp:textbox>
							<asp:textbox id="txtCurrentChatID" style="DISPLAY: none" runat="server" borderstyle="None" height="20px" width="26px"></asp:textbox>
							<asp:textbox id="txtLastMessageID" style="DISPLAY: none" runat="server" borderstyle="None" height="20px" width="26px"></asp:textbox>
							<asp:textbox id="txtSpeakerClass" style="DISPLAY: none" runat="server" borderstyle="None" height="20px" width="26px"></asp:textbox>
							<asp:textbox id="txtSpeakerName" style="DISPLAY: none" runat="server" borderstyle="None" height="20px" width="26px"></asp:textbox>
							<asp:textbox id="txtScreenName" style="DISPLAY: none" runat="server" borderstyle="None" height="20px" width="26px"></asp:textbox>
							<asp:textbox id="txtMessageClass" style="DISPLAY: none" runat="server" borderstyle="None" height="20px" width="26px"></asp:textbox>
							<asp:textbox id="txtMessageColor" style="DISPLAY: none" runat="server" borderstyle="None" height="20px" width="26px" value="blue"></asp:textbox>
							<asp:textbox id="txtSpeakerColor" style="DISPLAY: none" runat="server" borderstyle="None" height="20px" width="26px" value="black"></asp:textbox>
							<asp:textbox id="txtError" style="DISPLAY: none" runat="server" height="20px" width="26px" textmode="MultiLine"></asp:textbox>
						</td>
					</tr>
				</table>
			</div>
			<div id="divMessages" style="OVERFLOW-Y: scroll; Z-INDEX: 99; WIDTH: 100%; POSITION: relative; TOP: 5%; HEIGHT: 95%" DESIGNTIMEDRAGDROP="63">
				<table style="Z-INDEX: 99; WIDTH: 100%; HEIGHT: 100%" border="0">
					<tr>
						<td vAlign="top" style="WIDTH:85%" align="left" id="tblMessageCol">
							<asp:table id="tblNewMessages" runat="server" style="height19px:" valign="top" width="400"></asp:table>
						</td>
						<td vAlign="bottom" align="left" style="WIDTH:15%" bgColor="#afeeee">
							<asp:table id="tblChatters" runat="server" height="19" valign="top"></asp:table>
						</td>
					</tr>
				</table>
			</div>
			<div id="divBackgGround" style="Z-INDEX:50; LEFT:0px; WIDTH:100%; POSITION:absolute; TOP:5%; HEIGHT:95%">
				<iframe id="ChatTheme" name="ChatTheme" src="" style="Z-INDEX:50; LEFT:0px; WIDTH:100%; POSITION:absolute; TOP:0px; HEIGHT:100%">
				</iframe>
			</div>
		</form>
		<script language="JavaScript" src="../includes/ChatFuncsIE.js"></script>
		<script language="JavaScript">

	function doStartTimeOut(){
		try {
			window.setInterval("doAddTableRows()", 2000);			
			window.setInterval("doGetChatUsers()", 2050);	

			
		}
		catch (error) {
				alert("doStartTimeOut() in ChatIEMessages.aspx caused the following error: " + error.description)
			}
		}
		

		



	function doClearMessageTable()  {
		try {
			//Note:	This function is a wrapper to the "doClearTable()" function so that it is easier (for me, at least (ds)) to be called
			//		From other forms.
			doClearTable(tblNewMessages);
		}
		catch (error) {
			alert("doClearMessageTable() in ChatIEMessages.aspx caused the following error: " + error.description)
		}
	}

	function doOnUnload() {
		try {
			//On the unload of the form, we want to log off the current user so that they do not
			//appear to still be in the chat
			parent.frames(1).document.Form1.btSignOut.click();
		}
		catch (error) {
			alert("doOnUnload() in ChatIEMessages.aspx caused the following error: " + error.description)
		}

	}

	function doClearTable(tblData)  {
		try {
			var nTotalRows = tblData.rows.length;
			for (var nCounter = 0; nCounter < nTotalRows; nCounter++)  {
				tblData.deleteRow();
			}
		
		}
		catch (error) {
			alert("doClearTable() in ChatIEMessages.aspx caused the following error: " + error.description)
		}
	}


	function doAddSingleTableRow(strName, strMessage,strFontScheme) {
		try {
			var oRow;
			var oCell;
			var strMessageText;
			var strFontName = "arial";
			strFontName = "Courier";
			var strFontColor = "black";
			var strFontSize = "3";
			var strSpeakerClass = Form1.txtSpeakerClass.value ;		//"SpeakerTextWayTooLarge";
			var strMessageClass = Form1.txtMessageClass.value;		//"MessageTextWayTooLarge";



			var strSpeakerColor = Form1.txtSpeakerColor.value; 
			var strMessageColor=Form1.txtMessageColor.value; 

			//strSpeakerColor = "white";
			//strMessageColor = "yellow";



			//strName = Form1.txtSpeakerName.value;


			var strMessageText = "&nbsp;&nbsp;&nbsp;&nbsp;" + "<span name=txtSpeakerText id=txtSpeakerText class=" + strMessageClass + " style=color:" + strMessageColor + ";>" + strMessage +  "</span>"
			oRow = tblNewMessages.insertRow();
			oCell = oRow.insertCell();
			oCell.innerHTML = "<span width=100% name=txtSpeakerName id=txtSpeakerName class=" + strSpeakerClass + " style=color:" + strSpeakerColor + ";>" + strName + " says:" + "</font></span>"
			
			oRow = tblNewMessages.insertRow();
			oCell = oRow.insertCell();
			oCell.innerHTML = strMessageText

		}
		catch (error) {
			alert("doAddTableRows() in ChatMessages.aspx caused the following error: " + error.description)
		}
	}

	function doAddUserHeaderRow(strHeader, tblData, strClass) {
		try {
			var oRow;
			var oCell;
			var strMessageText;


			oRow = tblData.insertRow();
			oCell = oRow.insertCell();
			
			oCell.innerHTML = "<span name=txtChatUser id=txtChatUser class=" + strClass + ">"+ strHeader  + "</span>"
			

		}
		catch (error) {
			alert("doAddSingleUserRow() in ChatMessages.aspx caused the following error: " + error.description)
		}
	}

	function doAddSingleUserRow(strName, tblData, strClass, strUserID) {
		try {
			var oRow;
			var oCell;
			var strMessageText;


			oRow = tblData.insertRow();
			oCell = oRow.insertCell();
			oCell.innerHTML = "<span name=txtChatUser id=txtChatUser class=" + strClass + "><a href=javascript:doShowUser('" + strUserID + "')>" + strName  + "</a></span>"
			

		}
		catch (error) {
			alert("doAddSingleUserRow() in ChatMessages.aspx caused the following error: " + error.description)
		}
	}

	function doShowUser(strID) {
		try {
			var strEmoticon = doShowDialog("../UserInfo/ShowUserInfo.aspx?UserID=" + strID, "320px", "180px")
			
			//Set focus to the text box.  If this is not done, they enter key will not trigger when they press enter.
			parent.frames("footer").document.Form1.txtSendMessage.focus();
			
			
		} 
		catch (error) {
			alert("doShowEmoticonsSmall() in ChatIEBottom.aspx caused the following error: " + error.description)
		}
	}



	function doLoadXMLMessages()  {
		try {

			alert("You are here!");

			var strChatID = "206";
			var strLastMessageID = "1"
			var strSQL = "GetMessageXML.asmx/doGetLatestMessages?strChatID=" + strChatID + "&strLastMessageID=" + strLastMessageID
			alert(strSQL);
		
			objXML = new ActiveXObject("Microsoft.XMLDOM");
			objXML.async = false
			if (objXML.load(strSQL))
			{
				alert(objXML.xml);
			}
			else
			{
			alert("Error: " + objXML.parseError.reason);
			}

		
			alert(objXML.xml)

			}
		
	
		catch (error) {
			alert("doLoadXML() in ChatIEMessages.aspx caused the following error: " + error.description)
		}
	}

		</script>
		<script language="vbscript">
	function doAddTableRows() 
		dim objXML, strFullName, strMessage, strChatID, strLastMessageID, bNewData
		'msgbox("Hello")
		
			'doLoadXMLMessages()
			
		strChatID = Form1.txtCurrentChatID.value
		strLastMessageID = Form1.txtLastMessageID.value
		if strLastMessageID = "" or strLastMessageID = "0" then
			strLastMessageID = "0"
		end if
		set objXML = CreateObject("Microsoft.XMLDOM")

	
		
		
		objXML.async = false
		
		strSQL = "/localhost/ChattyWays/GetMessageXML.asmx/doGetLatestMessages?strChatID=" & strChatID & "&strLastMessageID=" & strLastMessageID
		msgbox(strSQL)
		bNewData = false
		objXML.load(strSQL)
		msgbox(objXML.xml)
		set objNodes = objXML.selectNodes("//Table")
		for each objNode in objNodes
			'strFullName = objNode.selectSingleNode("FirstName").text & " " & objNode.selectSingleNode("LastName").text
			
			strFullName = GetNodeValue(objNode, "ScreenName")
			if trim(strFullName) = "" then
				strFullName = GetNodeValue(objNode, "FirstName") & " " & GetNodeValue(objNode, "LastName")
			end if
			strMessage = GetNodeValue(objNode, "MessageText")
			strMessage = doAddEmoticons(strMessage)
			doAddSingleTableRow strFullName, strMessage
			document.all.txtLastMessageID.value = objNode.selectSingleNode("MessageID").text
			bNewData = true
		next
		
		if bNewData then
			tblNewMessages.scrollIntoView(false)
		end if
		
	end function
	
	function doGetChatUsers() 
		dim objXML, strFullName, strMessage, strChatID, strLastMessageID, bNewData, strChatHeader
		dim strScreenName, strFirstName, strLastName

		strChatID = Form1.txtCurrentChatID.value
		if strChatID = ""  then
			strChatID = "0"
		end if
		set objXML = CreateObject("Microsoft.XMLDOM")

		doClearTable(document.all.tblChatters)

		objXML.async = false
		
		'Call a Web Service to return all of the users of the current chat
		strSQL = "GetChatUsers.asmx/doGetChatUsers?strChatID=" & strChatID


		bNewData = false
		objXML.load(strSQL)

		'Extract all of the users and display them in the Chat Users section
		set objNodes = objXML.selectNodes("//Table")
		doAddUserHeaderRow "Current Chatters in:", tblChatters, "UserHeader"
		doAddUserHeaderRow Form1.txtCurrentChatDesc.value, tblChatters, "UserHeader"
		'msgbox(Form1.txtCurrentChatDesc.value)
		
		for each objNode in objNodes
			strScreenName = GetNodeValue(objNode, "ScreenName")
			strFirstName = GetNodeValue(objNode, "FirstName")
			strLastName = GetNodeValue(objNode, "LastName")
			strFullName = strFirstName & " " & strLastName  '& "(" & objNode.selectSingleNode("ScreenName").text & ")"
			if trim(strScreenName) <> "" then
				strFullName = strFullName & "(" & strScreenName & ")"
			end if

			strUserID = objNode.selectSingleNode("UserID").text
			doAddSingleUserRow strFullname, tblChatters, "UserData", strUserID
		next
		
	end function


	
	
		</script>
	</BODY>
</HTML>
