1
|
|
2
|
/* ---- Variables ---- */
|
3
|
var actb_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
|
4
|
var actb_lim = 5; // Number of elements autocomplete can show (-1: no limit)
|
5
|
var actb_firstText = false; // should the auto complete be limited to the beginning of keyword?
|
6
|
/* ---- Variables ---- */
|
7
|
|
8
|
/* --- Styles --- */
|
9
|
var actb_bgColor = '#FFFFFF';
|
10
|
var actb_textColor = '#000000';
|
11
|
var actb_hBgColor = '#990000';
|
12
|
var actb_htextColor = '#FFFFFF';
|
13
|
var actb_fFamily = 'Courier';
|
14
|
var actb_fSize = '14px';
|
15
|
var actb_hStyle = 'text-decoration:underline;font-weight="bold"';
|
16
|
/* --- Styles --- */
|
17
|
|
18
|
/* ---- Constants ---- */
|
19
|
var actb_keywords = new Array();
|
20
|
var actb_display = true;
|
21
|
var actb_pos = 0;
|
22
|
var actb_total = 0;
|
23
|
var actb_curr = null;
|
24
|
var actb_rangeu = 0;
|
25
|
var actb_ranged = 0;
|
26
|
var actb_bool = new Array();
|
27
|
var actb_pre = 0;
|
28
|
var actb_toid;
|
29
|
var actb_tomake = true;
|
30
|
/* ---- Constants ---- */
|
31
|
|
32
|
function actb_parse(n){
|
33
|
var t = escape(actb_curr.value);
|
34
|
var tobuild = '';
|
35
|
var i;
|
36
|
var re = "";
|
37
|
|
38
|
if (actb_firstText){
|
39
|
re = new RegExp("^" + t, "i");
|
40
|
}else{
|
41
|
re = new RegExp(t, "i");
|
42
|
}
|
43
|
var p = n.search(re);
|
44
|
|
45
|
for (i=0;i<p;i++){
|
46
|
tobuild += n.substr(i,1);
|
47
|
}
|
48
|
tobuild += ""
|
49
|
for (i=p;i<t.length+p;i++){
|
50
|
tobuild += n.substr(i,1);
|
51
|
}
|
52
|
tobuild += "";
|
53
|
for (i=t.length+p;i<n.length;i++){
|
54
|
tobuild += n.substr(i,1);
|
55
|
}
|
56
|
return tobuild;
|
57
|
}
|
58
|
function actb_generate(){
|
59
|
if(navigator.appName == "Microsoft Internet Explorer")
|
60
|
if (document.getElementById('tat_frame')) document.body.removeChild(document.getElementById('tat_frame'));
|
61
|
if (document.getElementById('tat_table')) document.body.removeChild(document.getElementById('tat_table'));
|
62
|
if(navigator.appName == "Microsoft Internet Explorer") {
|
63
|
frame = document.createElement('iframe');
|
64
|
frame.cellSpacing='1px';
|
65
|
frame.cellPadding='2px';
|
66
|
frame.style.zIndex = 3;
|
67
|
frame.style.position='absolute';
|
68
|
frame.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
|
69
|
frame.style.left = curLeft() + "px";
|
70
|
frame.style.backgroundColor=actb_bgColor;
|
71
|
frame.id = 'tat_frame';
|
72
|
}
|
73
|
a = document.createElement('table');
|
74
|
a.cellSpacing='1px';
|
75
|
a.cellPadding='2px';
|
76
|
a.style.border = '1px solid #990000';
|
77
|
a.style.zIndex = 5;
|
78
|
a.style.position='absolute';
|
79
|
a.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
|
80
|
a.style.left = curLeft() + "px";
|
81
|
a.style.backgroundColor=actb_bgColor;
|
82
|
a.id = 'tat_table';
|
83
|
if(navigator.appName == "Microsoft Internet Explorer")
|
84
|
document.body.appendChild(frame);
|
85
|
document.body.appendChild(a);
|
86
|
var i;
|
87
|
var first = true;
|
88
|
var j = 1;
|
89
|
var height = 0;
|
90
|
var counter = 0;
|
91
|
for (i=0;i<actb_keywords.length;i++){
|
92
|
if (actb_bool[i]){
|
93
|
counter++;
|
94
|
r = a.insertRow(-1);
|
95
|
if (first && !actb_tomake){
|
96
|
r.style.backgroundColor = actb_hBgColor;
|
97
|
first = false;
|
98
|
actb_pos = counter;
|
99
|
}else if(actb_pre == i){
|
100
|
r.style.backgroundColor = actb_hBgColor;
|
101
|
first = false;
|
102
|
actb_pos = counter;
|
103
|
}else{
|
104
|
r.style.backgroundColor = actb_bgColor;
|
105
|
r.style.color = actb_bgColor;
|
106
|
}
|
107
|
r.id = 'tat_tr'+(j);
|
108
|
c = r.insertCell(-1);
|
109
|
c.style.color = actb_textColor;
|
110
|
counter = 0;
|
111
|
first = true;
|
112
|
if (first && !actb_tomake){
|
113
|
c.style.color = actb_htextColor;
|
114
|
first = false;
|
115
|
actb_pos = counter;
|
116
|
}else if(actb_pre == i){
|
117
|
c.style.color = actb_htextColor;
|
118
|
first = false;
|
119
|
actb_pos = counter;
|
120
|
}else{
|
121
|
c.style.color = actb_textColor;
|
122
|
}
|
123
|
c.style.fontFamily = actb_fFamily;
|
124
|
a.style.zIndex = 5;
|
125
|
c.style.fontSize = actb_fSize;
|
126
|
c.innerHTML = actb_parse(actb_keywords[i]);
|
127
|
c.id = 'tat_td'+(j);
|
128
|
height = height + c.offsetHeight;
|
129
|
width = c.offsetWidth;
|
130
|
j++;
|
131
|
}
|
132
|
if (j - 1 == actb_lim && j < actb_total){
|
133
|
r = a.insertRow(-1);
|
134
|
r.style.backgroundColor = actb_bgColor;
|
135
|
c = r.insertCell(-1);
|
136
|
c.style.color = actb_textColor;
|
137
|
a.style.zIndex = 5;
|
138
|
c.style.fontFamily = 'arial narrow';
|
139
|
c.style.fontSize = actb_fSize;
|
140
|
c.align='center';
|
141
|
c.innerHTML = '\\/';
|
142
|
break;
|
143
|
}
|
144
|
}
|
145
|
actb_rangeu = 1;
|
146
|
actb_ranged = j-1;
|
147
|
actb_display = true;
|
148
|
if (actb_pos <= 0) actb_pos = 1;
|
149
|
if(navigator.appName == "Microsoft Internet Explorer") {
|
150
|
frame.width=width;
|
151
|
frame.height=height + 5;
|
152
|
}
|
153
|
}
|
154
|
function curTop(){
|
155
|
actb_toreturn = 0;
|
156
|
obj = actb_curr;
|
157
|
while(obj){
|
158
|
actb_toreturn += obj.offsetTop;
|
159
|
obj = obj.offsetParent;
|
160
|
}
|
161
|
return actb_toreturn;
|
162
|
}
|
163
|
function curLeft(){
|
164
|
actb_toreturn = 0;
|
165
|
obj = actb_curr;
|
166
|
while(obj){
|
167
|
actb_toreturn += obj.offsetLeft;
|
168
|
obj = obj.offsetParent;
|
169
|
}
|
170
|
return actb_toreturn;
|
171
|
}
|
172
|
function actb_remake() {
|
173
|
document.body.removeChild(document.getElementById('tat_table'));
|
174
|
if(navigator.appName == "Microsoft Internet Explorer") {
|
175
|
document.body.removeChild(document.getElementById('tat_frame'));
|
176
|
frame = document.createElement('iframe');
|
177
|
frame.cellSpacing='2px';
|
178
|
frame.cellPadding='3px';
|
179
|
frame.style.position='absolute';
|
180
|
frame.style.zIndex = 5;
|
181
|
frame.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
|
182
|
frame.style.left = curLeft() + "px";
|
183
|
frame.style.backgroundColor=actb_bgColor;
|
184
|
frame.id = 'tat_frame';
|
185
|
}
|
186
|
a = document.createElement('table');
|
187
|
a.cellSpacing='2px';
|
188
|
a.cellPadding='3px';
|
189
|
a.style.position='absolute';
|
190
|
a.style.zIndex = 5;
|
191
|
a.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
|
192
|
a.style.left = curLeft() + "px";
|
193
|
a.style.backgroundColor=actb_bgColor;
|
194
|
a.id = 'tat_table';
|
195
|
if(navigator.appName == "Microsoft Internet Explorer")
|
196
|
document.body.appendChild(frame);
|
197
|
document.body.appendChild(a);
|
198
|
var width = 0;
|
199
|
var height = 0;
|
200
|
var i;
|
201
|
var first = true;
|
202
|
var j = 1;
|
203
|
if (actb_rangeu > 1){
|
204
|
r = a.insertRow(-1);
|
205
|
r.style.backgroundColor = actb_bgColor;
|
206
|
c = r.insertCell(-1);
|
207
|
c.style.color = actb_textColor;
|
208
|
c.style.fontFamily = 'arial narrow';
|
209
|
a.style.zIndex = 5;
|
210
|
c.style.fontSize = actb_fSize;
|
211
|
c.align='center';
|
212
|
c.innerHTML = '/\\';
|
213
|
}
|
214
|
for (i=0;i<actb_keywords.length;i++){
|
215
|
if (actb_bool[i]){
|
216
|
if (j >= actb_rangeu && j <= actb_ranged){
|
217
|
r = a.insertRow(-1);
|
218
|
r.style.backgroundColor = actb_bgColor;
|
219
|
r.id = 'tat_tr'+(j);
|
220
|
c = r.insertCell(-1);
|
221
|
c.style.color = actb_textColor;
|
222
|
c.style.fontFamily = actb_fFamily;
|
223
|
a.style.zIndex = 5;
|
224
|
c.style.fontSize = actb_fSize;
|
225
|
c.innerHTML = actb_parse(actb_keywords[i]);
|
226
|
c.id = 'tat_td'+(j);
|
227
|
j++;
|
228
|
}else{
|
229
|
j++;
|
230
|
}
|
231
|
}
|
232
|
if (j > actb_ranged) break;
|
233
|
}
|
234
|
if (j-1 < actb_total){
|
235
|
r = a.insertRow(-1);
|
236
|
r.style.backgroundColor = actb_bgColor;
|
237
|
c = r.insertCell(-1);
|
238
|
c.style.color = actb_textColor;
|
239
|
c.style.fontFamily = 'arial narrow';
|
240
|
c.style.fontSize = actb_fSize;
|
241
|
c.align='center';
|
242
|
c.innerHTML = '\\/';
|
243
|
height = height + c.height;
|
244
|
width = c.width;
|
245
|
}
|
246
|
if(navigator.appName == "Microsoft Internet Explorer") {
|
247
|
frame.width=width
|
248
|
frame.height=height;
|
249
|
}
|
250
|
}
|
251
|
function actb_goup(){
|
252
|
if (!actb_display) return;
|
253
|
if (actb_pos == 1) return;
|
254
|
document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
|
255
|
document.getElementById('tat_td'+actb_pos).style.color = actb_textColor;
|
256
|
actb_pos--;
|
257
|
if (actb_pos < actb_rangeu) actb_moveup();
|
258
|
document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hBgColor;
|
259
|
document.getElementById('tat_td'+actb_pos).style.color = actb_htextColor;
|
260
|
if (actb_toid) clearTimeout(actb_toid);
|
261
|
if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
|
262
|
}
|
263
|
function actb_godown(){
|
264
|
if (!actb_display) return;
|
265
|
if (actb_pos == actb_total) return;
|
266
|
document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
|
267
|
document.getElementById('tat_td'+actb_pos).style.color = actb_textColor;
|
268
|
actb_pos++;
|
269
|
if (actb_pos > actb_ranged) actb_movedown();
|
270
|
document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hBgColor;
|
271
|
document.getElementById('tat_td'+actb_pos).style.color= actb_htextColor;
|
272
|
if (actb_toid) clearTimeout(actb_toid);
|
273
|
if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
|
274
|
}
|
275
|
function actb_movedown(){
|
276
|
actb_rangeu++;
|
277
|
actb_ranged++;
|
278
|
actb_remake();
|
279
|
}
|
280
|
function actb_moveup(){
|
281
|
actb_rangeu--;
|
282
|
actb_ranged--;
|
283
|
actb_remake();
|
284
|
}
|
285
|
function actb_penter(){
|
286
|
if (!actb_display) return;
|
287
|
actb_display = 0;
|
288
|
var word = '';
|
289
|
var c = 0;
|
290
|
for (var i=0;i<=actb_keywords.length;i++){
|
291
|
if (actb_bool[i]) c++;
|
292
|
if (c == actb_pos){
|
293
|
word = actb_keywords[i];
|
294
|
break;
|
295
|
}
|
296
|
}
|
297
|
a = word;//actb_keywords[actb_pos-1];//document.getElementById('tat_td'+actb_pos).;
|
298
|
actb_curr.value = a;
|
299
|
actb_removedisp();
|
300
|
}
|
301
|
function actb_removedisp(){
|
302
|
actb_display = 0;
|
303
|
if(navigator.appName == "Microsoft Internet Explorer")
|
304
|
if (document.getElementById('tat_frame')) document.body.removeChild(document.getElementById('tat_frame'));
|
305
|
if (document.getElementById('tat_table')) document.body.removeChild(document.getElementById('tat_table'));
|
306
|
if (actb_toid) clearTimeout(actb_toid);
|
307
|
}
|
308
|
function actb_checkkey(evt, sndr){
|
309
|
a = evt.keyCode;
|
310
|
if (a == 38){ // up key
|
311
|
actb_goup();
|
312
|
}else if(a == 40){ // down key
|
313
|
actb_godown();
|
314
|
}else if(a == 13){
|
315
|
actb_penter();
|
316
|
}
|
317
|
}
|
318
|
function actb_tocomplete(sndr,evt,arr){
|
319
|
if (arr) actb_keywords = arr;
|
320
|
if (evt.keyCode == 38 || evt.keyCode == 40 || evt.keyCode == 13) return;
|
321
|
var i;
|
322
|
if (actb_display){
|
323
|
var word = 0;
|
324
|
var c = 0;
|
325
|
for (i=0;i<=actb_keywords.length;i++){
|
326
|
if (actb_bool[i]) c++;
|
327
|
if (c == actb_pos){
|
328
|
word = i;
|
329
|
break;
|
330
|
}
|
331
|
}
|
332
|
actb_pre = word;//actb_pos;
|
333
|
}else{ actb_pre = -1};
|
334
|
|
335
|
if (!sndr) sndr = evt.srcElement;
|
336
|
actb_curr = sndr;
|
337
|
|
338
|
if (sndr.value == ''){
|
339
|
actb_removedisp();
|
340
|
return;
|
341
|
}
|
342
|
var t = sndr.value;
|
343
|
var re = "";
|
344
|
if (actb_firstText){
|
345
|
re = new RegExp("^" + t, "i");
|
346
|
}else{
|
347
|
re = new RegExp(t, "i");
|
348
|
}
|
349
|
|
350
|
actb_total = 0;
|
351
|
actb_tomake = false;
|
352
|
for (i=0;i<actb_keywords.length;i++){
|
353
|
actb_bool[i] = false;
|
354
|
if (re.test(actb_keywords[i])){
|
355
|
actb_total++;
|
356
|
actb_bool[i] = true;
|
357
|
if (actb_pre == i) actb_tomake = true;
|
358
|
}
|
359
|
}
|
360
|
if (actb_toid) clearTimeout(actb_toid);
|
361
|
if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
|
362
|
actb_generate(actb_bool);
|
363
|
}
|