1var date_approved = []; 2var date2approve = []; 3 4 5//////////////////////////////////////////////////////////////////////////// 6// Days Selections - support functions 7//////////////////////////////////////////////////////////////////////////// 8 9/** 10 * Get first day of selection 11 * 12 * @param dates 13 * @returns {string|*} 14 */ 15function get_first_day_of_selection(dates) { 16 17 // Multiple days selections 18 if ( dates.indexOf( ',' ) != -1 ){ 19 var dates_array = dates.split( /,\s*/ ); 20 var length = dates_array.length; 21 var element = null; 22 var new_dates_array = []; 23 24 for ( var i = 0; i < length; i++ ){ 25 26 element = dates_array[ i ].split( /\./ ); 27 28 new_dates_array[ new_dates_array.length ] = element[ 2 ] + '.' + element[ 1 ] + '.' + element[ 0 ]; //2013.12.20 29 } 30 new_dates_array.sort(); 31 32 element = new_dates_array[ 0 ].split( /\./ ); 33 34 return element[ 2 ] + '.' + element[ 1 ] + '.' + element[ 0 ]; //20.12.2013 35 } 36 37 // Range days selection 38 if ( dates.indexOf( ' - ' ) != -1 ){ 39 var start_end_date = dates.split( " - " ); 40 return start_end_date[ 0 ]; 41 } 42 43 // Single day selection 44 return dates; //20.12.2013 45} 46 47// Get last day of selection 48function get_last_day_of_selection(dates) { 49 50 // Multiple days selections 51 if ( dates.indexOf(',') != -1 ){ 52 var dates_array =dates.split(/,\s*/); 53 var length = dates_array.length; 54 var element = null; 55 var new_dates_array = []; 56 57 for (var i = 0; i < length; i++) { 58 59 element = dates_array[i].split(/\./); 60 61 new_dates_array[new_dates_array.length] = element[2]+'.' + element[1]+'.' + element[0]; //2013.12.20 62 } 63 new_dates_array.sort(); 64 65 element = new_dates_array[(new_dates_array.length-1)].split(/\./); 66 67 return element[2]+'.' + element[1]+'.' + element[0]; //20.12.2013 68 } 69 70 // Range days selection 71 if ( dates.indexOf(' - ') != -1 ){ 72 var start_end_date = dates.split(" - "); 73 return start_end_date[(start_end_date.length-1)]; 74 } 75 76 // Single day selection 77 return dates; //20.12.2013 78} 79 80 81/** 82 * Check ID of selected additional calendars 83 * 84 * @param int bk_type 85 * @returns array 86 */ 87function wpbc_get_arr_of_selected_additional_calendars( bk_type ){ //FixIn: 8.5.2.26 88 89 var selected_additionl_calendars = []; 90 91 // Checking according additional calendars 92 if ( document.getElementById( 'additional_calendars' + bk_type ) != null ){ 93 94 var id_additional_str = document.getElementById( 'additional_calendars' + bk_type ).value; 95 var id_additional_arr = id_additional_str.split( ',' ); 96 97 var is_all_additional_days_unselected = true; 98 99 for ( var ia = 0; ia < id_additional_arr.length; ia++ ){ 100 if ( document.getElementById( 'date_booking' + id_additional_arr[ ia ] ).value != '' ){ 101 selected_additionl_calendars.push( id_additional_arr[ ia ] ); 102 } 103 } 104 } 105 return selected_additionl_calendars; 106} 107 108//////////////////////////////////////////////////////////////////////////// 109// Submit Booking Data 110//////////////////////////////////////////////////////////////////////////// 111 112// Check fields at form and then send request 113function mybooking_submit( submit_form , bk_type, wpdev_active_locale){ 114 115 var target_elm = jQuery( ".booking_form_div" ).trigger( "booking_form_submit_click", [bk_type, submit_form, wpdev_active_locale] ); //FixIn: 8.8.3.13 116 if ( 117 ( jQuery( target_elm ).find( 'input[name="booking_form_show_summary"]' ).length > 0 ) 118 && ( 'pause_submit' === jQuery( target_elm ).find( 'input[name="booking_form_show_summary"]' ).val() ) 119 ) 120 { 121 return false; 122 } 123 124 //FixIn: 8.4.0.2 125 var is_error = wpbc_check_errors_in_booking_form( bk_type ); 126 if ( is_error ) { return false; } 127 128 // Show message if no selected days in Calendar(s) 129 if (document.getElementById('date_booking' + bk_type).value == '') { 130 131 var arr_of_selected_additional_calendars = wpbc_get_arr_of_selected_additional_calendars( bk_type ); //FixIn: 8.5.2.26 132 133 if ( arr_of_selected_additional_calendars.length == 0 ) {
134 wpbc_front_end__show_message__error_under_element( '#booking_form_div' + bk_type + ' .bk_calendar_frame', message_verif_selectdts, 3000 ); 135 return; 136 } 137 } 138 139 var count = submit_form.elements.length; 140 var formdata = ''; 141 var inp_value; 142 var element; 143 var el_type; 144 145 146 //FixIn:6.1.1.3 147 if( typeof( wpbc_is_this_time_selection_not_available ) == 'function' ) { 148 149 if ( document.getElementById('date_booking' + bk_type).value == '' ) { // Primary calendar not selected. 150 151 if ( document.getElementById('additional_calendars' + bk_type ) != null ) { // Checking additional calendars. 152 153 var id_additional_str = document.getElementById('additional_calendars' + bk_type).value; //Loop have to be here based on , sign 154 var id_additional_arr = id_additional_str.split(','); 155 var is_times_dates_ok = false; 156 for ( var ia=0;ia<id_additional_arr.length;ia++ ) { 157 if ( 158 ( document.getElementById('date_booking' + id_additional_arr[ia] ).value != '' ) 159 && ( ! wpbc_is_this_time_selection_not_available( id_additional_arr[ia], submit_form.elements ) ) 160 ){ 161 is_times_dates_ok = true; 162 } 163 } 164 if ( ! is_times_dates_ok ) return; 165 } 166 } else { //Primary calendar selected. 167 if ( wpbc_is_this_time_selection_not_available( bk_type, submit_form.elements ) ) 168 return; 169 } 170 } 171 172 173 174 // Serialize form here 175 for ( var i = 0; i < count; i++ ){ //FixIn: 9.1.5.1 176 element = submit_form.elements[i]; 177 178 if ( jQuery( element ).closest( '.booking_form_garbage' ).length ) { 179 continue; // Skip elements from garbage //FixIn: 7.1.2.14 180 } 181 182 if ( 183 ( element.type !== 'button' ) 184 && ( element.type !== 'hidden' ) 185 && ( element.name !== ( 'date_booking' + bk_type ) ) 186 // && ( jQuery( element ).is( ':visible' ) ) //FixIn: 7.2.1.12.2 // Its prevent of saving hints, and some other hidden element 187 ) { // Skip buttons and hidden element - type //FixIn: 7.2.1.12 188 189 190 // Get Element Value 191 if ( element.type == 'checkbox' ){ 192 193 if (element.value == '') { 194 inp_value = element.checked; 195 } else { 196 if (element.checked) inp_value = element.value; 197 else inp_value = ''; 198 } 199 200 } else if ( element.type == 'radio' ) { 201 202 if (element.checked) { 203 inp_value = element.value; 204 } else { 205 // Check if this radio required, and if it does not check, then show warning, otherwise if it is not required or some other option checked skip this loop 206 // We need to check it here, because radio have the several options with same name and type, and otherwise we will save several options with selected and empty values. 207 if ( //FixIn: 7.0.1.62 208 ( element.className.indexOf('wpdev-validates-as-required') !== -1 ) 209 && ( jQuery( element ).is( ':visible' ) ) //FixIn: 7.2.1.12.2 // Its prevent of saving hints, and some other hidden element 210 && ( ! jQuery(':radio[name="'+element.name+'"]', submit_form).is(":checked") ) ) { 211 wpbc_front_end__show_message__warning( element, message_verif_requred_for_radio_box ); //FixIn: 8.5.1.3 212 return; 213 } 214 continue; 215 } 216 } else { 217 inp_value = element.value; 218 } 219 220 // Get value in selectbox of multiple selection 221 if (element.type =='select-multiple') { 222 inp_value = jQuery('[name="'+element.name+'"]').val() ; 223 if (( inp_value == null ) || (inp_value.toString() == '' )) 224 inp_value=''; 225 } 226 227 // Make validation only for visible elements 228 if ( jQuery( element ).is( ':visible' ) ) { //FixIn: 7.2.1.12.2 229 230 231 // Recheck for max num. available visitors selection 232 if ( typeof (wpbc__is_less_than_required__of_max_available_slots__bl) == 'function' ){ 233 if ( wpbc__is_less_than_required__of_max_available_slots__bl( bk_type, element ) ){ 234 return; 235 } 236 } 237 238 239 // Phone validation 240 /*if ( element.name == ('phone'+bk_type) ) { 241 // we validate a phone number of 10 digits with no comma, no spaces, no punctuation and there will be no + sign in front the number - See more at: http://www.w3resource.com/javascript/form/phone-no-vali
241dation.php#sthash.U9FHwcdW.dpuf 242 var reg = /^\d{10}$/; 243 var message_verif_phone = "Please enter correctly phone number"; 244 if ( inp_value != '' ) 245 if(reg.test(inp_value) == false) {wpbc_front_end__show_message__warning( element , message_verif_phone );return;} 246 }*/ 247 248 // Validation Check --- Requred fields 249 if ( element.className.indexOf('wpdev-validates-as-required') !== -1 ){ 250 if ((element.type =='checkbox') && ( element.checked === false)) { 251 if ( ! jQuery(':checkbox[name="'+element.name+'"]', submit_form).is(":checked") ) { 252 wpbc_front_end__show_message__warning( element , message_verif_requred_for_check_box ); //FixIn: 8.5.1.3 253 return; 254 } 255 } 256 if (element.type =='radio') { 257 if ( ! jQuery(':radio[name="'+element.name+'"]', submit_form).is(":checked") ) { 258 wpbc_front_end__show_message__warning( element , message_verif_requred_for_radio_box ); //FixIn: 8.5.1.3 259 return; 260 } 261 } 262 263 if ( (element.type != 'checkbox') && (element.type != 'radio') && ( '' === wpbc_trim( inp_value ) ) ){ //FixIn: 8.8.1.3 //FixIn:7.0.1.39 //FixIn: 8.7.11.12 264 wpbc_front_end__show_message__warning( element , message_verif_requred ); //FixIn: 8.5.1.3 265 return; 266 } 267 } 268 269 // Validation Check --- Email correct filling field 270 if ( element.className.indexOf('wpdev-validates-as-email') !== -1 ){ 271 inp_value = inp_value.replace(/^\s+|\s+$/gm,''); // Trim white space //FixIn: 5.4.5 272 var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,})$/; 273 if ( inp_value != '' ) 274 if(reg.test(inp_value) == false) { 275 wpbc_front_end__show_message__warning( element , message_verif_emeil ); //FixIn: 8.5.1.3 276 return; 277 } 278 } 279 280 // Validation Check --- Same Email Field 281 if ( ( element.className.indexOf('wpdev-validates-as-email') !== -1 ) && ( element.className.indexOf('same_as_') !== -1 ) ) { 282 283 // Get the name of Primary Email field from the "same_as_NAME" class 284 var primary_email_name = element.className.match(/same_as_([^\s])+/gi); 285 if (primary_email_name != null) { // We found 286 primary_email_name = primary_email_name[0].substr(8); 287 288 // Recehck if such primary email field exist in the booking form 289 if (jQuery('[name="' + primary_email_name + bk_type + '"]').length > 0) { 290 291 // Recheck the values of the both emails, if they do not equla show warning 292 if ( jQuery('[name="' + primary_email_name + bk_type + '"]').val() !== inp_value ) { 293 wpbc_front_end__show_message__warning( element , message_verif_same_emeil ); //FixIn: 8.5.1.3 294 return; 295 } 296 } 297 } 298 // Skip one loop for the email veryfication field 299 continue; //FixIn: 8.1.2.15 300 } 301 302 } 303 304 // Get Form Data 305 if ( element.name !== ('captcha_input' + bk_type) ) { 306 if (formdata !=='') formdata += '~'; // next field element 307 308 el_type = element.type; 309 if ( element.className.indexOf('wpdev-validates-as-email') !== -1 ) el_type='email'; 310 if ( element.className.indexOf('wpdev-validates-as-coupon') !== -1 ) el_type='coupon'; 311 312 inp_value = inp_value + ''; 313 inp_value = inp_value.replace(new RegExp("\\^",'g'), '^'); // replace registered characters 314 inp_value = inp_value.replace(new RegExp("~",'g'), '~'); // replace registered characters 315 316 inp_value = inp_value.replace(/"/g, '"'); // replace double quot 317 inp_value = inp_value.replace(/'/g, '''); // replace single quot 318 319 formdata += el_type + '^' + element.name + '^' + inp_value ; // element attr 320 } 321 } 322 323 } // End Fields Loop 324 325 326 // TODO: here was function for 'Check if visitor finish dates selection. 327 328 329 // Cpatch verify 330 var captcha = document.getElementById('wpdev_captcha_challenge_' + bk_type); 331 332 //Disable Submit button 333 if (captcha != null) form_submit_send( bk_type, formdata, captcha.value, document.getElementById('captcha_input' + bk_type).value ,wpdev_active_locale); 334 else form_submit_send( bk_type, formdata, '', '' , wpdev_active_locale); 335 return; 336} 337 338 339// Gathering params for sending Ajax request and then send it 340function form_submit_send( bk_type, formdata, captcha_chalange, user_captcha ,wpdev_active_locale){ 341 342 //document.getElementById('submiting' + bk_type).innerHTML = '<div style="height:20px;width:100%;text-align:center;margin:15px auto;"><img style="vertical-align:middle;box-shadow:none;width:14px;" src="'+wpdev_bk_plugin_url+'/assets/img/ajax-loader.gif"><//div>'; 343 344 var my_booking_form = ''; 345 var my_booking_hash = ''; 346 if (document.getElementById('booking_form_type' + bk_type) != undefined) 347 my_booking_form =document.getElementById('booking_form_type' + bk_type).value; 348 349 if ( wpdev_bk_edit_id_hash != '' ) my_booking_hash = wpdev_bk_edit_id_hash; 350 351 var is_send_emeils = 1; 352 if ( jQuery('#is_send_email_for_pending').length ) { 353 is_send_emeils = jQuery( '#is_send_email_for_pending' ).is( ':checked' ); //FixIn: 8.7.9.5 354 if ( false === is_send_emeils ) { is_send_emeils = 0; } 355 else { is_send_emeils = 1; } 356 } 357 358 if ( document.getElementById('date_booking' + bk_type).value != '' ) //FixIn:6.1.1.3 359 send_ajax_submit(bk_type,formdata,captcha_chalange,user_captcha,is_send_emeils,my_booking_hash,my_booking_form,wpdev_active_locale ); // Ajax sending request 360 else { 361 jQuery('#booking_form_div' + bk_type ).hide(); 362 jQuery('#submiting' + bk_type ).hide(); 363 } 364 365 var formdata_additional_arr; 366 var formdata_additional; 367 var my_form_field; 368 var id_additional; 369 var id_additional_str; 370 var id_additional_arr; 371 if (document.getElementById('additional_calendars' + bk_type) != null ) { 372 373 id_additional_str = document.getElementById('additional_calendars' + bk_type).value; //Loop have to be here based on , sign 374 id_additional_arr = id_additional_str.split(','); 375 376 377 //TODO: remove this spinner and add the new !!! 378 //FixIn: 8.5.2.26 379 if ( ! jQuery( '#booking_form_div' + bk_type ).is( ':visible' ) ) { 380 jQuery( '#booking_form_div' + bk_type ).after( 381 '<div class="wpbc_submit_spinner" style="height:20px;width:100%;text-align:center;margin:15px auto;"><img style="vertical-align:middle;box-shadow:none;width:14px;" src="'+wpdev_bk_plugin_url+'/assets/img/ajax-loader.gif"></div>' 382 ); 383 } 384 385 386 387 for (var ia=0;ia<id_additional_arr.length;ia++) { 388 formdata_additional_arr = formdata; 389 formdata_additional = ''; 390 id_additional = id_additional_arr[ia]; 391 392 393 formdata_additional_arr = formdata_additional_arr.split('~'); 394 for (var j=0;j<formdata_additional_arr.length;j++) { 395 my_form_field = formdata_additional_arr[j].split('^'); 396 if (formdata_additional !=='') formdata_additional += '~'; 397 398 if (my_form_field[1].substr( (my_form_field[1].length -2),2)=='[]') 399 my_form_field[1] = my_form_field[1].substr(0, (my_form_field[1].length - (''+bk_type).length ) - 2 ) + id_additional + '[]'; 400 else 401 my_form_field[1] = my_form_field[1].substr(0, (my_form_field[1].length - (''+bk_type).length ) ) + id_additional ; 402 403 404 formdata_additional += my_form_field[0] + '^' + my_form_field[1] + '^' + my_form_field[2]; 405 } 406 407 if ( jQuery('#gateway_payment_forms' + bk_type).length > 0 ) { // If Payment form for main booking resources is showing then append payment form for additional calendars. 408 jQuery('#gateway_payment_forms' + bk_type).after('<div id="gateway_payment_forms'+id_additional+'"></div>'); 409 jQuery('#gateway_payment_forms' + bk_type).after('<div id="ajax_respond_insert'+id_additional+'" style="display:none;"></div>'); 410 } 411 //FixIn: 8.5.2.17 412 send_ajax_submit( id_additional ,formdata_additional,captcha_chalange,user_captcha,is_send_emeils,my_booking_hash,my_booking_form ,wpdev_active_locale ); // Submit 413 } 414 } 415} 416 417 418//<![CDATA[ 419function send_ajax_submit( resource_id, formdata, captcha_chalange, user_captcha, is_send_emeils, my_booking_hash, my_booking_form, wpdev_active_locale ){ 420 421 // Disable Submit | Show spin loader 422 wpbc_booking_form__on_submit__ui_elements_disable( resource_id ) 423 424 425 var is_exit = wpbc_ajx_booking__create( { 426 'resource_id' : resource_id, 427 'dates_ddmmyy_csv' : document.getElementById( 'date_booking' + resource_id ).value, 428 'formdata' : formdata, 429 'booking_hash' : my_booking_hash, 430 'custom_form' : my_booking_form, 431 'aggregate_resource_id_arr': ( ( null !== _wpbc.booking__get_param_value( resource_id, 'aggregate_resource_id_arr' )) 432 ? _wpbc.booking__get_param_value( resource_id, 'aggregate_resource_id_arr' ).join( ',' ) : ''), 433 434 435 'captcha_chalange' : captcha_chalange, 436 'captcha_user_input' : user_captcha, 437 438 'is_emails_send' : is_send_emeils, 439 'active_locale' : wpdev_active_locale 440 } ); 441 if ( true === is_exit ){ 442 return; 443 } 444} 445//]]> 446
447//////////////////////////////////////////////////////////////////////////// 448 449 450// Hint labels inside of input boxes 451jQuery(document).ready( function(){ 452 453 jQuery('div.inside_hint').on( 'click', function(){ //FixIn: 8.7.11.12 454 jQuery(this).css('visibility', 'hidden').siblings('.has-inside-hint').trigger( 'focus' ); //FixIn: 8.7.11.12 455 }); 456 457 jQuery('input.has-inside-hint').on( 'blur', function(){ //FixIn: 8.7.11.12 458 if ( this.value == '' ) 459 jQuery(this).siblings('.inside_hint').css('visibility', ''); 460 }).on( 'focus', function(){ //FixIn: 8.7.11.12 461 jQuery(this).siblings('.inside_hint').css('visibility', 'hidden'); 462 }); 463 464 jQuery('.booking_form_div input[type=button]').prop("disabled", false); 465}); 466 467 468 469// Support Functions 470 471//FixIn: 8.8.1.3 472/** 473 * Trim strings and array joined with (,) 474 * 475 * @param string_to_trim string / array 476 * @returns string 477 */ 478function wpbc_trim( string_to_trim ){ 479 480 if ( Array.isArray( string_to_trim ) ){ 481 string_to_trim = string_to_trim.join( ',' ); 482 } 483 484 if ( 'string' == typeof (string_to_trim) ){ 485 string_to_trim = string_to_trim.trim(); 486 } 487 488 return string_to_trim; 489} 490 491 492function wpdev_in_array (array_here, p_val) { 493 for(var i = 0, l = array_here.length; i < l; i++) { 494 if(array_here[i] == p_val) { 495 return true; 496 } 497 } 498 return false; 499} 500 501 502function days_between(date1, date2) { 503 504 // The number of milliseconds in one day 505 var ONE_DAY = 1000 * 60 * 60 * 24; 506 507 // Convert both dates to milliseconds 508 var date1_ms = date1.getTime(); 509 var date2_ms = date2.getTime(); 510 511 // Calculate the difference in milliseconds 512 var difference_ms = date1_ms - date2_ms; 513 514 // Convert back to days and return 515 return Math.round(difference_ms/ONE_DAY); 516 517} 518 519 520 521 522 523//FixIn: 8.4.0.2 524/** 525 * Check errors in booking form fields, and show warnings if some errors exist. 526 * Check errors, like not selected dates or not filled requred form fields, or not correct entering email or phone fields, etc... 527 * 528 * @param bk_type int (ID of booking resource) 529 */ 530function wpbc_check_errors_in_booking_form( bk_type ) { 531 532 var is_error_in_field = false; // By default all is good - no error 533 534 var my_form = jQuery( '#booking_form' + bk_type ); 535 536 if ( my_form.length ) { 537 538 var fields_with_errors_arr = []; 539 540 // Pseudo-selector that get form elements <input , <textarea , <select, <button... 541 my_form.find( ':input' ).each( function( index, el ) { 542 543 // Skip some elements 544 var skip_elements = [ 'hidden', 'button' ]; 545 546 if ( -1 == skip_elements.indexOf( jQuery( el ).attr( 'type' ) ) ){ 547 548 // Check Calendar Dates Selection 549 if ( ( 'date_booking' + bk_type ) == jQuery( el ).attr( 'name' ) ) { 550 551 // Show Warning only if the calendar visible ( we are at step with calendar) 552 if ( 553 ( ( jQuery( '#calendar_booking' + bk_type ).is( ':visible' ) ) && ( '' == jQuery( el ).val() ) ) 554 && ( wpbc_get_arr_of_selected_additional_calendars( bk_type ).length == 0 ) //FixIn: 8.5.2.26 555 ){ //FixIn: 8.4.4.5 556 557 var notice_message_id = wpbc_front_end__show_message__error_under_element( '#booking_form_div' + bk_type + ' .bk_calendar_frame', message_verif_selectdts , 3000 ); 558 559 //wpbc_do_scroll('#calendar_booking' + bk_type); // Scroll to the calendar //FixIn: 8.5.1.3 560 is_error_in_field = true; // Error 561 } 562 } 563 564 // Check only visible elements at this step 565 if ( jQuery( el ).is( ':visible' ) ){ 566// console.log( '|id, type, val, visible|::', jQuery( el ).attr( 'name' ), '|' + jQuery( el ).attr( 'type' ) + '|', jQuery( el ).val(), jQuery( el ).is( ':visible' ) ); 567 568 // Is Required 569 if ( jQuery( el ).hasClass( 'wpdev-validates-as-required' ) ){ 570 571 // Checkboxes 572 if ( 'checkbox' == jQuery( el ).attr( 'type' ) ){ 573 574 if ( 575 ( ! jQuery( el ).is( ':checked' )) 576 && ( ! jQuery( ':checkbox[name="' + el.name + '"]', my_form ).is( ":checked" ) ) //FixIn: 8.5.2.12 577 ){ 578 var checkbox_parent_element; 579 580 if ( jQuery( el ).parents( '.wpdev-form-control-wrap' ).length > 0 ){ 581 582 checkbox_parent_element = jQuery( el ).parents( '.wpdev-form-control-wrap' ); 583 584 } else if ( jQuery( el ).parents( '.controls' ).length > 0 ){ 585 586 checkbox_parent_element = jQuery( el ).parents( '.controls' ); 587 588 } else { 589 590 checkbox_parent_element = jQuery( el ); 591 } 592 var notice_message_id = wpbc_front_end__show_message__warning( checkbox_parent_element, message_verif_requred_for_check_box ); 593 594 fields_with_errors_arr.push( el ); 595 is_error_in_field = true; // Error 596 } 597 598 // Radio boxes 599 } else if ( 'radio' == jQuery( el ).attr( 'type' ) ){ 600 601 if ( !jQuery( ':radio[name="' + jQuery( el ).attr( 'name' ) + '"]', my_form ).is( ':checked' ) ){ 602 var notice_message_id = wpbc_front_end__show_message__warning( jQuery( el ).parents('.wpdev-form-control-wrap'), message_verif_requred_for_radio_box ); 603 fields_with_errors_arr.push( el ); 604 is_error_in_field = true; // Error 605 } 606 607 // Other elements 608 } else { 609 610 var inp_value = jQuery( el ).val(); 611 612 if ( '' === wpbc_trim( inp_value ) ){ //FixIn: 8.8.1.3 //FixIn: 8.7.11.12 613 614 var notice_message_id = wpbc_front_end__show_message__warning( el, message_verif_requred ); 615 616 fields_with_errors_arr.push( el ); 617 is_error_in_field = true; // Error 618 } 619 } 620 } 621 622 // Validate Email 623 if ( jQuery( el ).hasClass( 'wpdev-validates-as-email' ) ){ 624 var inp_value = jQuery( el ).val(); 625 inp_value = inp_value.replace( /^\s+|\s+$/gm, '' ); // Trim white space //FixIn: 5.4.5 626 var reg = /^([A-Za-z0-9_\-\.\+])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,})$/; 627 if ( (inp_value != '') && (reg.test( inp_value ) == false) ){ 628 629 var notice_message_id = wpbc_front_end__show_message__warning( el, message_verif_emeil ); 630 fields_with_errors_arr.push( el ); 631 is_error_in_field = true; // Error 632 } 633 } 634 635 // Validate For digit entering - for example for - Phone 636 // <p>Digit Field:<br />[text* dig_field class:validate_as_digit] </p> 637 // <p>Phone:<br />[text* phone class:validate_digit_8] </p> 638 639 var classList = jQuery( el ).attr( 'class' ); 640 641 if ( classList ){ 642 643 classList = classList.split( /\s+/ ); 644 645 jQuery.each( classList, function ( cl_index, cl_item ){ 646
647 //////////////////////////////////////////////////////////////////////////////////////////// 648 649 // Validate field value as "Date" [CSS class - 'validate_as_digit'] 650 if ( 'validate_as_date' === cl_item ) { 651 652 // Valid values: 09-25-2018, 09/25/2018, 09-25-2018, 31-9-1918 --- m/d/Y, m.d.Y, m-d-Y, d/m/Y, d.m.Y, d-m-Y 653 var regex = new RegExp( '^[0-3]?\\d{1}[\\/\\.\\-]+[0-3]?\\d{1}[\\/\\.\\-]+[0-2]+\\d{3}$' ); // Check for Date 09/25/2018 654 var message_verif_phone = 'This field must be valid date like this ' + '09/25/2018'; 655 var inp_value = jQuery( el ).val(); 656 657 if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){ 658 wpbc_front_end__show_message__warning( el, message_verif_phone ); 659 fields_with_errors_arr.push( el ); 660 is_error_in_field = true; // Error 661 } 662 } 663
664 //////////////////////////////////////////////////////////////////////////////////////////// 665 666 // Validate field value as "DIGIT" [CSS class - 'validate_as_digit'] 667 if ( 'validate_as_digit' === cl_item ) { 668 669 var regex = new RegExp( '^[0-9]+\\.?[0-9]*$' ); // Check for digits 670 var message_verif_phone = 'This field must contain only digits'; 671 var inp_value = jQuery( el ).val(); 672 673 if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){ 674 wpbc_front_end__show_message__warning( el, message_verif_phone ); 675 fields_with_errors_arr.push( el ); 676 is_error_in_field = true; // Error 677 } 678 } 679 680 //////////////////////////////////////////////////////////////////////////////////////////// 681 682 // Validate field value as "Phone" number or any other valid number wth specific number of digits [CSS class - 'validate_digit_8' || 'validate_digit_10' ] 683 var is_validate_digit = cl_item.substring( 0, 15 ); 684 685 // Check if class start with 'validate_digit_' 686 if ( 'validate_digit_' === is_validate_digit ){ 687 688 // Get number of digit in class: validate_digit_8 => 8 or validate_digit_10 => 10 689 var digits_to_check = parseInt( cl_item.substring( 15 ) ); 690 691 // Check about any errors in 692 if ( !isNaN( digits_to_check ) ){ 693 694 var regex = new RegExp( '^\\d{' + digits_to_check + '}$' ); // We was valid it as parseInt - only integer variable - digits_to_check 695 var message_verif_phone = 'This field must contain ' + digits_to_check + ' digits'; 696 var inp_value = jQuery( el ).val(); 697 698 if ( ( inp_value != '' ) && ( regex.test( inp_value ) == false ) ){ 699 wpbc_front_end__show_message__warning( el, message_verif_phone ); 700 fields_with_errors_arr.push( el ); 701 is_error_in_field = true; // Error 702 } 703 } 704 } 705
706 //////////////////////////////////////////////////////////////////////////////////////////// 707 708 }); 709 } 710 } 711 } 712 } ); 713 714 if ( fields_with_errors_arr.length > 0 ){ 715 jQuery( fields_with_errors_arr[ 0 ] ).trigger( 'focus' ); //FixIn: 9.3.1.9 716 } 717 } 718 719 return is_error_in_field; 720} 721 722 723//FixIn: 8.4.4.4 724function bk_calendar_step_click( el ){ 725 var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val(); 726 var is_error = wpbc_check_errors_in_booking_form( br_id ); 727 if ( is_error ){ 728 return false; 729 } 730 if ( br_id != undefined ){ 731 jQuery( "#booking_form" + br_id + " .bk_calendar_step" ).css( {"display": "none"} ); 732 jQuery( "#booking_form" + br_id + " .bk_form_step" ).css( {"display": "block"} ); 733 } else { 734 jQuery( ".bk_calendar_step" ).css( {"display": "none"} ); 735 jQuery( ".bk_form_step" ).css( {"display": "block"} ); 736 } 737} 738 739function bk_form_step_click( el ){ 740 var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val(); 741 var is_error = false; // wpbc_check_errors_in_booking_form( br_id ); //FixIn: 8.4.5.6 742 if ( is_error ){ 743 return false; 744 } 745 if ( br_id != undefined ){ 746 jQuery( "#booking_form" + br_id + " .bk_calendar_step" ).css( {"display": "block"} ); 747 jQuery( "#booking_form" + br_id + " .bk_form_step" ).css( {"display": "none"} ); 748 wpbc_do_scroll( "#bklnk" + br_id ); 749 } else { 750 jQuery( ".bk_calendar_step" ).css( {"display": "block"} ); 751 jQuery( ".bk_form_step" ).css( {"display": "none"} ); 752 } 753} 754 755//FixIn: 8.6.1.15 756/** 757 * Go to next specific step in Wizard style booking form, with 758 * check all required elements specific step, otherwise show warning message! 759 * 760 * @param el 761 * @param step_num 762 * @returns {boolean} 763 */ 764function wpbc_wizard_step( el, step_num, step_from ){ 765 var br_id = jQuery( el ).closest( 'form' ).find( 'input[name^="bk_type"]' ).val(); 766 767 //FixIn: 8.8.1.5 768 if ( ( undefined == step_from ) || ( step_num > step_from ) ){ 769 if ( 1 != step_num ){ //FixIn: 8.7.7.8 770 var is_error = wpbc_check_errors_in_booking_form( br_id ); 771 if ( is_error ){ 772 return false; 773 } 774 } 775 } 776 777 if ( wpbc_is_some_elements_visible( br_id, ['rangetime', 'durationtime', 'starttime', 'endtime'] ) ){ 778 if ( wpbc_is_this_time_selection_not_available( br_id, document.getElementById( 'booking_form' + br_id ) ) ){ 779 return false; 780 } 781 } 782 783 if ( br_id != undefined ){ 784 jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" ).css( {"display": "none"} ); 785 jQuery( "#booking_form" + br_id + " .wpbc_wizard_step" + step_num ).css( {"display": "block"} ); 786 } 787} 788 789 790//FixIn: 8.6.1.15 791/** 792 * Check if at least one element from array of elements names in booking form visible or not. 793 * Usage Example: if ( wpbc_is_some_elements_visible( br_id, ['rangetime', 'durationtime', 'starttime', 'endtime'] ) ){ ... } 794 * 795 * @param bk_type 796 * @param elements_names 797 * @returns {boolean} 798 */ 799function wpbc_is_some_elements_visible( bk_type, elements_names ){ 800 801 var is_some_elements_visible = false; 802 803 var my_form = jQuery( '#booking_form' + bk_type ); 804 805 if ( my_form.length ){ 806 807 // Pseudo-selector that get form elements <input , <textarea , <select, <button... 808 my_form.find( ':input' ).each( function ( index, el ){ 809 810 // Skip some elements 811 var skip_elements = ['hidden', 'button']; 812 813 if ( -1 == skip_elements.indexOf( jQuery( el ).attr( 'type' ) ) ){ 814 815 for ( var ei = 0; ei < ( elements_names.length - 1) ; ei++ ){ 816 817 // Check Calendar Dates Selection 818 if ( (elements_names[ ei ] + bk_type) == jQuery( el ).attr( 'name' ) ){ 819 820 if ( jQuery( el ).is( ':visible' ) ){ 821 is_some_elements_visible = true; 822 } 823 } 824 } 825 } 826 } ); 827 } 828 return is_some_elements_visible; 829} 830 831//FixIn: 9.2.3.4 832/** 833 * Select dates in calendar 834 * 835 * @param int resource_id 1 836 * @param array selected_dates [ [ 2022, "09", 20 ], [ 2022, "09", 21 ], ... ] 837 */
838function wpbc_select_days_in_calendar( resource_id, selected_dates ){ 839 840 //clearTimeout( timeout_DSwindow ); 841 842 var inst = jQuery.datepick._getInst( document.getElementById( 'calendar_booking' + resource_id ) ); 843 inst.dates = []; 844 var original_array = []; 845 var date; 846 847 var bk_inputing = document.getElementById( 'date_booking' + resource_id ); 848 var bk_distinct_dates = []; 849 850 if ( 0 ){ // Select one additional day in calendar, during editing of booking //FixIn: 6.2.3.6 851 var last_selected_date = new Date(); 852 last_selected_date.setFullYear( parseInt( selected_dates[ selected_dates.length - 1 ][ 0 ] ) ); 853 last_selected_date.setMonth( parseInt( selected_dates[ selected_dates.length - 1 ][ 1 ] - 1 ) ); 854 last_selected_date.setDate( parseInt( selected_dates[ selected_dates.length - 1 ][ 2 ] ) ); 855 last_selected_date.setHours( 0 ); 856 last_selected_date.setMinutes( 0 ); 857 last_selected_date.setSeconds( 0 ); 858 var last_selected_next_date = new Date( last_selected_date.getTime() + 1000 * 60 * 60 * 24 ); 859 selected_dates.push( new Array( last_selected_next_date.getFullYear(), (last_selected_next_date.getMonth() + 1), last_selected_next_date.getDate() ) ); 860 } 861 862 for ( var i = 0; i < selected_dates.length; i++ ){ 863 864 var dta = selected_dates[ i ]; 865 866 date = new Date(); 867 date.setFullYear( dta[ 0 ], (dta[ 1 ] - 1), dta[ 2 ] ); // get date 868 original_array.push( jQuery.datepick._restrictMinMax( inst, jQuery.datepick._determineDate( inst, date, null ) ) ); //add date 869 870 // Add leading 0 for number from 1 to 9 //FixIn: 8.0.2.2 871 dta[ 2 ] = parseInt( dta[ 2 ] ); 872 if ( dta[ 2 ] < 10 ){ 873 dta[ 2 ] = '0' + dta[ 2 ]; 874 } 875 dta[ 1 ] = parseInt( dta[ 1 ] ); 876 if ( dta[ 1 ] < 10 ){ 877 dta[ 1 ] = '0' + dta[ 1 ]; 878 } 879 if ( !wpdev_in_array( bk_distinct_dates, dta[ 2 ] + '.' + dta[ 1 ] + '.' + dta[ 0 ] ) ) 880 bk_distinct_dates.push( dta[ 2 ] + '.' + dta[ 1 ] + '.' + dta[ 0 ] ); 881 } 882 883 for ( var j = 0; j < original_array.length; j++ ){ //loop array of dates 884 if ( original_array[ j ] != -1 ) inst.dates.push( original_array[ j ] ); 885 } 886 var dateStr = (inst.dates.length == 0 ? '' : jQuery.datepick._formatDate( inst, inst.dates[ 0 ] )); // Get first date 887 for ( i = 1; i < inst.dates.length; i++ ) 888 dateStr += jQuery.datepick._get( inst, 'multiSeparator' ) + jQuery.datepick._formatDate( inst, inst.dates[ i ] ); // Gathering all dates 889 jQuery( '#date_booking' + resource_id ).val( dateStr ); // Fill the input box 890 891 if ( original_array.length > 0 ){ // Set showing of start month 892 inst.cursorDate = original_array[ 0 ]; 893 inst.drawMonth = inst.cursorDate.getMonth(); 894 inst.drawYear = inst.cursorDate.getFullYear(); 895 } 896 897 // Update calendar 898 jQuery.datepick._notifyChange( inst ); 899 jQuery.datepick._adjustInstDate( inst ); 900 jQuery.datepick._showDate( inst ); 901 jQuery.datepick._updateDatepick( inst ); 902 903 if ( bk_inputing != null ) 904 bk_inputing.value = bk_distinct_dates.join( ', ' ); 905 906 907 if ( typeof (check_condition_sections_in_bkform) == 'function' ){ 908 check_condition_sections_in_bkform( jQuery( '#date_booking' + resource_id ).val(), resource_id ); 909 } 910 911 912 if ( typeof (showCostHintInsideBkForm) == 'function' ){ 913 showCostHintInsideBkForm( resource_id ); 914 } 915} 916
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.