Statistics
| Branch: | Revision:

m2u-upass-admin / WebContent / js / common.js @ 85:b21ea78dfbb4

History | View | Annotate | Download (14.3 KB)

1
// Updated 14/02/08
2

    
3
// For custom requiredIf rules in struts
4
function validateConditionalRequired (field)
5
{
6
                var isValid = true;
7
        var focusField = null;
8
        var i = 0;
9
        var isCheck = -1;
10

    
11
                if (field.type == 'text' ||
12
                         field.type == 'textarea' ||
13
                        field.type == 'file' ||
14
                        field.type == 'select-one' ||
15
                        field.type == 'password')
16
                {
17
                  var value = '';
18

    
19
                        if (field.type == 'select-one')
20
                        {
21
                                var si = field.selectedIndex;
22
                                if (si > 0)
23
                                {
24
                                        value = field.options[si].value;
25
                                }
26
                        } else {
27
                                value = field.value;
28
                        }
29

    
30
                  if (trim(value).length == 0)
31
                  {
32
                                isValid = false;
33
                  }
34
                }
35
                else if (field.length > 0 && (field[0].type == 'radio' ||
36
               field[0].type == 'checkbox'))
37
                {
38
                        name = field[0].name;
39

    
40
                        for (loop = 0; loop < field.length; loop++)
41
                        {
42
                                if (field[loop].checked)
43
                                {
44
                                        isCheck=loop;
45
                                        break;
46
                                }
47
                        }
48

    
49
                        if (isCheck < 0)
50
                        {
51
                                isValid = false;
52
                        }
53
           }
54
           else if (field.type == 'radio' || field.type == 'checkbox')
55
           {
56
                        name = field.name;
57

    
58
                        if (field.checked)
59
                        {
60
                                isCheck=1;
61
                        }
62

    
63
                        if (isCheck < 0)
64
                        {
65
                                isValid = false;
66
                        }
67
           }
68

    
69
           if (!isValid)
70
           {
71
                   field.focus();
72
           }
73

    
74
        return isValid;
75
}
76

    
77
// Trim whitespace from left and right sides of s.
78
function trim(s)
79
{
80
    return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
81
}
82

    
83
function errorMessageHandler (isValid, fieldName, msg)
84
{
85
        if (!isValid)
86
        {
87
                if (document.getElementById(fieldName + 'Error') != null)
88
                {
89
                        if (msg.length > 0)
90
                        {
91
                                document.getElementById(fieldName + 'Error').innerHTML = msg + '<br>';
92
                        }
93
                        else
94
                        {
95
                                document.getElementById(fieldName + 'Error').innerHTML = '';
96
                        }
97

    
98
                }
99

    
100
                if (document.getElementById(fieldName + 'ErrorSymbol') != null)
101
                {
102
                        document.getElementById(fieldName + 'ErrorSymbol').innerHTML = '*';
103
                }
104

    
105
                if (document.getElementById(fieldName + 'Label') != null)
106
                {
107
                        document.getElementById(fieldName + 'Label').className = 'error';
108
                }
109

    
110
                hideOverlay();
111
        }
112
        else
113
        {
114
                if (document.getElementById(fieldName + 'Error') != null)
115
                {
116
                        document.getElementById(fieldName + 'Error').innerHTML = '';
117
                }
118

    
119
                if (document.getElementById(fieldName + 'ErrorSymbol') != null)
120
                {
121
                        document.getElementById(fieldName + 'ErrorSymbol').innerHTML = '';
122
                }
123

    
124
                if (document.getElementById(fieldName + 'Label') != null)
125
                {
126
                        document.getElementById(fieldName + 'Label').className = '';
127
                }
128
        }
129
}
130

    
131
function clearErrorMessage ()
132
{
133
        var all = document.all ? document.all : document.getElementsByTagName('*');
134
        var elements = new Array();
135
        var index = 0;
136

    
137
        for (var i = 0; i < all.length; i++)
138
        {
139
                var idValue = all[i].id;
140
                var re1 = /Error$/;
141
                var re2 = /ErrorSymbol$/;
142
                var re3 = /Label$/;
143
                var re4 = /resultStatusMessage$/;
144

    
145
                if(re1.test(idValue) || re2.test(idValue) || re4.test(idValue))
146
                {
147
                        all[i].innerHTML = '';
148
                }
149
                else if (re3.test(idValue))
150
                {
151
                        all[i].className = '';
152
                }
153
        }
154
}
155

    
156

    
157
// Fixed clearing error messages.
158
function clearAll(theform)
159
{
160
        for (i = 0; i < theform.elements.length; i++)
161
        {
162
                var fieldName = theform.elements[i].name;
163

    
164
                if (theform.elements[i].type=="text" ||
165
                        theform.elements[i].type=="textarea" ||
166
                        theform.elements[i].type=="password")
167
                {
168
                        theform.elements[i].value = '';
169
                }
170
                else if (theform.elements[i].type == "checkbox" || theform.elements[i].type=="radio")
171
                {
172
                        theform.elements[i].checked = false;
173
                }
174
                else if (theform.elements[i].type=="select-one")
175
                {
176
                        theform.elements[i].value = theform.elements[i].options[0].value;
177
                }
178

    
179
                if (document.getElementById(fieldName + 'Error') != null)
180
                {
181
                        document.getElementById(fieldName + 'Error').innerHTML = '';
182
                }
183

    
184
                if (document.getElementById(fieldName + 'ErrorSymbol') != null)
185
                {
186
                        document.getElementById(fieldName + 'ErrorSymbol').innerHTML = '';;
187
                }
188

    
189
                if (document.getElementById(fieldName + 'Label') != null)
190
                {
191
                        document.getElementById(fieldName + 'Label').className = '';
192
                }
193
        }
194

    
195
        if (document.getElementById('serverSideError') != null)
196
        {
197
                document.getElementById('serverSideError').innerHTML = '';
198
        }
199
}
200

    
201

    
202
function visitReceiptPage (link)
203
{
204
        window.open (link,'receipt','location=0,scrollbars=1,status=1,width=550,height=500,top=50,left=30');
205
}
206

    
207
function visitKafalahReceiptPage (link)
208
{
209
        window.open (link,'receipt','location=0,scrollbars=1,status=1,width=900,height=500,top=50,left=30');
210
}
211

    
212

    
213
function printPage()
214
{
215
//        if(window.print)
216
//        {
217
                window.print();
218
//        }
219
//        else
220
//        {
221
//                alert("Your browser doesn't support printing. Please use File->print option.");
222
//        }
223
}
224

    
225

    
226
function visitBillPaymentPopUp ()
227
{
228
        var corperationName         = document.forms[0].corporationName.value;
229
        var billAccountNumber         = document.forms[0].fromAccountDisplay.value;
230
        var approvalCode                 = document.forms[0].approvalCode.value;
231
        var bankReferenceNumber = document.forms[0].billReferenceNo.value;
232
        var transactionDate         = document.forms[0].transactionDateTime.value;
233
        var status                                 = document.forms[0].statusMessage.value;
234
        var transactionAmount         = document.forms[0].amountDisplay.value;
235
        var referenceNumber         = document.forms[0].referenceNo.value;
236
        var payeeCode                         = document.forms[0].payeeCodeDisplay.value;
237
        var merchantURL                 = document.forms[0].merchantURL.value;
238
        var payeeType                        = document.forms[0].paymentType.value;
239

    
240
        if (payeeType == "Kiosk")
241
        {
242
                referenceNumber = request.getParameter("billReferenceNo");
243
        }
244

    
245
        var parameters = "../jsp/m1200_onlinebillpayment/mbbBillPaymentPopUp.jsp?merchantURL="+escape(merchantURL)+"&transactionDate="+escape(transactionDate)+"&status="+status+"&transactionAmount="+transactionAmount+"&referenceNumber="+referenceNumber+"&payeeCode="+payeeCode+"&approvalCode="+approvalCode+"&bankReferenceNumber="+bankReferenceNumber+"&billAccountNumber="+billAccountNumber+"&corperationName="+escape(corperationName);
246
        window.open(parameters, 'popup', 'width=500,height=350,status=0,scrollbars=1,resizable=1');
247
}
248

    
249
function getPageSize()
250
{
251
        var xScroll, yScroll;
252

    
253
        if (window.innerHeight && window.scrollMaxY) {
254
                xScroll = document.body.scrollWidth;
255
                yScroll = window.innerHeight + window.scrollMaxY;
256
        } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
257
                xScroll = document.body.scrollWidth;
258
                yScroll = document.body.scrollHeight;
259
        } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
260
                xScroll = document.body.offsetWidth;
261
                yScroll = document.body.offsetHeight;
262
        }
263

    
264
        var windowWidth, windowHeight;
265
        if (self.innerHeight) {        // all except Explorer
266
                windowWidth = self.innerWidth;
267
                windowHeight = self.innerHeight;
268
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
269
                windowWidth = document.documentElement.clientWidth;
270
                windowHeight = document.documentElement.clientHeight;
271
        } else if (document.body) { // other Explorers
272
                windowWidth = document.body.clientWidth;
273
                windowHeight = document.body.clientHeight;
274
        }
275

    
276
        // for small pages with total height less then height of the viewport
277
        if(yScroll < windowHeight){
278
                pageHeight = windowHeight;
279
        } else {
280
                pageHeight = yScroll;
281
        }
282

    
283
        // for small pages with total width less then width of the viewport
284
        if(xScroll < windowWidth){
285
                pageWidth = windowWidth;
286
        } else {
287
                pageWidth = xScroll;
288
        }
289

    
290
        arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
291
        return arrayPageSize;
292
}
293

    
294
function overlay()
295
{
296
        clearErrorMessage();
297

    
298
        var pageSize = getPageSize();
299
        var pageSizeHeight = pageSize[1];
300
        pageSizeHeight = pageSizeHeight <= 665?460:pageSizeHeight-160;
301

    
302
        divTD = document.getElementById("div_td");
303
        divTable = document.getElementById("div_table");
304
        divElement = document.getElementById("overlay");
305
        divTable.width = "100%";
306
        divTD.width = "100%";
307
        divTD.height = pageSizeHeight +"px";
308

    
309
        divElement.style.width = "100%";
310
        divElement.style.height = pageSizeHeight +"px";
311
        divElement.style.visibility="visible";
312

    
313
        promptMessage();
314
}
315

    
316
function getPagePosition()
317
{
318
        var windowTop, windowLeft;
319
        if (self.innerHeight) {        // all except Explorer
320
                windowTop = '45%';
321
                windowLeft = '30%';
322
                windowLeftPopup = '10%';
323
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
324
                windowTop = '43%';
325
                windowLeft = '30%';
326
                windowLeftPopup = '10%';
327
        } else if (document.body) { // other Explorers
328
                windowTop = '50%';
329
                windowLeft = '30%';
330
                windowLeftPopup = '10%';
331
        }
332

    
333
        arrayPagePosition = new Array(windowTop,windowLeft,windowLeftPopup);
334
        return arrayPagePosition;
335
}
336

    
337

    
338
function promptMessage()
339
{
340
        var pagePosition = getPagePosition();
341
        var windowTop = pagePosition[0];
342
        var windowLeft = pagePosition[1];
343

    
344
        lightbox = document.getElementById("overlayBox");
345
        lightbox.style.top = windowTop;
346
        lightbox.style.left = windowLeft;
347
        lightbox.style.visibility="visible";
348
}
349

    
350
function promptMessagePopUp()
351
{
352
        var pagePosition = getPagePosition();
353
        var windowTop = pagePosition[0];
354
        var windowLeft = pagePosition[2];
355

    
356
        lightbox = document.getElementById("overlayBox");
357
        lightbox.style.top = windowTop;
358
        lightbox.style.left = windowLeft;
359
        lightbox.style.visibility="visible";
360
}
361

    
362
function overlayCancel()
363
{
364
        overlay();
365
        bCancel = true; //to bypass struts validation for cancel button
366
}
367

    
368
function overlayPopUp()
369
{
370
        clearErrorMessage();
371

    
372
        var pageSize = getPageSize();
373
        var pageSizeHeight = pageSize[1]-80;
374

    
375
        divTD = document.getElementById("div_td");
376
        divTable = document.getElementById("div_table");
377
        divElement = document.getElementById("overlay");
378

    
379
        divTable.width = "100%";
380
        divTD.width = "100%";
381
        divTD.height = pageSizeHeight +"px";
382

    
383
        divElement.style.width = "100%";
384
        divElement.style.height= pageSizeHeight +"px";
385
        divElement.style.visibility="visible";
386
}
387

    
388
function overlayPopUpCancel()
389
{
390
        overlayPopUp();
391
        bCancel = true; //to bypass struts validation for cancel button
392
}
393

    
394
function hideOverlay()
395
{
396

    
397
        divElement2 = document.getElementById("overlayBox");
398
        divElement2.style.visibility="hidden";
399
        divElement = document.getElementById("overlay");
400
        divElement.style.visibility="hidden";
401
}
402

    
403
function clearInputDate()
404
{
405
        document.eStandingBean.terminateDay.value = "";
406
        document.eStandingBean.terminateMonth.value = "";
407
        document.eStandingBean.terminateYear.value = "";
408
        document.eStandingBean.terminateDay.disabled = true;
409
        document.eStandingBean.terminateMonth.disabled = true;
410
        document.eStandingBean.terminateYear.disabled = true;
411
        return true;
412
}
413

    
414
function validateInputDate()
415
{
416
        document.eStandingBean.terminateDay.disabled = false;
417
        document.eStandingBean.terminateMonth.disabled = false;
418
        document.eStandingBean.terminateYear.disabled = false;
419
        return true;
420
}
421

    
422
/*
423
-can used on condition
424
 i.for parent window  only use for onclick event , user trigger event,not used for page onload event,
425
 ii.for pop up window , can be used anyway
426
*/
427
function reset_session_timer() {
428
        var date = new Date();
429
        var lastEvent = date.getTime();
430
        if(document.getElementById('lastEvent')!=null)
431
        {
432
                document.getElementById('lastEvent').value=lastEvent;
433
                //alert("1. reset session at :"+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());
434
        }
435

    
436
        if (window.opener && !window.opener.closed)
437
                if(window.opener.document.getElementById('lastEvent')!=null)
438
                {
439
                        window.opener.document.getElementById('lastEvent').value=lastEvent;
440
                        //alert("2. reset session at :"+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds());
441
                }
442
}
443

    
444
/* Create Exception*/
445

    
446
function changeSelected(string){
447
        var com = document.getElementById("com");
448
        var sys = document.getElementById("sys");
449
        var ibg = document.getElementById("ibg");
450
        var usr = document.getElementById("usr");
451

    
452
        if(string == "com"){
453
                com.className = "selected";
454
                sys.className = "";
455
                ibg.className = "";
456
                usr.className = "";
457
        }
458
        else if(string == "sys"){
459
                com.className = "";
460
                sys.className = "selected";
461
                ibg.className = "";
462
                usr.className = "";
463
        }
464
        else if(string == "ibg"){
465
                com.className = "";
466
                sys.className = "";
467
                ibg.className = "selected";
468
                usr.className = "";
469
        }
470
        else if(string == "usr"){
471
                com.className = "";
472
                sys.className = "";
473
                ibg.className = "";
474
                usr.className = "selected";
475
        }
476
        
477
        onLoadNavigation();
478
}
479

    
480

    
481
function cloneRow(theCell) 
482
{
483
        if( document.createElement && document.childNodes ) 
484
        {
485
                var thisRow = theCell.parentNode;
486
                var newElement = thisRow.cloneNode(true);
487
                thisRow.parentNode.insertBefore(newElement,thisRow .nextSibling);
488
        }
489
}
490

    
491
function deleteRow(theCell) 
492
{
493
        if( document.createElement && document.childNodes )
494
        {
495
                var thisRow = theCell.parentNode;
496
                thisRow.parentNode.removeChild(thisRow);
497
        }
498
}
499

    
500
function addRow(id, date , desc, hiding )
501
{
502
        var tableID = document.getElementById(id);
503
        var tbody = document.getElementById(id).getElementsByTagName("tbody")[1];
504
        var rows = tbody.rows;
505
        var row = document.createElement("tr");
506
        row.setAttribute("class", "even");
507
        //var rowCount = table.rows.length;  
508
        //var row = table.insertRow(rowCount);  
509
    
510
        var td0 = document.createElement("td");
511
        var td1 = document.createElement("td");
512
        var td2 = document.createElement("td");
513
        var td3 = document.createElement("td");
514
        
515
        S0 = document.createElement("input");
516
        S1 = document.createElement("input");
517
        S2 = document.createElement("input");
518
        S3 = document.createElement("input");
519
        
520
        S0.setAttribute("type","checkbox");
521
        S1.setAttribute("type","text");
522
        S1.setAttribute("name",date);
523
        S1.setAttribute("maxlength","15");
524
        S1.setAttribute("styleId",rows.length);
525
        S2.setAttribute("type","text");
526
        S2.setAttribute("name",desc);
527
        S2.setAttribute("maxlength","15");
528
        S2.setAttribute("styleId",rows.length);
529
        S3.setAttribute("type","hidden");
530
        S3.setAttribute("name",hiding);
531
        S3.setAttribute("maxlength","15");
532
        
533
        for(var i=0; i<rows.length; i++) 
534
        {  
535
                var rowing = tableID.rows[i];  
536

    
537
                var chkboxing = rowing.cells[0].childNodes[0];  
538

    
539
                if(null != chkboxing && true == chkboxing.checked) 
540
                {  
541
                        alert("woii");
542
                 }  
543
         }  
544
        
545
        
546
        S3.setAttribute("value",tableID.rows);
547
        td0.appendChild(S0);
548
        td1.appendChild(S1);
549
        td2.appendChild(S2);
550
        td3.appendChild(S3);
551
        
552
        row.appendChild(td0);
553
        row.appendChild(td1);
554
        row.appendChild(td2);
555
        row.appendChild(td3);
556
        
557
        tbody.appendChild(row);
558
}
559

    
560
 function deleteRow(tableID) 
561
 {  
562
        try 
563
        {  
564
                var table = document.getElementById(tableID);  
565

    
566
                var rowCount = table.rows.length;  
567

    
568
                for(var i=0; i<rowCount; i++) 
569
                {  
570
                        var row = table.rows[i];  
571

    
572
                        var chkbox = row.cells[0].childNodes[0];  
573

    
574
                        if(null != chkbox && true == chkbox.checked) 
575
                        {  
576
                                table.deleteRow(i);  
577
                                 rowCount--;  
578
                                 i--;  
579
                         }  
580
                 }  
581
        }
582
        catch(e) 
583
        {  
584
                alert(e);  
585
        }  
586

    
587
}  
588

    
589