-
Notifications
You must be signed in to change notification settings - Fork 0
/
GTAjax-5.5.js
1381 lines (1331 loc) · 44.5 KB
/
GTAjax-5.5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//<!--
/*
* GTAjax.js
* @abstract: General-Targeted Ajax
* @author: wadelau@hotmail.com,wadelau@gmail.com
* @since: 2006-2-17 14:04
* @update: Tue Feb 1 20:47:03 GMT 2011
* @code: 5.4 // a.bc , funcs added b+, errs updated c+
* @NOTICE: DO NOT USE THIS COMMERICALLY WITHOUT AUTHOR'S PAPER AUTHORIZATION
* Tue Jan 25 12:55:01 GMT 2011
* Wed Jan 26 17:31:33 GMT 2011
* Wed Jul 20 08:08:09 BST 2011
* Fri Mar 16 16:36:52 CST 2012
* Sun Jan 24 12:56:43 CST 2016
* Fri May 25 08:51:23 CST 2018, code format refine and cA.sort bugfix
*/
//---- DO NOT CHANGE ANY PART OF THE CODE UNDER THIS LINE ---
var GTAj = null ;
var GTAjVar = {helpurl:'http://ufqi.com/dev/gtajax/'} ;
var GTAjStatus = {hdlcp:0, nowopen:0, lastopen:0, gti:0, tlpid:0, bki:0,maxbk:9, ierdy:0};
var GTAjBK = {} ;
function GTAjax(){
//--- initiate
GTAjStatus.gti++;
GTAj = this ;
GTAj.sRe = '' ; //-- sReturn
GTAj.iTm = 0 ; //-- iTimer
GTAj.sTd = 0 ; //-- sToid
GTAj.sTd2 = 0 ; //--- process id
GTAj.sPtWi= 'myPOstWIn'; //-- sPstWin
GTAj.sUrl = '?' ;
GTAj.sMtd = 'GET' ; //-- sMethod
GTAj.iItl = 1000 ; // iInterval, one second
GTAj.isWtRp = false ; //-- isWaitResponse
GTAj.sForm = '' ;
GTAj.sFld = '' ; //-- sField
GTAj.sBkCt = '' ; //-- sBackCont
GTAj.nEmt = null ; //-- newElmt
GTAj.wFl = false ; //-- withFile
GTAj.tErr = new Error() ; //-- tmpErr
GTAj.nEmt2 = null ;
GTAj.gtFDiv = 'icld200607232107'; //-- gtfloatdiv
//GTAj.tBro = navigator.appName; //-- tmpBro
GTAj.tBro = (navigator.userAgent).toLowerCase(); //-- tmpBro
GTAj.tLgu = navigator.language?navigator.language:navigator.userLanguage ; //--- user charset
GTAj.myBdTt = null ; //-- myBodyTarget
GTAj.pswd = 'Processing';
GTAj.rtns = null; //--- return status
GTAj.noticed = 0; //-- form submitting during process will be noticed, added on 20110126
GTAj.ti = 0; //-- runing track id, positioning by line no, added on 20160124
GTAj.cA = new Array();
GTAj.vA = new Array()
GTAj.vA['sbv'] = 'Submit' ;
GTAj.vA['mul'] = 3*60*1000 ;
GTAj.vA['ta'] = '' ;
GTAj.vA['rn'] = ' Return ' ;
GTAj.vA['ib'] = false ;
GTAj.vA['rdo'] = false ;
GTAj.vA['ic'] = true ;
GTAj.vA['cf'] = '' ;
GTAj.vA['ff'] = true; // false ;
GTAj.vA['pb'] = true ;
GTAj.vA['bl'] = true ;
GTAj.vA['fft'] = 'fftag';
GTAj.vA['req'] = 'undefined';
GTAj.vA['nbl'] = '' ;
GTAj.vA['ncp'] = false ;
GTAj.vA['fbl'] = false ;
GTAj.vA['chkv'] = 1 ;
GTAj.vA['cfs'] = '::' ; //- chkformsep, reform since v5.2, 201107
GTAj.vArr = new Array()
GTAj.vArr['subbtnval']='sbv';
GTAj.vArr['maxuploadfiletime']='mul';
GTAj.vArr['targetarea']='ta';
GTAj.vArr['returnname']='rn';
GTAj.vArr['isdebug']='ib';
GTAj.vArr['returndataonly']='rdo';
GTAj.vArr['iscache']='ic';
GTAj.vArr['chkform']='cf';
GTAj.vArr['forceframe']='ff';
GTAj.vArr['processbar']='pb';
GTAj.vArr['backlink']='bl';
GTAj.vArr['forceframetag']='fft';
GTAj.vArr['request'] = 'req';
GTAj.vArr['nobacktag'] = 'nbl';
GTAj.vArr['nocopy'] = 'ncp';
GTAj.vArr['forcebacktag'] = 'fbl';
GTAj.vArr['callback'] = 'cb'; //- callback function, added on Sun Mar 11 12:56:52 CST 2012
GTAj.xmlhttp = null ;
//- set runtime variables
this.set = function(sName,sVal){
try{
if(sName=='chkform'){
if(sVal!=null && sVal!=''){
var sValA = sVal.split(GTAj.vA['cfs'],3); //- remedy 20110711
// formfield:chktype:errmsg, validate bgn
if(sValA[0]!=null && sValA[0]!=''){
if(sValA[1]==null || sValA[1]==''){
sValA[1] = 'notvalue=' ;
}
if(sValA[2]==null || sValA[2]==''){
sValA[2] = ' has not expected value.' ;
}
GTAj.cA[sValA[0]] = sValA[1]+GTAj.vA['cfs']+sValA[2];
}
if(GTAj.cA.length==0){
GTAj.cA[100] = '1' ;
}
//-- validate end
}
}
else{
GTAj.vA[ GTAj.vArr[sName]] = sVal ;
}
if( GTAj.vA['ff'] && ( GTAj.vA['rdo'] ) ){
GTAj.vA['chkv'] = 0 ;
GTAj.tErr.message = 'returndataonly cannot be with forceframe!';
}
else if( GTAj.vA['fbl'] && GTAj.vA['nbl']){
GTAj.vA['chkv'] = 0 ;
GTAj.tErr.message = 'forcebacktag cannot be with nobacktag!';
}
}
catch(e6){
return this._RGT('this.set',e6);
}
}
//- main method, prepare, encapsulate, validate, submit a request
//- and read response for further handling
this.get = function( sForm ){
var iswaiting = false ;
var isnum = false ;
var tmpgti = GTAjStatus.gti ;
if(sForm == null || sForm == ''){
GTAj.tErr.message = 'invalid form/url:['+sForm+'] found, stopped.';
return this._RGT('invalidForm/URL',GTAj.tErr);
}
else if( typeof sForm == 'number' ){
//--- numeric, the waiting-req come again..
tmpgti = sForm ;
eval('GTAj=GTAjStatus.pid'+tmpgti+';');
if( tmpgti == GTAjStatus.nowopen
|| ( GTAjStatus.nowopen == 0 && tmpgti == GTAjStatus.lastopen+1 ) ){
//--- will go on with nowopen or next one in queue, added on 201102
}
else{
//--- another instance is runing, keep waiting again
iswaiting = true ;
}
this._DBG( GTAj.vA['ib'],'process-num','sForm:['+tmpgti+'] gti:'+GTAjStatus.gti
+',req:['+GTAj.reg.req+'] ta:['+GTAj.vA['ta']+'] waiting:['+iswaiting
+'] nowopen:['+GTAjStatus.nowopen+'] lastopen:['+GTAjStatus.lastopen+']');
isnum = true ;
}
else{
//--- new instanceof, save settings in an GTAjStatus with a newly pid
GTAj.vA['req'] = sForm ;
GTAj.reg = {req:sForm};
if( GTAjStatus.nowopen!=0 ){
//--- another instance is runing , queue and keep waiting...
iswaiting = true ;
}
this._DBG( GTAj.vA['ib'],'process-not-num', 'sForm:['+sForm+'] typeof:['+typeof sForm
+'] gti:['+GTAjStatus.gti+'],req:['+GTAj.reg.req+'] ta2:['+GTAj.vA['ta']
+'] waiting:['+iswaiting+']') ;
}
if( GTAj.tBro.indexOf('explorer')>-1 && document.readyState!='complete' ){
iswaiting = true ;
}
if( iswaiting ){
//--- waiting... // && !(GTAj.tBro.indexOf('Explorer')>-1 && document.readyState!='complete')
if( !isnum ){
eval('GTAjStatus.pid'+GTAjStatus.gti+' = GTAj;');
}
var waitingi = GTAjStatus.gti ;
if( isnum ){
waitingi = tmpgti ;
}
GTAjStatus.tlpid = window.setTimeout('GTAj.get('+waitingi+');',GTAj.iItl);
this._DBG( GTAj.vA['ib'],'process-waiting', 'gti:['+GTAjStatus.gti
+'] nowopen:['+GTAjStatus.nowopen+'] req:['+GTAj.reg.req+'] ta:['+GTAj.vA['ta']
+'] waitingi:['+waitingi+'] tlpid:['+GTAjStatus.tlpid+']');
if( typeof GTAj.vA['req'] == 'string'){
try{
if( GTAj.noticed==0){
GTAj.noticed=1;
document.getElementById( GTAj.vA['req']).onsubmit= this._DFM_F ;
this._SAY( GTAj.sFld,'Attention: The request has added in processing....', false);
}
}
catch(e1650){
this._DBG( GTAj.vA['ib'],'disable-possible-onsubmit', 'sForm:['+GTAj.vA['req']+']');
}
}
}
else {
if( GTAjStatus.nowopen==0 ){
GTAjStatus.nowopen = tmpgti ;
}
if( GTAjStatus.hdlcp==0 || GTAj.vA['ncp'] != GTAjStatus.hdlcp ){
this._DISCP( GTAj.vA['ncp'] ); //--- do no copy handle
GTAjStatus.hdlcp = GTAj.vA['ncp'] ;
}
//- init a new request
if( !GTAj.isWtRp ){
if( GTAj.sTd2 == 0){
this._PSD( GTAj.iTm );
//-- update to dynamic again 2007-10-4 21:19, take static process div instead of dynamic,
//- updated 20060810, 201102
}
else{
this._DBG( GTAj.vA['ib'],'process-GTAj.sTd2', 'gti:['+GTAjStatus.nowopen
+'] sTd2:['+GTAj.sTd2+'] ta:['+GTAj.vA['ta']+']') ;
}
//------------- reinit a new
GTAj.sRe = '' ;
GTAj.rtns = '';
sForm = GTAj.vA['req'] ;
var sPara = '';
GTAj.isDN = false ; //--- isdone, is complete request
this._DBG( GTAj.vA['ib'],'sForm',sForm);
try{
sForm = document.forms[sForm] ;
if(sForm.id == null || sForm.id == '')
{
sForm.id = GTAj.vA['req']; //-- for form.id is missing, 20110711
}
}
catch (eFNm){
}
if( sForm!=null && typeof sForm !='undefined' ){
this._DBG( GTAj.vA['ib'],'ta-1', GTAj.vA['ta']);
document.getElementById(GTAj.vA['req']).onsubmit= this._DFM_F ;
if( GTAj.vA['chkv']==0 ){
return this._RGT('this.set.chkvar',GTAj.tErr);
}
try{
if( GTAj.vA['ta']=='' && GTAj.vA['rdo'] == false ){
//--- if rdo==true,omited this block,updated 2006-7-23 11:42
var Emsg = 'targetarea is empty.';
if(typeof sForm != 'undefined'){
GTAj.vA['ta'] = sForm.parentNode.getAttribute('id') ;
}
else{
GTAj.tErr.message = Emsg ;
return this._RGT( 'formElement',GTAj.tErr );
}
if( typeof GTAj.vA['ta']=='undefined'
|| GTAj.vA['ta']=='' || GTAj.vA['ta']==null ){
GTAj.tErr.message = Emsg;
return this._RGT( 'formElement1',GTAj.tErr );
}
else{
this._DBG( GTAj.vA['ib'],'ta', GTAj.vA['ta']);
}
}
}
catch(e8){
return this._RGT( 'parentArea', e8 ); // when err reinit the environment...
}
try{
GTAj.sUrl = sForm.action ;
GTAj.sMtd = sForm.method ;
for (var i = sForm.elements.length-1 ; i>=0; i--){
var el = sForm.elements[i];
var myCFM = this._CFM ;
var typeOfElement = (typeof GTAj.cA[el.name]);
if(typeOfElement == 'function'){ //- May 26, 2018
this._DBG( GTAj.vA['ib'],'formValidate-201805250855', 'typeof '+el.name+' is '
+ typeOfElement
+ ', conflict with JavaScript native code, please rename it to xxx'
+ el.name+' or '+el.name+'xxx.') ;
continue;
}
if (el.tagName.toLowerCase() == 'select') {
for (var j = 0; j < el.options.length; j++){
var op = el.options[j];
if (op.selected){
if(!this._chkAccept(sForm, el, myCFM)){ return false; }
if(typeOfElement != 'undefined'){
if(!myCFM(sForm,el.name,op.value,GTAj.cA[el.name])){
return false;
}
}
sPara += '&' + encodeURIComponent(el.name) + '='
+ encodeURIComponent(el.value);
}
}
}
else if (el.tagName.toLowerCase() == 'textarea'){
if(!this._chkAccept(sForm, el, myCFM)){ return false; }
if(typeOfElement != 'undefined'){
if(!myCFM(sForm,el.name,el.value,GTAj.cA[el.name]))
{
return false;
}
}
sPara += '&' + encodeURIComponent(el.name) + '='
+ encodeURIComponent(el.value);
}
else if (el.tagName.toLowerCase() == 'input'){
if (el.type.toLowerCase() == 'checkbox'
|| el.type.toLowerCase() == 'radio'){
if (el.checked){
sPara += '&' + encodeURIComponent(el.name) + '='
+ encodeURIComponent(el.value);
}
if(!this._chkAccept(sForm, el, myCFM)){ return false; }
if(typeOfElement != 'undefined'){
if(!myCFM(sForm,el.name,el.value,GTAj.cA[el.name]))
{
return false;
}
}
}
else if( el.type.toLowerCase() == 'file'){
if(!this._chkAccept(sForm, el, myCFM)){ return false; }
if(typeOfElement != 'undefined'){
if(!myCFM(sForm,el.name,el.value,GTAj.cA[el.name]))
{
return false;
}
}
if(el.value!='' && el.value!=null){
GTAj.wFl = true ;
this._DBG( GTAj.vA['ib'],'fileUpload2',GTAj.wFl);
if(eval(GTAj.cA.length)==0)
{
break ;
}
}
}
else if(el.type.toLowerCase() != 'button'
&& el.type.toLowerCase() != 'submit'){
if(!this._chkAccept(sForm, el, myCFM)){ return false; }
if(typeOfElement != 'undefined'){
if(!myCFM(sForm,el.name,el.value,GTAj.cA[el.name])){
return false;
}
}
sPara += '&' + encodeURIComponent(el.name) + '='
+ encodeURIComponent(el.value);
}
else{
if(el.type.toLowerCase()=='submit'){
if( el.name ){
GTAj.sFld = el.name ;
}
else{
GTAj.sFld = el.id ;
}
if(el.value != ''){
GTAj.vA['sbv'] = el.value;
}
if( GTAj.sFld!=null && typeof GTAj.sFld !='undefined'
&& GTAj.sFld!='' && document.getElementById(GTAj.sFld)){
//--- added on 2007-1-29 23:22
document.getElementById(GTAj.sFld).disabled =true ;
}
else if( GTAj.tBro.indexOf("netscape")==-1 && GTAj.sFld!=null
&& typeof GTAj.sFld !='undefined' && GTAj.sFld!=''
&& document.getElementByName(GTAj.sFld)){
document.getElementsByName(GTAj.sFld).disabled =true ;
}
else{
GTAj.tErr.message = 'submit field in form:['+sForm
+'] not NAMEed or IDed.';
return this._RGT('invalidsubmit',GTAj.tErr);
}
// for firefox
this._SAY(GTAj.sFld,'Data Collecting',false);
}
}
}
}
}
catch(e2){
return this._RGT( 'formElement3',e2 ); // when err reinit the environment...
}
//---- end of real form action
}
else{
//--- handle url
sForm = GTAj.vA['req'];
this._DBG( GTAj.vA['ib'],'handleurl', sForm);
try{
if( GTAj.vA['ta']=='' && GTAj.vA['rdo']==false ){
//--- if rdo==true, omited this block
var sLinks = document.links;
var sLinkHref = '' ;
for(var i=0;i<sLinks.length;i++){
sLinkHref = sLinks[i].href ;
if(sLinkHref.indexOf(sForm)>-1){
sForm = sLinks[i];
GTAj.sUrl = sForm ;
break;
}
}
var Emsg = 'targetarea is empty.';
if(typeof sForm != 'undefined'){
GTAj.vA['ta'] = sForm.parentNode.getAttribute('id') ;
}
else{
GTAj.tErr.message = Emsg ;
return this._RGT('formElement2',GTAj.tErr) ;
}
if(typeof GTAj.vA['ta']=='undefined'
|| GTAj.vA['ta']=='' || GTAj.vA['ta']==null){
GTAj.tErr.message = Emsg ;
return this._RGT('formElement4',GTAj.tErr) ;
}
else{
this._DBG( GTAj.vA['ib'],'ta', GTAj.vA['ta']);
}
sLinks = null ;
sForm = null ;
GTAjStatus.bki++;
if( GTAjStatus.bki>GTAjStatus.maxbk ){
GTAjStatus.bki = 0 ;
}
eval('GTAjBK.bk'+GTAjStatus.bki+'=document.getElementById('+GTAj.vA['ta']
+').innerHTML');
this._DBG( GTAj.vA['ib'], 'GTAjBK.bk'+GTAjStatus.bki,'val');
GTAj.sBkCt = '1' ;
}
else if( GTAj.vA['ta']!=''){
if(!document.getElementById( GTAj.vA['ta'])){
GTAj.tErr.message = 'cant find target:['+ GTAj.vA['ta']+'].';
return this._RGT('invalidta',GTAj.tErr);
}
}
if(GTAj.sUrl=='?'){ GTAj.sUrl = sForm ; }
if(GTAj.sUrl.indexOf(GTAj.vA['fft'])>-1){
GTAj.vA['ff']=true;
}
}
catch(e9){
return this._RGT('parentElement',e9 );
// when err reinit the environment...
}
}
//- create a request object
if( GTAj.wFl || GTAj.vA['ff'] ){
//--- use form submit
try{
this._SAY(GTAj.sFld,'Loading data...',false);
var randframei = (new Date).getMilliseconds(); // for firefox continual fileuploads...
GTAj.sPtWi= GTAj.sPtWi+ randframei ;
var postFrame = '<iframe name="'+GTAj.sPtWi+'" id="'+GTAj.sPtWi+'" '
+ 'style="border:0px;width:0px;height:0px"><\/iframe>'
+ '';
var myBdTt2 = null ;
if( document.getElementById( GTAj.gtFDiv )){
myBdTt2 = document.getElementById( GTAj.gtFDiv ) ;
}
else{
this._DBG( GTAj.vA['ib'],'iframefail',
document.getElementById( GTAj.gtFDiv ).innerHTML);
}
GTAj.nEmt = document.createElement('div');
GTAj.nEmt.setAttribute('id', 'icld'+GTAj.sPtWi);
myBdTt2.appendChild(GTAj.nEmt);
document.getElementById('icld'+GTAj.sPtWi).innerHTML = postFrame ;
var dgt = document;
var fgt = dgt.frames ? dgt.frames[GTAj.sPtWi] : dgt.getElementById(GTAj.sPtWi);
fgt.src = 'about:blank'; // for opera compatible
this._SUB(sForm,GTAj.sUrl,GTAj.sPtWi, GTAj.vA['ib'], GTAj.vA['ff']);
GTAj.isWtRp = true ;
eval('GTAjStatus.pid'+GTAjStatus.nowopen+'=GTAj;');
GTAj.sTd = window.setTimeout( 'GTAj._LOP()',GTAj.iItl);
postFrame= null ;
randframei = null ;
this._DBG( GTAj.vA['ib'],'iframeListen','starting');
}
catch (e4){
return this._RGT('fileUpload or forceFrame',e4 ) ;
}
}
else{
// using xmlhttp
var isAsync = false ;
this._SAY(GTAj.sFld,'Initiating',false);
try{
if (window.XMLHttpRequest){
GTAj.xmlhttp = new XMLHttpRequest();
this._DBG( GTAj.vA['ib'],'xmlhttp1',GTAj.xmlhttp
+',type:['+(typeof GTAj.xmlhttp)+']');
}
else if (window.ActiveXObject){
try{
GTAj.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
this._DBG( GTAj.vA['ib'],'GTAj.xmlhttp2',GTAj.xmlhttp+',type:['
+(typeof GTAj.xmlhttp)+']');
}
catch(e){
try {
GTAj.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
this._DBG( GTAj.vA['ib'],'GTAj.xmlhttp3',GTAj.xmlhttp+',type:['
+(typeof GTAj.xmlhttp)+']');
}
catch(e1){
//--- xmlhttp.open fail, set ff==true and try again..
this._SAY(GTAj.sFld, GTAj.vA['sbv'],true);
GTAj.vA['ff'] = true ;
eval('GTAjStatus.pid'+GTAjStatus.nowopen+'=GTAj;');
GTAj.sTd = window.setTimeout('GTAj._LOP()',GTAj.iItl);
}
}
}
}
catch(e39){
//--- xmlhttp.open fail, set ff==true and try again..
this._SAY(GTAj.sFld, GTAj.vA['sbv'],true);
GTAj.vA['ff'] = true ;
eval('GTAjStatus.pid'+GTAjStatus.nowopen+'=GTAj;');
GTAj.sTd = window.setTimeout('GTAj._LOP()',GTAj.iItl);
}
//- submitting request
this._SAY(GTAj.sFld,'Communicating',false);
GTAj.sMtd = GTAj.sMtd.toUpperCase();
if( GTAj.xmlhttp!=null && typeof GTAj.xmlhttp!='undefined' ){
this._SAY( GTAj.sFld,'Transacting',false );
try {
if ( GTAj.sMtd == 'GET' ){
if(!GTAj.vA['ic'] ){
if( sPara == null || typeof sPara =='undefined' ){
sPara = '' ;
}
if( true ){
var ici = Math.random() ;
var lastc = sPara.substr(sPara.length-1,1) ; // 20080410
if( lastc != '&' && lastc != '' ){
sPara += '&' ;
}
sPara += 'ici='+ici ;
lastc = null ;
ici = null ;
}
}
var lastc = GTAj.sUrl.substr(GTAj.sUrl.length-1,1);
if( GTAj.sUrl.indexOf('?') > 0 ){
if( lastc != '?' ){
GTAj.sUrl += '&' ;
}
}
else{
GTAj.sUrl += '?' ;
}
lastc = null ;
GTAj.sUrl += sPara ;
this._DBG( GTAj.vA['ib'],'GTAj.xmlhttp-open',('mth:['+GTAj.sMtd
+'] GTAj.sUrl:['
+GTAj.sUrl+'] isAsync:['+isAsync+']'));
try{
GTAj.xmlhttp.open(GTAj.sMtd,GTAj.sUrl,isAsync);
}
catch(e1116){
return this._RGT('GTAj.xmlhttp-open',e1116 ) ;
}
this._DBG( GTAj.vA['ib'],'GTAj.xmlhttp-try0',(new Date()));
if(! GTAj.vA['ic']){
GTAj.xmlhttp.setRequestHeader(
'If-Modified-Since', 'Sat, 1 Jan 2000 00:00:01 GMT');
}
sPara = null ;
}
else{
GTAj.xmlhttp.open(GTAj.sMtd, GTAj.sUrl, isAsync);
GTAj.xmlhttp.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
GTAj.xmlhttp.setRequestHeader("Accept", "text/*");
try{
GTAj.xmlhttp.setRequestHeader("Accept-Language", GTAj.tLgu);
}
catch(e1101){
}
}
this._DBG( GTAj.vA['ib'],'GTAj.sMtd',GTAj.sMtd+',GTAj.sUrl: '+GTAj.sUrl
+', sPara:'+sPara);
if( sPara ){
sPara = sPara.substring(1);
//--- added on 2007-7-6 17:40, delete one at the very beginning, '&'
}
GTAj.xmlhttp.send(sPara);
try{
this._DBG( GTAj.vA['ib'],'GTAj.xmlhttp-try',(new Date()));
GTAj.xmlhttp.onreadystatechange = this._RCV;
}
catch(e1140){
return this._RGT('GTAj.xmlhttp-status',e1140 ) ;
}
if(GTAj.sRe==''){ // for firefox confirm
GTAj.sRe = GTAj.xmlhttp.responseText ;
if( GTAj.sRe!='' ){
GTAj.rtns = 'complete' ;
}
}
this._DBG( GTAj.vA['ib'],'GTAj.xmlhttp-sRe',GTAj.sRe
+ ', GTAj.rtns:['+GTAj.rtns +'] ');
}
catch(e3){
//--- xmlhttp.open fail, set ff==true and try again..
this._DBG(GTAj.vA["ib"],"GTAj.xmlhttp.fail","xmlhttp:["
+GTAj.xmlhttp+"],failed.");
if( !document.forms[GTAj.vA['req']]
|| (document.forms[GTAj.vA['req']]
&& (GTAj.tBro.indexOf('gecko')!=-1
|| GTAj.tBro.indexOf('firefox')!=-1 ) ) ){
GTAj.vA['ff'] = true ;
eval('GTAjStatus.pid'+GTAjStatus.nowopen+'=GTAj;');
GTAj.sTd = window.setTimeout( 'GTAj._LOP()',GTAj.iItl );
}
else{
e3.message += "\nmaybe you can gtajax.set('forceframe',true) to try again.";
this._RGT('formXmlHttpFail',e3 );
}
}
GTAj.xmlhttp = null ;
}
}
if(GTAj.isDN){
this._SAY( GTAj.sFld,'Loaded Successfully',false );
}
//------------- end of sending data .
}
else if( GTAj.isWtRp ){ //- waiting in a defined _LOP
try{
if( !dgt ){
var dgt = document;
var fgt = dgt.frames ? dgt.frames[GTAj.sPtWi] : dgt.getElementById(GTAj.sPtWi);
}
var pgt = fgt.document || fgt.contentWindow.document;
if( typeof pgt == 'undefined' || pgt == null){
//window.alert('isWtRp-error! dgt:['+dgt+'] fgt:['+fgt+'] pgt:['+pgt+']');
GTAj.tErr.name = 'GTAj.readResp';
GTAj.tErr.message = 'dgt:['+dgt+'] fgt:['+fgt+'] pgt:['+pgt+']';
this._RGT('GTAj.isWtRp',GTAj.tErr);
return false;
}
var sRe2 = pgt.body.innerHTML ;
GTAj.rtns = pgt.readyState ;
if( GTAj.rtns=='complete' && sRe2==''){
GTAj.rtns = ''; //-- remedy on 20101111 for chrome
}
if( GTAj.rtns!=null && typeof GTAj.rtns!='undefined' ){
GTAj.sRe = sRe2;
}
else {
if( ( GTAj.sRe!=null && sRe2!=null && GTAj.sRe!='' && sRe2!='' )
&& GTAj.sRe.length==sRe2.length ){
GTAj.rtns = 'complete';
}
GTAj.sRe = sRe2 ;
GTAj.iItl = 2000 ;
}
if( GTAj.tBro.indexOf('opera')>-1 ){
GTAj.sRe = GTAj.sRe.replace(/\n{3,}/,''); //--- for opera compatible
}
this._DBG( GTAj.vA['ib'],'GTAj.rtns', GTAj.rtns + ',GTAj.sRe:['+GTAj.sRe+']');
if( GTAj.rtns==null || typeof GTAj.rtns=='undefined' ){
GTAj.rtns = '';
}
if( GTAj.rtns.toLowerCase()!='complete' ){
if(GTAj.iTm < GTAj.vA['mul']){
eval('GTAjStatus.pid'+GTAjStatus.nowopen+'=GTAj;');
GTAj.sTd = window.setTimeout( 'GTAj._LOP()',GTAj.iItl );
this._DBG( GTAj.vA['ib'],'!=complelte-1534','sTd:['+GTAj.sTd
+'] iTm:['+GTAj.iTm+']');
}
else{
this._DBG( GTAj.vA['ib'],'connTimeOut','connection timeout');
}
}
else{
window.clearTimeout(GTAj.sTd);
window.clearTimeout(GTAj.sTd2);
}
sRe2 = null ;
}
catch( e7 ){
this._DBG( GTAj.vA['ib'],'accessRe',e7.message );
//--- tell script to waiting again,Modified on 2006-7-7 11:36
eval('GTAjStatus.pid'+GTAjStatus.nowopen+'=GTAj;');
GTAj.sTd = window.setTimeout('GTAj._LOP()',GTAj.iItl);
}
//--- end of get content from iframe
}
//- read response
if( GTAj.rtns!=null && typeof GTAj.rtns!='undefined'
&& GTAj.rtns.toLowerCase()=='complete' ){
this._SAY(GTAj.sFld, GTAj.vA['sbv'],true);
GTAj.ti = 1241259; //-- mmddHHii
try{
if(GTAj.nEmt2){
if(GTAj.myBdTt!=null && typeof GTAj.myBdTt !='undefined'){
try{
GTAj.myBdTt.removeChild(GTAj.nEmt2);
}
catch(erm){
}
}
else{
document.body.removeChild(GTAj.nEmt2); //--- refer to this._PSD()
}
GTAj.nEmt2=null;
//window.alert('nEmt2 is cleared!');
}
else{
this._DBG(GTAj.vA['ib'],'return','nEmt2 is nothing!');
}
GTAj.ti = 1241300;
if( ( GTAj.sFld!=''|| GTAj.vA['fbl'] ) && !GTAj.vA['rdo'] ){
if( GTAj.vA['bl'] || GTAj.vA['fbl'] ){
//--- need bl or not, updated 2006-9-22 11:55
if( GTAj.sBkCt=='' ){
GTAjStatus.bki++;
if( GTAjStatus.bki > GTAjStatus.maxbk ){
GTAjStatus.bki = 0 ;
}
eval('GTAjBK.bk'+GTAjStatus.bki+'=document.getElementById(\''
+GTAj.vA['ta']+'\').innerHTML');
this._DBG( GTAj.vA['ib'],'GTAjBK.bk'+GTAjStatus.bki,'val');
GTAj.sBkCt = '1' ;
}
GTAj.ti = 1241301;
var sbackstr = ' <br/> <br/><a href="javascript:void(0);" '
+'onclick="javascript:GTAj.backGTAjax(\''
+ GTAj.vA['ta']+'\',\''+GTAjStatus.bki+'\');">«'
+ GTAj.vA['rn']+'</a><br/> ' ;
if( GTAj.vA['nbl']!='' ){
if( GTAj.sRe.indexOf( GTAj.vA['nbl'] ) == -1 ){
GTAj.sRe += sbackstr ;
}
}
else{
GTAj.sRe += sbackstr ;
}
}
}
GTAj.ti = 1241301;
//-- callback function, added on Sun Mar 11 12:56:18 CST 2012
if(GTAj.vA['cb'] != undefined && GTAj.vA['cb'] != ''){
//console.log("callback:["+GTAj.vA['cb']+"]");
GTAj.vA['cb'].call(GTAj.sRe);
GTAj.ti = 1241302;
}
else if(GTAj.wFl || ( GTAj.vA['ff'] && !GTAj.vA['rdo'] )
|| (!GTAj.wFl && !GTAj.vA['rdo']) ){ // GTAj.wFl==true,always write directly
GTAj.ti = 1241303;
if( typeof GTAj.vA['ta'] !='undefined' && GTAj.vA['ta']!='' ){
document.getElementById( GTAj.vA['ta']).innerHTML = GTAj.sRe ;
}
}
if( sRe2 ){
sRe2 = null ;
}
eval('GTAjStatus.pid'+GTAjStatus.nowopen+'=null;') ;
GTAjStatus.lastopen = GTAjStatus.nowopen ;
GTAjStatus.nowopen = 0 ;
if( GTAj.sTd != 0 ){
window.clearTimeout( GTAj.sTd ) ;
}
GTAj.ti = 1241304;
if( true || GTAj.sTd2 != 0 ){
window.clearTimeout( GTAj.sTd2 ) ;
this._DBG( GTAj.vA['ib'],'sTd2-accessRe-2', GTAj.sTd2 );
}
this._RGT('done',GTAj.tErr);
return GTAj.sRe ;
}
catch(e5){
console.log("e5:["+JSON.stringify(e5)+"] ti:["+GTAj.ti+"]");
return this._RGT('finishJob',e5);
}
}
else if(!GTAj.isWtRp){
this._DBG( GTAj.vA['ib'],'serverResponse',' emptyValue');
}
else{
this._DBG( GTAj.vA['ib'],'sRe-waiting','sRe:['+GTAj.sRe+'],state:['+GTAj.rtns+']');
}
}
}
//- output debug info when isdebug=1
this._DBG = function(ib,sName,sVal){
if( ib ){
try{
var debugid = 'gtajax-debugid';
var isieready = GTAjStatus.ierdy ;
if( isieready == 0) {
if( GTAj.tBro.indexOf('explorer')>-1 ){
if( document.readyState!='complete' ){
}
else {
isieready = 1;
GTAjStatus.ierdy = isieready;
}
}
else{
isieready = 1;
GTAjStatus.ierdy = isieready;
}
}
if( isieready == 0 ){
window.alert('the '+sName+' is:['+sVal+']');
}
else{
if( !document.getElementById( debugid ) ){
var debugdiv = document.createElement('div');
debugdiv.setAttribute('id', debugid );
document.body.appendChild( debugdiv );
}
document.getElementById( debugid ).innerHTML += "<br/><br/>"+(new Date).getTime()
+":<br/>";
if(GTAj.tBro.indexOf('firefox') > -1){
if(sVal.replace){
sVal = sVal.replace((new RegExp('<','gm')),'<');
}
document.getElementById( debugid ).innerHTML += sName+': ['+sVal+']';
}
else{
document.getElementById( debugid ).innerText += sName+': ['+sVal+']';
}
}
}
catch( edebug ){
this._RPT('edebug',edebug);
}
}
}
//- intimate a waiting loop on curret request for resonse, with a globle process counter
this._LOP = function(){
try{
if( GTAj){
GTAj.get( GTAjStatus.nowopen );
GTAj.iTm += GTAj.iItl; //-- remedy on Wed Jan 26 15:38:16 GMT 2011
GTAj._PSD( GTAj.iTm );
GTAj._DBG(GTAj.vA['ib'],'_LOP', 'req:['+GTAj.reg.req+']');
}
}
catch(e1609){
if( GTAj){
return GTAj._RGT('GTAj._LOP()',e1609)
}
else{
return this._RGT('this._LOP()',e1609)
}
}
}
//- report message while _SAY failed...
this._RPT = function(sTag,sObj){
try{
var Errmsg = 'err@GTAjax: '+sTag ;
if( sObj.name ){
Errmsg += '\n name:'+sObj.name
+'\n message:'+sObj.message;
if(true || GTAj.tBro.indexOf('explorer')!= -1 ){
Errmsg += '\n location:'+sObj.location;
}
Errmsg += '\n description:'+sObj.description + '. ['+JSON.stringify(sObj)
+'] more at '+GTAjVar.helpurl;
}
else{
Errmsg = sObj ;
}
window.alert( Errmsg );
}
catch(rpte){
window.alert('this._RPT: '+rpte+', sObj:'+(typeof sObj)+', sTag: '+sTag);
return false;
}
}
//- display processing message
this._SAY = function(sFld,sProcess,isAble){
if( sFld!=null && typeof sFld !='undefined'
&& sFld!='' && document.getElementById(sFld)){
var inPro = '....';
if(isAble){
document.getElementById(sFld).disabled = false ;
document.getElementsByName(sFld).disabled = false ; // for firefox
}
if(sProcess!= GTAj.vA['sbv']){ sProcess += inPro; }
document.getElementById(sFld).value = sProcess ;
document.getElementsByName(sFld).value = sProcess ;
}
else if(sFld=='' && ! GTAj.vA['rdo']){
//---disabled process text when prcsDiv is on ...
if( sProcess.indexOf("Attention:") == 0 ){
window.alert( sProcess );
}
}
}
//- submit request via either a request object or an iframe
this._SUB = function(sForm,sUrlx,sPtWi,ib,fft){
var postForm = null ;
if( document.getElementById( GTAj.reg.req ) ){
postForm = document.getElementById( GTAj.reg.req ) ;
}
else{
//--- when ff==true, need a virtual form to skip on,udpate on 20060918,
//--- always create form in a top-level of a html body at the very first time Initiating...
var myforceform = 'myff200607251525';
var myff = myforceform+'_f';
try{
if(!document.getElementById(myforceform)){
GTAj.nEmt = document.createElement('div');
GTAj.nEmt.setAttribute('id', myff);
document.body.appendChild(GTAj.nEmt);
document.getElementById(myff).innerHTML = '<form id="'+myforceform
+'" name="'+myforceform+'"></form>';
}
postForm = document.getElementById(myforceform) ;
}
catch(efrmdiv){
this._RGT('postFormInit',efrmdiv);
}
}
postForm.lang = GTAj.tLgu;
if(GTAj.wFl){
postForm.encoding = "multipart/form-data";
}
else{
postForm.encoding = "application/x-www-form-urlencoded";
}
postForm.target = sPtWi;
var iQmark = sUrlx.indexOf('?');
var sUrlPart;
if(iQmark>0){
sUrlPart = sUrlx.substring(0,iQmark);
}
else{
sUrlPart = sUrlx ;
}
if(fft){
if(sUrlx.indexOf(GTAj.vA['fft'])==-1){
if( iQmark > -1 ){
sUrlx += '&';
}
else{
sUrlx += '?';
}
sUrlx += GTAj.vA['fft']+'=1';
}
}
if(sUrlPart.indexOf('.htm')>0 || sUrlPart.indexOf('.txt')>0 ){
//--- only if main action url is .htm or .txt file, use this, update on 2006-10-18 9:24
postForm.method = 'GET';
}
else{
postForm.method = 'POST';
}
postForm.action = sUrlx;
postForm.submit();
this._DBG( GTAj.vA['ib'],'this._SUB',sForm+':'+postForm.method+':'+sUrlx+':'+sPtWi
+ ',ff:['+fft+'] postform:['+postForm.name+'] enctype:['+postForm.encoding+']');
postForm = null ;
}
//- reset all into inital status after a complete request
this._RGT = function( eTag, tErr ){
//--- reset();
if( typeof GTAj == 'undefined' || GTAj==null){
window.alert('GTAj is null? ');
document.getElementById( this.gtFDiv ).innerHTMl = '';
document.getElementById( this.gtFDiv+'_x' ).innerHTMl = '';
//return true;
}
else if(GTAj.reg != null){
this._DBG( GTAj.vA['ib'],'need to reset-GTAj', 'req:['+GTAj.reg.req+'] eTag:['+eTag+']' );
}
if( eTag!='' && eTag!='done' && eTag != 'formValidate-0' && eTag != 'formValidate-1' ){
this._RPT(eTag,tErr);