3 <title>Citadel Instant Messenger</title>
4 <script type="text/javascript" src="prototype.js"></script>
5 <script type="text/javascript" src="wclib.js"></script>
12 <script type="text/javascript">
14 var gexp_divs = new Array();
15 var num_gexp_divs = 0;
17 function SendSomething(which_div, sendform, recipient) {
18 thetext = document.forms[sendform].elements['sendthis'].value;
21 // If the user didn't type anything, don't do anything.
27 document.forms[sendform].elements['sendthis'].value = '';
29 // Write it to the window
30 $(which_div).innerHTML = $(which_div).innerHTML
32 + '<font color=\"#FF0000\">'
39 // Send the text to the server
40 parms = 'r=' + Math.random()
41 + '&g_cmd=SEXP ' + recipient + '|' + thetext;
42 new Ajax.Request('../ajax_servcmd',
49 // Don't submit the form
53 function ShowNewMsg(gexp_xmlresponse) {
55 // It isn't really XML. It's a Citadel server response.
56 gexp_response = gexp_xmlresponse.responseText;
58 if (gexp_response.substring(0, 1) != '1') {
63 breakpos = gexp_response.indexOf('\n');
64 result = gexp_response.substring(0, breakpos-1);
65 the_message = gexp_response.substring(breakpos+1);
66 the_message = the_message.substring(0, the_message.indexOf('\n000'));
67 sender = extract_token(result.substring(4), 3, '|');
69 // Figure out which div to write it to...
71 if (num_gexp_divs > 0) {
72 for (i=0; i<num_gexp_divs; ++i) {
73 if (gexp_divs[i] == sender) {
74 which_div = 'gexp' + i ;
79 // Not found? Create it.
80 if (which_div == '') {
81 gexp_divs[num_gexp_divs] = sender;
82 which_div = 'gexp' + num_gexp_divs;
84 $('main').innerHTML = $('main').innerHTML + '<table border=2><tr><td>'
85 + '<div id=\"' + which_div + '\"></div>'
86 + '<div id=\"response_' + which_div + '\">'
87 + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
88 + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
89 + which_div + '\', \'' + sender + '\');\">'
90 + '<input type=\"text\" size=\"80\" maxlength=\"80\" name=\"sendthis\">'
93 + '</td></tr></table><br><br>\n';
96 // Write it to the window
97 $(which_div).innerHTML = $(which_div).innerHTML
99 + '<font color=\"#0000FF\">'
107 // This is called periodically to check for new incoming messages
108 function FetchNewMsgs() {
109 parms = 'g_cmd=GEXP&r=' + Math.random();
110 new Ajax.Request('../ajax_servcmd',
114 onSuccess: ShowNewMsg
119 // ...and here's how we cause it to be called periodically.
120 new PeriodicalExecuter(FetchNewMsgs, 3);