PageSourceSearch

https://alphamusicbg.com/wp-content/plugins/woocommerce-econt/inc/js/econt.js?ver=1.7.5

js alphamusicbg.com collected 2026-10-03 18:20:27 UTC 76,484 bytes, 2,073 lines download raw bytes

1var $econt_aiaks;
2var $econt_flf;
3var $econt_town_city_id;
4var $econt_local_storage;
5var $econt_lang;
6var $econt_flf_el;
7var $econt_add_loading_link;
8
9jQuery(document).ready(function($){
10//econt checkout and order office autocomplete
11$econt_local_storage = localStorage.econt ? JSON.parse(localStorage.econt) : new Object;
12$econt_lang = document.getElementsByTagName('html')[0].getAttribute('lang');
13//econt checkout and order office autocompleteselect2
14jQuery("#econt_offices, #woocommerce_econt_shipping_method_office_code, #econt_sender_offices").select2({
15  language: {
16    inputTooShort: function () {
17      return econt_php_vars.selectStartTypingText;
18    },
19    noResults: function(){
20      return econt_php_vars.selectNRFText;
21    },
22    searching: function(){
23      return econt_php_vars.selectSearchOfficeText;
24    },
25    errorLoading:function(){
26      return econt_php_vars.selectSearchOfficeText;
27    },
28  }
29});
30
31//fix a bug which shrinks the width with some WP themes
32if(econt_php_vars.isCheckout){
33  setTimeout(function(){
34    jQuery(".select2-container").css("width", "100%");
35  }, 500);
36  //offices map
37  jQuery('#econt_offices_map, #econt_machines_map, #map').width(jQuery('#econt_offices_map').parent().width());
38}else{ //order edit page
39  //offices map
40  var mapWidth = jQuery('.econt-table').width();
41  if(mapWidth == 0){
42    mapWidth = 400;
43  }
44  jQuery('#econt_offices_map, #econt_machines_map, #map').width(mapWidth);
45}
46
47jQuery('#econt_offices_town, #woocommerce_econt_shipping_method_office_town, #econt_sender_offices_town').select2({
48  language: {
49  inputTooShort: function () {
50    return econt_php_vars.selectSelectResultsText;
51  },
52  noResults: function(){
53    return econt_php_vars.selectNRFText;
54  },
55  searching: function(){
56    return econt_php_vars.selectSearchPlaceText;
57  },
58  errorLoading:function(){
59      return econt_php_vars.selectSearchPlaceText;
60    },
61},
62  minimumInputLength: 2,
63  ajax: {
64    //url: ajaxurl,
65    url: econt_php_vars.ajaxURL,
66    dataType: 'json',
67    delay: econt_php_vars.autocompleteAjaxDelay,
68    data: function (params) {
69    var country_code = jQuery('select[name=billing_country] option').filter(':selected').val();
70    if(!econt_php_vars.isCheckout){
71      country_code = jQuery('select[name=_billing_country] option').filter(':selected').val();
72    }
73    var queryParameters = {
74      lang: $econt_lang,
75      city: params.term,
76      country_code: country_code,
77      action:'econt_handle_ajax', 
78    }
79
80    return queryParameters;
81    },
82    processResults: function (data) {
83      return {
84        results: data
85      };
86    },
87    cache: true,
88
89  },
90  
91});
92
93jQuery('#econt_door_street').on('select2:select', function (e) {
94  var data = e.params.data;
95  localStorageUpdate(data, 'econt_door_street_selected');
96});
97
98jQuery('#econt_door_quarter').on('select2:select', function (e) {
99  var data = e.params.data;
100  localStorageUpdate(data, 'econt_door_quarter_selected');
101});
102
103jQuery('#econt_offices').on('select2:select', function (e) {
104  var data = e.params.data;
105  localStorageUpdate(data, 'econt_office_offices_selected');
106});
107
108jQuery('#econt_machines').on('select2:select', function (e) {
109  var data = e.params.data;
110  localStorageUpdate(data, 'econt_machine_machines_selected');
111});
112if(jQuery('#econt_user_address').val() == 0){
113  window.setTimeout(function() {
114  if(Object.hasOwnProperty('hasOwn') && Object.hasOwn($econt_local_storage, 'econt_shipping_to')){
115    if($('#econt_shipping_to_buttons_DOOR').length == 0) {
116      jQuery('#econt_shipping_to').val($econt_local_storage.econt_shipping_to).trigger('change');
117    }else{
118      jQuery('#econt_shipping_to_buttons_' + $econt_local_storage.econt_shipping_to).attr('checked', true).trigger('change');
119      
120    }
121  }
122  }, 500 );
123}
124jQuery('#econt_offices_town, #woocommerce_econt_shipping_method_office_town, #econt_sender_offices_town').on('select2:select', function (e) {
125    jQuery('#econtLoader').show();
126    var data = e.params.data;
127    localStorageUpdate(data, 'econt_offices_town_selected');
128    jQuery('#econt_offices_postcode, #woocommerce_econt_shipping_method_office_postcode, #econt_sender_offices_postcode').prop('value', data.post_code);
129    var country_code = jQuery('select[name=billing_country] option').filter(':selected').val();
130    if(!econt_php_vars.isCheckout){
131      country_code = jQuery('select[name=_billing_country] option').filter(':selected').val();
132    }
133    jQuery('#econt_offices_field, #econt_sender_offices_field').slideDown();
134
135    if( econt_php_vars.openLayersMapsOfficeLocator.length == 0 || econt_php_vars.openLayersMapsOfficeLocator == 1 ){
136      jQuery('#econt_offices_map').slideDown();
137    }
138
139    jQuery.ajax({
140      //url: ajaxurl,
141      url: econt_php_vars.ajaxURL,
142      dataType: "json",
143      data: {
144      lang: $econt_lang,
145      action:'econt_handle_ajax', 
146      office_city_id: data.city_id,
147      office_city_name: data.id, 
148      delivery_type: 'to_office'
149      },
150      success: function( data ) {
151        jQuery('#econtLoader').hide();
152        jQuery('#econt_offices, #woocommerce_econt_shipping_method_office_code, #econt_sender_offices').empty();
153        //load maps with offices
154        var markersOffices = [];
155
156        jQuery.each(data, function(key, value) {
157
158          var newOption = new Option(value.value + ' [о.к.:' + value.id + ']', value.id, false, false);
159          jQuery('#econt_offices, #woocommerce_econt_shipping_method_office_code, #econt_sender_offices').append(newOption).trigger('change');
160          markersOffices.push({
161            "id": value.id,
162            "title": value.name,
163            "lat": value.latitude,
164            "lng": value.longitude,
165            "description": value.description,
166            //"icon": speedy_php_vars.openLayersMapsOfficeIcon
167          });
168
169        });
170        localStorageUpdate(data, 'econt_office_offices');
171        if( econt_php_vars.openLayersMapsOfficeLocator.length == 0 || econt_php_vars.openLayersMapsOfficeLocator == 1 ){
172          jQuery('#econt_offices_map').empty();
173          window.setTimeout(function() {
174              load_map(markersOffices, 'office');
175          }, 500);
176        }
177        
178        if(econt_php_vars.isCheckout){ //if we are in checkout not in admin panel
179          jQuery(".select2-container").css("width", "100%"); //fix a bug which shrinks the width with some WP themes
180          //calculate_loading(); //calculate loading cost for shipping to office
181        }
182        calculate_loading(); //calculate loading cost for shipping to office
183      }
184    });
185
186});
187
188//end of econt checkout and order office autocomplete
189
190//econt checkout and order machine autocomplete
191//Query("#econt_offices, #woocommerce_econt_shipping_method_office_code, #econt_sender_offices"
192jQuery("#econt_machines, #woocommerce_econt_shipping_method_machine_machine, #econt_sender_machines, #woocommerce_econt_shipping_method_machine_code").select2({
193  language: {
194    inputTooShort: function () {
195      return econt_php_vars.selectStartTypingText;
196    },
197    noResults: function(){
198      return econt_php_vars.selectNRFText;
199    },
200    searching: function(){
201      return econt_php_vars.selectSearchAPSText;
202    },
203    errorLoading:function(){
204      return econt_php_vars.selectSearchAPSText;
205    },
206  }
207});
208
209jQuery('#econt_machines_town, #woocommerce_econt_shipping_method_machine_town').select2({
210  language: {
211  // You can find all of the options in the language files provided in the
212  // build. They all must be functions that return the string that should be
213  // displayed.
214  inputTooShort: function () {
215      return econt_php_vars.selectSelectResultsText;
216    },
217    noResults: function(){
218      return econt_php_vars.selectNRFText;
219    },
220    searching: function(){
221      return econt_php_vars.selectSearchPlaceText;
222    },
223    errorLoading:function(){
224      return econt_php_vars.selectSearchPlaceText;
225    },
226  },
227  minimumInputLength: 2,
228  ajax: {
229    //url: ajaxurl,
230    url: econt_php_vars.ajaxURL,
231    dataType: 'json',
232    delay: econt_php_vars.autocompleteAjaxDelay,
233    data: function (params) {
234    var country_code = jQuery('select[name=billing_country] option').filter(':selected').val();
235    if(!econt_php_vars.isCheckout){
236      country_code = jQuery('select[name=_billing_country] option').filter(':selected').val();
237    }
238    var queryParameters = {
239      //q: params.q,
240      lang: $econt_lang,
241      city: params.term,
242      country_code: country_code,
243      action:'econt_handle_ajax', 
244    }
245    return queryParameters;
246    },
247    processResults: function (data) {
248      // Transforms the top-level key of the response object from 'items' to 'results'
249      return {
250        results: data
251        //results: [{"text":"Sofia","id":"41"},{"text":"Varna","id":"26382"}]
252      };
253    },
254    cache: true,
255  },
256  
257});
258
259jQuery('#econt_machines_town, #woocommerce_econt_shipping_method_machine_town').on('select2:select', function (e) {
260    jQuery('#econtLoader').show();
261    var data = e.params.data;
262    localStorageUpdate(data, 'econt_machines_town_selected');
263    jQuery('#econt_machines_postcode, #woocommerce_econt_shipping_method_machine_postcode').prop('value', data.post_code);
264    jQuery('#econt_machines_field').slideDown();
265
266    if( econt_php_vars.openLayersMapsOfficeLocator.length == 0 || econt_php_vars.openLayersMapsOfficeLocator == 1 ){
267      jQuery('#econt_machines_map').slideDown();
268    }
269
270    jQuery.ajax({
271      //url: ajaxurl,
272      url: econt_php_vars.ajaxURL,
273      dataType: "json",
274      data: {
275      lang: $econt_lang,
276      action:'econt_handle_ajax', 
277      machine_city_id: data.city_id,
278      machine_city_name: data.id,
279      delivery_type: 'to_office'
280      },
281      success: function( data ) {
282        jQuery('#econtLoader').hide();
283        jQuery('#econt_machines, #woocommerce_econt_shipping_method_machine_code').empty();
284        var markersMachines = [];
285        jQuery.each(data, function(key, value) {
286
287          var newOption = new Option(value.value + ' [о.к.:' + value.id + ']', value.id, false, false);
288          jQuery('#econt_machines, #woocommerce_econt_shipping_method_machine_code').append(newOption).trigger('change');
289
290          markersMachines.push({
291              "id": value.id,
292              "title": value.name,
293              "lat": value.latitude,
294              "lng": value.longitude,
295              "description": value.description,
296              //"icon": speedy_php_vars.openLayersMapsOfficeIcon
297          });
298
299        });
300        localStorageUpdate(data, 'econt_machine_machines');
301        if( econt_php_vars.openLayersMapsOfficeLocator.length == 0 || econt_php_vars.openLayersMapsOfficeLocator == 1 ){
302          jQuery('#econt_machines_map').empty();
303          window.setTimeout(function() {
304              load_map(markersMachines, 'machine');
305          }, 500);
306        }
307
308        if(econt_php_vars.isCheckout){ //if we are in checkout not in admin panel
309          jQuery(".select2-container").css("width", "100%"); //fix a bug which shrinks the width with some WP themes
310          calculate_loading(); //calculate loading cost for shipping to office
311        }
312      }
313    });
314
315});
316//end of econt checkout and order machine autocomplete
317
318
319//econt admin settings office autocomplete
320jQuery( "#woocommerce_econt_shipping_method_office_town" ).autocomplete({
321minLength: 2,
322source: function( request, response ) {
323jQuery.ajax({
324//url: ajaxurl,
325url: econt_php_vars.ajaxURL,
326dataType: "json",
327data: {
328lang: $econt_lang,
329action:'econt_handle_ajax', 
330city: request.term
331
332},
333success: function( data ) {
334  response(jQuery.map(data, function(item) {
335                        return {
336                            label:      item.label,
337                            value:      item.value,
338                            city_id:    item.id,
339                            post_code:   item.post_code
340                            
341                       };
342                }));
343
344},
345
346
347});
348},
349
350
351
352select: function( event, ui ) {
353   
354var city_id = ui.item.city_id;
355var post_code = ui.item.post_code;
356
357
358jQuery('#woocommerce_econt_shipping_method_office_postcode').val(post_code);
359
360jQuery.ajax({
361url: econt_php_vars.ajaxURL2,
362dataType: "json",
363data: {
364lang: $econt_lang,
365action:'econt_handle_ajax', 
366office_city_id: city_id,
367delivery_type: 'from_office'
368
369},
370success: function( data ) {
371
372 jQuery('#woocommerce_econt_shipping_method_office_office').empty()
373
374//selectValues = { "1": "test 1", "2": "test 2" };
375jQuery.each(data, function(key, value) {
376    jQuery('#woocommerce_econt_shipping_method_office_office').append(jQuery("<option/>", {
377        value: value.id,
378        text: value.value
379    }));
380    
381});
382jQuery('#woocommerce_econt_shipping_method_office_office').on('change, click', function() {
383jQuery('#woocommerce_econt_shipping_method_office_code').val(this.value);
384
385});
386
387}
388});
389
390},
391
392});
393
394//econt checkout and order to/from door autocomplete
395jQuery('#econt_door_town').select2({
396  language: {
397  inputTooShort: function () {
398    return econt_php_vars.selectSelectResultsText;
399  },
400  noResults: function(){
401    return econt_php_vars.selectNRFText;
402  },
403  searching: function(){
404    return econt_php_vars.selectSearchPlaceText;
405  },
406  errorLoading:function(){
407    return econt_php_vars.selectSearchPlaceText;
408  },
409},
410  minimumInputLength: 2,
411  ajax: {
412    //url: ajaxurl,
413    url: econt_php_vars.ajaxURL,
414    dataType: 'json',
415    delay: econt_php_vars.autocompleteAjaxDelay,
416    data: function (params) {
417    var country_code = jQuery('select[name=billing_country] option').filter(':selected').val();
418    if(!econt_php_vars.isCheckout){
419      country_code = jQuery('select[name=_billing_country] option').filter(':selected').val();
420    }
421
422    var queryParameters = {
423      //q: params.q,
424      lang: $econt_lang,
425      city: params.term,
426      country_code: country_code,
427      action:'econt_handle_ajax', 
428    }
429
430    return queryParameters;
431    },
432    processResults: function (data) {
433      // Transforms the top-level key of the response object from 'items' to 'results'
434      return {
435        results: data
436        //results: [{"text":"Sofia","id":"41"},{"text":"Varna","id":"26382"}]
437      };
438    },
439    cache: true,
440  },
441  
442});
443
444jQuery('#econt_door_town').on('select2:select', function (e) {
445    $econt_town_city_id = e.params.data.city_id;
446    var data = e.params.data;
447    localStorageUpdate(data, 'econt_door_town_selected');
448    var country_code = jQuery('select[name=billing_country] option').filter(':selected').val();
449    if(!econt_php_vars.isCheckout){
450      country_code = jQuery('select[name=_billing_country] option').filter(':selected').val();
451    }
452    //jQuery('#econt_door_street, #econt_door_quarter').select2('enable');
453    if(country_code == 'RO' || country_code == 'GR'){
454      jQuery('#econt_door_street_intl_field, #econt_door_quarter_intl_field, #econt_door_street_num_field, #econt_door_street_bl_field, #econt_door_street_vh_field, #econt_door_street_et_field, #econt_door_street_ap_field, #econt_door_other_field, #econt_delivery_days_field, #econt_priority_time_type_field, #econt_priority_time_hour_field').slideDown();
455    }else{
456      jQuery('#econt_door_street_field, #econt_door_quarter_field, #econt_door_street_num_field, #econt_door_street_bl_field, #econt_door_street_vh_field, #econt_door_street_et_field, #econt_door_street_ap_field, #econt_door_other_field, #econt_delivery_days_field, #econt_priority_time_type_field, #econt_priority_time_hour_field').slideDown();
457    }
458    jQuery('#econt_door_postcode').prop('value', e.params.data.post_code);
459    if(econt_php_vars.isCheckout){ //if we are in checkout not in admin panel
460      calculate_loading(); //calculate loading cost for shipping to office
461    }
462
463    if(econt_php_vars.hideQuarterFields == 1){
464      setTimeout(function(){
465      jQuery('#econt_door_quarter_field, #econt_door_street_bl_field').hide();
466      }, 50);
467    }
468});
469
470
471jQuery('#econt_door_street').select2({
472  language: {
473    // You can find all of the options in the language files provided in the
474    // build. They all must be functions that return the string that should be
475    // displayed.
476    inputTooShort: function () {
477      return econt_php_vars.selectSelectResultsText;
478    },
479    noResults: function(){
480      return econt_php_vars.selectNRFText;
481    },
482    searching: function(){
483      return econt_php_vars.selectStreetSearchText;
484    },
485    errorLoading:function(){
486      return econt_php_vars.selectStreetSearchText;
487    },
488  },
489  //containerCssClass: 'mysel-con',
490  allowClear: true,
491  minimumInputLength: 2,
492  ajax: {
493    //url: ajaxurl,
494    url: econt_php_vars.ajaxURL,
495    dataType: 'json',
496    delay: econt_php_vars.autocompleteAjaxDelay,
497    data: function (params) {
498    var country_code = jQuery('select[name=billing_country] option').filter(':selected').val();
499    if(!econt_php_vars.isCheckout){
500      country_code = jQuery('select[name=_billing_country] option').filter(':selected').val();
501    }
502    var queryParameters = {
503      //q: params.q,
504      lang: $econt_lang,
505      action:'econt_handle_ajax',
506      door_city_id: $econt_town_city_id,
507      door_street_name: params.term,
508      country_code: country_code,
509      type: 'street' 
510    }
511
512    return queryParameters;
513    },
514    processResults: function (data) {
515      // Transforms the top-level key of the response object from 'items' to 'results'
516      return {
517        results: data
518        //results: [{"text":"Sofia","id":"41"},{"text":"Varna","id":"26382"}]
519      };
520    },
521    cache: true,
522  },
523  
524});
525
526
527jQuery('#econt_door_quarter').select2({
528  language: {
529    // You can find all of the options in the language files provided in the
530    // build. They all must be functions that return the string that should be
531    // displayed.
532    inputTooShort: function () {
533      return econt_php_vars.selectSelectResultsText;
534    },
535    noResults: function(){
536      return econt_php_vars.selectNRFText;
537    },
538    searching: function(){
539      return econt_php_vars.selectSearchNeighborhoodText;
540    },
541    errorLoading:function(){
542      return econt_php_vars.selectSearchNeighborhoodText;
543    },
544  },
545  allowClear: true,
546  minimumInputLength: 2,
547  ajax: {
548    //url: ajaxurl,
549    url: econt_php_vars.ajaxURL,
550    dataType: 'json',
551    delay: econt_php_vars.autocompleteAjaxDelay,
552    data: function (params) {
553    var country_code = jQuery('select[name=billing_country] option').filter(':selected').val();
554    if(!econt_php_vars.isCheckout){
555      country_code = jQuery('select[name=_billing_country] option').filter(':selected').val();
556    }
557    var queryParameters = {
558      //q: params.q,
559      lang: $econt_lang,
560      action:'econt_handle_ajax',
561      door_city_id: $econt_town_city_id,
562      door_quarter_name: params.term,
563      country_code: country_code,
564      type: 'quarter' 
565    }
566
567    return queryParameters;
568    },
569    processResults: function (data) {
570      // Transforms the top-level key of the response object from 'items' to 'results'
571      return {
572        results: data
573        //results: [{"text":"Sofia","id":"41"},{"text":"Varna","id":"26382"}]
574      };
575    },
576    cache: true,
577  },
578  
579});
580
581//International Streets and Quarters Autocomplete
582
583jQuery( "#econt_door_street_intl" ).autocomplete({
584minLength: 2,
585source: function( request, response ) {
586var country_code = jQuery('select[name=billing_country] option').filter(':selected').val();
587if(!econt_php_vars.isCheckout){
588  country_code = jQuery('select[name=_billing_country] option').filter(':selected').val();
589}
590jQuery.ajax({
591//url: ajaxurl,
592url: econt_php_vars.ajaxURL,
593dataType: "json",
594data: {
595lang: $econt_lang,
596action:'econt_handle_ajax', 
597//city: request.term
598door_city_id: $econt_town_city_id,
599door_street_name: request.term,
600country_code: country_code,
601type: 'street'
602
603},
604success: function( data ) {
605//response( data );
606  response(jQuery.map(data, function(item) {
607                        return {
608                            label:      item.text,
609                            value:      item.id,
610                            //city_id:    item.id,
611                            //post_code:   item.post_code
612                            
613                       };
614                }));
615
616
617
618},
619
620
621
622
623});
624//calculate_loading(); //calculate loading to door
625},
626
627});
628
629
630
631
632
633jQuery( "#econt_door_quarter_intl" ).autocomplete({
634minLength: 2,
635source: function( request, response ) {
636var country_code = jQuery('select[name=billing_country] option').filter(':selected').val();
637if(!econt_php_vars.isCheckout){
638  country_code = jQuery('select[name=_billing_country] option').filter(':selected').val();
639}
640
641jQuery.ajax({
642//url: ajaxurl,
643url: econt_php_vars.ajaxURL,
644dataType: "json",
645data: {
646lang: $econt_lang,
647action:'econt_handle_ajax', 
648//city: request.term
649door_city_id: $econt_town_city_id,
650door_quarter_name: request.term,
651country_code: country_code,
652type: 'quarter'
653
654},
655success: function( data ) {
656//response( data );
657  response(jQuery.map(data, function(item) {
658                        return {
659                            label:      item.text,
660                            value:      item.id,
661                            //city_id:    item.id,
662                            //post_code:   item.post_code
663                            
664                       };
665                }));
666
667},
668
669
670});
671},
672
673});
674
675//end of econt checkout and order to/from door autocomplete
676
677
678//hide and show fields in checkout and order
679
680jQuery('#econt_shipping_to').on('change', function () {
681    localStorageUpdate(this.value, 'econt_shipping_to');
682    if(this.value == 'DOOR'){
683
684jQuery('.econt_shipping_to_office').hide();
685jQuery('.econt_shipping_to_machine').hide();
686jQuery('.econt_office_locator_map').hide();
687
688
689if(Object.hasOwnProperty('hasOwn') && Object.hasOwn($econt_local_storage, 'econt_door_town_selected')){
690  //LocalStorage
691  $econt_town_city_id = $econt_local_storage.econt_door_town_selected.city_id;
692  var newOption = new Option($econt_local_storage.econt_door_town_selected.text, $econt_local_storage.econt_door_town_selected.id, true, true);
693  $('#econt_door_town').append(newOption).trigger('change');
694  jQuery('#econt_door_postcode').prop('value', $econt_local_storage.econt_door_town_selected.post_code);
695  if(Object.hasOwnProperty('hasOwn') && Object.hasOwn($econt_local_storage, 'econt_door_street_selected')){
696    var newOption = new Option($econt_local_storage.econt_door_street_selected.text, $econt_local_storage.econt_door_street_selected.id, false, false);
697    $('#econt_door_street').append(newOption).trigger('change');
698    var newOption = new Option($econt_local_storage.econt_door_street_selected.text, $econt_local_storage.econt_door_street_selected.id, true, true);
699    $('#econt_door_street').append(newOption).trigger('change');
700  }
701
702  if(Object.hasOwnProperty('hasOwn') && Object.hasOwn($econt_local_storage, 'econt_door_quarter_selected')){
703    var newOption = new Option($econt_local_storage.econt_door_quarter_selected.text, $econt_local_storage.econt_door_quarter_selected.id, true, true);
704    $('#econt_door_quarter').append(newOption).trigger('change');
705  }
706
707  jQuery.each(['econt_door_street_num', 'econt_door_street_bl', 'econt_door_street_vh', 'econt_door_street_et', 'econt_door_street_ap', 'econt_door_other', 'econt_door_street_intl', 'econt_door_quarter_intl'], function(key, value) {
708    if(Object.hasOwnProperty('hasOwn') && Object.hasOwn($econt_local_storage, value)){
709      $('#' + value).prop('value', $econt_local_storage[value]);
710    }
711  });
712
713  var country_code = jQuery('select[name=billing_country] option').filter(':selected').val();
714    if(!econt_php_vars.isCheckout){
715      country_code = jQuery('select[name=_billing_country] option').filter(':selected').val();
716    }
717    //jQuery('#econt_door_street, #econt_door_quarter').select2('enable');
718    if(country_code == 'RO' || country_code == 'GR'){
719      jQuery('#econt_door_street_intl_field, #econt_door_quarter_intl_field, #econt_door_street_num_field, #econt_door_street_bl_field, #econt_door_street_vh_field, #econt_door_street_et_field, #econt_door_street_ap_field, #econt_door_other_field, #econt_delivery_days_field, #econt_priority_time_type_field, #econt_priority_time_hour_field').slideDown();
720    }else{
721      jQuery('#econt_door_street_field, #econt_door_quarter_field, #econt_door_street_num_field, #econt_door_street_bl_field, #econt_door_street_vh_field, #econt_door_street_et_field, #econt_door_street_ap_field, #econt_door_other_field, #econt_delivery_days_field, #econt_priority_time_type_field, #econt_priority_time_hour_field').slideDown();
722    }
723    
724
725
726  if(econt_php_vars.isCheckout){ //if we are in checkout not in admin panel
727    calculate_loading(); //calculate loading cost for shipping to office
728  }
729
730}else{
731
732jQuery('#econt_door_town').empty();
733jQuery('#econt_door_postcode').removeAttr('value');
734jQuery('#econt_door_street').empty();
735jQuery('#econt_door_quarter').empty();
736jQuery('#econt_door_street_intl').removeAttr('value');
737jQuery('#econt_door_quarter_intl').removeAttr('value');
738jQuery('#econt_door_street_num').removeAttr('value');
739jQuery('#econt_door_street_bl').removeAttr('value');
740jQuery('#econt_door_street_vh').removeAttr('value');
741jQuery('#econt_door_street_et').removeAttr('value');
742jQuery('#econt_door_street_ap').removeAttr('value');
743jQuery('#econt_door_other').removeAttr('value');
744
745}
746
747jQuery('.econt_shipping_to_door').slideDown();
748jQuery('#econt_door_postcode_field, #econt_door_street_field, #econt_door_quarter_field, #econt_door_street_intl_field, #econt_door_quarter_intl_field, #econt_door_street_num_field, #econt_door_street_bl_field, #econt_door_street_vh_field, #econt_door_street_et_field, #econt_door_street_ap_field, #econt_door_other_field, #econt_delivery_days_field, #econt_priority_time_type_field, #econt_priority_time_hour_field').hide();
749
750}else if(this.value == 'OFFICE'){ 
751
752jQuery('.econt_shipping_to_door').hide();
753jQuery('.econt_shipping_to_machine').hide();
754jQuery("#econt_city_courier_field").hide();
755//jQuery('#econt_offices_map').hide();
756jQuery('#econt_machines_map').hide();
757if(Object.hasOwnProperty('hasOwn') && Object.hasOwn($econt_local_storage, 'econt_offices_town_selected') && Object.hasOwn($econt_local_storage, 'econt_office_offices')){
758  //LocalStorage
759  var newOption = new Option($econt_local_storage.econt_offices_town_selected.text, $econt_local_storage.econt_offices_town_selected.id, true, true);
760  $('#econt_offices_town').append(newOption).trigger('change');
761  var markersOffices = [];
762  jQuery.each($econt_local_storage.econt_office_offices, function(key, value) {
763    if(Object.hasOwnProperty('hasOwn') && Object.hasOwn($econt_local_storage, 'econt_office_offices_selected') && $econt_local_storage.econt_office_offices_selected.id == value.id){
764      var newOption = new Option(value.value, value.id, true, true);
765    }else{
766      var newOption = new Option(value.value, value.id, false, false);
767    }
768    $('#econt_offices').append(newOption).trigger('change');
769
770    markersOffices.push({
771      "id": value.id,
772      "title": value.name,
773      "lat": value.latitude,
774      "lng": value.longitude,
775      "description": value.description,
776      //"icon": speedy_php_vars.openLayersMapsOfficeIcon
777    });
778
779  });
780
781  if( econt_php_vars.openLayersMapsOfficeLocator.length == 0 || econt_php_vars.openLayersMapsOfficeLocator == 1 ){
782    jQuery('#econt_offices_map').empty();
783      window.setTimeout(function() {
784        load_map(markersOffices, 'office');
785    }, 500);
786    jQuery('#econt_offices_map').slideDown();
787  }
788
789  jQuery('#econt_offices_postcode, #woocommerce_econt_shipping_method_office_postcode, #econt_sender_offices_postcode').prop('value', $econt_local_storage.econt_offices_town_selected.post_code);
790  jQuery('#econt_offices_field, #econt_sender_offices_field').slideDown();
791  if(econt_php_vars.isCheckout){ //if we are in checkout not in admin panel
792    calculate_loading(); //calculate loading cost for shipping to office
793  }
794
795}else{
796  jQuery('#econt_offices_town').empty();
797  jQuery('#econt_offices_postcode').removeAttr('value');
798  jQuery('#econt_offices').empty();
799}
800//jQuery('.econt_shipping_to_office').slideToggle();
801jQuery('.econt_shipping_to_office').slideDown();
802jQuery('#econt_offices_postcode_field, #econt_offices_field').hide();
803
804} else if(this.value == 'MACHINE'){
805jQuery('.econt_shipping_to_door').hide();
806jQuery('.econt_shipping_to_office').hide();
807jQuery("#econt_city_courier_field").hide();
808jQuery('#econt_offices_map').hide();
809//jQuery('#econt_machines_map').hide();
810
811if(Object.hasOwnProperty('hasOwn') && Object.hasOwn($econt_local_storage, 'econt_machines_town_selected') && Object.hasOwn($econt_local_storage, 'econt_machine_machines')){
812  //LocalStorage
813  var newOption = new Option($econt_local_storage.econt_machines_town_selected.text, $econt_local_storage.econt_machines_town_selected.id, true, true);
814  $('#econt_machines_town').append(newOption).trigger('change');
815  var markersMachines = [];
816  jQuery.each($econt_local_storage.econt_machine_machines, function(key, value) {
817    if(Object.hasOwnProperty('hasOwn') && Object.hasOwn($econt_local_storage, 'econt_machine_machines_selected') && $econt_local_storage.econt_machine_machines_selected.id == value.id){
818      var newOption = new Option(value.value, value.id, true, true);
819    }else{
820      var newOption = new Option(value.value, value.id, false, false);
821    }
822    $('#econt_machines').append(newOption).trigger('change');
823
824    markersMachines.push({
825      "id": value.id,
826      "title": value.name,
827      "lat": value.latitude,
828      "lng": value.longitude,
829      "description": value.description,
830      //"icon": speedy_php_vars.openLayersMapsOfficeIcon
831    });
832
833  });
834
835  if( econt_php_vars.openLayersMapsOfficeLocator.length == 0 || econt_php_vars.openLayersMapsOfficeLocator == 1 ){
836    jQuery('#econt_machines_map').empty();
837      window.setTimeout(function() {
838        load_map(markersMachines, 'machine');
839    }, 500);
840    jQuery('#econt_machines_map').slideDown();
841  }
842
843  jQuery('#econt_machines_postcode, #woocommerce_econt_shipping_method_machine_postcode, #econt_sender_machines_postcode').prop('value', $econt_local_storage.econt_machines_town_
843selected.post_code);
844  jQuery('#econt_machines_field, #econt_sender_machines_field').slideDown();
845  if(econt_php_vars.isCheckout){ //if we are in checkout not in admin panel
846    calculate_loading(); //calculate loading cost for shipping to office
847  }
848
849}else{
850  jQuery('#econt_machines_town').empty();
851  jQuery('#econt_machines_postcode').removeAttr('value');
852  jQuery('#econt_machines').empty();
853}
854
855//jQuery('.econt_shipping_to_machine').slideToggle();
856jQuery('.econt_shipping_to_machine').slideDown();
857jQuery('#econt_machines_postcode_field, #econt_machines_field').hide();
858
859} else if(this.value == 0) {
860
861jQuery('.econt_shipping_to_door').hide();
862jQuery('.econt_shipping_to_office').hide();
863jQuery('.econt_shipping_to_machine').hide();
864jQuery("#econt_city_courier_field").hide();
865jQuery('.econt_office_locator_map').hide();
866
867
868}
869
870jQuery('#button_calculate_loading').val(econt_php_vars.calculateShippingCostText);
871
872});
873
874//admin order details show only the needed field when to/from APS
875var receiver_shipping_to = jQuery("#receiver_shipping_to").val();
876var sender_door_or_office = jQuery("#sender_door_or_office").val();
877if( receiver_shipping_to == 'MACHINE' || sender_door_or_office == 'MACHINE' ){
878
879 jQuery('.not_used_to_aps').hide();
880 jQuery('.used_from_aps').hide();
881jQuery('.priority_time').hide();
882 
883 if ( sender_door_or_office == 'MACHINE' && receiver_shipping_to != 'MACHINE' ) {
884 
885 jQuery('.used_from_aps').slideDown();
886 
887 if( receiver_shipping_to == 'DOOR' ){
888   jQuery('.priority_time').slideDown(); 
889 }
890
891
892 }
893
894
895}
896
897//hide size under 60cm if not office to office
898if ( sender_door_or_office != 'OFFICE' || receiver_shipping_to != 'OFFICE' ) {
899    jQuery('#size_under_60cm').hide();
900}
901
902jQuery('#sender_door_or_office').on('change', function () {
903 if( (this.value == 'DOOR' && receiver_shipping_to != 'MACHINE') || (this.value == 'DOOR2' && receiver_shipping_to != 'MACHINE') || (this.value == 'OFFICE' && receiver_shipping_to != 'MACHINE') ){
904
905jQuery('#order_cd').removeAttr('disabled');
906 jQuery('.not_used_to_aps').slideDown();
907 jQuery('.used_from_aps').slideDown();
908 jQuery('.priority_time').slideDown();
909 jQuery('#row_order_cd').slideDown();
910
911
912 } else if(this.value == 'MACHINE' || receiver_shipping_to == 'MACHINE') {
913
914 jQuery('.not_used_to_aps').hide();
915 jQuery('.used_from_aps').hide();
916 jQuery('.priority_time').hide();
917
918 if ( this.value == 'MACHINE' && receiver_shipping_to != 'MACHINE' ) {
919 
920 jQuery('.used_from_aps').slideDown();
921 
922 if( receiver_shipping_to == 'DOOR' ){
923   Query('.priority_time').slideDown(); 
924 }
925
926
927 }
928}
929//hide size under 60cm if not office to office
930if(this.value != 'OFFICE'){
931  jQuery('#size_under_60cm').hide();   
932}
933
934if(this.value == 'OFFICE' && receiver_shipping_to == 'OFFICE'){
935  jQuery('#size_under_60cm').slideDown();
936}
937
938});
939
940var woocommerce_econt_shipping_method_send_from = jQuery('#woocommerce_econt_shipping_method_send_from').val();
941
942jQuery('#woocommerce_econt_shipping_method_send_from').on('change', function () {
943if(this.value == 'MACHINE'){
944if(jQuery('#woocommerce_econt_shipping_method_cd').val() == 1 && jQuery('#woocommerce_econt_shipping_method_client_cd_num').val() == 0 ){
945
946//alert('Когато изпращате от АПС и активирате услугата плащане при доставка (наложен платеж) е задължително да изпозвате споразумение за събиране на наложен платеж!');
947alert(econt_php_vars.apsAlertText2);
948jQuery('#woocommerce_econt_shipping_method_send_from').val( woocommerce_econt_shipping_method_send_from );
949
950
951} else {
952    //alert('услуги, които можете да използвате, когато изпращате от АПС са:\n- наложен платеж (когато използвате споразумение за събиране на НП) \n- обратна разписка\n- двупосочна пратка\n- Час за приоритет (когато изпращате до адрес)\n- Преглед\n- Преглед и тест\n- Преглед, тест и избор');
953    alert(econt_php_vars.apsAlertText2);
954} 
955
956}
957
958});
959
960//jQuery("#woocommerce_econt_shipping_method_refreshdata").prop('value', 'Обнови');
961jQuery("#woocommerce_econt_shipping_method_refreshdata").prop('value', econt_php_vars.refreshText);
962jQuery("#woocommerce_econt_shipping_method_refreshdata_intl").prop('value', econt_php_vars.refreshText);
963//econt admin settings refresh econt offices and adresses
964jQuery('#woocommerce_econt_shipping_method_refreshdata').click(function(){
965
966    var username  = jQuery("#woocommerce_econt_shipping_method_username").val();
967    var password  = jQuery("#woocommerce_econt_shipping_method_password").val();
968    var live      = jQuery("#woocommerce_econt_shipping_method_live").val();
969
970
971jQuery("#woocommerce_econt_shipping_method_refreshdata").prop('value', econt_php_vars.refreshWaitText);
972jQuery("#woocommerce_econt_shipping_method_refreshdata").addClass('ui-autocomplete-loading');
973    jQuery.ajax({
974
975        url: econt_php_vars.ajaxURL2,
976        dataType: "json",
977        data:{
978        action:'econt_handle_ajax',
979        refresh_data: 1
980        }, 
981        //type: 'post',
982
983
984        success: function(data){
985        jQuery("#woocommerce_econt_shipping_method_refreshdata").removeClass('ui-autocomplete-loading');
986        jQuery("#woocommerce_econt_shipping_method_refreshdata").prop('value', data.msg);
987
988            if(data.error === 1){
989                alert(data.msg);
990            }
991        },
992    });
993
994
995});
996
997//econt admin settings refresh econt international offices and cities
998jQuery('#woocommerce_econt_shipping_method_refreshdata_intl').click(function(){
999
1000    var username  = jQuery("#woocommerce_econt_shipping_method_username").val();
1001    var password  = jQuery("#woocommerce_econt_shipping_method_password").val();
1002    var live      = jQuery("#woocommerce_econt_shipping_method_live").val();
1003
1004
1005jQuery("#woocommerce_econt_shipping_method_refreshdata_intl").prop('value', econt_php_vars.refreshWaitText);
1006jQuery("#woocommerce_econt_shipping_method_refreshdata_intl").addClass('ui-autocomplete-loading');
1007    jQuery.ajax({
1008
1009        url: econt_php_vars.ajaxURL2,
1010        dataType: "json",
1011        data:{
1012        action:'econt_handle_ajax',
1013        refresh_data_intl: 1
1014        }, 
1015        //type: 'post',
1016
1017
1018        success: function(data){
1019        jQuery("#woocommerce_econt_shipping_method_refreshdata_intl").removeClass('ui-autocomplete-loading');
1020        jQuery("#woocommerce_econt_shipping_method_refreshdata_intl").prop('value', data.msg);
1021            if(data.error === 1){
1022                alert(data.msg);
1023            }
1024        },
1025    });
1026
1027
1028});
1029//end of econt admin settings refresh econt offices and adresses
1030
1031
1032//start of econt admin sync profile and clients_access
1033jQuery("#woocommerce_econt_shipping_method_refreshprofile").prop('value', econt_php_vars.refreshText);
1034
1035//econt admin settings sync econt profile and clients_access
1036jQuery("#woocommerce_econt_shipping_method_refreshprofile").click(function(){
1037
1038    var username  = jQuery("#woocommerce_econt_shipping_method_username").val();
1039    var password  = jQuery("#woocommerce_econt_shipping_method_password").val();
1040    var live      = jQuery("#woocommerce_econt_shipping_method_live").val();
1041
1042
1043
1044jQuery("#woocommerce_econt_shipping_method_refreshprofile").prop('value', econt_php_vars.refreshWaitText);
1045jQuery("#woocommerce_econt_shipping_method_refreshprofile").addClass('ui-autocomplete-loading');
1046    jQuery.ajax({
1047
1048        url: econt_php_vars.ajaxURL2,
1049        dataType: "json",
1050        data:{
1051        action:'econt_handle_ajax',
1052        sync_profile: 1,
1053        username: username,
1054        password: password,
1055        live: live,
1056        }, 
1057        //type: 'post',
1058
1059
1060        success: function(data){
1061        jQuery("#woocommerce_econt_shipping_method_refreshprofile").removeClass('ui-autocomplete-loading');
1062        jQuery("#woocommerce_econt_shipping_method_refreshprofile").prop('value', data.msg);
1063            //if(data.indexOf('Error') === -1){
1064            if(data.error === 0){
1065                location.reload();
1066            }else if(data.error === 1){
1067                alert(data.msg);
1068            }
1069        },
1070    });
1071
1072
1073});
1074//end of econt admin sync profile and clients_access
1075
1076
1077  var form = jQuery('#order_loading_form');
1078
1079//admin order calculate or create loading
1080   jQuery("#order_only_calculate_loading").click( function() {
1081
1082    var data2 = jQuery('#order_loading_form').serialize();
1083    jQuery('#econtLoader').show();
1084
1085    jQuery.ajax({
1086
1087        url: econt_php_vars.ajaxURL2,
1088        dataType: "json",
1089        data: data2 + '&action=econt_handle_ajax&action2=only_calculate_loading',
1090        type: 'POST',
1091    
1092        success: function(data){
1093            jQuery('#econtLoader').hide();
1094            jQuery('#create_loading tr').remove();
1095            if(data.length !== 0){
1096                if( data['warning'] ){
1097                  alert( data['warning'] );
1098                } else if(data.length === 0) {
1099                  alert('Възникна грешка. Моля, проверете потребителското име и парола в настройките за доставка с Еконт.');
1100                } else{
1101                  var currency_symbol = jQuery.isNumeric(data['customer_shipping_cost']) ? data['currency_symbol'] : '';
1102                  var customerShippingCost = jQuery.isNumeric(data['customer_shipping_cost']) ? (Math.round((Number(data['customer_shipping_cost']) + Number(data['customer_shipping_tax'])) * 100) / 100).toFixed(2)+currency_symbol : data['customer_shipping_cost'];
1103                  jQuery('<tr><td>'+econt_php_vars.totalShippingCostText+'</td><td id="total_shipping_cost"><strong>'+data['total_shipping_cost']+data['currency_symbol']+'</strong></td></tr>').appendTo('#create_loading');
1104                  jQuery('<tr><td>'+econt_php_vars.totalShippingCustomerCostText+'</td><td id="customer_shipping_cost"><strong>'+ customerShippingCost +'</strong></td></tr>').appendTo('#create_loading');
1105                  //if(data['delayed_delivery_warning']){
1106                  //  alert( data['delayed_delivery_warning'] );
1107                  //}
1108                }
1109            } else {
1110              alert('Възникна грешка. Моля, проверете потребителското име и парола в настройките за доставка с Еконт.');  
1111            }
1112
1113        },
1114    });
1115  });
1116
1117  jQuery("#order_create_loading").click( function() { 
1118    var $this = jQuery(this);
1119    $this.prop('disabled', true);
1120    var data2 = jQuery('#order_loading_form').serialize();
1121    jQuery('#econtLoader').show();
1122
1123    jQuery.ajax({
1124
1125        url: econt_php_vars.ajaxURL2,
1126        dataType: "json",
1127        data: data2 + '&action=econt_handle_ajax&action2=create_loading',
1128        type: 'POST',
1129
1130        
1131        success: function(data){   
1132        jQuery('#econtLoader').hide();
1133        jQuery('#create_loading tr').remove();
1134
1135            if( data['warning'] ){ 
1136            alert( data['warning'] ); 
1137            } else if(data.length === 0) {
1138            alert('Възникна грешка. Моля, проверете потребителското име и парола в настройките за доставка с Еконт.');
1139            } else { 
1140
1141                if( data['delayed_delivery_warning'] ){ 
1142                  alert( data['delayed_delivery_warning'] ); 
1143                }
1144
1145                jQuery('<tr><td>'+econt_php_vars.loadingPdfLinkText+'</td><td id="pdf_url"><strong><a href="'+data['pdf_url']+'" target="_blank">'+data['pdf_url']+'</a></strong></td></tr>').appendTo('#create_loading');
1146            
1147            
1148               jQuery('<tr><td>'+econt_php_vars.loadingNumberText+'</td><td id="loading_num"><strong>'+data['loading_num']+'</strong></td></tr>').appendTo('#create_loading');
1149             
1150                
1151                jQuery('<tr><td>'+econt_php_vars.totalShippingCostText+'</td><td id="total_sum"><strong>'+data['total_shipping_cost']+data['currency_symbol']+'</strong></td></tr>').appendTo('#create_loading');
1152             
1153                
1154                jQuery('<tr><td>'+econt_php_vars.totalShippingCustomerCostText+'</td><td id="order_total_sum"><strong>'+data['customer_shipping_cost']+data['currency_symbol']+'</strong></td></tr>').appendTo('#create_loading');
1155             
1156                
1157                if(jQuery('.econt_wc_orders_list', window.parent.document).length){
1158                  
1159                  parent.$econt_add_loading_link(data['loading_num'], data['pdf_url']);
1160                  parent.jQuery.fn.colorbox.close();
1161                  
1162                }else{
1163                  location.reload();
1164                }
1165                //$this.prop('disabled', false);
1166            }
1167        },
1168    });
1169  });
1170//end of admin order calculate or create loading
1171
1172//jQuery("#econt_offices_town", "#woocommerce_econt_shipping_method_office_town", "#econt_door_town", "#econt_door_street", "#econt_door_quarter").prop("autocomplete","off");
1173
1174//hide econtLoading div in checkout
1175jQuery('#econtLoader').hide();
1176
1177function calculate_loading(loading){
1178
1179var econt_user_address = jQuery('#econt_user_address').val();
1180var country_code = jQuery('select[name=billing_country] option').filter(':selected').val();
1181if(!econt_php_vars.isCheckout){
1182  country_code = jQuery('select[name=_billing_country] option').filter(':selected').val();
1183}
1184var country_codes = {'RO': 'ROU', 'GR': 'GRC'};
1185var intl_delivery = (country_code == 'RO' || country_code == 'GR') ? true : false;
1186
1187var econt_shipping_to = (econt_user_address == '1') ? jQuery("#econt_shipping_to_user").val() : jQuery("#econt_shipping_to").val();
1188
1189var payment_method = '';
1190
1191var receiver_country_code = ( intl_delivery == true ) ? country_codes[country_code] : 'BGR';
1192var receiver_city = '';
1193var receiver_post_code = '';
1194var receiver_office_code = '';
1195var receiver_street = '';
1196var receiver_quarter = '';
1197var receiver_street_num = '';
1198var receiver_street_bl = '';
1199var receiver_street_vh = '';
1200var receiver_street_et = '';
1201var receiver_street_ap = '';
1202var receiver_street_other = '';
1203var econt_city_courier = '';
1204var delivery_day_id = '';
1205var priority_time_type = '';
1206var priority_time_hour = '';
1207
1208if(jQuery('#payment_method_cod').is(':checked')){ 
1209  payment_method = 'cod'; 
1210}
1211
1212if(jQuery('#payment_method_econt_payment').is(':checked')){ 
1213  payment_method = 'econt_payment'; 
1214}
1215
1216var pack_count = 1;
1217
1218var receiver_name = jQuery("#billing_company").val();
1219var receiver_name_person = jQuery("#billing_first_name").val()+' '+jQuery("#billing_last_name").val();
1220//receiver_name = (receiver_name.length === 0) ? receiver_name_person : receiver_name;
1221receiver_name = (receiver_name) ? receiver_name : receiver_name_person;
1222var receiver_phone_num = jQuery("#billing_phone").val();
1223var receiver_email = jQuery("#billing_email").val();
1224
1225if ( econt_shipping_to == 'DOOR' ){
1226
1227receiver_city = (econt_user_address == '1') ? jQuery("#econt_door_town_user").val() : jQuery("#econt_door_town").val();
1228receiver_post_code = (econt_user_address == '1') ? jQuery("#econt_door_postcode_user").val() : jQuery("#econt_door_postcode").val();
1229receiver_street = (intl_delivery == true) ? (econt_user_address == '1') ? jQuery("#econt_door_street_intl_user").val() : jQuery("#econt_door_street_intl").val() : (econt_user_address == '1') ? jQuery("#econt_door_street_user").val() : jQuery("#econt_door_street").val();
1230receiver_quarter = (intl_delivery == true) ? (econt_user_address == '1') ? jQuery("#econt_door_quarter_intl_user").val() : jQuery("#econt_door_quarter_intl").val() : (econt_user_address == '1') ? jQuery("#econt_door_quarter_user").val() : jQuery("#econt_door_quarter").val();
1231receiver_street_num = (econt_user_address == '1') ? jQuery("#econt_door_street_num_user").val() : jQuery("#econt_door_street_num").val();
1232receiver_street_bl = (econt_user_address == '1') ? jQuery("#econt_door_street_bl_user").val() : jQuery("#econt_door_street_bl").val();
1233receiver_street_vh = (econt_user_address == '1') ? jQuery("#econt_door_street_vh_user").val() : jQuery("#econt_door_street_vh").val();
1234receiver_street_et = (econt_user_address == '1') ? jQuery("#econt_door_street_et_user").val() : jQuery("#econt_door_street_et").val();
1235receiver_street_ap = (econt_user_address == '1') ? jQuery("#econt_door_street_ap_user").val() : jQuery("#econt_door_street_ap").val();
1236receiver_street_other = (econt_user_address == '1') ? jQuery("#econt_door_other_user").val() : jQuery("#econt_door_other").val();
1237econt_city_courier = jQuery("#econt_city_courier").val();
1238delivery_day_id = jQuery("#econt_delivery_days").val();
1239priority_time_type = jQuery("#econt_priority_time_type").val();
1240priority_time_hour = jQuery("#econt_priority_time_hour").val();
1241
1242}else if (econt_shipping_to == 'OFFICE'){
1243
1244var receiver_city =  (econt_user_address == '1') ? jQuery("#econt_offices_town_user").val() : jQuery("#econt_offices_town").val();
1245var receiver_post_code = (econt_user_address == '1') ? jQuery("#econt_office
1245s_postcode_user").val() : jQuery("#econt_offices_postcode").val();
1246var receiver_office_code = (econt_user_address == '1') ? jQuery("#econt_offices_user").val() : jQuery("#econt_offices").val();
1247
1248}else if (econt_shipping_to == 'MACHINE'){
1249
1250var receiver_city =  (econt_user_address == '1') ? jQuery("#econt_machines_town_user").val() : jQuery("#econt_machines_town").val();
1251var receiver_post_code = (econt_user_address == '1') ? jQuery("#econt_machines_postcode_user").val() : jQuery("#econt_machines_postcode").val();
1252var receiver_office_code = (econt_user_address == '1') ? jQuery("#econt_machines_user").val() : jQuery("#econt_machines").val();
1253
1254}
1255
1256if(receiver_city != null && receiver_city.length < 1){
1257  return;
1258}
1259
1260if(typeof loading !== 'undefined'){    
1261    jQuery('#econtLoader').show();
1262    jQuery('input[type="submit"]').prop('disabled','disabled');
1263}
1264
1265jQuery.ajax({
1266
1267        url: econt_php_vars.ajaxURL2,
1268        dataType: "json",
1269        
1270        data: {
1271        action: 'econt_handle_ajax',
1272        action2: 'only_calculate_loading',
1273        receiver_name: receiver_name,
1274        receiver_name_person: receiver_name_person,
1275        receiver_phone_num: receiver_phone_num,
1276        receiver_email: receiver_email,
1277        receiver_shipping_to: econt_shipping_to,
1278        receiver_country_code: receiver_country_code,
1279        receiver_city: receiver_city,
1280        receiver_post_code: receiver_post_code,
1281        receiver_office_code: receiver_office_code,
1282        receiver_street: receiver_street,
1283        receiver_quarter: receiver_quarter,
1284        receiver_street_num: receiver_street_num,
1285        receiver_street_bl: receiver_street_bl,
1286        receiver_street_vh: receiver_street_vh,
1287        receiver_street_et: receiver_street_et,
1288        receiver_street_ap: receiver_street_ap,
1289        receiver_street_other: receiver_street_other,
1290        econt_city_courier: econt_city_courier,
1291        delivery_day_id: delivery_day_id,
1292        priority_time_type: priority_time_type,
1293        priority_time_hour: priority_time_hour,
1294        pack_count: pack_count,
1295        payment_method: payment_method,
1296
1297        },
1298        type: 'POST',
1299
1300        success: function(data){
1301            if(data.length !== 0){
1302              if(data['warning']){
1303                alert( data['warning'] );
1304              } else{
1305                jQuery("#econt_customer_shipping_cost").prop('value', data['customer_shipping_cost'] );
1306                jQuery("#econt_customer_shipping_tax").prop('value', data['customer_shipping_tax'] );
1307                jQuery("#econt_total_shipping_cost").prop('value', data['total_shipping_cost'] );
1308                 
1309                if(econt_php_vars.incShippingCost == 1){
1310                  jQuery( 'body' ).trigger( 'update_checkout', ['calculate_loading'] ); //inc shipping cost fee
1311                  jQuery( 'body' ).on( 'updated_checkout', function() {
1312                    var customer_shipping_cost = jQuery("#econt_customer_shipping_cost").val();
1313                    if(typeof customer_shipping_cost !== 'undefined' && jQuery.isNumeric( customer_shipping_cost ) === false){
1314                      var dots = econt_php_vars.shippingMethodTitleType == 'image' ? '' : ':';
1315                      jQuery('label[for=shipping_method_0_econt_shipping_method]').html(econt_php_vars.shippingMethodTitle + dots + ' <span class="woocommerce-Price-amount amount">' + jQuery("#econt_customer_shipping_cost").val() + '</span>');
1316                    }
1317                  });
1318                }
1319                
1320                if(econt_php_vars.incShippingCost == 0){
1321                  //console.log(data['customer_shipping_cost']);
1322                  var customer_shipping_total_cost = '';
1323                  if(typeof data['customer_shipping_cost'] !== 'undefined' && jQuery.isNumeric( data['customer_shipping_cost'] ) === false){
1324                    customer_shipping_total_cost = data['customer_shipping_cost'];
1325                  }else{
1326                    customer_shipping_total_cost = (Math.round((Number(data['customer_shipping_cost']) + Number(data['customer_shipping_tax']))*100)/100).toFixed(2);
1327                    customer_shipping_total_cost += ' ' + data['currency_symbol'];
1328                  }
1329                  
1330                  jQuery('#econt_shipping_expenses').remove();
1331                  jQuery('.woocommerce-checkout-review-order-table tr:last').after('<tr id="econt_shipping_expenses"><td>'+econt_php_vars.shippingMethodTitle+'</td><td><strong>'+customer_shipping_total_cost+'</strong></td></tr>').appendTo('.woocommerce-checkout-review-order-table');   
1332                }
1333                //if(data['delayed_delivery_warning']){
1334                //  alert( data['delayed_delivery_warning'] );
1335                //}
1336              }
1337            }
1338            
1339            if(typeof loading !== 'undefined'){    
1340                jQuery('#econtLoader').hide();
1341                jQuery('input[type="submit"]').removeAttr('disabled');
1342            }
1343
1344        },
1345
1346
1347 });
1348
1349}
1350
1351    //avtomatizirano kalkulirane na cenata za shipping i nalojen platej
1352    jQuery("#econt_door_other, #button_calculate_loading, #econt_door_street, #econt_door_quarter").on('click' , function(e){
1353       if(econt_php_vars.isCheckout){ //if we are in checkout not in admin panel
1354        //calculate_loading();
1355      }
1356
1357    });
1358
1359    jQuery("#econt_city_courier, #econt_delivery_days, #econt_priority_time_hour").on('change' , function(e){
1360      if(econt_php_vars.isCheckout){ //if we are in checkout not in admin panel
1361        calculate_loading();
1362      }
1363
1364    });
1365
1366    //preizchislqva cenata za dostavka i NP pri smqna na payment method
1367    jQuery( 'body' ).on( 'updated_checkout', function() {
1368      jQuery('input[name="payment_method"]').change(function(){
1369        var loading = 'yes';
1370        calculate_loading(loading);
1371      });
1372    });
1373   
1374jQuery("#delete_loading").click(function(e){
1375
1376var loading_num = jQuery("#loading_num").val();
1377jQuery('#econtLoader').show();
1378
1379jQuery.ajax({
1380
1381        url: econt_php_vars.ajaxURL2,
1382        dataType: "json",
1383        
1384        data: {
1385        action: 'econt_handle_ajax',
1386        action2: 'delete_loading',
1387        loading_num: loading_num,
1388
1389        },
1390        type: 'POST',
1391
1392        success: function(data){
1393
1394          if(data.error === 1){
1395            alert(data.msg);
1396          }
1397        jQuery('#econtLoader').hide();
1398        location.reload(); 
1399
1400        },
1401
1402
1403 });
1404
1405 });
1406
1407
1408jQuery("#button_request_of_courier").click(function(e){
1409
1410window.open('http://ee.econt.com/?target=EeMyRequestOfCourier', '_blank');
1411
1412});
1413
1414//zabranqva promqnata na ofis kod i poshtenski ofis kod v admin nastrojkite na plugina
1415jQuery('#woocommerce_econt_shipping_method_office_postcode, #woocommerce_econt_shipping_method_office_code, #woocommerce_econt_shipping_method_machine_postcode, #woocommerce_econt_shipping_method_machine_code').prop('readonly', true);
1416
1417//zatvarq sekciqta "customer fileds" v poruchkata
1418jQuery('#postcustom').addClass('closed');
1419
1420
1421
1422
1423function edit_receiver_address(id, type){
1424
1425var econt_shipping_to = jQuery("#econt_shipping_to").val();
1426
1427//DOOR
1428var billing_country = jQuery('select[name=_billing_country] option').filter(':selected').val();
1429var intl_delivery = (billing_country == 'RO' || billing_country == 'GR') ? true : false;
1430var econt_door_town = jQuery("#econt_door_town").val();
1431var econt_door_postcode = jQuery("#econt_door_postcode").val();
1432var econt_door_street = (intl_delivery == true) ? jQuery("#econt_door_street_intl").val() : jQuery("#econt_door_street").val();
1433var econt_door_quarter = (intl_delivery == true) ? jQuery("#econt_door_quarter_intl").val() : jQuery("#econt_door_quarter").val();
1434var econt_door_street_intl = (intl_delivery == true) ? jQuery("#econt_door_street_intl").val() : '';
1435var econt_door_quarter_intl = (intl_delivery == true) ? jQuery("#econt_door_quarter_intl").val() : '';
1436//var econt_door_street = jQuery("#econt_door_street").val();
1437//var econt_door_quarter = jQuery("#econt_door_quarter").val();
1438var econt_door_street_num = jQuery("#econt_door_street_num").val();
1439var econt_door_street_bl = jQuery("#econt_door_street_bl").val();
1440var econt_door_street_vh = jQuery("#econt_door_street_vh").val();
1441var econt_door_street_et = jQuery("#econt_door_street_et").val();
1442var econt_door_street_ap = jQuery("#econt_door_street_ap").val();
1443var econt_door_other = jQuery("#econt_door_other").val();
1444//OFFICE
1445var econt_offices_town =  jQuery("#econt_offices_town").val();
1446var econt_offices_postcode = jQuery("#econt_offices_postcode").val();
1447var econt_offices = jQuery("#econt_offices").val();
1448//MACHINE
1449var econt_machines_town =  jQuery("#econt_machines_town").val();
1450var econt_machines_postcode = jQuery("#econt_machines_postcode").val();
1451var econt_machines = jQuery("#econt_machines").val();
1452//Shipping Cost
1453var econt_total_shipping_cost = jQuery("#econt_total_shipping_cost").val();
1454var econt_customer_shipping_cost = jQuery("#econt_customer_shipping_cost").val();
1455
1456jQuery.ajax({
1457
1458        url: econt_php_vars.ajaxURL2,
1459        dataType: "json",
1460        
1461        data: {
1462        action: 'econt_handle_ajax',
1463        action2: 'edit_receiver_address',
1464        econt_shipping_to: econt_shipping_to,
1465        billing_country: billing_country,
1466        econt_door_town: econt_door_town,
1467        econt_door_postcode: econt_door_postcode,
1468        econt_door_street: econt_door_street,
1469        econt_door_street_intl: econt_door_street_intl,
1470        econt_door_quarter: econt_door_quarter,
1471        econt_door_quarter_intl: econt_door_quarter_intl,
1472        econt_door_street_num: econt_door_street_num,
1473        econt_door_street_bl: econt_door_street_bl,
1474        econt_door_street_vh: econt_door_street_vh,
1475        econt_door_street_et: econt_door_street_et,
1476        econt_door_street_ap: econt_door_street_ap,
1477        econt_door_other: econt_door_other,
1478        econt_offices_town: econt_offices_town,
1479        econt_offices_postcode: econt_offices_postcode,
1480        econt_offices: econt_offices,
1481        econt_machines_town: econt_machines_town,
1482        econt_machines_postcode: econt_machines_postcode,
1483        econt_machines: econt_machines,
1484        econt_total_shipping_cost: econt_total_shipping_cost,
1485        econt_customer_shipping_cost: econt_customer_shipping_cost,
1486        id: id,
1487        type: type,
1488
1489        },
1490        type: 'POST',
1491
1492        success: function(data){
1493
1494          if( data['warning'] ){ 
1495            alert( data['warning'] ); 
1496          }else{
1497            location.reload();
1498          }
1499
1500        },
1501
1502
1503 });
1504
1505}
1506
1507jQuery("#save_receiver_address").click(function(e){
1508
1509  edit_receiver_address(order_id, 'order');
1510
1511});
1512
1513jQuery("#save_user_address").click(function(e){
1514
1515  edit_receiver_address(user_id, 'user');
1516
1517});
1518
1519jQuery("a.edit_econt_address").click(function(e){
1520  e.preventDefault();
1521  if(loading_is_imported != '1'){ //if loading is imported prevent from editing receiver address
1522    jQuery('.econt-table').hide();
1523    jQuery('#econt_edit_receiver_address').slideDown();
1524  }
1525});
1526
1527
1528    var env = jQuery('select[name=woocommerce_econt_shipping_method_live]').val();
1529
1530    var set_env = function(env){
1531  
1532      var html_live = econt_php_vars.htmlLiveText;
1533      var html_test = econt_php_vars.htmlTestText;
1534
1535      if( env == 1){
1536
1537        jQuery("#woocommerce_econt_shipping_method_live_description").html(html_live);
1538
1539      }else if (env == 0){
1540
1541        jQuery("#woocommerce_econt_shipping_method_live_description").html(html_test);
1542
1543      }
1544
1545    }
1546
1547    set_env(env);
1548
1549
1550    jQuery("#woocommerce_econt_shipping_method_live").change(function(){
1551
1552      var env = jQuery('select[name=woocommerce_econt_shipping_method_live]').val();
1553
1554      set_env(env);
1555
1556    });
1557
1558  function disableAutofill(){    
1559    jQuery.each([ 'econt_offices_town', 'econt_machines_town', 'econt_door_town', 'econt_door_street', 'econt_door_quarter', 'econt_door_street_num', 'econt_door_street_bl', 'econt_door_street_vh', 'econt_door_street_et', 'econt_door_street_ap', 'econt_door_other' ], function( index, value ){  
1560      //jQuery("input[name='"+ value +"']").prop("autocomplete", "new-username");
1561      jQuery("input[name='"+ value +"']").prop("autocomplete", "disabled");  //dissable, off or false
1562    });
1563  }
1564
1565  setTimeout(function(){
1566    disableAutofill();
1567  }, 500);
1568
1569  if( econt_php_vars.isCart && econt_php_vars.hideCardShippingDescr == 1 ){
1570    jQuery('.woocommerce-shipping-destination').css('display', 'none');
1571  }
1572//Checkout tooltips
1573if( econt_php_vars.checkoutTooltips.length == 0 || econt_php_vars.checkoutTooltips == 1 ){
1574
1575  jQuery('#econt_door_town_field, #econt_offices_town_field, #econt_machines_town_field').tooltipster({
1576      theme: 'tooltipster-borderless',
1577      content: econt_php_vars.tooltipTownText,
1578      trigger: 'hover',
1579      //timer: 5000,
1580      maxWidth: jQuery(window).width()*0.85,
1581      functionPosition: function(instance, helper, position){
1582          //position.coord.top += 10;
1583          position.coord.left += jQuery(window).width()*0.04;
1584          return position;
1585      },
1586  });
1587
1588  jQuery('#econt_door_quarter_field').tooltipster({
1589    theme: 'tooltipster-borderless',
1590    content: econt_php_vars.tooltipQuarterText,
1591    trigger: 'hover',
1592    //timer: 5000,
1593    maxWidth: jQuery(window).width()*0.85,
1594    functionPosition: function(instance, helper, position){
1595        //position.coord.top += 10;
1596        position.coord.left += jQuery(window).width()*0.05;
1597        return position;
1598    },
1599  });
1600
1601  jQuery('#econt_door_street_field').tooltipster({
1602    theme: 'tooltipster-borderless',
1603    content: econt_php_vars.tooltipStreetText,
1604    trigger: 'hover',
1605    //timer: 5000,
1606    maxWidth: jQuery(window).width()*0.85,
1607    functionPosition: function(instance, helper, position){
1608        //position.coord.top += 10;
1609        position.coord.left += jQuery(window).width()*0.05;
1610        return position;
1611    },
1612});
1613
1614   jQuery('#econt_user_checkout_field, .econt_user_address').tooltipster({
1615    theme: 'tooltipster-borderless',
1616    content: econt_php_vars.tooltipUserCheckoutText,
1617    trigger: 'hover',
1618    //timer: 5000,
1619    maxWidth: jQuery(window).width()*0.85,
1620    functionPosition: function(instance, helper, position){
1621        //position.coord.top += 10;
1622        position.coord.left += jQuery(window).width()*0.05;
1623        return position;
1624    },
1625});
1626
1627}
1628//end of Checkout tooltips
1629
1630jQuery('form.checkout').on('change','input[name^=cart]',function() {
1631  setTimeout(function(){
1632    var loading = 'yes';
1633    calculate_loading(loading);
1634  }, 1000);
1635});
1636
1637//fix select2 and jQuery >= 3.6 conflict of search field focus
1638if(econt_php_vars.isCheckout){
1639  jQuery(document).on('select2:open', () => {
1640      document.querySelector('.select2-search__field').focus();
1641  });
1642}
1643
1644//fast create loading
1645jQuery(".econt_fast_create_loading").off().on('click' , function(e){
1646  e.preventDefault();
1647
1648  var href = jQuery(this).attr('href');
1649  
1650  if( href.indexOf("http://") != 0 && href.indexOf("https://") != 0 ){
1651    var $this = jQuery(this);
1652    $this.prop('disabled', true);
1653
1654    jQuery('#econtLoader').show();
1655
1656    jQuery.ajax({
1657
1658        url: econt_php_vars.ajaxURL2,
1659        dataType: "json",
1660        data: {
1661                action: 'econt_handle_ajax',
1662                action2: 'create_loading',
1663                action3: 'fast',
1664                order_id: href,
1665        },
1666        type: 'POST',
1667
1668        
1669        success: function(data){
1670        jQuery('#econtLoader').hide();
1671            if( data['warning'] ){ 
1672            alert( data['warning'] ); 
1673            } else if(data.length === 0) {
1674            alert('Възникна грешка. Моля, проверете потребителското име и парола в настройките за доставка с Еконт.');
1675            } else {
1676              $this.attr("href", data['pdf_url']);
1677              $this.attr("target", '_blank');
1678              $this.removeAttr('id');
1679              $this.removeClass("econt_fast_create_loading");
1680              $this.addClass("econt_pdf_loading");
1681              $this.text(data['loading_num']);
1682              $this.prop('disabled', false);
1683              $this.next().remove();
1684              jQuery($this).after(' <button class="econt_wc_orders_list" href="" onclick="$econt_aiaks(\'loading_tracking\', ' + data['loading_num'] + ');return false;" target="_blank">' + econt_php_vars.trackingTxt + '</button><div id="econtLoader" style="display:none;"></div><!-- loading spinner -->');
1685              if( data['delayed_delivery_warning'] ){ 
1686                alert( data['delayed_delivery_warning'] ); 
1687              }
1688            }
1689        },
1690    });
1691
1692  }else{
1693    window.open(href, '_blank');
1694  }
1695
1696});
1697//end of fast create loading
1698
1699jQuery(".econt_pdf_loading").off('click').on('click' , function(e){
1700  e.preventDefault();
1701  var href = jQuery(this).attr('href');
1702  window.open(href, '_blank');
1703});
1704
1705jQuery('body').off('click', '.econt_pdf_loading_form').on('click', '.econt_pdf_loading_form', function(e) {
1706  e.preventDefault();
1707  var href = jQuery(this).attr('href');
1708  if (href) {
1709    window.open(href, '_blank');
1710  }
1711});
1712
1713//calculate shipping cost on updated_cart_totals event
1714jQuery('body').on('update_checkout', function(event, trigerring){
1715    if(econt_php_vars.isCheckout){
1716      var econt_door_town =  jQuery("#econt_door_town").val();
1717      var econt_door_postcode = jQuery("#econt_door_postcode").val();
1718      var econt_offices_town =  jQuery("#econt_offices_town").val();
1719      var econt_offices_postcode = jQuery("#econt_offices_postcode").val();
1720      var econt_machines_town =  jQuery("#econt_machines_town").val();
1721      var econt_machines_postcode = jQuery("#econt_machines_postcode").val();
1722      if((econt_door_town && econt_door_postcode) || (econt_offices_town && econt_offices_postcode) || (econt_machines_town && econt_machines_postcode) ){
1723        if(trigerring != 'calculate_loading'){
1724          calculate_loading(); //calculate loading cost
1725        }
1726      }
1727    }
1728});
1729//end of calculate shipping cost on updated_cart_totals event
1730
1731//tracking colorbox modal 
1732$econt_aiaks = function econt_aiaks(action, loading_num){
1733  jQuery('#econtLoader').show();
1734  jQuery.ajax({
1735
1736        url: econt_php_vars.ajaxURL2,
1737        dataType: "json",
1738        
1739        data: {
1740        action: 'econt_handle_ajax',
1741        action2: action,
1742        loading_num: loading_num,
1743
1744        },
1745        type: 'POST',
1746
1747        success: function(data){
1748        jQuery('#econtLoader').hide();
1749            jQuery.colorbox({
1750              opacity:"0.6", 
1751              width: "600", 
1752              height: "500", 
1753              //href: data.url + '?' + result,
1754              html: data.html,
1755            });
1756        },
1757
1758
1759  });
1760}
1761//end of tracking colorbox modal
1762
1763//fast loading form colorbox modal 
1764$econt_flf = function econt_flf(order_id, el){
1765  jQuery('#econtLoader').show();
1766  $econt_flf_el = jQuery(el);
1767  jQuery.ajax({
1768
1769        url: econt_php_vars.ajaxURL2,
1770        dataType: "json",
1771        
1772        data: {
1773        action: 'econt_handle_ajax',
1774        action2: 'fast_loading_form',
1775        order_id: order_id,
1776        },
1777        type: 'POST',
1778
1779        success: function(data){
1780        jQuery('#econtLoader').hide();
1781            jQuery.colorbox({
1782              opacity:"0.6", 
1783              width: "900", 
1784              height: "500",
1785              trapFocus: false, 
1786              //href: data.url + '?' + result,
1787              html: data.html,
1788            });
1789        },
1790
1791
1792  });
1793}
1794
1795$econt_add_loading_link = function econt_add_loading_link(loading_num, pdf_url){
1796  jQuery($econt_flf_el).prev().remove();
1797  jQuery($econt_flf_el).attr("href", pdf_url);
1798  jQuery($econt_flf_el).attr("target", '_blank');
1799  jQuery($econt_flf_el).removeClass("econt_fast_create_loading");
1800  jQuery($econt_flf_el).removeClass("econt_fast_create_loading_form");
1801  jQuery($econt_flf_el).removeAttr('onclick');
1802  jQuery($econt_flf_el).addClass("econt_pdf_loading_form");
1803  jQuery($econt_flf_el).text(loading_num);
1804  jQuery($econt_flf_el).prop('disabled', false);
1805
1806  //jQuery($econt_flf_el).prop('disabled', false);
1807  //jQuery($econt_flf_el).prop("onclick", null).off("click");
1808
1809  jQuery($econt_flf_el).after(' <button class="econt_wc_orders_list" href="" onclick="$econt_aiaks(\'loading_tracking\', ' + loading_num + ');return false;" target="_blank">' + econt_php_vars.trackingTxt + '</button><div id="econtLoader" style="display:none;"></div><!-- loading spinner -->');
1810}
1811//end of fast loading form colorbox modal
1812
1813//hide and show Checkout fields 
1814if(econt_php_vars.isCheckout){
1815  jQuery( function() {
1816
1817    // woocommerce_params is required to continue, ensure the object exists
1818    if ( typeof woocommerce_params === 'undefined' ) {
1819      return false;
1820    }
1821
1822    jQuery(document).on( 'change', '#shipping_method input[type="radio"]', function() {
1823      econtCheckoutFieldsShowHide(this.value);
1824    });
1825
1826    //for MrejaNet change of shipping methods (Econt and Speedy) snippet
1827    jQuery('input[name=mrejanet_shipping_method]').on('change', function(){
1828      econtCheckoutFieldsShowHide(this.value);
1829    });
1830
1831    jQuery( 'body' ).on( 'updated_checkout', function() {
1832      var shipping_method_radio = jQuery('#shipping_method input[type="radio"]:checked').val();
1833      var shipping_method_hidden = jQuery('input[name="shipping_method[0]"]').val();
1834      if(typeof shipping_method_radio === 'undefined'){
1835        econtCheckoutFieldsShowHide(shipping_method_hidden);
1836      }else{
1837        econtCheckoutFieldsShowHide(shipping_method_radio);
1838      }
1839    });
1840
1841    function econtCheckoutFieldsShowHide(shipping_method_name){
1842      jQuery('.econt_dynamic_fields').toggleClass('econt_hide', shipping_method_name == 'econt_shipping_method');
1843      jQuery('#econt_custom_checkout_field, #econt_user_checkout_field').toggleClass('econt_hide', shipping_method_name != 'econt_shipping_method');
1844    }
1845
1846  });
1847}
1848//end of show and hide Checout fields
1849
1850//set priority time
1851jQuery('#econt_priority_time_type').on('change', function () {
1852 
1853  var hour = jQuery('#econt_priority_time_hour').val();
1854
1855  var html = '<option value="10">10</option>';
1856  html += '<option value="11">11</option>';
1857  html += '<option value="12">12</option>';
1858  html += '<option value="13">13</option>';
1859  html += '<option value="14">14</option>';
1860  html += '<option value="15">15</option>';
1861  html += '<option value="16">16</option>';
1862  html += '<option value="17">17</option>';
1863
1864  if(this.value == 'BEFORE'){
1865    html += '<option value="18">18</option>';
1866  } else if (this.value == 'IN') {
1867    html = '<option value="9">9</option>' + html + '<option value="18">18</option>';
1868  }
1868 else if (this.value == 'AFTER') {
1869    html = '<option value="9">9</option>' + html;
1870  }
1871
1872  jQuery('#econt_priority_time_hour').html('<option value="">' + econt_php_vars.pleaseSelectText +'</option>' + html);
1873
1874  if( jQuery("#econt_priority_time_hour option[value='" + hour + "']").length > 0 ) {
1875    jQuery('#econt_priority_time_hour').val(hour).attr('selected', 'selected');
1876  }
1877
1878});
1879
1880//
1881
1882
1883//OpenLayer maps offices
1884function load_map(markers, type) {
1885  // Array of Icon features
1886  var iconFeatures=[];
1887  for (var i = 0; i < markers.length; i++) {
1888    var data = markers[i];
1889    var iconFeature = new ol.Feature({
1890      type: 'click',
1891      data: data,
1892      geometry: new ol.geom.Point(ol.proj.transform([data.lng, data.lat], 'EPSG:4326', 'EPSG:3857')),
1893    });
1894
1895    iconFeatures.push(iconFeature);
1896  }
1897
1898  var vectorSource = new ol.source.Vector({
1899    features: iconFeatures
1900  });
1901
1902  // Custom image for marker
1903  var iconStyle = new ol.style.Style({
1904      image: new ol.style.Icon({
1905        anchor: [0.5, 0.5],
1906        anchorXUnits: 'fraction',
1907        anchorYUnits: 'fraction',
1908        //src: './map-pin.png',
1909        src: econt_php_vars.openLayersMapsOfficeIcon,
1910        scale: 1.15
1911        })
1912  });
1913    
1914  var vectorLayer = new ol.layer.Vector({
1915    source: vectorSource,
1916    style: iconStyle,
1917    updateWhileAnimating: true,
1918    updateWhileInteracting: true,
1919  });
1920  // Create our initial map view
1921  var mapCenter = ol.proj.fromLonLat([markers[0].lng, markers[0].lat]);
1922  var view = new ol.View({
1923    center: mapCenter,
1924    maxZoom: 19,
1925    zoom: 12
1926  });
1927
1928  // Now create our map
1929  var map = new ol.Map({
1930    target: 'econt_' + type + 's_map', //id of html element to display map in
1931    view: view,
1932    layers: [
1933      new ol.layer.Tile({
1934        source: new ol.source.OSM(),
1935      }),
1936    ],
1937    loadTilesWhileAnimating: true,
1938  });
1939map.addLayer(vectorLayer);
1940  var popup = new ol.Overlay.Popup();
1941  map.addOverlay(popup);
1942
1943  // Add an event handler for when someone clicks on a marker
1944  map.on('singleclick', function(evt) {
1945      // Hide existing popup and reset it's offset
1946      popup.hide();
1947      popup.setOffset([0, 0]);
1948
1949      // Attempt to find a feature in one of the visible vector layers
1950      var feature = map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
1951          return feature;
1952      });
1953
1954      if (feature) {
1955          var coord = feature.getGeometry().getCoordinates();
1956          var props = feature.getProperties();
1957          var info = '<div style="width:200px; margin-top:3px; color:black; font-weight:600; font-size:12px">' + props.data.description + '</div>';
1958          // Offset the popup so it points at the middle of the marker not the tip
1959          //popup.setOffset([0, -22]);
1960          popup.show(coord, info);
1961          jQuery('#econt_' + type + 's').val(props.data.id);
1962          jQuery('#econt_' + type + 's').trigger('change.select2');
1963          localStorageUpdate(props.data, 'econt_' + type + '_' + type + 's_selected');
1964      }
1965  });
1966
1967  // Add an event handler for when someone hovers over a marker
1968  // This changes the cursor to a pointer
1969  map.on("pointermove", function (evt) {
1970      var hit = map.forEachFeatureAtPixel(evt.pixel, function(feature, layer) {
1971          return true;
1972      }); 
1973      if (hit) {
1974          this.getTargetElement().style.cursor = 'pointer';
1975      } else {
1976          this.getTargetElement().style.cursor = '';
1977      }
1978  });
1979}
1980//end of OpenLayer maps offices
1981
1982
1983//user shipping fields
1984jQuery("#econt_user_checkout_field").click(function(e){
1985  e.preventDefault();
1986    jQuery('#econt_user_checkout_field').hide();
1987    jQuery('.econt_office_locator_map').hide();
1988    jQuery('#econt_custom_checkout_field').slideDown();
1989    jQuery('#econt_user_address').val('0');
1990    if(Object.hasOwnProperty('hasOwn') && Object.hasOwn($econt_local_storage, 'econt_shipping_to')){
1991      if($('#econt_shipping_to_buttons_DOOR').length == 0) {
1992        jQuery('#econt_shipping_to').val($econt_local_storage.econt_shipping_to).trigger('change');
1993      }else{
1994        jQuery('#econt_shipping_to_buttons_' + $econt_local_storage.econt_shipping_to).attr('checked', true).trigger('change');
1995        
1996      }
1997    }
1998
1999});
2000
2001jQuery(function(){
2002  if(econt_php_vars.userAddress == '1' && econt_php_vars.isCheckout){
2003    jQuery('#econt_custom_checkout_field').hide();
2004    calculate_loading();
2005  }
2006});
2007
2008jQuery('input[name=econt_shipping_to_buttons]').on('change', function () {
2009  jQuery('#econt_shipping_to').val(this.value).trigger('change');
2010});
2011
2012$.fn.extend({
2013        donetyping: function(callback,timeout){
2014            timeout = timeout || 1e3; // 1 second default timeout
2015            var timeoutReference,
2016                doneTyping = function(el){
2017                    if (!timeoutReference) return;
2018                    timeoutReference = null;
2019                    callback.call(el);
2020                };
2021            return this.each(function(i,el){
2022                var $el = $(el);
2023                // Chrome Fix (Use keyup over keypress to detect backspace)
2024                // thank you @palerdot
2025                $el.is(':input') && $el.on('keyup keypress paste',function(e){
2026                    // This catches the backspace button in chrome, but also prevents
2027                    // the event from triggering too preemptively. Without this line,
2028                    // using tab/shift+tab will make the focused element fire the callback.
2029                    if (e.type=='keyup' && e.keyCode!=8) return;
2030                    
2031                    // Check if timeout has been set. If it has, "reset" the clock and
2032                    // start over again.
2033                    if (timeoutReference) clearTimeout(timeoutReference);
2034                    timeoutReference = setTimeout(function(){
2035                        // if we made it here, our timeout has elapsed. Fire the
2036                        // callback
2037                        doneTyping(el);
2038                    }, timeout);
2039                }).on('blur',function(){
2040                    // If we can, fire the event since we're leaving the field
2041                    doneTyping(el);
2042                });
2043            });
2044        }
2045 });
2046
2047
2048$('#econt_door_street_num, #econt_door_street_bl, #econt_door_street_vh, #econt_door_street_et, #econt_door_street_ap, #econt_door_other, #econt_door_street_intl, #econt_door_quarter_intl').donetyping(function(e){
2049  var id = $(this).attr('id');
2050  var value = $(this).val();
2051  localStorageUpdate(value,id);
2052});
2053
2054function localStorageUpdate(data, name){
2055  //console.log('localStorageUpdate econt_php_vars.localStorage', econt_php_vars.localStorage);
2056  if(econt_php_vars.localStorage != 1){
2057    return false;
2058  }
2059  var econt = localStorage.econt ? JSON.parse(localStorage.econt) : new Object;
2060  econt[name] = data;
2061  $econt_local_storage = econt;
2062  localStorage.setItem('econt', JSON.stringify(econt));
2063  return econt;
2064}
2065
2066
2067
2068});
2069
2070
2071
2072
2073 

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.