Merge remote branch 'kc/new/enh/bug_2965' into kcmaster
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / js / members.js
1 // this function checks id date is like DD/MM/YYYY
2 function CheckDate(field) {
3 var d = field.value;
4 if (d!="") {
5       var amin = 1900; 
6       var amax = 2100; 
7       var date = d.split("/");
8       var ok=1;
9       var msg;
10       if ( (date.length < 2) && (ok==1) ) {
11         msg = MSG_SEPARATOR+field.name;
12         alert(msg); ok=0; field.focus();
13         return;
14       }
15       var dd   = date[0];
16       var mm   = date[1];
17       var yyyy = date[2]; 
18       // checking days
19       if ( ((isNaN(dd))||(dd<1)||(dd>31)) && (ok==1) ) {
20         msg = MSG_INCORRECT_DAY+field.name;
21             alert(msg); ok=0; field.focus();
22             return false;
23       }
24       // checking months
25       if ( ((isNaN(mm))||(mm<1)||(mm>12)) && (ok==1) ) {
26         msg = MSG_INCORRECT_MONTH+field.name;
27             alert(msg); ok=0; field.focus();
28             return false;
29       }
30       // checking years
31       if ( ((isNaN(yyyy))||(yyyy<amin)||(yyyy>amax)) && (ok==1) ) {
32         msg = MSG_INCORRECT_YEAR+field.name;
33             alert(msg); ok=0; field.focus();
34             return false;
35       }
36    }
37 }
38
39 //function test if member is unique and if it's right the member is registred
40 function unique() {
41 var msg1;
42 var msg2;
43 if (  document.form.check_member.value==1){
44         if (document.form.categorycode.value != "I"){
45                 
46                 msg1 += MSG_DUPLICATE_PATRON;
47                 alert(msg1);
48         check_form_borrowers(0);
49         document.form.submit();
50         
51         }else{
52                 msg2 += MSG_DUPLICATE_ORGANIZATION;
53                 alert(msg2);
54         check_form_borrowers(0);
55         }
56 }
57 else
58 {
59         document.form.submit();
60 }
61
62 }
63 //end function
64 //function test if date enrooled < date expiry
65 // WARNING: format-specific test.
66 function check_manip_date(status) {
67 if (status=='verify'){
68 // this part of function('verify') is used to check if dateenrolled<date expiry
69 if (document.form.dateenrolled != '' && document.form.dateexpiry.value !='') {
70 var myDate1=document.form.dateenrolled.value.split ('/');
71 var myDate2=document.form.dateexpiry.value.split ('/');
72         if ((myDate1[2]>myDate2[2])||(myDate1[2]==myDate2[2] && myDate1[1]>myDate2[1])||(myDate1[2]==myDate2[2] && myDate1[1]>=myDate2[1] && myDate1[0]>=myDate2[0]))
73         
74                 { 
75                 document.form.dateenrolled.focus();
76                 var msg = MSG_LATE_EXPIRY;
77                 alert(msg);
78                 }
79         }
80         }
81 }
82 //end function
83
84
85 // function to test all fields in forms and nav in different forms(1 ,2 or 3)
86 function check_form_borrowers(nav){
87         var statut=0;
88         if (document.form.check_member.value == 1 )
89         {
90                 if (document.form_double.answernodouble) {
91                         if( (!(document.form_double.answernodouble.checked))){
92                                 document.form.nodouble.value=0;
93                         } else {
94                                 document.form.nodouble.value=1;
95                         }
96                 }
97         } 
98         
99         if (document.form.BorrowerMandatoryField.value=='')
100         {}
101         else
102         {
103             var champ_verif = document.form.BorrowerMandatoryField.value.split ('|');
104             var message = MSG_MISSING_MANDATORY
105             message += "\n";
106             var message_champ="";
107                 for (var i=0; i<champ_verif.length; i++) {
108                         if (document.getElementsByName(""+champ_verif[i]+"")[0]) {
109                                 var val_champ=eval("document.form."+champ_verif[i]+".value");
110                                 var ref_champ=eval("document.form."+champ_verif[i]);
111                                 //check if it's a select
112                                 if (ref_champ.type=='select-one'){
113                                         // check to see if first option is selected and is blank
114                                         if (ref_champ.options[0].selected &&
115                                             ref_champ.options[0].text == ''){
116                                                 // action if field is empty
117                                                 message_champ+=champ_verif[i]+"\n";
118                                                 //test to know if you must show a message with error
119                                                 statut=1;
120                                         }
121                                 } else {
122                                         if ( val_champ == '' ) {
123                                                 // action if the field is not empty
124                                                 message_champ+=champ_verif[i]+"\n";
125                                                 statut=1;
126                                         }       
127                             }
128                         }
129                 }
130         }
131         //patrons form to test if you checked no to the question of double
132         if (statut!=1 && document.form.check_member.value > 0 ) {
133                 if (!(document.form_double.answernodouble.checked)){
134                         message ="";
135                         message_champ+= MSG_DUPLICATE_SUSPICION;
136                         statut=1;
137                         document.form.nodouble.value=0;
138                 } else {
139                         document.form.nodouble.value=1;
140                 }
141         }
142                 
143         if (statut==1){
144                 //alert if at least 1 error
145                 alert(message+"\n"+message_champ);
146                 return false;
147         } else {
148                 document.form.submit();
149         }
150 }
151
152 function Dopop(link) {
153 // //   var searchstring=document.form.value[i].value;
154         var newin=window.open(link,'popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=no,top');
155 }
156
157 function Dopopguarantor(link) {
158
159         var newin=window.open(link,'popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=yes,top');
160 }