3 <title>Citadel Instant Messenger</title>
4 <script type="text/javascript" src="prototype.js"></script>
5 <script type="text/javascript" src="wclib.js"></script>
7 <body onLoad='FetchNewMsgs();'>
9 <div id="thetop" style="position:fixed;width:100%;height:15%;top:0%;left:0%">
10 <div id="spacer1" style="background:#aaaaaa"><br></div>
11 <div id="tab_bar" style="background:#aaaaaa"> </div>
12 <div id="spacer2" style="background:#aaaaaa"><br></div>
15 <div id="main" style="position:fixed;width:100%;height:85%;top:15%;left:0%;overflow:auto;background:#ffffff"></div>
17 <script type="text/javascript">
19 * $Id: instant_messanger.html 7193 2009-03-07 17:24:58Z dothebart $
20 * Copyright 2000 - 2009 The Citadel Team
21 * Licensed under the GPL V3
23 * Chat window for Person 2 Person Chat
27 var gexp_divs = new Array();
28 var num_gexp_divs = 0;
32 function SendSomething(which_div, sendform, recipient) {
33 thetext = document.forms[sendform].elements['sendthis'].value;
35 // If the user didn't type anything, don't do anything.
41 document.forms[sendform].elements['sendthis'].value = '';
43 // Write it to the tab
44 $(which_div).innerHTML = $(which_div).innerHTML
46 + '<font color=\"#FF0000\">'
53 // Scroll to the bottom of the tab
54 $('main').scrollTop = 999999;
56 // Send the text to the server
57 parms = 'r=' + Math.random()
58 + '&g_cmd=SEXP ' + recipient + '|-\n' + escape(thetext);
59 new Ajax.Request('../ajax_servcmd',
66 // Refocus to the text box
67 document.forms[sendform].elements['sendthis'].focus();
69 // Don't submit the form
73 function TabSelect(which_div) {
74 if (shown_div != '') {
75 $(shown_div).style.display = 'none' ;
76 if ($('select_'+shown_div)) {
77 $('select_'+shown_div).style.fontWeight = 'normal';
78 $('select_'+shown_div).style.backgroundColor = '#cccccc';
81 shown_div = 'tab_' + which_div;
82 $(shown_div).style.display = 'block' ;
83 if ($('select_'+shown_div)) {
84 $('select_'+shown_div).style.fontWeight='bold';
85 $('select_'+shown_div).style.backgroundColor = '#ffffff';
90 function ShowNewMsg(gexp_xmlresponse) {
92 // It isn't really XML. It's a Citadel server response.
93 gexp_response = gexp_xmlresponse.responseText;
95 if (gexp_response.substring(0, 1) != '1') {
100 breakpos = gexp_response.indexOf('\n');
101 result = gexp_response.substring(0, breakpos-1);
102 the_message = gexp_response.substring(breakpos+1);
103 the_message = the_message.substring(0, the_message.indexOf('\n000'));
104 sender = extract_token(result.substring(4), 3, '|');
106 // Figure out which div to write it to...
108 if (num_gexp_divs > 0) {
109 for (i=0; i<num_gexp_divs; ++i) {
110 if (gexp_divs[i] == sender) {
111 which_div = 'gexp' + i ;
116 // Not found? Create it.
117 if (which_div == '') {
118 gexp_divs[num_gexp_divs] = sender;
119 which_div = 'gexp' + num_gexp_divs;
121 $('main').innerHTML =
123 + '<div id=\"tab_' + which_div + '\" style=\"display:none;cursor:pointer\">'
124 + '<div id=\"' + which_div + '\">'
125 + '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />'
126 + '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />'
128 + '<div align=\"center\" id=\"response_'
129 + which_div + '\" style=\"background:#ddddee\">'
130 + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
131 + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
132 + which_div + '\', \'' + sender + '\');\">'
133 + '<img src=\"citadelchat_16x.gif\"> '
134 + '<input type=\"text\" size=\"72\" maxlength=\"600\" name=\"sendthis\">'
138 $('tab_bar').innerHTML =
139 $('tab_bar').innerHTML
140 + '<span id=\"select_tab_' + which_div + '\" onClick=\"TabSelect(\'' + which_div + '\');\">'
141 + ' ' + sender + ' '
142 + '</span> ';
144 // Raise the window in case it was buried
149 TabSelect(which_div);
151 // Write it to the tab
152 $(which_div).innerHTML = $(which_div).innerHTML
154 + '<font color=\"#0000FF\">'
161 // Scroll to the bottom of the tab
162 $('main').scrollTop = 999999;
164 // Refocus to the send box
165 document.forms['sendform_'+which_div].elements['sendthis'].focus();
167 // Keep trying for new messages until the server tells us to stop.
171 // This is called periodically to check for new incoming messages
172 function FetchNewMsgs() {
173 parms = 'g_cmd=GEXP&r=' + Math.random();
174 new Ajax.Request('../ajax_servcmd',
178 onSuccess: ShowNewMsg
183 // Perform some initialization.
184 parms = 'g_cmd=GREG _SELF_&r=' + Math.random();
185 new Ajax.Request('../ajax_servcmd',
189 onSuccess: GrabMyName
194 function GrabMyName(greg_xmlresponse) {
196 // It isn't really XML. It's a Citadel server response.
197 greg_response = greg_xmlresponse.responseText;
199 if (greg_response.substring(0, 1) != '1') {
204 breakpos = greg_response.indexOf('\n');
205 result = greg_response.substring(0, breakpos);
206 my_name = result.substring(4);
210 // Cause FetchNewMsgs() to be called periodically.
211 new PeriodicalExecuter(FetchNewMsgs, 10);