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="spacer1" style="background: #aaaaaa"><br></div>
10 <div id="tab_bar" style="background: #aaaaaa"> </div>
11 <div id="spacer2" style="background: #aaaaaa"><br></div>
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 TabSelect(which_div) {
56 if (shown_div != '') {
57 $(shown_div).style.display = 'none' ;
58 if ($('select_'+shown_div)) {
59 $('select_'+shown_div).style.fontWeight = 'normal';
60 $('select_'+shown_div).style.backgroundColor = '#cccccc';
63 shown_div = 'tab_' + which_div;
64 $(shown_div).style.display = 'block' ;
65 if ($('select_'+shown_div)) {
66 $('select_'+shown_div).style.fontWeight='bold';
67 $('select_'+shown_div).style.backgroundColor = '#ffffff';
72 function ShowNewMsg(gexp_xmlresponse) {
74 // It isn't really XML. It's a Citadel server response.
75 gexp_response = gexp_xmlresponse.responseText;
77 if (gexp_response.substring(0, 1) != '1') {
82 breakpos = gexp_response.indexOf('\n');
83 result = gexp_response.substring(0, breakpos-1);
84 the_message = gexp_response.substring(breakpos+1);
85 the_message = the_message.substring(0, the_message.indexOf('\n000'));
86 sender = extract_token(result.substring(4), 3, '|');
88 // Figure out which div to write it to...
90 if (num_gexp_divs > 0) {
91 for (i=0; i<num_gexp_divs; ++i) {
92 if (gexp_divs[i] == sender) {
93 which_div = 'gexp' + i ;
98 // Not found? Create it.
99 if (which_div == '') {
100 gexp_divs[num_gexp_divs] = sender;
101 which_div = 'gexp' + num_gexp_divs;
103 $('main').innerHTML =
105 + '<div id=\"tab_' + which_div + '\" style=\"display:none;cursor:pointer\">'
106 + '<div id=\"' + which_div + '\"></div>'
107 + '<div id=\"response_' + which_div + '\">'
108 + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
109 + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
110 + which_div + '\', \'' + sender + '\');\">'
111 + '<input type=\"text\" size=\"80\" maxlength=\"80\" name=\"sendthis\">'
115 $('tab_bar').innerHTML =
116 $('tab_bar').innerHTML
117 + '<span id=\"select_tab_' + which_div + '\" onClick=\"TabSelect(\'' + which_div + '\');\">'
118 + ' ' + sender + ' '
119 + '</span> ';
121 // Raise the window in case it was buried
126 TabSelect(which_div);
128 // Write it to the tab
129 $(which_div).innerHTML = $(which_div).innerHTML
131 + '<font color=\"#0000FF\">'
139 // This is called periodically to check for new incoming messages
140 function FetchNewMsgs() {
141 parms = 'g_cmd=GEXP&r=' + Math.random();
142 new Ajax.Request('../ajax_servcmd',
146 onSuccess: ShowNewMsg
151 // ...and here's how we cause it to be called periodically.
152 new PeriodicalExecuter(FetchNewMsgs, 3);