/
ciyam_interface.js.xrep
1697 lines (1405 loc) · 44.4 KB
/
ciyam_interface.js.xrep
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
`{`#$include @`}
var isOpera = navigator.userAgent.indexOf( 'Opera' ) > -1;
var isIE = navigator.userAgent.indexOf( 'MSIE' ) > 1 && !isOpera;
var isMoz = navigator.userAgent.indexOf( 'Mozilla/5.' ) == 0 && !isOpera;
var xmlReq = null;
var load_form = null;
var ServerApp = 'ciyam_interface.fcgi';
var qsContext = window.location.search.substring( 1 ); //i.e. remove the ? prefix
var qsFurther = '';
var secureOnly = false;
var encryptPosts = `{`?`$encrypt_data`&`@eq`(`$encrypt_data`,`'true`'`)true`,false`};
var usePageFadeIn = true;
var debugDynamicContent = false;
var source = window.location.href.split( ':' );
if( secureOnly && source[ 0 ] != 'https' )
window.location.replace( 'https:' + source[ 1 ] );
var scrollTop = 0;
var scrollLeft = 0;
var loggedIn = false;
var jump_back = false;
var had_act_error = false;
var pwdSalt = '';
var serverId = '';
var uniqueId = '';
var hashRounds = 100;
var validation_error = '';
var displayTimeout = 'Timeout occurred.';
var displayInvalidDate = 'Invalid date.';
var displayInvalidTime = 'Invalid time.';
var displayIncorrectDateFormat = 'Incorrect date format.';
var displayIncorrectTimeFormat = 'Incorrect time format.';
var displayEnterRequiredValues = 'Enter required values.';
var displayIncorrectBytesFormat = 'Incorrect bytes format.';
var displaySelectOneOrMoreItems = 'Select one or more items to perform this operation on.';
var displayIncorrectIntegerFormat = 'Incorrect integer format.';
var displayIncorrectNumericFormat = 'Incorrect numeric format.';
var displayIncorrectDurationFormat = 'Incorrect duration format.';
var displayMaximumTextLimitReached = 'Maximum text limit reached.';
var displayYourSessionIsAboutToExpire = 'Your session is about to expire. Click OK to continue.';
var displaySelectedRecordsWillBeRemoved = 'Selected record(s) will be permanently removed. Click OK to confirm.';
var displayPasswordVerificationIncorrect = 'Password verification incorrect.';
var dataFieldList = '';
var autoCompleteValues = [ ];
var extra_fields = '';
var extra_values = '';
var warn_refresh_func = '';
var auto_refresh_seconds = 30;
var warn_refresh_default = 500;
var warn_refresh_seconds = warn_refresh_default;
var warn_refresh_timer_id = 0;
var load_content_seconds = 15;
var load_content_timer_id = 0;
function is_leap_year( year )
{
return year % 4 == 0 && ( year % 100 != 0 || year % 400 == 0 );
}
function refresh( back )
{
if( isIE )
window.location = window.location;
else
window.location.replace( window.location );
if( isMoz && back != false )
history.go( -1 );
}
function replace_with_scroll_info( )
{
if( qsContext.length > 0 )
insert_scroll_info( );
var new_href = '';
new_href += window.location.href;
if( qsContext.length > 0 )
{
var pos = new_href.indexOf( '?' );
if( pos > 0 )
new_href = new_href.substr( 0, pos + 1 );
new_href += qsContext;
}
window.location.replace( new_href );
}
function auto_refresh( )
{
if( auto_refresh_seconds == 1 )
replace_with_scroll_info( );
else if( auto_refresh_seconds > 0 )
{
auto_refresh_seconds -= 1;
setTimeout( "auto_refresh( )", 1000 );
}
}
function warn_refresh( )
{
if( warn_refresh_seconds == 1 )
{
warn_refresh_seconds = 0;
if( confirm( displayYourSessionIsAboutToExpire ) )
{
if( warn_refresh_func != '' )
eval( warn_refresh_func );
else
replace_with_scroll_info( );
}
}
else if( warn_refresh_seconds > 0 )
{
warn_refresh_seconds -= 1;
warn_refresh_timer_id = setTimeout( "warn_refresh( )", 1000 );
}
}
function determine_scroll_info( )
{
if( typeof( window.pageYOffset ) == 'number' )
{
// Netscape compliant
scrollTop = window.pageYOffset;
scrollLeft = window.pageXOffset;
}
else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
{
// DOM compliant
scrollTop = document.body.scrollTop;
scrollLeft = document.body.scrollLeft;
}
else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
{
// IE6 standards compliant mode
scrollTop = document.documentElement.scrollTop;
scrollLeft = document.documentElement.scrollLeft;
}
else
{
scrollTop = 0;
scrollLeft = 0;
}
}
function insert_scroll_info( )
{
var qvars = qsContext.split( '&' );
qsContext = '';
determine_scroll_info( );
var sx = 'scrollx';
var sy = 'scrolly';
var foundx = false;
var foundy = false;
for( var i = 0; i < qvars.length; i++ )
{
if( qvars[ i ].length >= sx.length + 1
&& qvars[ i ].charAt( sx.length ) == '='
&& qvars[ i ].substring( 0, sx.length ) == sx )
{
foundx = true;
qvars[ i ] = sx + '=' + scrollLeft;
}
if( qvars[ i ].length >= sy.length + 1
&& qvars[ i ].charAt( sy.length ) == '='
&& qvars[ i ].substring( 0, sy.length ) == sy )
{
foundy = true;
qvars[ i ] = sy + '=' + scrollTop;
}
if( qsContext != '' )
qsContext += '&';
qsContext += qvars[ i ];
}
if( !foundx )
{
if( qsContext != '' )
qsContext += '&';
qsContext += 'scrollx=' + scrollLeft;
}
if( !foundy )
{
if( qsContext != '' )
qsContext += '&';
qsContext += 'scrolly=' + scrollTop;
}
}
function utf8_encode( string )
{
string = string.replace( /\r\n/g, "\n" );
var utftext = "";
for( var n = 0, k = string.length; n < k; n++ )
{
var c = string.charCodeAt( n );
if( c < 128 )
utftext += String.fromCharCode( c );
else if( ( c > 127 ) && ( c < 2048 ) )
{
utftext += String.fromCharCode( ( c >> 6 ) | 192 );
utftext += String.fromCharCode( ( c & 63 ) | 128 );
}
else
{
utftext += String.fromCharCode( ( c >> 12 ) | 224 );
utftext += String.fromCharCode( ( ( c >> 6 ) & 63 ) | 128 );
utftext += String.fromCharCode( ( c & 63 ) | 128 );
}
}
return utftext;
}
function utf8_decode( utftext )
{
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length )
{
c = utftext.charCodeAt( i );
if( c < 128 )
{
string += String.fromCharCode( c );
i++;
}
else if( ( c > 191 ) && ( c < 224 ) )
{
c2 = utftext.charCodeAt( i + 1 );
string += String.fromCharCode( ( ( c & 31 ) << 6 ) | ( c2 & 63 ) );
i += 2;
}
else
{
c2 = utftext.charCodeAt( i + 1 );
c3 = utftext.charCodeAt( i + 2 );
string += String.fromCharCode( ( ( c & 15 ) << 12 ) | ( ( c2 & 63 ) << 6 ) | ( c3 & 63 ) ) ;
i += 3;
}
}
return string;
}
function string_to_bytes( str )
{
var ch, st, re = [ ];
for( var i = 0; i < str.length; i++ )
{
ch = str.charCodeAt( i )
st = [ ];
do
{
st.push( ch & 0xFF );
ch = ch >> 8;
} while( ch );
re = re.concat( st.reverse( ) );
}
return re;
}
function trim( str )
{
return str.replace( /^\s+|\s+$/g, "" );
}
function load( )
{
clearTimeout( warn_refresh_timer_id );
// NOTE: This is necessary (at least for Firefox) to force a page
// reload to occur when going back in history.
window.onunload = function( ){ };
if( typeof window.ActiveXObject != 'undefined' )
{
xmlReq = new ActiveXObject( 'Microsoft.XMLHTTP' );
xmlReq.onreadystatechange = process;
}
else
{
xmlReq = new XMLHttpRequest( );
xmlReq.onload = process;
}
var session_id = '';
var has_session = false;
var all_cookies = document.cookie.split( ';' );
for( i = 0; i < all_cookies.length; i++ )
{
var next_cookie = all_cookies[ i ].split( '=' );
if( trim( next_cookie[ 0 ] ) == 'session' )
{
has_session = true;
var cookie_parts = next_cookie[ 1 ].split( ',' );
session_id = cookie_parts[ 0 ];
break;
}
}
if( !has_session )
{
session_id = 'new_session';
document.cookie = 'session=new_session';
}
var qs_both = qsContext;
var persistent = '';
if( qs_both == '' )
qs_both = qsFurther;
else if( qsFurther != '' )
qs_both += '&' + qsFurther;
var is_login = false;
var non_cookie = false;
var qvars = qs_both.split( '&' );
for( var i = 0; i < qvars.length; i++ )
{
var uname = 'username=';
if( qvars[ i ].indexOf( uname ) == 0 )
{
is_login = true;
document.cookie = 'user=' + qvars[ i ].substring( uname.length );
localStorage.setItem( 'user', qvars[ i ].substring( uname.length ) );
}
var pname = 'persistent=true';
if( qvars[ i ].indexOf( pname ) == 0 )
{
persistent = 'true';
if( is_login )
localStorage.setItem( 'fkey', sessionStorage.getItem( 'key' ) );
}
var sname = 'session=';
if( qvars[ i ].indexOf( sname ) == 0 )
{
non_cookie = true;
session_id = qvars[ i ].substring( sname.length );;
}
}
var full_context = module;
if( qsContext != '' )
{
if( full_context != '' )
full_context += '&';
full_context += qsContext;
}
var dummy = 'dummy=';
var num_random = 10 + Math.floor( Math.random( ) * 6 );
for( var i = 0; i < num_random; i++ )
dummy += String.fromCharCode( 65 + Math.floor( Math.random( ) * 26 ) );
full_context += '&' + dummy;
if( qsFurther != '' )
{
if( full_context != '' )
full_context += '&';
full_context += qsFurther;
}
if( dataFieldList != '' )
{
if( full_context != '' )
full_context += '&';
full_context += 'fieldlist=' + dataFieldList;
}
if( full_context != '' )
full_context += '&';
full_context += 'suffix=';
if( sessionStorage.getItem( 'key' ) == null && localStorage.getItem( 'fkey' ) != null )
sessionStorage.setItem( 'key', localStorage.getItem( 'fkey' ) );
xmlReq.open( 'POST', ServerApp, true );
if( !encryptPosts || source[ 0 ] == 'https' )
xmlReq.send( full_context );
else
{
var post_data = '';
var key = sessionStorage.getItem( 'key' );
if( has_session && key != null && encryptPosts )
{
var prefix = 'prefix=';
for( var i = 0; i < 22 - dummy.length; i++ )
prefix += String.fromCharCode( 65 + Math.floor( Math.random( ) * 26 ) );
full_context = prefix + '&' + full_context;
while( full_context.length % 40 )
full_context += String.fromCharCode( 65 + Math.floor( Math.random( ) * 26 ) );
var full_key = '';
full_key = sessionStorage.getItem( 'key' );
var last_key = full_key;
var all_bytes = string_to_bytes( full_context );
while( full_key.length < all_bytes.length )
{
var next = hex_sha1( last_key );
full_key += next;
last_key = next;
}
var encrypted = '';
// KLUDGE: The string is not encrypted in place as characters are UTF encoded
// so the encrypted string is actually a hex string. It may be instead better
// to use an array of bytes (which would require an extra base64 interface).
for( var i = 0; i < all_bytes.length; i++ )
{
var val = ( full_key.charCodeAt( i ) ^ all_bytes[ i ] );
var hex = '';
if( val < 16 )
hex += '0';
hex += val.toString( 16 );
encrypted += hex;
}
post_data = 'base64=' + Base64.encode( encrypted );
if( is_login )
{
post_data += '&cmd=login&username=' + localStorage.getItem( 'user' )
+ '&persistent=' + persistent + '&' + module + '&session=' + session_id;
}
else if( non_cookie )
post_data += '&' + module + '&session=' + session_id;
else
post_data += '&' + module;
}
else
post_data = full_context;
xmlReq.send( post_data );
}
if( load_form != null )
disable_form( load_form );
load_content_timer_id = setTimeout( load_timeout, load_content_seconds * 1000 );
}
function load_timeout( )
{
xmlReq.abort( );
if( load_form != null )
enable_form( load_form );
alert( displayTimeout );
if( encryptPosts )
{
if( sessionStorage.getItem( 'key' ) != null )
sessionStorage.setItem( 'key', hex_sha1( sessionStorage.getItem( 'key' ) ) );
}
}
function fade_in( n )
{
// NOTE: Currently only works for FF (under IE use blendTrans headers)
// in order to try and make the page rendering look a little smoother.
if( n <= 100 )
{
document.body.style.opacity = n / 100;
n += 25;
window.setTimeout( 'fade_in(' + n + ')', 10 );
}
}
function force_update( )
{
// NOTE: Add and after a minimal timeout remove a dummy node to force a DOM update.
var t = document.createTextNode( 'dummy' );
document.appendChild( t );
setTimeout( function( ) { t.parentNode.removeChild( t ); }, 0 );
}
function process( )
{
if( xmlReq.readyState != 4 )
return;
if( load_form != null )
enable_form( load_form );
clearTimeout( load_content_timer_id );
document.body.style.opacity = 25;
var response = xmlReq.responseText.substring( 2 );
var base64test = /[^A-Za-z0-9\+\/\=]/g;
base64test.exec( response ); // KLUDGE: Need to investigate javascript reg exps more to get rid of this.
// NOTE: If there is no whitespace found in the response then it is assumed to be base64.
if( base64test.exec( response ) )
{
var str = response;
if( debugDynamicContent )
{
str = str.replace( /&/g, '&' ).replace( /</g, '<' ).replace( />/g, '>' );
str = "<div id='debug'><pre>\n" + str + "\n</pre></div>\n";
str = response + str;
}
document.getElementById( 'content' ).innerHTML = str;
force_update( );
}
else
{
response = Base64.decode( response );
// NOTE: Now the encrypted hex string is decoded.
var full_key = sessionStorage.getItem( 'key' );
var last_key = full_key;
while( full_key.length < response.length / 2 )
{
var next = hex_sha1( last_key );
full_key += next;
last_key = next;
}
var decrypted = '';
for( i = 0; i < response.length; i += 2 )
{
var hex = response.charAt( i );
hex += response.charAt( i + 1 );
var val = parseInt( hex, 16 );
val = val ^ full_key.charCodeAt( i / 2 );
decrypted += String.fromCharCode( val );
}
document.getElementById( 'content' ).innerHTML = utf8_decode( decrypted );
force_update( );
}
if( document.getElementById( 'form_content_func' ) != null )
eval( document.getElementById( 'form_content_func' ).value );
if( document.getElementById( 'extra_content_func' ) != null )
eval( document.getElementById( 'extra_content_func' ).value );
if( encryptPosts )
{
if( !loggedIn )
sessionStorage.removeItem( 'key' );
else if( sessionStorage.getItem( 'key' ) != null )
sessionStorage.setItem( 'key', hex_sha1( sessionStorage.getItem( 'key' ) ) );
}
if( uniqueId != '' )
sessionStorage.setItem( 'uuid', uniqueId );
if( jump_back && !had_act_error )
history.back( );
else
{
jump_back = false;
if( usePageFadeIn )
fade_in( 0 );
// KLUDGE: A delay is needed in order for the focussing to work correctly in IE.
setTimeout( "focus_on_first_text( )", 50 );
}
}
function dyn_load( f, extra, clearContext )
{
if( f == null || validate( f ) )
{
if( clearContext )
qsContext = ''
if( extra.indexOf( 'username' ) != 0 )
insert_scroll_info( );
if( extra_fields != '' )
{
if( extra != '' )
extra += '&';
extra += 'extrafields=' + extra_fields;
extra += '&extravalues=' + extra_values;
}
qsFurther = extra;
load_form = f;
load( );
load_form = null;
}
return false;
}
function list_action( f, cls, act, lst, qvar, qval )
{
if( verify_one_or_more_checked( f ) )
{
if( qvar != null )
query_update( qvar, qval, true );
return dyn_load( f, 'act=' + act + '&app='
+ get_all_checked_names( f ) + '&cls=' + cls + '&listarg=' + lst, false );
}
else
return false;
}
function list_exec_action( f, cls, lst, exec, qvar1, qval1, qvar2, qval2, no_app )
{
if( no_app || verify_one_or_more_checked( f ) )
{
if( qvar1 != null )
query_update( qvar1, qval1, true );
if( qvar2 != null )
query_update( qvar2, qval2, true );
if( no_app )
return dyn_load( f, 'act=exec&cls=' + cls + '&exec=' + exec + '&listarg=' + lst, false );
else
return dyn_load( f, 'act=exec&app='
+ get_all_checked_names( f ) + '&cls=' + cls + '&exec=' + exec + '&listarg=' + lst, false );
}
else
return false;
}
function query_value( qvar )
{
var qval = '';
var qvars = qsContext.split( '&' );
for( var i = 0; i < qvars.length; i++ )
{
if( qvars[ i ].length >= qvar.length + 1
&& qvars[ i ].charAt( qvar.length ) == '='
&& qvars[ i ].substring( 0, qvar.length ) == qvar )
{
qval = qvars[ i ].substring( qvar.length + 1 );
break;
}
}
return qval;
}
function query_update( qvar, qval, keep_location )
{
var found = false;
var empty = ( qval == '' );
var qvars = qsContext.split( '&' );
qsContext = '';
for( var i = 0; i < qvars.length; i++ )
{
var skip = false;
if( qvars[ i ].length >= qvar.length + 1
&& qvars[ i ].charAt( qvar.length ) == '='
&& qvars[ i ].substring( 0, qvar.length ) == qvar )
{
if( empty )
skip = true;
else
qvars[ i ] = qvar + '=' + encodeURIComponent( qval );
found = true;
}
if( !skip )
{
if( qsContext != '' )
qsContext += '&';
qsContext += qvars[ i ];
}
}
if( !found && !empty )
qsContext += '&' + qvar + '=' + encodeURIComponent( qval );
if( keep_location != true )
{
insert_scroll_info( );
window.location.search = qsContext;
}
}
function sel_new_loc( sel )
{
if( sel.options[ sel.selectedIndex ].value != "" )
location.href = sel.options[ sel.selectedIndex ].value;
}
function sel_qry_update( sel, qvar )
{
query_update( qvar, sel.options[ sel.selectedIndex ].value );
}
function sel_list_action( f, cls, act, lst, sel, fld, qvar, qval )
{
if( sel.selectedIndex > 0 )
{
if( !verify_one_or_more_checked( f ) )
sel.selectedIndex = 0;
else
{
if( qvar != null )
query_update( qvar, qval, true );
dyn_load( f, 'act=' + act + '&app=' + get_all_checked_names( f ) + '&cls=' + cls
+ '&extra=' + sel.options[ sel.selectedIndex ].value + '&field=' + fld + '&listarg=' + lst, false );
}
}
}
function remove_table_row_error( tbl, row )
{
var is_error = false;
var row_num = 0;
var data_row_num = 0;
for( row_num = 0; row_num < tbl.rows.length; row_num++ )
{
// NOTE: It would make sense to use a special attribute for the error status, however,
// Opera (ver 8) seems to only be able to access to the 'class' attribute of a table row.
if( tbl.rows[ row_num ].getAttribute( 'class' ) == 'error'
|| tbl.rows[ row_num ].getAttribute( 'class' ) == 'odd_error'
|| tbl.rows[ row_num ].getAttribute( 'className' ) == 'error'
|| tbl.rows[ row_num ].getAttribute( 'className' ) == 'odd_error' )
is_error = true;
else
is_error = false;
if( data_row_num > row )
break;
else if( !is_error )
data_row_num++;
}
if( is_error )
tbl.deleteRow( row_num );
return true;
}
function remove_table_row_from_checkbox( cb )
{
var list_id = cb.getAttribute( 'list_id' );
var list_error = cb.getAttribute( 'list_error' );
if( list_id != null && list_error != null )
remove_table_row_error( document.getElementById( list_id ), list_error );
}
function prefill( v, n, c )
{
var s = '';
s += v;
while( s.length < n )
s = c + s;
return s;
}
function utc_dtm( dt )
{
var output = '';
output += dt.getUTCFullYear( );
output += '-' + prefill( dt.getUTCMonth( ) + 1, 2, '0' );
output += '-' + prefill( dt.getUTCDate( ), 2, '0' );
output += '_' + prefill( dt.getUTCHours( ), 2, '0' );
output += ':' + prefill( dt.getUTCMinutes( ), 2, '0' );
output += ':' + prefill( dt.getUTCSeconds( ), 2, '0' );
return output;
}
function hash_value( s, n )
{
for( var i = 0; i < n; i++ )
s = hex_sha1( s ).toLowerCase( );
return s;
}
function hash_password( salt, pwd, skip_id )
{
var retval = '';
// NOTE: If the password length is >= 40 then it is being
// assumed that it is already hashed (this will occur for
// record editing where it has not been changed).
if( pwd.length >= 40 )
retval = pwd;
else
retval = hash_value( serverId + pwd + salt, hashRounds ).toLowerCase( );
if( sessionStorage.getItem( 'uuid' ) != null )
uniqueId = sessionStorage.getItem( 'uuid' );
if( skip_id != true && uniqueId != '' )
retval += '@' + uniqueId;
if( encryptPosts )
{
if( sessionStorage.getItem( 'key' ) == null )
sessionStorage.setItem( 'key', hex_sha1( serverId + pwd + salt ) );
}
return retval;
}
function escape_char( input, ch )
{
var output = '';
for( var i = 0; i < input.length; i++ )
{
var next = input.charAt( i );
if( next == ch || next == '\\' )
output += '\\';
output += next;
}
return output;
}
function form_keys( event, enter, cancel )
{
if( enter != null && event.keyCode == 13 )
{
enter.click( );
return false;
}
else if( cancel != null && event.keyCode == 27 )
{
cancel.click( );
return false;
}
return true;
}
function getY( elem )
{
var y = 0;
while( elem != null )
{
y += elem.offsetTop;
elem = elem.offsetParent;
}
return y;
}
function scroll_page( x, y )
{
scrollLeft = x;
scrollTop = y;
scrollTo( scrollLeft, scrollTop );
}
function focus_on_first_text( )
{
var done = false;
var first = true;
for( var i = 0; i < document.forms.length; i++ )
{
var form = document.forms[ i ];
if( form.disabled ) // NOTE: Non-standard but IE supports this.
continue;
for( var j = 0; j < form.elements.length; j++ )
{
// NOTE: If the control above the scroll top then don't consider it for focus.
if( getY( form.elements[ j ] ) < scrollTop )
continue;
if( !form.elements[ j ].disabled && form.elements[ j ].getAttribute( 'nofocus' ) != 'true' )
{
if( first && ( form.elements[ j ].type == 'checkbox' || form.elements[ j ].type == 'select-one' ) )
{
first = false;
form.elements[ j ].focus( );
}
if( form.elements[ j ].type == 'file'
|| form.elements[ j ].type == 'text'
|| form.elements[ j ].type == 'textarea'
|| form.elements[ j ].type == 'password' )
{
if( form.elements[ j ].type == 'text' )
form.elements[ j ].select( );
form.elements[ j ].focus( );
done = true;
break;
}
}
}
if( done )
break;
}
}
function limit_text( limit_field, limit_count, limit_num )
{
if( limit_field.value.length > limit_num )
{
limit_field.value = limit_field.value.substring( 0, limit_num );
alert( displayMaximumTextLimitReached );
}
else if( limit_count != null )
document.getElementById( limit_count ).innerHTML = limit_num - limit_field.value.length;
}
function resize_text_rows( t, min, max )
{
a = t.value.split( '\n' );
b = 1;
for( x = 0; x < a.length; x++ )
{
if( a[ x ].length >= t.cols )
b += Math.floor( a[ x ].length / t.cols );
}
b += a.length;
if( min != null && b < min )
b = min;
if( max != null && b > max )
b = max;