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="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"> </div>
12 <div id="spacer2" style="background:#aaaaaa"><br></div>
15 <div id="main" style="position:fixed;width:100%;height:85%;top:15%;left:0%;overflow:auto;background:#ffffff"></div>
17 <script type="text/javascript">
19 var gexp_divs = new Array();
20 var num_gexp_divs = 0;
24 function SendSomething(which_div, sendform, recipient) {
25 thetext = document.forms[sendform].elements['sendthis'].value;
27 // If the user didn't type anything, don't do anything.
33 document.forms[sendform].elements['sendthis'].value = '';
35 // Write it to the window
36 $(which_div).innerHTML = $(which_div).innerHTML
38 + '<font color=\"#FF0000\">'
45 // Send the text to the server
46 parms = 'r=' + Math.random()
47 + '&g_cmd=SEXP ' + recipient + '|' + thetext;
48 new Ajax.Request('../ajax_servcmd',
55 // Don't submit the form
59 function TabSelect(which_div) {
60 if (shown_div != '') {
61 $(shown_div).style.display = 'none' ;
62 if ($('select_'+shown_div)) {
63 $('select_'+shown_div).style.fontWeight = 'normal';
64 $('select_'+shown_div).style.backgroundColor = '#cccccc';
67 shown_div = 'tab_' + which_div;
68 $(shown_div).style.display = 'block' ;
69 if ($('select_'+shown_div)) {
70 $('select_'+shown_div).style.fontWeight='bold';
71 $('select_'+shown_div).style.backgroundColor = '#ffffff';
76 function ShowNewMsg(gexp_xmlresponse) {
78 // It isn't really XML. It's a Citadel server response.
79 gexp_response = gexp_xmlresponse.responseText;
81 if (gexp_response.substring(0, 1) != '1') {
86 breakpos = gexp_response.indexOf('\n');
87 result = gexp_response.substring(0, breakpos-1);
88 the_message = gexp_response.substring(breakpos+1);
89 the_message = the_message.substring(0, the_message.indexOf('\n000'));
90 sender = extract_token(result.substring(4), 3, '|');
92 // Figure out which div to write it to...
94 if (num_gexp_divs > 0) {
95 for (i=0; i<num_gexp_divs; ++i) {
96 if (gexp_divs[i] == sender) {
97 which_div = 'gexp' + i ;
102 // Not found? Create it.
103 if (which_div == '') {
104 gexp_divs[num_gexp_divs] = sender;
105 which_div = 'gexp' + num_gexp_divs;
107 $('main').innerHTML =
109 + '<div id=\"tab_' + which_div + '\" style=\"display:none;cursor:pointer\">'
110 + '<div id=\"' + which_div + '\">'
112 + '<div id=\"response_' + which_div + '\">'
113 + '<br><form method=\"post\" action=\"null\" name=\"sendform_' + which_div + '\" '
114 + 'onSubmit=\"return SendSomething(\'' + which_div + '\', \'sendform_'
115 + which_div + '\', \'' + sender + '\');\">'
116 + '<input type=\"text\" size=\"80\" maxlength=\"80\" name=\"sendthis\">'
120 $('tab_bar').innerHTML =
121 $('tab_bar').innerHTML
122 + '<span id=\"select_tab_' + which_div + '\" onClick=\"TabSelect(\'' + which_div + '\');\">'
123 + ' ' + sender + ' '
124 + '</span> ';
126 // Raise the window in case it was buried
131 TabSelect(which_div);
133 // Write it to the tab
134 $(which_div).innerHTML = $(which_div).innerHTML
136 + '<font color=\"#0000FF\">'
143 // Scroll to the bottom of the tab
144 $(which_div).scrolltop = $(which_div).scrollHeight - $(which_div).clientHeight;
147 // This is called periodically to check for new incoming messages
148 function FetchNewMsgs() {
149 parms = 'g_cmd=GEXP&r=' + Math.random();
150 new Ajax.Request('../ajax_servcmd',
154 onSuccess: ShowNewMsg
159 // Perform some initialization.
160 parms = 'g_cmd=GREG _SELF_&r=' + Math.random();
161 new Ajax.Request('../ajax_servcmd',
165 onSuccess: GrabMyName
170 function GrabMyName(greg_xmlresponse) {
172 // It isn't really XML. It's a Citadel server response.
173 greg_response = greg_xmlresponse.responseText;
175 if (greg_response.substring(0, 1) != '1') {
180 breakpos = greg_response.indexOf('\n');
181 result = greg_response.substring(0, breakpos);
182 my_name = result.substring(4);
186 // Cause FetchNewMsgs() to be called periodically.
187 new PeriodicalExecuter(FetchNewMsgs, 3);