3 <title>Citadel Instant Messenger</title>
4 <script type="text/javascript" src="prototype.js"></script>
5 <script type="text/javascript" src="wclib.js"></script>
9 <div id="tab_bar"></div>
13 <script type="text/javascript">
15 var gexp_divs = new Array();
16 var num_gexp_divs = 0;
19 function SendSomething(which_div, sendform, recipient) {
20 thetext = document.forms[sendform].elements['sendthis'].value;
22 // If the user didn't type anything, don't do anything.
28 document.forms[sendform].elements['sendthis'].value = '';
30 // Write it to the window
31 $(which_div).innerHTML = $(which_div).innerHTML
33 + '<font color=\"#FF0000\">'
40 // Send the text to the server
41 parms = 'r=' + Math.random()
42 + '&g_cmd=SEXP ' + recipient + '|' + thetext;
43 new Ajax.Request('../ajax_servcmd',
50 // Don't submit the form
54 function TabSelect(which_div) {
55 if (shown_div != '') {
56 $(shown_div).style.display = 'none' ;
57 if ($('select_'+shown_div)) $('select_'+shown_div).style.fontWeight='normal';
59 shown_div = 'tab_' + which_div;
60 $(shown_div).style.display = 'block' ;
61 if ($('select_'+shown_div)) $('select_'+shown_div).style.fontWeight='bold';
65 function ShowNewMsg(gexp_xmlresponse) {
67 // It isn't really XML. It's a Citadel server response.
68 gexp_response = gexp_xmlresponse.responseText;
70 if (gexp_response.substring(0, 1) != '1') {
75 breakpos = gexp_response.indexOf('\n');
76 result = gexp_response.substring(0, breakpos-1);
77 the_message = gexp_response.substring(breakpos+1);
78 the_message = the_message.substring(0, the_message.indexOf('\n000'));
79 sender = extract_token(result.substring(4), 3, '|');
81 // Figure out which div to write it to...
83 if (num_gexp_divs > 0) {
84 for (i=0; i<num_gexp_divs; ++i) {
85 if (gexp_divs[i] == sender) {
86 which_div = 'gexp' + i ;
91 // Not found? Create it.
92 if (which_div == '') {
93 gexp_divs[num_gexp_divs] = sender;
94 which_div = 'gexp' + num_gexp_divs;
98 + '<div id=\"tab_' + which_div + '\" style=\"display:none\">'
99 + '<div id=\"' + which_div + '\"></div>'
100 + '<div id=\"response_' + which_div + '\">'
101 + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
102 + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
103 + which_div + '\', \'' + sender + '\');\">'
104 + '<input type=\"text\" size=\"80\" maxlength=\"80\" name=\"sendthis\">'
108 $('tab_bar').innerHTML =
109 $('tab_bar').innerHTML
110 + '<span id=\"select_tab_' + which_div + '\" onClick=\"TabSelect(\'' + which_div + '\');\">'
112 + '</span> ';
114 // Raise the window in case it was buried
119 TabSelect(which_div);
121 // Write it to the tab
122 $(which_div).innerHTML = $(which_div).innerHTML
124 + '<font color=\"#0000FF\">'
132 // This is called periodically to check for new incoming messages
133 function FetchNewMsgs() {
134 parms = 'g_cmd=GEXP&r=' + Math.random();
135 new Ajax.Request('../ajax_servcmd',
139 onSuccess: ShowNewMsg
144 // ...and here's how we cause it to be called periodically.
145 new PeriodicalExecuter(FetchNewMsgs, 3);