3 <title>Citadel Instant Messenger</title>
4 <script type="text/javascript" src="prototype.js"></script>
5 <script type="text/javascript" src="wclib.js"></script>
10 The buttons to toggle between conversations will go here.
14 <script type="text/javascript">
16 var gexp_divs = new Array();
17 var num_gexp_divs = 0;
20 function SendSomething(which_div, sendform, recipient) {
21 thetext = document.forms[sendform].elements['sendthis'].value;
23 // If the user didn't type anything, don't do anything.
29 document.forms[sendform].elements['sendthis'].value = '';
31 // Write it to the window
32 $(which_div).innerHTML = $(which_div).innerHTML
34 + '<font color=\"#FF0000\">'
41 // Send the text to the server
42 parms = 'r=' + Math.random()
43 + '&g_cmd=SEXP ' + recipient + '|' + thetext;
44 new Ajax.Request('../ajax_servcmd',
51 // Don't submit the form
55 function ShowNewMsg(gexp_xmlresponse) {
57 // It isn't really XML. It's a Citadel server response.
58 gexp_response = gexp_xmlresponse.responseText;
60 if (gexp_response.substring(0, 1) != '1') {
65 breakpos = gexp_response.indexOf('\n');
66 result = gexp_response.substring(0, breakpos-1);
67 the_message = gexp_response.substring(breakpos+1);
68 the_message = the_message.substring(0, the_message.indexOf('\n000'));
69 sender = extract_token(result.substring(4), 3, '|');
71 // Figure out which div to write it to...
73 if (num_gexp_divs > 0) {
74 for (i=0; i<num_gexp_divs; ++i) {
75 if (gexp_divs[i] == sender) {
76 which_div = 'gexp' + i ;
81 // Not found? Create it.
82 if (which_div == '') {
83 gexp_divs[num_gexp_divs] = sender;
84 which_div = 'gexp' + num_gexp_divs;
86 $('main').innerHTML = $('main').innerHTML
87 + '<div id=\"tab_' + which_div + '\" style=\"display:none\">'
88 + '<div id=\"' + which_div + '\"></div>'
89 + '<div id=\"response_' + which_div + '\">'
90 + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
91 + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
92 + which_div + '\', \'' + sender + '\');\">'
93 + '<input type=\"text\" size=\"80\" maxlength=\"80\" name=\"sendthis\">'
100 if (shown_div != '') {
101 $(shown_div).style.display = 'none' ;
103 shown_div = 'tab_' + which_div;
104 $(shown_div).style.display = 'block' ;
106 // Write it to the tab
107 $(which_div).innerHTML = $(which_div).innerHTML
109 + '<font color=\"#0000FF\">'
117 // This is called periodically to check for new incoming messages
118 function FetchNewMsgs() {
119 parms = 'g_cmd=GEXP&r=' + Math.random();
120 new Ajax.Request('../ajax_servcmd',
124 onSuccess: ShowNewMsg
129 // ...and here's how we cause it to be called periodically.
130 new PeriodicalExecuter(FetchNewMsgs, 3);