1 // this function checks id date is like DD/MM/YYYY
2 function CheckDate(field) {
7 var date = d.split("/");
10 if ( (date.length < 2) && (ok==1) ) {
11 msg = MSG_SEPARATOR.format(field.name);
12 alert(msg); ok=0; field.focus();
19 if ( ((isNaN(dd))||(dd<1)||(dd>31)) && (ok==1) ) {
20 msg = MSG_INCORRECT_DAY.format(field.name);
21 alert(msg); ok=0; field.focus();
25 if ( ((isNaN(mm))||(mm<1)||(mm>12)) && (ok==1) ) {
26 msg = MSG_INCORRECT_MONTH.format(field.name);
27 alert(msg); ok=0; field.focus();
31 if ( ((isNaN(yyyy))||(yyyy<amin)||(yyyy>amax)) && (ok==1) ) {
32 msg = MSG_INCORRECT_YEAR.format(field.name);
33 alert(msg); ok=0; field.focus();
39 //function test if member is unique and if it's right the member is registred
43 if ( document.form.check_member.value==1){
44 if (document.form.categorycode.value != "I"){
46 msg1 += MSG_DUPLICATE_PATRON;
48 check_form_borrowers(0);
49 document.form.submit();
52 msg2 += MSG_DUPLICATE_ORGANIZATION;
54 check_form_borrowers(0);
59 document.form.submit();
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]))
75 document.form.dateenrolled.focus();
76 var msg = MSG_LATE_EXPIRY;
84 function check_password( password ) {
85 if ( password.match(/^\s/) || password.match(/\s$/)) {
91 // function to test all fields in forms and nav in different forms(1 ,2 or 3)
92 function check_form_borrowers(nav){
96 if (document.form.check_member.value == 1 )
98 if (document.form.answernodouble) {
99 if( (!(document.form.answernodouble.checked))){
100 document.form.nodouble.value=0;
102 document.form.nodouble.value=1;
107 if ( document.form.password.value != document.form.password2.value ){
108 if ( message_champ !== '' ){
109 message_champ += "\n";
111 message_champ+= MSG_PASSWORD_MISMATCH;
115 if ( ! check_password( document.form.password.value ) ) {
116 message_champ += MSG_PASSWORD_CONTAINS_TRAILING_SPACES;
120 //patrons form to test if you checked no to the question of double
121 if (statut!=1 && document.form.check_member.value > 0 ) {
122 if (!(document.form.answernodouble.checked)){
123 message_champ+= MSG_DUPLICATE_SUSPICION;
125 document.form.nodouble.value=0;
127 document.form.nodouble.value=1;
132 //alert if at least 1 error
133 alert(message+"\n"+message_champ);
140 function Dopop(link) {
141 // // var searchstring=document.form.value[i].value;
142 var newin=window.open(link,'popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=no,top');
145 function Dopopguarantor(link) {
146 var newin=window.open(link,'popup','width=600,height=400,resizable=no,toolbar=false,scrollbars=yes,top');
149 function clear_entry(node) {
150 var original = $(node).parent();
151 $("textarea", original).attr('value', '');
152 $("select", original).attr('value', '');
155 function clone_entry(node) {
156 var original = $(node).parent();
157 var clone = original.clone();
159 var newId = 50 + parseInt(Math.random() * 100000);
160 $("input,select,textarea", clone).attr('id', function() {
161 return this.id.replace(/patron_attr_\d+/, 'patron_attr_' + newId);
163 $("input,select,textarea", clone).attr('name', function() {
164 return this.name.replace(/patron_attr_\d+/, 'patron_attr_' + newId);
166 $("label", clone).attr('for', function() {
167 return $(this).attr("for").replace(/patron_attr_\d+/, 'patron_attr_' + newId);
169 $("input#patron_attr_" + newId, clone).attr('value','');
170 $("select#patron_attr_" + newId, clone).attr('value','');
171 $(original).after(clone);
175 function update_category_code(category_code) {
176 if ( $(category_code).is("select") ) {
177 category_code = $("#categorycode_entry").find("option:selected").val();
179 var mytables = $(".attributes_table");
180 $(mytables).find("li").hide();
181 $(mytables).find(" li[data-category_code='"+category_code+"']").show();
182 $(mytables).find(" li[data-category_code='']").show();
185 function select_user(borrowernumber, borrower) {
186 var form = $('#entryform').get(0);
187 if (form.guarantorid.value) {
188 $("#contact-details").find('a').remove();
189 $("#contactname, #contactfirstname").parent().find('span').remove();
192 var id = borrower.borrowernumber;
193 form.guarantorid.value = id;
194 $('#contact-details')
197 .after('<a target="blank" href="/cgi-bin/koha/members/moremember.pl?borrowernumber=' + id + '">' + id + '</a>');
200 .val(borrower.surname)
201 .before('<span>' + borrower.surname + '</span>').get(0).type = 'hidden';
202 $(form.contactfirstname)
203 .val(borrower.firstname)
204 .before('<span>' + borrower.firstname + '</span>').get(0).type = 'hidden';
206 form.streetnumber.value = borrower.streetnumber;
207 form.address.value = borrower.address;
208 form.address2.value = borrower.address2;
209 form.city.value = borrower.city;
210 form.state.value = borrower.state;
211 form.zipcode.value = borrower.zipcode;
212 form.country.value = borrower.country;
213 form.branchcode.value = borrower.branchcode;
215 form.guarantorsearch.value = LABEL_CHANGE;
220 function CalculateAge(dateofbirth) {
221 var today = new Date();
222 var dob = Date_from_syspref(dateofbirth);
225 age.year = today.getFullYear() - dob.getFullYear();
226 age.month = today.getMonth() - dob.getMonth();
227 var day = today.getDate() - dob.getDate();
230 age.month = parseInt(age.month) -1;
234 age.year = parseInt(age.year) -1;
235 age.month = 12 + age.month;
241 function write_age() {
242 var hint = $("#dateofbirth").siblings(".hint").first();
243 hint.html(dateformat);
245 var age = CalculateAge(document.form.dateofbirth.value);
247 if (!age.year && !age.month) {
252 if (age.year || age.month) {
253 age_string = LABEL_AGE + ": ";
257 age_string += age.year > 1 ? MSG_YEARS.format(age.year) : MSG_YEAR.format(age.year);
262 age_string += age.month > 1 ? MSG_MONTHS.format(age.month) : MSG_MONTH.format(age.month);
265 hint.html(age_string);
268 $(document).ready(function(){
269 if($("#yesdebarred").is(":checked")){
270 $("#debarreduntil").show();
272 $("#debarreduntil").hide();
274 $("#yesdebarred,#nodebarred").change(function(){
275 if($("#yesdebarred").is(":checked")){
276 $("#debarreduntil").show();
277 $("#datedebarred").focus();
279 $("#debarreduntil").hide();
282 var mandatory_fields = $("input[name='BorrowerMandatoryField']").val().split ('|');
283 $(mandatory_fields).each(function(){
284 $("[name='"+this+"']").attr('required', 'required');
287 $("fieldset.rows input, fieldset.rows select").addClass("noEnterSubmit");
289 $("#guarantordelete").click(function() {
290 $("#contact-details").hide().find('a').remove();
291 $("#guarantorid, #contactname, #contactfirstname").each(function () { this.value = ""; });
292 $("#contactname, #contactfirstname")
293 .each(function () { this.type = 'text'; })
294 .parent().find('span').remove();
295 $("#guarantorsearch").val(LABEL_SET_TO_PATRON);
298 $("#select_city").change(function(){
299 var myRegEx=new RegExp(/(.*)\|(.*)\|(.*)\|(.*)/);
300 document.form.select_city.value.match(myRegEx);
301 document.form.zipcode.value=RegExp.$1;
302 document.form.city.value=RegExp.$2;
303 document.form.state.value=RegExp.$3;
304 document.form.country.value=RegExp.$4;
307 $("#dateofbirth").datepicker({ maxDate: "-1D", yearRange: "c-120:" });
308 dateformat = $("#dateofbirth").siblings(".hint").first().html();
310 if( $('#dateofbirth').length ) {
314 $("#entryform").validate({
326 submitHandler: function(form) {
327 $("body, form input[type='submit'], form button[type='submit'], form a").addClass('waiting');
328 if (form.beenSubmitted)
331 form.beenSubmitted = true;
336 var mrform = $("#manual_restriction_form");
337 var mrlink = $("#add_manual_restriction");
339 mrlink.on("click",function(e){
345 $("#cancel_manual_restriction").on("click",function(e){
346 $('#debarred_expiration').val('');
347 $('#add_debarment').val(0);
348 $('#debarred_comment').val('');
353 $('#floating-save').css( { bottom: parseInt( $('#floating-save').css('bottom') ) + $('#changelanguage').height() + 'px' } );