这里先把Anthem相关的脚本贴出来,以后我们要经常用到![]()
1
// IE 5.01 Patch [ 1498764 ]
2
function utf8(wide) {
3
var c, s;
4
var enc = "";
5
var i = 0;
6
while(i<wide.length) {
7
c= wide.charCodeAt(i++);
8
// handle UTF-16 surrogates
9
if (c>=0xDC00 && c<0xE000) continue;
10
if (c>=0xD800 && c<0xDC00) {
11
if (i>=wide.length) continue;
12
s= wide.charCodeAt(i++);
13
if (s<0xDC00 || c>=0xDE00) continue;
14
c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
15
}
16
// output value
17
if (c<0x80) enc += String.fromCharCode(c);
18
else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
19
else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
20
else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
21
}
22
return enc;
23
}
24
25
var hexchars = "0123456789ABCDEF";
26
27
function toHex(n) {
28
return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
29
}
30
31
var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
32
33
function encodeURIComponentNew(s) {
34
var s = utf8(s);
35
var c;
36
var enc = "";
37
for (var i= 0; i<s.length; i++) {
38
if (okURIchars.indexOf(s.charAt(i))==-1)
39
enc += "%"+toHex(s.charCodeAt(i));
40
else
41
enc += s.charAt(i);
42
}
43
return enc;
44
}
45
46
function Anthem_Encode(s){
47
if (typeof encodeURIComponent == "function") {
48
// Use JavaScript built-in function
49
// IE 5.5+ and Netscape 6+ and Mozilla
50
return encodeURIComponent(s);
51
} else {
52
// Need to mimic the JavaScript version
53
// Netscape 4 and IE 4 and IE 5.0
54
return encodeURIComponentNew(s);
55
}
56
}
57
58
function Anthem_AddEvent(obj, evType, fn, useCapture) {
59
if (obj.addEventListener) {
60
obj.addEventListener(evType, fn, useCapture);
61
return true;
62
} else if (obj.attachEvent) {
63
var r = obj.attachEvent("on" + evType, fn);
64
return r;
65
} else {
66
alert("Anthem_AddEvent could not add event!");
67
}
68
}
69
70
function Anthem_GetXMLHttpRequest() {
71
if (window.XMLHttpRequest) {
72
return new XMLHttpRequest();
73
} else {
74
if (window.Anthem_XMLHttpRequestProgID) {
75
return new ActiveXObject(window.Anthem_XMLHttpRequestProgID);
76
} else {
77
var progIDs = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
78
for (var i = 0; i < progIDs.length; ++i) {
79
var progID = progIDs[i];
80
try {
81
var x = new ActiveXObject(progID);
82
window.Anthem_XMLHttpRequestProgID = progID;
83
return x;
84
} catch (e) {
85
}
86
}
87
}
88
}
89
return null;
90
}
91
92
function Anthem_CallBack(url, target, id, method, args, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack) {
93
if (window.Anthem_PreCallBack) {
94
var preCallBackResult = Anthem_PreCallBack();
95
if (!(typeof preCallBackResult == "undefined" || preCallBackResult)) {
96
if (window.Anthem_CallBackCancelled) {
97
Anthem_CallBackCancelled();
98
}
99
return null;
100
}
101
}
102
var x = Anthem_GetXMLHttpRequest();
103
var result = null;
104
if (!x) {
105
result = { "value": null, "error": "NOXMLHTTP" };
106
Anthem_DebugError(result.error);
107
if (window.Anthem_Error) {
108
Anthem_Error(result);
109
}
110
if (clientCallBack) {
111
clientCallBack(result, clientCallBackArg);
112
}
113
return result;
114
}
115
x.open("POST", url ? url : Anthem_DefaultURL, clientCallBack ? true : false);
116
x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
117
x.setRequestHeader("Accept-Encoding", "gzip, deflate");
118
if (clientCallBack) {
119
x.onreadystatechange = function() {
120
if (x.readyState != 4) {
121
return;
122
}
123
Anthem_DebugResponseText(x.responseText);
124
result = Anthem_GetResult(x);
125
if (result.error) {
126
Anthem_DebugError(result.error);
127
if (window.Anthem_Error) {
128
Anthem_Error(result);
129
}
130
}
131
if (updatePageAfterCallBack) {
132
Anthem_UpdatePage(result);
133
}
134
Anthem_EvalClientSideScript(result);
135
clientCallBack(result, clientCallBackArg);
136
x = null;
137
if (window.Anthem_PostCallBack) {
138
Anthem_PostCallBack();
139
}
140
}
141
}
142
var encodedData = "";
143
if (target == "Page") {
144
encodedData += "&Anthem_PageMethod=" + method;
145
} else if (target == "MasterPage") {
146
encodedData += "&Anthem_MasterPageMethod=" + method;
147
} else if (target == "Control") {
148
encodedData += "&Anthem_ControlID=" + id.split(":").join("_");
149
encodedData += "&Anthem_ControlMethod=" + method;
150
}
151
if (args) {
152
for (var argsIndex = 0; argsIndex < args.length; ++argsIndex) {
153
if (args[argsIndex] instanceof Array) {
154
for (var i = 0; i < args[argsIndex].length; ++i) {
155
encodedData += "&Anthem_CallBackArgument" + argsIndex + "=" + Anthem_Encode(args[argsIndex][i]);
156
}
157
} else {
158
encodedData += "&Anthem_CallBackArgument" + argsIndex + "=" + Anthem_Encode(args[argsIndex]);
159
}
160
}
161
}
162
if (updatePageAfterCallBack) {
163
encodedData += "&Anthem_UpdatePage=true";
164
}
165
if (includeControlValuesWithCallBack) {
166
var form = document.getElementById(Anthem_FormID);
167
if (form != null) {
168
for (var elementIndex = 0; elementIndex < form.length; ++elementIndex) {
169
var element = form.elements[elementIndex];
170
if (element.name) {
171
var elementValue = null;
172
if (element.nodeName.toUpperCase() == "INPUT") {
173
var inputType = element.getAttribute("type").toUpperCase();
174
if (inputType == "TEXT" || inputType == "PASSWORD" || inputType == "HIDDEN") {
175
elementValue = element.value;
176
} else if (inputType == "CHECKBOX" || inputType == "RADIO") {
177
if (element.checked) {
178
elementValue = element.value;
179
}
180
}
181
} else if (element.nodeName.toUpperCase() == "SELECT") {
182
if (element.multiple) {
183
elementValue = [];
184
for (var i = 0; i < element.length; ++i) {
185
if (element.options[i].selected) {
186
elementValue.push(element.options[i].value);
187
}
188
}
189
} else if (element.length == 0) {
190
elementValue = null;
191
} else {
192
elementValue = element.value;
193
}
194
} else if (element.nodeName.toUpperCase() == "TEXTAREA") {
195
elementValue = element.value;
196
}
197
if (elementValue instanceof Array) {
198
for (var i = 0; i < elementValue.length; ++i) {
199
encodedData += "&" + element.name + "=" + Anthem_Encode(elementValue[i]);
200
}
201
} else if (elementValue != null) {
202
encodedData += "&" + element.name + "=" + Anthem_Encode(elementValue);
203
}
204
}
205
}
206
// ASP.NET 1.1 won't fire any events if neither of the following
207
// two parameters are not in the request so make sure they're
208
// always in the request.
209
if (typeof form.__VIEWSTATE == "undefined") {
210
encodedData += "&__VIEWSTATE=";
211
}
212
if (typeof form.__EVENTTARGET == "undefined") {
213
encodedData += "&__EVENTTARGET=";
214
}
215
}
216
}
217
Anthem_DebugRequestText(encodedData.split("&").join("\n&"));
218
x.send(encodedData);
219
if (!clientCallBack) {
220
Anthem_DebugResponseText(x.responseText);
221
result = Anthem_GetResult(x);
222
if (result.error) {
223
Anthem_DebugError(result.error);
224
if (window.Anthem_Error) {
225
Anthem_Error(result);
226
}
227
}
228
if (updatePageAfterCallBack) {
229
Anthem_UpdatePage(result);
230
}
231
Anthem_EvalClientSideScript(result);
232
if (window.Anthem_PostCallBack) {
233
Anthem_PostCallBack();
234
}
235
}
236
return result;
237
}
238
239
function Anthem_GetResult(x) {
240
var result = { "value": null, "error": null };
241
var responseText = x.responseText;
242
try {
243
result = eval("(" + responseText + ")");
244
} catch (e) {
245
if (responseText.length == 0) {
246
result.error = "NORESPONSE";
247
} else {
248
result.error = "BADRESPONSE";
249
result.responseText = responseText;
250
}
251
}
252
return result;
253
}
254
255
function Anthem_SetHiddenInputValue(form, name, value) {
256
var input = null;
257
if (form[name]) {
258
input = form[name];
259
} else {
260
input = document.createElement("input");
261
input.setAttribute("name", name);
262
input.setAttribute("type", "hidden");
263
}
264
input.setAttribute("value", value);
265
var parentElement = input.parentElement ? input.parentElement : input.parentNode;
266
if (parentElement == null) {
267
form.appendChild(input);
268
form[name] = input;
269
}
270
}
271
272
function Anthem_RemoveHiddenInput(form, name) {
273
var input = form[name];
274
var parentElement = input.parentElement ? input.parentElement : input.parentNode;
275
if (input && parentElement == form) {
276
form[name] = null;
277
form.removeChild(input);
278
}
279
}
280
281
function Anthem_FireEvent(eventTarget, eventArgument, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack) {
282
var form = document.getElementById(Anthem_FormID);
283
Anthem_SetHiddenInputValue(form, "__EVENTTARGET", eventTarget);
284
Anthem_SetHiddenInputValue(form, "__EVENTARGUMENT", eventArgument);
285
Anthem_CallBack(null, null, null, null, null, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack);
286
form.__EVENTTARGET.value = "";
287
form.__EVENTARGUMENT.value = "";
288
}
289
290
function Anthem_UpdatePage(result) {
291
var form = document.getElementById(Anthem_FormID);
292
if (result.viewState) {
293
Anthem_SetHiddenInputValue(form, "__VIEWSTATE", result.viewState);
294
}
295
if (result.viewStateEncrypted) {
296
Anthem_SetHiddenInputValue(form, "__VIEWSTATEENCRYPTED", result.viewStateEncrypted);
297
}
298
if (result.eventValidation) {
299
Anthem_SetHiddenInputValue(form, "__EVENTVALIDATION", result.eventValidation);
300
}
301
if (result.controls) {
302
for (var controlID in result.controls) {
303
var containerID = "Anthem_" + controlID.split("$").join("_") + "__";
304
var control = document.getElementById(containerID);
305
if (control) {
306
control.innerHTML = result.controls[controlID];
307
if (result.controls[controlID] == "") {
308
control.style.display = "none";
309
} else {
310
control.style.display = "";
311
}
312
}
313
}
314
}
315
if (result.pagescript) {
316
Anthem_LoadPageScript(result, 0);
317
}
318
}
319
320
// Load each script in order and wait for each one to load before proceeding
321
function Anthem_LoadPageScript(result, index) {
322
if (index < result.pagescript.length) {
323
try {
324
var script = document.createElement('script');
325
script.type = 'text/javascript';
326
if (result.pagescript[index].indexOf('src=') == 0) {
327
script.src = result.pagescript[index].substring(4);
328
} else {
329
if (script.canHaveChildren ) {
330
script.appendChild(document.createTextNode(result.pagescript[index]));
331
} else {
332
script.text = result.pagescript[index];
333
}
334
}
335
document.getElementsByTagName('head')[0].appendChild(script);
336
if (typeof script.readyState != "undefined") {
337
script.onreadystatechange = function() {
338
if (script.readyState != "complete" && script.readyState != "loaded") {
339
return;
340
} else {
341
Anthem_LoadPageScript(result, index + 1);
342
}
343
}
344
} else {
345
Anthem_LoadPageScript(result, index + 1);
346
}
347
} catch (e) {
348
Anthem_DebugError("Error adding page script to head. " + e.name + ": " + e.message);
349
}
350
}
351
}
352
353
function Anthem_EvalClientSideScript(result) {
354
if (result.script) {
355
for (var i = 0; i < result.script.length; ++i) {
356
try {
357
eval(result.script[i]);
358
} catch (e) {
359
alert("Error evaluating client-side script!\n\nScript: " + result.script[i] + "\n\nException: " + e);
360
}
361
}
362
}
363
}
364
365
function Anthem_DebugRequestText(text) {
366
}
367
368
function Anthem_DebugResponseText(text) {
369
}
370
371
function Anthem_DebugError(text) {
372
}
373
374
//Fix for bug #1429412, "Reponse callback returns previous response after file push".
375
//see http://sourceforge.net/tracker/index.php?func=detail&aid=1429412&group_id=151897&atid=782464
376
function Anthem_Clear__EVENTTARGET() {
377
var form = document.getElementById(Anthem_FormID);
378
Anthem_SetHiddenInputValue(form, "__EVENTTARGET", "");
379
}
380
381
function Anthem_InvokePageMethod(methodName, args, clientCallBack, clientCallBackArg) {
382
Anthem_Clear__EVENTTARGET(); // fix for bug #1429412
383
return Anthem_CallBack(null, "Page", null, methodName, args, clientCallBack, clientCallBackArg, true, true);
384
}
385
386
function Anthem_InvokeMasterPageMethod(methodName, args, clientCallBack, clientCallBackArg) {
387
Anthem_Clear__EVENTTARGET(); // fix for bug #1429412
388
return Anthem_CallBack(null, "MasterPage", null, methodName, args, clientCallBack, clientCallBackArg, true, true);
389
}
390
391
function Anthem_InvokeControlMethod(id, methodName, args, clientCallBack, clientCallBackArg) {
392
Anthem_Clear__EVENTTARGET(); // fix for bug #1429412
393
return Anthem_CallBack(null, "Control", id, methodName, args, clientCallBack, clientCallBackArg, true, true);
394
}
395
396
function Anthem_PreProcessCallBack(
397
control,
398
e,
399
eventTarget,
400
causesValidation,
401
validationGroup,
402
imageUrlDuringCallBack,
403
textDuringCallBack,
404
enabledDuringCallBack,
405
preCallBackFunction,
406
callBackCancelledFunction,
407
preProcessOut
408
) {
409
preProcessOut.Enabled = !control.disabled;
410
var preCallBackResult = true;
411
if (preCallBackFunction) {
412
preCallBackResult = preCallBackFunction(control);
413
}
414
if (typeof preCallBackResult == "undefined" || preCallBackResult) {
415
var valid = true;
416
if (causesValidation && typeof Page_ClientValidate == "function") {
417
valid = Page_ClientValidate(validationGroup);
418
}
419
if (valid) {
420
var inputType = control.getAttribute("type");
421
inputType = (inputType == null) ? '' : inputType.toUpperCase();
422
if (inputType == "IMAGE" && e != null) {
423
var form = document.getElementById(Anthem_FormID);
424
if (e.offsetX) {
425
Anthem_SetHiddenInputValue(form, eventTarget + ".x", e.offsetX);
426
Anthem_SetHiddenInputValue(form, eventTarget + ".y", e.offsetY);
427
} else {
428
Anthem_SetHiddenInputValue(form, eventTarget + ".x", e.clientX - control.offsetLeft + 1);
429
Anthem_SetHiddenInputValue(form, eventTarget + ".y", e.clientY - control.offsetTop + 1);
430
}
431
}
432
preProcessOut.OriginalText = control.innerHTML;
433
if (imageUrlDuringCallBack || textDuringCallBack) {
434
if (control.nodeName.toUpperCase() == "INPUT") {
435
if (inputType == "CHECKBOX" || inputType == "RADIO" || inputType == "TEXT") {
436
preProcessOut.OriginalText = GetLabelText(control.id);
437
SetLabelText(control.id, textDuringCallBack);
438
} else if (inputType == "IMAGE") {
439
if (imageUrlDuringCallBack) {
440
preProcessOut.OriginalText = control.src;
441
control.src = imageUrlDuringCallBack;
442
} else {
443
preProcessOut.ParentElement = control.parentElement ? control.parentElement : control.parentNode;
444
if (preProcessOut.ParentElement) {
445
preProcessOut.OriginalText = preProcessOut.ParentElement.innerHTML;
446
preProcessOut.ParentElement.innerHTML = textDuringCallBack;
447
}
448
}
449
} else if (inputType == "SUBMIT") {
450
preProcessOut.OriginalText = control.value;
451
control.value = textDuringCallBack;
452
}
453
} else if (control.nodeName.toUpperCase() == "SELECT") {
454
preProcessOut.OriginalText = GetLabelText(control.id);
455
SetLabelText(control.id, textDuringCallBack);
456
} else {
457
control.innerHTML = textDuringCallBack;
458
}
459
}
460
control.disabled = (typeof enabledDuringCallBack == "undefined") ? false : !enabledDuringCallBack;
461
return true;
462
} else {
463
return false;
464
}
465
} else {
466
if (callBackCancelledFunction) {
467
callBackCancelledFunction(control);
468
}
469
return false;
470
}
471
}
472
473
function Anthem_PreProcessCallBackOut() {
474
// Fields
475
this.ParentElement = null;
476
this.OriginalText = '';
477
this.Enabled = true;
478
}
479
480
function Anthem_PostProcessCallBack(
481
result,
482
control,
483
eventTarget,
484
clientCallBack,
485
clientCallBackArg,
486
imageUrlDuringCallBack,
487
textDuringCallBack,
488
postCallBackFunction,
489
preProcessOut
490
) {
491
if (postCallBackFunction) {
492
postCallBackFunction(control);
493
}
494
control.disabled = !preProcessOut.Enabled;
495
var inputType = control.getAttribute("type");
496
inputType = (inputType == null) ? '' : inputType.toUpperCase();
497
if (inputType == "IMAGE") {
498
var form = document.getElementById(Anthem_FormID);
499
Anthem_RemoveHiddenInput(form, eventTarget + ".x");
500
Anthem_RemoveHiddenInput(form, eventTarget + ".y");
501
}
502
if (imageUrlDuringCallBack || textDuringCallBack) {
503
if (control.nodeName.toUpperCase() == "INPUT") {
504
if (inputType == "CHECKBOX" || inputType == "RADIO" || inputType == "TEXT") {
505
SetLabelText(control.id, preProcessOut.OriginalText);
506
} else if (inputType == "IMAGE") {
507
if (imageUrlDuringCallBack) {
508
control.src = preProcessOut.OriginalText;
509
} else {
510
preProcessOut.ParentElement.innerHTML = preProcessOut.OriginalText;
511
}
512
} else if (inputType == "SUBMIT") {
513
control.value = preProcessOut.OriginalText;
514
}
515
} else if (control.nodeName.toUpperCase() == "SELECT") {
516
SetLabelText(control.id, preProcessOut.OriginalText);
517
} else {
518
control.innerHTML = preProcessOut.OriginalText;
519
}
520
}
521
if (clientCallBack) {
522
clientCallBack(result, clientCallBackArg);
523
}
524
}
525
526
function Anthem_FireCallBackEvent(
527
control,
528
e,
529
eventTarget,
530
eventArgument,
531
causesValidation,
532
validationGroup,
533
imageUrlDuringCallBack,
534
textDuringCallBack,
535
enabledDuringCallBack,
536
preCallBackFunction,
537
postCallBackFunction,
538
callBackCancelledFunction,
539
includeControlValuesWithCallBack,
540
updatePageAfterCallBack
541
) {
542
var preProcessOut = new Anthem_PreProcessCallBackOut();
543
var preProcessResult = Anthem_PreProcessCallBack(
544
control,
545
e,
546
eventTarget,
547
causesValidation,
548
validationGroup,
549
imageUrlDuringCallBack,
550
textDuringCallBack,
551
enabledDuringCallBack,
552
preCallBackFunction,
553
callBackCancelledFunction,
554
preProcessOut
555
);
556
if (preProcessResult) {
557
Anthem_FireEvent(
558
eventTarget,
559
eventArgument,
560
function(result) {
561
Anthem_PostProcessCallBack(
562
result,
563
control,
564
eventTarget,
565
null,
566
null,
567
imageUrlDuringCallBack,
568
textDuringCallBack,
569
postCallBackFunction,
570
preProcessOut
571
);
572
},
573
null,
574
includeControlValuesWithCallBack,
575
updatePageAfterCallBack
576
);
577
}
578
}
579
580
function AnthemListControl_OnClick(
581
e,
582
causesValidation,
583
validationGroup,
584
textDuringCallBack,
585
enabledDuringCallBack,
586
preCallBackFunction,
587
postCallBackFunction,
588
callBackCancelledFunction,
589
includeControlValuesWithCallBack,
590
updatePageAfterCallBack
591
) {
592
var target = e.target || e.srcElement;
593
if (target.nodeName.toUpperCase() == "LABEL" && target.htmlFor != '')
594
return;
595
var eventTarget = target.id.split("_").join("$");
596
Anthem_FireCallBackEvent(
597
target,
598
e,
599
eventTarget,
600
'',
601
causesValidation,
602
validationGroup,
603
'',
604
textDuringCallBack,
605
enabledDuringCallBack,
606
preCallBackFunction,
607
postCallBackFunction,
608
callBackCancelledFunction,
609
true,
610
true
611
);
612
}
613
614
function GetLabelText(id) {
615
var labels = document.getElementsByTagName('label');
616
for (var i = 0; i < labels.length; i++) {
617
if (labels[i].htmlFor == id) {
618
return labels[i].innerHTML;
619
}
620
}
621
return null;
622
}
623
624
function SetLabelText(id, text) {
625
var labels = document.getElementsByTagName('label');
626
for (var i = 0; i < labels.length; i++) {
627
if (labels[i].htmlFor == id) {
628
labels[i].innerHTML = text;
629
return;
630
}
631
}
632
}
633
634
// IE 5.01 Patch [ 1498764 ]2
function utf8(wide) {3
var c, s;4
var enc = "";5
var i = 0;6
while(i<wide.length) {7
c= wide.charCodeAt(i++);8
// handle UTF-16 surrogates9
if (c>=0xDC00 && c<0xE000) continue;10
if (c>=0xD800 && c<0xDC00) {11
if (i>=wide.length) continue;12
s= wide.charCodeAt(i++);13
if (s<0xDC00 || c>=0xDE00) continue;14
c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;15
}16
// output value17
if (c<0x80) enc += String.fromCharCode(c);18
else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));19
else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));20
else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));21
}22
return enc;23
}24

25
var hexchars = "0123456789ABCDEF";26

27
function toHex(n) {28
return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);29
}30

31
var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";32

33
function encodeURIComponentNew(s) {34
var s = utf8(s);35
var c;36
var enc = "";37
for (var i= 0; i<s.length; i++) {38
if (okURIchars.indexOf(s.charAt(i))==-1)39
enc += "%"+toHex(s.charCodeAt(i));40
else41
enc += s.charAt(i);42
}43
return enc;44
}45

46
function Anthem_Encode(s){47
if (typeof encodeURIComponent == "function") {48
// Use JavaScript built-in function49
// IE 5.5+ and Netscape 6+ and Mozilla50
return encodeURIComponent(s);51
} else {52
// Need to mimic the JavaScript version53
// Netscape 4 and IE 4 and IE 5.054
return encodeURIComponentNew(s);55
}56
}57

58
function Anthem_AddEvent(obj, evType, fn, useCapture) {59
if (obj.addEventListener) {60
obj.addEventListener(evType, fn, useCapture);61
return true;62
} else if (obj.attachEvent) {63
var r = obj.attachEvent("on" + evType, fn);64
return r;65
} else {66
alert("Anthem_AddEvent could not add event!");67
}68
}69

70
function Anthem_GetXMLHttpRequest() {71
if (window.XMLHttpRequest) {72
return new XMLHttpRequest();73
} else {74
if (window.Anthem_XMLHttpRequestProgID) {75
return new ActiveXObject(window.Anthem_XMLHttpRequestProgID);76
} else {77
var progIDs = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];78
for (var i = 0; i < progIDs.length; ++i) {79
var progID = progIDs[i];80
try {81
var x = new ActiveXObject(progID);82
window.Anthem_XMLHttpRequestProgID = progID;83
return x;84
} catch (e) {85
}86
}87
}88
}89
return null;90
}91

92
function Anthem_CallBack(url, target, id, method, args, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack) {93
if (window.Anthem_PreCallBack) {94
var preCallBackResult = Anthem_PreCallBack();95
if (!(typeof preCallBackResult == "undefined" || preCallBackResult)) {96
if (window.Anthem_CallBackCancelled) {97
Anthem_CallBackCancelled();98
}99
return null;100
}101
}102
var x = Anthem_GetXMLHttpRequest();103
var result = null;104
if (!x) {105
result = { "value": null, "error": "NOXMLHTTP" };106
Anthem_DebugError(result.error);107
if (window.Anthem_Error) {108
Anthem_Error(result);109
}110
if (clientCallBack) {111
clientCallBack(result, clientCallBackArg);112
}113
return result;114
}115
x.open("POST", url ? url : Anthem_DefaultURL, clientCallBack ? true : false);116
x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");117
x.setRequestHeader("Accept-Encoding", "gzip, deflate");118
if (clientCallBack) {119
x.onreadystatechange = function() {120
if (x.readyState != 4) {121
return;122
}123
Anthem_DebugResponseText(x.responseText);124
result = Anthem_GetResult(x);125
if (result.error) {126
Anthem_DebugError(result.error);127
if (window.Anthem_Error) {128
Anthem_Error(result);129
}130
}131
if (updatePageAfterCallBack) {132
Anthem_UpdatePage(result);133
}134
Anthem_EvalClientSideScript(result);135
clientCallBack(result, clientCallBackArg);136
x = null;137
if (window.Anthem_PostCallBack) {138
Anthem_PostCallBack();139
}140
}141
}142
var encodedData = "";143
if (target == "Page") {144
encodedData += "&Anthem_PageMethod=" + method;145
} else if (target == "MasterPage") {146
encodedData += "&Anthem_MasterPageMethod=" + method;147
} else if (target == "Control") {148
encodedData += "&Anthem_ControlID=" + id.split(":").join("_");149
encodedData += "&Anthem_ControlMethod=" + method;150
}151
if (args) {152
for (var argsIndex = 0; argsIndex < args.length; ++argsIndex) {153
if (args[argsIndex] instanceof Array) {154
for (var i = 0; i < args[argsIndex].length; ++i) {155
encodedData += "&Anthem_CallBackArgument" + argsIndex + "=" + Anthem_Encode(args[argsIndex][i]);156
}157
} else {158
encodedData += "&Anthem_CallBackArgument" + argsIndex + "=" + Anthem_Encode(args[argsIndex]);159
}160
}161
}162
if (updatePageAfterCallBack) {163
encodedData += "&Anthem_UpdatePage=true";164
}165
if (includeControlValuesWithCallBack) {166
var form = document.getElementById(Anthem_FormID);167
if (form != null) {168
for (var elementIndex = 0; elementIndex < form.length; ++elementIndex) {169
var element = form.elements[elementIndex];170
if (element.name) {171
var elementValue = null;172
if (element.nodeName.toUpperCase() == "INPUT") {173
var inputType = element.getAttribute("type").toUpperCase();174
if (inputType == "TEXT" || inputType == "PASSWORD" || inputType == "HIDDEN") {175
elementValue = element.value;176
} else if (inputType == "CHECKBOX" || inputType == "RADIO") {177
if (element.checked) {178
elementValue = element.value;179
}180
}181
} else if (element.nodeName.toUpperCase() == "SELECT") {182
if (element.multiple) {183
elementValue = [];184
for (var i = 0; i < element.length; ++i) {185
if (element.options[i].selected) {186
elementValue.push(element.options[i].value);187
}188
}189
} else if (element.length == 0) {190
elementValue = null;191
} else {192
elementValue = element.value;193
}194
} else if (element.nodeName.toUpperCase() == "TEXTAREA") {195
elementValue = element.value;196
}197
if (elementValue instanceof Array) {198
for (var i = 0; i < elementValue.length; ++i) {199
encodedData += "&" + element.name + "=" + Anthem_Encode(elementValue[i]);200
}201
} else if (elementValue != null) {202
encodedData += "&" + element.name + "=" + Anthem_Encode(elementValue);203
}204
}205
}206
// ASP.NET 1.1 won't fire any events if neither of the following207
// two parameters are not in the request so make sure they're208
// always in the request.209
if (typeof form.__VIEWSTATE == "undefined") {210
encodedData += "&__VIEWSTATE=";211
}212
if (typeof form.__EVENTTARGET == "undefined") {213
encodedData += "&__EVENTTARGET=";214
}215
}216
}217
Anthem_DebugRequestText(encodedData.split("&").join("\n&"));218
x.send(encodedData);219
if (!clientCallBack) {220
Anthem_DebugResponseText(x.responseText);221
result = Anthem_GetResult(x);222
if (result.error) {223
Anthem_DebugError(result.error);224
if (window.Anthem_Error) {225
Anthem_Error(result);226
}227
}228
if (updatePageAfterCallBack) {229
Anthem_UpdatePage(result);230
}231
Anthem_EvalClientSideScript(result);232
if (window.Anthem_PostCallBack) {233
Anthem_PostCallBack();234
}235
}236
return result;237
}238

239
function Anthem_GetResult(x) {240
var result = { "value": null, "error": null };241
var responseText = x.responseText;242
try {243
result = eval("(" + responseText + ")");244
} catch (e) {245
if (responseText.length == 0) {246
result.error = "NORESPONSE";247
} else {248
result.error = "BADRESPONSE";249
result.responseText = responseText;250
}251
}252
return result;253
}254

255
function Anthem_SetHiddenInputValue(form, name, value) {256
var input = null;257
if (form[name]) {258
input = form[name];259
} else {260
input = document.createElement("input");261
input.setAttribute("name", name);262
input.setAttribute("type", "hidden");263
}264
input.setAttribute("value", value);265
var parentElement = input.parentElement ? input.parentElement : input.parentNode;266
if (parentElement == null) {267
form.appendChild(input);268
form[name] = input;269
}270
}271

272
function Anthem_RemoveHiddenInput(form, name) {273
var input = form[name];274
var parentElement = input.parentElement ? input.parentElement : input.parentNode;275
if (input && parentElement == form) {276
form[name] = null;277
form.removeChild(input);278
}279
}280

281
function Anthem_FireEvent(eventTarget, eventArgument, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack) {282
var form = document.getElementById(Anthem_FormID);283
Anthem_SetHiddenInputValue(form, "__EVENTTARGET", eventTarget);284
Anthem_SetHiddenInputValue(form, "__EVENTARGUMENT", eventArgument);285
Anthem_CallBack(null, null, null, null, null, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack);286
form.__EVENTTARGET.value = "";287
form.__EVENTARGUMENT.value = "";288
}289

290
function Anthem_UpdatePage(result) {291
var form = document.getElementById(Anthem_FormID);292
if (result.viewState) {293
Anthem_SetHiddenInputValue(form, "__VIEWSTATE", result.viewState);294
}295
if (result.viewStateEncrypted) {296
Anthem_SetHiddenInputValue(form, "__VIEWSTATEENCRYPTED", result.viewStateEncrypted);297
}298
if (result.eventValidation) {299
Anthem_SetHiddenInputValue(form, "__EVENTVALIDATION", result.eventValidation);300
}301
if (result.controls) {302
for (var controlID in result.controls) {303
var containerID = "Anthem_" + controlID.split("$").join("_") + "__";304
var control = document.getElementById(containerID);305
if (control) {306
control.innerHTML = result.controls[controlID];307
if (result.controls[controlID] == "") {308
control.style.display = "none";309
} else {310
control.style.display = "";311
}312
}313
}314
}315
if (result.pagescript) {316
Anthem_LoadPageScript(result, 0);317
}318
}319

320
// Load each script in order and wait for each one to load before proceeding321
function Anthem_LoadPageScript(result, index) {322
if (index < result.pagescript.length) {323
try {324
var script = document.createElement('script');325
script.type = 'text/javascript';326
if (result.pagescript[index].indexOf('src=') == 0) {327
script.src = result.pagescript[index].substring(4);328
} else {329
if (script.canHaveChildren ) {330
script.appendChild(document.createTextNode(result.pagescript[index]));331
} else {332
script.text = result.pagescript[index];333
}334
}335
document.getElementsByTagName('head')[0].appendChild(script);336
if (typeof script.readyState != "undefined") {337
script.onreadystatechange = function() {338
if (script.readyState != "complete" && script.readyState != "loaded") {339
return;340
} else {341
Anthem_LoadPageScript(result, index + 1);342
}343
}344
} else {345
Anthem_LoadPageScript(result, index + 1);346
}347
} catch (e) {348
Anthem_DebugError("Error adding page script to head. " + e.name + ": " + e.message);349
}350
}351
}352

353
function Anthem_EvalClientSideScript(result) {354
if (result.script) {355
for (var i = 0; i < result.script.length; ++i) {356
try {357
eval(result.script[i]);358
} catch (e) {359
alert("Error evaluating client-side script!\n\nScript: " + result.script[i] + "\n\nException: " + e);360
}361
}362
}363
}364

365
function Anthem_DebugRequestText(text) {366
}367

368
function Anthem_DebugResponseText(text) {369
}370

371
function Anthem_DebugError(text) {372
}373

374
//Fix for bug #1429412, "Reponse callback returns previous response after file push".375
//see http://sourceforge.net/tracker/index.php?func=detail&aid=1429412&group_id=151897&atid=782464376
function Anthem_Clear__EVENTTARGET() {377
var form = document.getElementById(Anthem_FormID);378
Anthem_SetHiddenInputValue(form, "__EVENTTARGET", "");379
}380

381
function Anthem_InvokePageMethod(methodName, args, clientCallBack, clientCallBackArg) {382
Anthem_Clear__EVENTTARGET(); // fix for bug #1429412383
return Anthem_CallBack(null, "Page", null, methodName, args, clientCallBack, clientCallBackArg, true, true);384
}385

386
function Anthem_InvokeMasterPageMethod(methodName, args, clientCallBack, clientCallBackArg) {387
Anthem_Clear__EVENTTARGET(); // fix for bug #1429412388
return Anthem_CallBack(null, "MasterPage", null, methodName, args, clientCallBack, clientCallBackArg, true, true);389
}390

391
function Anthem_InvokeControlMethod(id, methodName, args, clientCallBack, clientCallBackArg) {392
Anthem_Clear__EVENTTARGET(); // fix for bug #1429412393
return Anthem_CallBack(null, "Control", id, methodName, args, clientCallBack, clientCallBackArg, true, true);394
}395

396
function Anthem_PreProcessCallBack(397
control,398
e,399
eventTarget,400
causesValidation, 401
validationGroup, 402
imageUrlDuringCallBack, 403
textDuringCallBack, 404
enabledDuringCallBack,405
preCallBackFunction,406
callBackCancelledFunction,407
preProcessOut408
) {409
preProcessOut.Enabled = !control.disabled;410
var preCallBackResult = true;411
if (preCallBackFunction) {412
preCallBackResult = preCallBackFunction(control);413
}414
if (typeof preCallBackResult == "undefined" || preCallBackResult) {415
var valid = true;416
if (causesValidation && typeof Page_ClientValidate == "function") {417
valid = Page_ClientValidate(validationGroup);418
}419
if (valid) {420
var inputType = control.getAttribute("type");421
inputType = (inputType == null) ? '' : inputType.toUpperCase();422
if (inputType == "IMAGE" && e != null) {423
var form = document.getElementById(Anthem_FormID);424
if (e.offsetX) {425
Anthem_SetHiddenInputValue(form, eventTarget + ".x", e.offsetX);426
Anthem_SetHiddenInputValue(form, eventTarget + ".y", e.offsetY);427
} else {428
Anthem_SetHiddenInputValue(form, eventTarget + ".x", e.clientX - control.offsetLeft + 1);429
Anthem_SetHiddenInputValue(form, eventTarget + ".y", e.clientY - control.offsetTop + 1);430
}431
}432
preProcessOut.OriginalText = control.innerHTML;433
if (imageUrlDuringCallBack || textDuringCallBack) {434
if (control.nodeName.toUpperCase() == "INPUT") {435
if (inputType == "CHECKBOX" || inputType == "RADIO" || inputType == "TEXT") {436
preProcessOut.OriginalText = GetLabelText(control.id);437
SetLabelText(control.id, textDuringCallBack);438
} else if (inputType == "IMAGE") {439
if (imageUrlDuringCallBack) {440
preProcessOut.OriginalText = control.src;441
control.src = imageUrlDuringCallBack;442
} else {443
preProcessOut.ParentElement = control.parentElement ? control.parentElement : control.parentNode;444
if (preProcessOut.ParentElement) {445
preProcessOut.OriginalText = preProcessOut.ParentElement.innerHTML;446
preProcessOut.ParentElement.innerHTML = textDuringCallBack;447
}448
}449
} else if (inputType == "SUBMIT") {450
preProcessOut.OriginalText = control.value;451
control.value = textDuringCallBack;452
}453
} else if (control.nodeName.toUpperCase() == "SELECT") {454
preProcessOut.OriginalText = GetLabelText(control.id);455
SetLabelText(control.id, textDuringCallBack);456
} else {457
control.innerHTML = textDuringCallBack;458
}459
}460
control.disabled = (typeof enabledDuringCallBack == "undefined") ? false : !enabledDuringCallBack;461
return true;462
} else {463
return false;464
}465
} else {466
if (callBackCancelledFunction) {467
callBackCancelledFunction(control);468
}469
return false;470
}471
}472

473
function Anthem_PreProcessCallBackOut() {474
// Fields475
this.ParentElement = null;476
this.OriginalText = '';477
this.Enabled = true;478
}479

480
function Anthem_PostProcessCallBack(481
result, 482
control,483
eventTarget, 484
clientCallBack, 485
clientCallBackArg, 486
imageUrlDuringCallBack, 487
textDuringCallBack, 488
postCallBackFunction, 489
preProcessOut490
) {491
if (postCallBackFunction) {492
postCallBackFunction(control);493
}494
control.disabled = !preProcessOut.Enabled;495
var inputType = control.getAttribute("type");496
inputType = (inputType == null) ? '' : inputType.toUpperCase();497
if (inputType == "IMAGE") {498
var form = document.getElementById(Anthem_FormID);499
Anthem_RemoveHiddenInput(form, eventTarget + ".x");500
Anthem_RemoveHiddenInput(form, eventTarget + ".y");501
}502
if (imageUrlDuringCallBack || textDuringCallBack) {503
if (control.nodeName.toUpperCase() == "INPUT") {504
if (inputType == "CHECKBOX" || inputType == "RADIO" || inputType == "TEXT") {505
SetLabelText(control.id, preProcessOut.OriginalText);506
} else if (inputType == "IMAGE") {507
if (imageUrlDuringCallBack) {508
control.src = preProcessOut.OriginalText;509
} else {510
preProcessOut.ParentElement.innerHTML = preProcessOut.OriginalText;511
}512
} else if (inputType == "SUBMIT") {513
control.value = preProcessOut.OriginalText;514
}515
} else if (control.nodeName.toUpperCase() == "SELECT") {516
SetLabelText(control.id, preProcessOut.OriginalText);517
} else {518
control.innerHTML = preProcessOut.OriginalText;519
}520
}521
if (clientCallBack) {522
clientCallBack(result, clientCallBackArg);523
}524
}525

526
function Anthem_FireCallBackEvent(527
control,528
e,529
eventTarget,530
eventArgument,531
causesValidation,532
validationGroup,533
imageUrlDuringCallBack,534
textDuringCallBack,535
enabledDuringCallBack,536
preCallBackFunction,537
postCallBackFunction,538
callBackCancelledFunction,539
includeControlValuesWithCallBack,540
updatePageAfterCallBack541
) {542
var preProcessOut = new Anthem_PreProcessCallBackOut();543
var preProcessResult = Anthem_PreProcessCallBack(544
control, 545
e, 546
eventTarget,547
causesValidation, 548
validationGroup, 549
imageUrlDuringCallBack, 550
textDuringCallBack, 551
enabledDuringCallBack, 552
preCallBackFunction, 553
callBackCancelledFunction, 554
preProcessOut555
);556
if (preProcessResult) {557
Anthem_FireEvent(558
eventTarget,559
eventArgument,560
function(result) {561
Anthem_PostProcessCallBack(562
result, 563
control, 564
eventTarget,565
null, 566
null, 567
imageUrlDuringCallBack, 568
textDuringCallBack, 569
postCallBackFunction, 570
preProcessOut571
);572
},573
null,574
includeControlValuesWithCallBack,575
updatePageAfterCallBack576
);577
}578
}579

580
function AnthemListControl_OnClick(581
e,582
causesValidation,583
validationGroup,584
textDuringCallBack,585
enabledDuringCallBack,586
preCallBackFunction,587
postCallBackFunction,588
callBackCancelledFunction,589
includeControlValuesWithCallBack,590
updatePageAfterCallBack591
) {592
var target = e.target || e.srcElement;593
if (target.nodeName.toUpperCase() == "LABEL" && target.htmlFor != '')594
return;595
var eventTarget = target.id.split("_").join("$");596
Anthem_FireCallBackEvent(597
target, 598
e,599
eventTarget, 600
'', 601
causesValidation, 602
validationGroup, 603
'',604
textDuringCallBack, 605
enabledDuringCallBack, 606
preCallBackFunction, 607
postCallBackFunction, 608
callBackCancelledFunction, 609
true, 610
true611
);612
}613

614
function GetLabelText(id) {615
var labels = document.getElementsByTagName('label');616
for (var i = 0; i < labels.length; i++) {617
if (labels[i].htmlFor == id) {618
return labels[i].innerHTML;619
}620
}621
return null;622
}623

624
function SetLabelText(id, text) {625
var labels = document.getElementsByTagName('label');626
for (var i = 0; i < labels.length; i++) {627
if (labels[i].htmlFor == id) {628
labels[i].innerHTML = text;629
return;630
}631
}632
}633

634



