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(window.location.protocol == 'https:') return;
|
61
|
if(actb_keywords.length < 1) return; // if no items setup, do not invoke code. prevent ie crashing.
|
62
|
if (document.getElementById('tat_frame')) document.body.removeChild(document.getElementById('tat_frame'));
|
63
|
}
|
64
|
if (document.getElementById('tat_table')) document.body.removeChild(document.getElementById('tat_table'));
|
65
|
if(navigator.appName == "Microsoft Internet Explorer") {
|
66
|
frame = document.createElement('iframe');
|
67
|
frame.cellSpacing='1px';
|
68
|
frame.cellPadding='2px';
|
69
|
frame.style.zIndex = 3;
|
70
|
frame.style.position='absolute';
|
71
|
frame.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
|
72
|
frame.style.left = curLeft() + "px";
|
73
|
frame.style.backgroundColor=actb_bgColor;
|
74
|
frame.id = 'tat_frame';
|
75
|
}
|
76
|
a = document.createElement('table');
|
77
|
a.cellSpacing='1px';
|
78
|
a.cellPadding='2px';
|
79
|
a.style.border = '1px solid #990000';
|
80
|
a.style.zIndex = 5;
|
81
|
a.style.position='absolute';
|
82
|
a.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
|
83
|
a.style.left = curLeft() + "px";
|
84
|
a.style.backgroundColor=actb_bgColor;
|
85
|
a.id = 'tat_table';
|
86
|
if(navigator.appName == "Microsoft Internet Explorer")
|
87
|
document.body.appendChild(frame);
|
88
|
document.body.appendChild(a);
|
89
|
var i;
|
90
|
var first = true;
|
91
|
var j = 1;
|
92
|
var height = 0;
|
93
|
var counter = 0;
|
94
|
for (i=0;i<actb_keywords.length;i++){
|
95
|
if (actb_bool[i]){
|
96
|
counter++;
|
97
|
r = a.insertRow(-1);
|
98
|
if (first && !actb_tomake){
|
99
|
r.style.backgroundColor = actb_hBgColor;
|
100
|
first = false;
|
101
|
actb_pos = counter;
|
102
|
}else if(actb_pre == i){
|
103
|
r.style.backgroundColor = actb_hBgColor;
|
104
|
first = false;
|
105
|
actb_pos = counter;
|
106
|
}else{
|
107
|
r.style.backgroundColor = actb_bgColor;
|
108
|
r.style.color = actb_bgColor;
|
109
|
}
|
110
|
r.id = 'tat_tr'+(j);
|
111
|
c = r.insertCell(-1);
|
112
|
c.style.color = actb_textColor;
|
113
|
counter = 0;
|
114
|
first = true;
|
115
|
if (first && !actb_tomake){
|
116
|
c.style.color = actb_htextColor;
|
117
|
first = false;
|
118
|
actb_pos = counter;
|
119
|
}else if(actb_pre == i){
|
120
|
c.style.color = actb_htextColor;
|
121
|
first = false;
|
122
|
actb_pos = counter;
|
123
|
}else{
|
124
|
c.style.color = actb_textColor;
|
125
|
}
|
126
|
c.style.fontFamily = actb_fFamily;
|
127
|
a.style.zIndex = 5;
|
128
|
c.style.fontSize = actb_fSize;
|
129
|
c.innerHTML = actb_parse(actb_keywords[i]);
|
130
|
c.id = 'tat_td'+(j);
|
131
|
height = height + c.offsetHeight;
|
132
|
width = c.offsetWidth;
|
133
|
j++;
|
134
|
}
|
135
|
if (j - 1 == actb_lim && j < actb_total){
|
136
|
r = a.insertRow(-1);
|
137
|
r.style.backgroundColor = actb_bgColor;
|
138
|
c = r.insertCell(-1);
|
139
|
c.style.color = actb_textColor;
|
140
|
a.style.zIndex = 5;
|
141
|
c.style.fontFamily = 'arial narrow';
|
142
|
c.style.fontSize = actb_fSize;
|
143
|
c.align='center';
|
144
|
c.innerHTML = '\\/';
|
145
|
break;
|
146
|
}
|
147
|
}
|
148
|
actb_rangeu = 1;
|
149
|
actb_ranged = j-1;
|
150
|
actb_display = true;
|
151
|
if (actb_pos <= 0) actb_pos = 1;
|
152
|
if(navigator.appName == "Microsoft Internet Explorer") {
|
153
|
frame.width=width;
|
154
|
frame.height=height + 5;
|
155
|
}
|
156
|
}
|
157
|
function curTop(){
|
158
|
actb_toreturn = 0;
|
159
|
obj = actb_curr;
|
160
|
while(obj){
|
161
|
actb_toreturn += obj.offsetTop;
|
162
|
obj = obj.offsetParent;
|
163
|
}
|
164
|
return actb_toreturn;
|
165
|
}
|
166
|
function curLeft(){
|
167
|
actb_toreturn = 0;
|
168
|
obj = actb_curr;
|
169
|
while(obj){
|
170
|
actb_toreturn += obj.offsetLeft;
|
171
|
obj = obj.offsetParent;
|
172
|
}
|
173
|
return actb_toreturn;
|
174
|
}
|
175
|
function actb_remake() {
|
176
|
document.body.removeChild(document.getElementById('tat_table'));
|
177
|
if(navigator.appName == "Microsoft Internet Explorer") {
|
178
|
document.body.removeChild(document.getElementById('tat_frame'));
|
179
|
frame = document.createElement('iframe');
|
180
|
frame.cellSpacing='2px';
|
181
|
frame.cellPadding='3px';
|
182
|
frame.style.position='absolute';
|
183
|
frame.style.zIndex = 5;
|
184
|
frame.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
|
185
|
frame.style.left = curLeft() + "px";
|
186
|
frame.style.backgroundColor=actb_bgColor;
|
187
|
frame.id = 'tat_frame';
|
188
|
}
|
189
|
a = document.createElement('table');
|
190
|
a.cellSpacing='2px';
|
191
|
a.cellPadding='3px';
|
192
|
a.style.position='absolute';
|
193
|
a.style.zIndex = 5;
|
194
|
a.style.top = eval(curTop() + actb_curr.offsetHeight) + "px";
|
195
|
a.style.left = curLeft() + "px";
|
196
|
a.style.backgroundColor=actb_bgColor;
|
197
|
a.id = 'tat_table';
|
198
|
if(navigator.appName == "Microsoft Internet Explorer")
|
199
|
document.body.appendChild(frame);
|
200
|
document.body.appendChild(a);
|
201
|
var width = 0;
|
202
|
var height = 0;
|
203
|
var i;
|
204
|
var first = true;
|
205
|
var j = 1;
|
206
|
if (actb_rangeu > 1){
|
207
|
r = a.insertRow(-1);
|
208
|
r.style.backgroundColor = actb_bgColor;
|
209
|
c = r.insertCell(-1);
|
210
|
c.style.color = actb_textColor;
|
211
|
c.style.fontFamily = 'arial narrow';
|
212
|
a.style.zIndex = 5;
|
213
|
c.style.fontSize = actb_fSize;
|
214
|
c.align='center';
|
215
|
c.innerHTML = '/\\';
|
216
|
}
|
217
|
for (i=0;i<actb_keywords.length;i++){
|
218
|
if (actb_bool[i]){
|
219
|
if (j >= actb_rangeu && j <= actb_ranged){
|
220
|
r = a.insertRow(-1);
|
221
|
r.style.backgroundColor = actb_bgColor;
|
222
|
r.id = 'tat_tr'+(j);
|
223
|
c = r.insertCell(-1);
|
224
|
c.style.color = actb_textColor;
|
225
|
c.style.fontFamily = actb_fFamily;
|
226
|
a.style.zIndex = 5;
|
227
|
c.style.fontSize = actb_fSize;
|
228
|
c.innerHTML = actb_parse(actb_keywords[i]);
|
229
|
c.id = 'tat_td'+(j);
|
230
|
j++;
|
231
|
}else{
|
232
|
j++;
|
233
|
}
|
234
|
}
|
235
|
if (j > actb_ranged) break;
|
236
|
}
|
237
|
if (j-1 < actb_total){
|
238
|
r = a.insertRow(-1);
|
239
|
r.style.backgroundColor = actb_bgColor;
|
240
|
c = r.insertCell(-1);
|
241
|
c.style.color = actb_textColor;
|
242
|
c.style.fontFamily = 'arial narrow';
|
243
|
c.style.fontSize = actb_fSize;
|
244
|
c.align='center';
|
245
|
c.innerHTML = '\\/';
|
246
|
height = height + c.height;
|
247
|
width = c.width;
|
248
|
}
|
249
|
if(navigator.appName == "Microsoft Internet Explorer") {
|
250
|
frame.width=width
|
251
|
frame.height=height;
|
252
|
}
|
253
|
}
|
254
|
function actb_goup(){
|
255
|
if (!actb_display) return;
|
256
|
if (actb_pos == 1) return;
|
257
|
document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
|
258
|
document.getElementById('tat_td'+actb_pos).style.color = actb_textColor;
|
259
|
actb_pos--;
|
260
|
if (actb_pos < actb_rangeu) actb_moveup();
|
261
|
document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hBgColor;
|
262
|
document.getElementById('tat_td'+actb_pos).style.color = actb_htextColor;
|
263
|
if (actb_toid) clearTimeout(actb_toid);
|
264
|
if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
|
265
|
}
|
266
|
function actb_godown(){
|
267
|
if (!actb_display) return;
|
268
|
if (actb_pos == actb_total) return;
|
269
|
document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_bgColor;
|
270
|
document.getElementById('tat_td'+actb_pos).style.color = actb_textColor;
|
271
|
actb_pos++;
|
272
|
if (actb_pos > actb_ranged) actb_movedown();
|
273
|
document.getElementById('tat_tr'+actb_pos).style.backgroundColor = actb_hBgColor;
|
274
|
document.getElementById('tat_td'+actb_pos).style.color= actb_htextColor;
|
275
|
if (actb_toid) clearTimeout(actb_toid);
|
276
|
if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
|
277
|
}
|
278
|
function actb_movedown(){
|
279
|
actb_rangeu++;
|
280
|
actb_ranged++;
|
281
|
actb_remake();
|
282
|
}
|
283
|
function actb_moveup(){
|
284
|
actb_rangeu--;
|
285
|
actb_ranged--;
|
286
|
actb_remake();
|
287
|
}
|
288
|
function actb_penter(){
|
289
|
if (!actb_display) return;
|
290
|
actb_display = 0;
|
291
|
var word = '';
|
292
|
var c = 0;
|
293
|
for (var i=0;i<=actb_keywords.length;i++){
|
294
|
if (actb_bool[i]) c++;
|
295
|
if (c == actb_pos){
|
296
|
word = actb_keywords[i];
|
297
|
break;
|
298
|
}
|
299
|
}
|
300
|
a = word;//actb_keywords[actb_pos-1];//document.getElementById('tat_td'+actb_pos).;
|
301
|
actb_curr.value = a;
|
302
|
actb_removedisp();
|
303
|
}
|
304
|
function actb_removedisp(){
|
305
|
actb_display = 0;
|
306
|
if(navigator.appName == "Microsoft Internet Explorer")
|
307
|
if (document.getElementById('tat_frame')) document.body.removeChild(document.getElementById('tat_frame'));
|
308
|
if (document.getElementById('tat_table')) document.body.removeChild(document.getElementById('tat_table'));
|
309
|
if (actb_toid) clearTimeout(actb_toid);
|
310
|
}
|
311
|
function actb_checkkey(evt, sndr){
|
312
|
a = evt.keyCode;
|
313
|
if (a == 38){ // up key
|
314
|
actb_goup();
|
315
|
}else if(a == 40){ // down key
|
316
|
actb_godown();
|
317
|
}else if(a == 13){
|
318
|
actb_penter();
|
319
|
}
|
320
|
}
|
321
|
function actb_tocomplete(sndr,evt,arr){
|
322
|
if (arr) actb_keywords = arr;
|
323
|
if (evt.keyCode == 38 || evt.keyCode == 40 || evt.keyCode == 13) return;
|
324
|
var i;
|
325
|
if (actb_display){
|
326
|
var word = 0;
|
327
|
var c = 0;
|
328
|
for (i=0;i<=actb_keywords.length;i++){
|
329
|
if (actb_bool[i]) c++;
|
330
|
if (c == actb_pos){
|
331
|
word = i;
|
332
|
break;
|
333
|
}
|
334
|
}
|
335
|
actb_pre = word;//actb_pos;
|
336
|
}else{ actb_pre = -1};
|
337
|
|
338
|
if (!sndr) sndr = evt.srcElement;
|
339
|
actb_curr = sndr;
|
340
|
|
341
|
if (sndr.value == ''){
|
342
|
actb_removedisp();
|
343
|
return;
|
344
|
}
|
345
|
var t = sndr.value;
|
346
|
var re = "";
|
347
|
if (actb_firstText){
|
348
|
re = new RegExp("^" + t, "i");
|
349
|
}else{
|
350
|
re = new RegExp(t, "i");
|
351
|
}
|
352
|
|
353
|
actb_total = 0;
|
354
|
actb_tomake = false;
|
355
|
for (i=0;i<actb_keywords.length;i++){
|
356
|
actb_bool[i] = false;
|
357
|
if (re.test(actb_keywords[i])){
|
358
|
actb_total++;
|
359
|
actb_bool[i] = true;
|
360
|
if (actb_pre == i) actb_tomake = true;
|
361
|
}
|
362
|
}
|
363
|
if (actb_toid) clearTimeout(actb_toid);
|
364
|
if (actb_timeOut > 0) actb_toid = setTimeout("actb_removedisp()",actb_timeOut);
|
365
|
actb_generate(actb_bool);
|
366
|
}
|