webcit_before_automake is now the trunk
[citadel.git] / webcit / static / instant_messenger.html
1 <html>
2 <head>
3         <title>Citadel Instant Messenger</title>
4         <script type="text/javascript" src="prototype.js"></script>
5         <script type="text/javascript" src="wclib.js"></script>
6 </head>
7 <body onLoad='FetchNewMsgs();'>
8
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">&nbsp;&nbsp;</div>
12 <div id="spacer2" style="background:#aaaaaa"><br></div>
13 </div>
14
15 <div id="main" style="position:fixed;width:100%;height:85%;top:15%;left:0%;overflow:auto;background:#ffffff"></div>
16
17 <script type="text/javascript">
18
19 var gexp_divs = new Array();
20 var num_gexp_divs = 0;
21 var shown_div = '';
22 var my_name = '';
23
24 function SendSomething(which_div, sendform, recipient) {
25         thetext = document.forms[sendform].elements['sendthis'].value;
26
27         // If the user didn't type anything, don't do anything.
28         if (thetext == '') {
29                 return false;
30         }
31
32         // Clear the box
33         document.forms[sendform].elements['sendthis'].value = '';
34
35         // Write it to the tab
36         $(which_div).innerHTML = $(which_div).innerHTML
37                                 + '<b>'
38                                 + '<font color=\"#FF0000\">'
39                                 + my_name
40                                 + '</font>'
41                                 + ':</b> '
42                                 + thetext
43                                 + '<br />\n';
44
45         // Scroll to the bottom of the tab
46         $('main').scrollTop = 999999;
47
48         // Send the text to the server
49         parms = 'r=' + Math.random()
50                 + '&g_cmd=SEXP ' + recipient + '|' + thetext;
51         new Ajax.Request('../ajax_servcmd',
52                 {
53                         method: 'get',
54                         parameters: parms
55                 }
56         );
57
58         // Refocus to the text box
59         document.forms[sendform].elements['sendthis'].focus();
60
61         // Don't submit the form
62         return false;
63 }
64
65 function TabSelect(which_div) {
66         if (shown_div != '') {
67                 $(shown_div).style.display = 'none' ;
68                 if ($('select_'+shown_div)) {
69                         $('select_'+shown_div).style.fontWeight = 'normal';
70                         $('select_'+shown_div).style.backgroundColor = '#cccccc';
71                 }
72         }
73         shown_div = 'tab_' + which_div;
74         $(shown_div).style.display = 'block' ;
75         if ($('select_'+shown_div)) {
76                 $('select_'+shown_div).style.fontWeight='bold';
77                 $('select_'+shown_div).style.backgroundColor = '#ffffff';
78         }
79 }
80
81
82 function ShowNewMsg(gexp_xmlresponse) {
83
84         // It isn't really XML.  It's a Citadel server response.
85         gexp_response = gexp_xmlresponse.responseText;
86
87         if (gexp_response.substring(0, 1) != '1') {
88                 return;
89         }
90
91         // Extract fields...
92         breakpos = gexp_response.indexOf('\n');
93         result = gexp_response.substring(0, breakpos-1);
94         the_message = gexp_response.substring(breakpos+1);
95         the_message = the_message.substring(0, the_message.indexOf('\n000'));
96         sender = extract_token(result.substring(4), 3, '|');
97
98         // Figure out which div to write it to...
99         which_div = '';
100         if (num_gexp_divs > 0) {
101                 for (i=0; i<num_gexp_divs; ++i) {
102                         if (gexp_divs[i] == sender) {
103                                 which_div = 'gexp' + i ;
104                         }
105                 }
106         }
107
108         // Not found?  Create it.
109         if (which_div == '') {
110                 gexp_divs[num_gexp_divs] = sender;
111                 which_div = 'gexp' + num_gexp_divs;
112                 ++num_gexp_divs;
113                 $('main').innerHTML =
114                           $('main').innerHTML
115                         + '<div id=\"tab_' + which_div + '\" style=\"display:none;cursor:pointer\">'
116                         + '<div id=\"' + which_div + '\">'
117                         + '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />'
118                         + '<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />'
119                         + '</div>'
120                         + '<div align=\"center\" id=\"response_'
121                         + which_div + '\" style=\"background:#ddddee\">'
122                         + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
123                         + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
124                         + which_div + '\', \'' + sender + '\');\">'
125                         + '<img src=\"citadelchat_16x.gif\">&nbsp;'
126                         + '<input type=\"text\" size=\"72\" maxlength=\"72\" name=\"sendthis\">'
127                         + '</form>'
128                         + '<br></div>'
129                         + '</div>\n';
130                 $('tab_bar').innerHTML =
131                           $('tab_bar').innerHTML
132                         + '<span id=\"select_tab_' + which_div + '\" onClick=\"TabSelect(\'' + which_div + '\');\">'
133                         + '&nbsp;' + sender + '&nbsp;'
134                         + '</span>&nbsp;&nbsp;&nbsp;';
135
136                 // Raise the window in case it was buried
137                 window.focus();
138         }
139
140         // Switch tabs
141         TabSelect(which_div);
142
143         // Write it to the tab
144         $(which_div).innerHTML = $(which_div).innerHTML
145                                 + '<b>'
146                                 + '<font color=\"#0000FF\">'
147                                 + sender
148                                 + '</font>'
149                                 + ':</b> '
150                                 + the_message
151                                 + '<br />\n';
152
153         // Scroll to the bottom of the tab
154         $('main').scrollTop = 999999;
155
156         // Refocus to the send box
157         document.forms['sendform_'+which_div].elements['sendthis'].focus();
158
159         // Keep trying for new messages until the server tells us to stop.
160         FetchNewMsgs();
161 }
162
163 // This is called periodically to check for new incoming messages
164 function FetchNewMsgs() {
165         parms = 'g_cmd=GEXP&r=' + Math.random();
166         new Ajax.Request('../ajax_servcmd',
167                 {
168                         method: 'get',
169                         parameters: parms,
170                         onSuccess: ShowNewMsg
171                 }
172         );
173 }
174
175 // Perform some initialization.
176 parms = 'g_cmd=GREG _SELF_&r=' + Math.random();
177 new Ajax.Request('../ajax_servcmd',
178         {
179                 method: 'get',
180                 parameters: parms,
181                 onSuccess: GrabMyName
182         }
183 );
184
185 // Learn my name.
186 function GrabMyName(greg_xmlresponse) {
187
188         // It isn't really XML.  It's a Citadel server response.
189         greg_response = greg_xmlresponse.responseText;
190
191         if (greg_response.substring(0, 1) != '1') {
192                 return;
193         }
194
195         // Extract fields...
196         breakpos = greg_response.indexOf('\n');
197         result = greg_response.substring(0, breakpos);
198         my_name = result.substring(4);
199 }
200
201
202 // Cause FetchNewMsgs() to be called periodically.
203 new PeriodicalExecuter(FetchNewMsgs, 10);
204
205 </script>
206
207
208 </body>
209 </html>