PageSourceSearch

https://www.patmosrentacar.com/assets/js/webapp.js

js patmosrentacar.com collected 2026-09-28 17:35:49 UTC 65,143 bytes, 1,852 lines download raw bytes

1var result = 0;
2$(window).on("load", function() {
3  $('[data-toggle="tooltip"]').tooltip({
4    html: true
5  });
6  if ($("#mapPoint").length) { 
7    var $lat = $("#mapPoint").data('lat');
8    var $lng = $("#mapPoint").data('lng');
9    var pos = {
10              lat: $lat,
11              lng: $lng
12            };
13    bounds  = new google.maps.LatLngBounds();
14    loc = new google.maps.LatLng($lat, $lng);
15    bounds.extend(loc);
16    mapPoint = new google.maps.Map(document.getElementById('mapPoint'), {
17        center: pos ,
18        zoom: 12
19      });
20     mapPoint.panToBounds(bounds);
21
22   var marker = new google.maps.Marker({
23        map: mapPoint,
24        draggable: false
25    });
26    marker.setIcon(({
27        url: "https://app.workadu.com/assets/images/heart-map.png",
28        origin: new google.maps.Point(0, 0),
29        anchor: new google.maps.Point(10, 30)
30    }));
31    marker.setPosition(pos);
32  }
33
34  if ($("#mapZone").length) { 
35    var polygons =  eval('[' + $("#mapZone").data('polygon') + ']');
36    
37     bounds  = new google.maps.LatLngBounds();
38     mapZone = new google.maps.Map(document.getElementById('mapZone'), {
39          zoom: 11,
40          mapTypeId: 'terrain'
41        });
42
43     locZone = [];
44      // preload rest Zones polygons -------------------------
45      polygons.forEach(function(loadPath_str) {
46          var loadPath = eval(loadPath_str);
47         loadPath.forEach(function(path) {
48          locZone.push(new google.maps.LatLng(path.lat,path.lng));
49         });
50          newPolys = new google.maps.Polygon({
51              paths: loadPath,
52              editable: false,
53              draggable: false,
54              fillOpacity: 0.3,
55              strokeOpacity: 0.2,
56              fillColor: '#00e8bb'
57          });
58          newPolys.setMap(mapZone);
59      });
60      for (var i = 0; i < locZone.length; i++) {
61           bounds.extend(locZone[i]);
62      }
63      mapZone.fitBounds(bounds);
64  }
65
66
67  if ($(".owl-carousel").length) { 
68    $(".owl-carousel").each(function (index) {
69       var items = $(this).data('items') || 3;
70
71        $(this).owlCarousel({
72          animateOut: 'slideOutDown',
73          animateIn: 'flipInX',
74          nav:true,
75          navContainer:$(this),
76          items: items, 
77          margin: 10, 
78          navText: ['<i class="fa fa-angle-left fa-2x "  aria-hidden="true"></i>','<i class="fa fa-angle-right fa-2x" aria-hidden="true"></i>'],
79        responsive:{
80            0:{
81                items:1.2
82            },
83            600:{
84                items:1.2
85            },
86            1000:{
87                items:items
88            }
89        }
90       });
91    });
92  };
93
94  $(".owl-carousel").on('initialized.owl.carousel changed.owl.carousel refreshed.owl.carousel', function (event) {
95    if (!event.namespace) return;
96    var carousel = event.relatedTarget,
97        element = event.target,
98        current = carousel.current();
99    $('.owl-next', element).toggleClass('disabled', current === carousel.maximum());
100    $('.owl-prev', element).toggleClass('disabled', current === carousel.minimum());
101  });
102
103  var newDay = new Date();
104  var tomorrow = new Date();
105  tomorrow.setDate(newDay.getDate()+1);
106
107  $("#pickup_range").flatpickr({
108    altInput: true,
109    enableTime: true,
110    mode: "range",
111    allowInput:true,
112    minDate: "today",
113  });
114
115  $("#pickup_date_time").flatpickr({
116    altInput: true,
117    enableTime: true,
118
119  });
120
121  $("#pickup_date").flatpickr({
122    altInput: true,
123     minDate: "today"
124  });
125  // $('.flatpickr-input').prop('required', true);
126
127        var today = new Date();
128
129        today.setHours(today.getHours()+2);
130        dateToday = today.getFullYear()+'-'+today.getMonth()+1+'-'+today.getDate();
131         flatpickr('#pickup_range_no_time', {
132            // enableTime: true,
133            mode: "range",
134            minDate: "today",
135            //defaultDate: [newDay , tomorrow],
136
137            // allowInput:true
138            onChange: function (selectedDates) {
139                  var startDate = new Date(selectedDates[0]);
140                  var dd = (startDate.getDate() < 10 ? '0' : '') + startDate.getDate();
141                var MM = ((startDate.getMonth() + 1) < 10 ? '0' : '') + (startDate.getMonth() + 1);
142                var yyyy = startDate.getFullYear();
143
144               if (jQuery('#pickup_time').val() == '') {
145                  var startTime =  new Date();
146               } else {
147                 var startTime =  new Date (jQuery('#pickup_time').val());
148               }
149
150                var HH  = (startTime.getHours() < 10 ? '0' : '') + startTime.getHours();
151                var ii  = (startTime.getMinutes() < 10 ? '0' : '') + startTime.getMinutes();
152                  startDate = yyyy + "-" + MM  + "-" +dd + " " + HH + ":"+ ii;
153                jQuery("#pickup_datetime").val(startDate);
154                
155                var endDate = new Date(selectedDates[1]);
156                  var dd = (endDate.getDate() < 10 ? '0' : '') + endDate.getDate();
157                var MM = ((endDate.getMonth() + 1) < 10 ? '0' : '') + (endDate.getMonth() + 1);
158                var yyyy = endDate.getFullYear();
159
160                if (jQuery('#return_time').val() == '') {
161                  var  endTime =  new Date();
162               } else {
163                 var  endTime =  new Date (jQuery('#return_time').val());
164               }
165                var HH  = (endTime.getHours() < 10 ? '0' : '') + endTime.getHours();
166                var ii  = (endTime.getMinutes() < 10 ? '0' : '') + endTime.getMinutes();
167                  endDate = yyyy + "-" + MM  + "-" +dd + " " + HH + ":"+ ii;
168                jQuery("#return_datetime").val(endDate);
169              }
170        });
171
172 flatpickr('#pickup_time', {
173      enableTime: true,
174      noCalendar:true,
175      dateFormat:"H:i",
176      // defaultDate:"09:00" ,
177      time_24hr: true,
178       allowInput:true,
179      onChange: function (selectedDates) {
180            var startDate = new Date(selectedDates[0]);
181            var selectedDateString = jQuery('#pickup_datetime').val();
182            var selectedDateArr = selectedDateString.split(' ')[0]; //Get the params
183            var selectedDate = new Date(selectedDateArr);
184
185            var dd = (selectedDate.getDate() < 10 ? '0' : '') + selectedDate.getDate();
186          var MM = ((selectedDate.getMonth() + 1) < 10 ? '0' : '') + (selectedDate.getMonth() + 1);
187          var yyyy = selectedDate.getFullYear();
188          var HH  = (startDate.getHours() < 10 ? '0' : '') + startDate.getHours();
189          var ii  = (startDate.getMinutes() < 10 ? '0' : '') + startDate.getMinutes();
190            startDate = yyyy + "-" + MM  + "-" +dd + " " + HH + ":"+ ii;
191          jQuery("#pickup_datetime").val(startDate);
192          
193
194          var startDate = new Date(selectedDates[0]);
195          var selectedDateString = jQuery('#return_datetime').val();
196            var selectedDateArr = selectedDateString.split(' ')[0]; //Get the params
197            var selectedDate = new Date(selectedDateArr);
198
199            var dd = (selectedDate.getDate() < 10 ? '0' : '') + selectedDate.getDate();
200          var MM = ((selectedDate.getMonth() + 1) < 10 ? '0' : '') + (selectedDate.getMonth() + 1);
201          var yyyy = selectedDate.getFullYear();
202          var HH  = (startDate.getHours() < 10 ? '0' : '') + startDate.getHours();
203          var ii  = (startDate.getMinutes() < 10 ? '0' : '') + startDate.getMinutes();
204            startDate = yyyy + "-" + MM  + "-" +dd + " " + HH + ":"+ ii;
205          if (!isNaN(HH) && !isNaN(ii)) {
206              jQuery("#return_time").val(HH + ":" + ii);
207          }
208          jQuery("#return_datetime").val(startDate);
209        
210        }
211      // allowInput:true
212  });
213
214        flatpickr('#return_time', {
215            enableTime: true,
216            noCalendar:true,
217            dateFormat:"H:i",
218            time_24hr: true,
219             // defaultDate:"09:00",
220            onChange: function (selectedDates) {
221                var startDate = new Date(selectedDates[0]);
222                  var selectedDate = new Date (jQuery('#return_datetime').val());
223                  var dd = (selectedDate.getDate() < 10 ? '0' : '') + selectedDate.getDate();
224                var MM = ((selectedDate.getMonth() + 1) < 10 ? '0' : '') + (selectedDate.getMonth() + 1);
225                var yyyy = selectedDate.getFullYear();
226                var HH  = (startDate.getHours() < 10 ? '0' : '') + startDate.getHours();
227                var ii  = (startDate.getMinutes() < 10 ? '0' : '') + startDate.getMinutes();
228                  startDate = yyyy + "-" + MM  + "-" +dd + " " + HH + ":"+ ii;
229                if (!isNaN(HH) && !isNaN(ii)) {
230                    jQuery("#return_time").val(HH + ":" + ii);
231                }
232                jQuery("#return_datetime").val(startDate);
233              
234              }
235            // allowInput:true
236        });
237
238  $("#more-filters").on('click change', function(event) {
239      event.preventDefault();
240      $('.return-group').toggleClass('hidden');
241      $(this).find('span').toggleClass('hidden');
242
243  });
244
245  $(function(){
246    $('.carousel').carousel();
247  });
248  
249
250  var data = {};
251  $(document).on("click", ".select-dates", function(e) {
252    e.preventDefault();
253    var row    = $(this).data('id');
254    values = $('.'+row+' .service-book .select-dates').data('data');
255    var oldValue;
256    var rowTotal = 0;
257    var self = $(this);
258    var $routeUrl = app_url + '/webapp/spots' ;
259
260    if(this.tagName.toLowerCase() === 'a' && !self.hasClass('book-button')){
261
262      data = {
263        "id"            : row ,
264        "spots"         : values,
265        "start"         : self.data('start'),
266        "end"           : self.data('end'),
267        'language'      : self.data('language'),
268        'filters'       : $('.'+row+' .service-book .select-dates').data('filters'),
269        'extraFilters' : [],
270      };
271      $.ajax({url: app_url + '/webapp/modal_exists',
272        data: {'id': row},
273        success(response){
274          $("#filtersModal").removeClass("hidden");
275          if(!response.modalExists){
276            $.when(ajax1()).done(function(a1){
277              $('#selectDatesModal').modal('show');
278            });
279          }
280        }  
281      });
282    }else{
283        if(((!data.id)) || (data.id != row) && (row != undefined)){
284          data = {
285            "id"            : row ,
286            "spots"         : values,
287            "start"         : self.data('start'),
288            "end"           : self.data('end'),
289            'language'      : self.data('language'),
290            'filters'       : $('.'+row+' .service-book .select-dates').data('filters'),
291            'extraFilters' : [],
292          };
293        }else{
294            data.extraFilters = [$("input[name=adults]").val(), $("input[name=children]").val(), $("input[name=infants]").val()];
295        }
296      $("#filtersModal").addClass("hidden");
297      $.when(ajax1()).done(function(a1){
298        $('#selectDatesModal').modal('show');
299      });
300    }
301    function ajax1() {
302        return $.ajax({
303            url: $routeUrl ,
304            data: {myData:JSON.stringify(data)},
305            dataType:"json",
306            cache: false,
307            type: "POST",
308            success: function(json) {
309                $("#slots").html('<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>')
310                console.log('-----------Success-----------');
311                if (json.say == "ok") {
312                   $('#slots').html(json.view);
313                   var total = 0;
314                   var next = false;
315                   var totalNext = 0;
316                   var currency = $('.total-price-modal').first().text();
317                   $("#slots .timeCell").on("click", function() {
318                      var dateValue = $(this).data('date');
319                      var rowIndex = $('.dateRow').index($(this).closest('.dateRow'));
320                      var thisDay =  $('.dateRow').eq(rowIndex);
321                      var initialDate = thisDay.find('input[name="start"]').val();
322                      if ($(this).hasClass('ui-selectee')) {
323                        $(this).addClass("ui-selected");
324                        $("#slots .date-"+dateValue).find('.timeCell').removeClass("ui-selectee");
325                        $(this).next('.timeCell').addClass("ui-selectee");
326                        if ($(this).next('.timeCell').length == 0 ) {
327                          var nextDay =  $('.dateRow').eq(rowIndex + 1);
328                          oldValue = nextDay.find('input[name="start"]').val();
329                          nextDay.find('.timeCell').first().addClass("ui-selectee");
330                          nextDay.find('input[name="start"]').val(initialDate);
331                          oldDate = $(this).data('date');
332                          next = true;
333                        } else {
334                           if (next == true){
335                            // newTotal = parseFloat($('#total-'+ oldDate).val()); 
336                            total =  newTotal ;
337                            total =  $(this).data('value');
338                           } else {
339                             total =  $(this).data('value');
340
341                           }
342                           next = false;
343                        }
344
345                      } else {
346                         $("#slots").find('.timeCell').removeClass("ui-selected");
347                        $(this).addClass("ui-selected");
348                        $(this).next('.timeCell').addClass("ui-selectee");
349                        if (oldValue) {
350                           thisDay.find('input[name="start"]').val(oldValue);
351                        }
352                        next = false;
353
354                        if ($(this).next('.timeCell').length == 0 ) {
355                          var nextDay =  $('.dateRow').eq(rowIndex + 1);
356                          nextDay.find('.timeCell').first().addClass("ui-selectee");
357                          nextDay.find('input[name="start"]').val(initialDate);
358                          oldDate = $(this).data('date');
359                          next = true;
360                        }
361                        $('.total-price-modal ').text(''); 
362                        total =  $(this).data('value');
363                      }
364                      $('.btn-slot').prop('disabled', true); 
365
366                      $('.total-price-modal ').removeClass('hidden');
367                      
368                      $('#button-'+$(this).data("date")).prop("disabled", false);
369                      $('#no-charge').addClass('hidden');
370                      $('#no-charge-'+$(this).data("date")).removeClass('hidden');
371                      var slotsArray = [];
372                      var slotsNo = 0; 
373                      $('.ui-selected').each(function(e) {
374                        slotsNo = slotsNo + 1;
375                        slotsArray.push($(this).data('time'))
376                      });
377                      var self2 = $(this) ;
378                       newTotal = parseFloat(total);
379                      var data2 = {
380                            "id"            : data.id ,
381                            "spots"         : data.spots,
382                            "start"         : data.start,
383                            "end"           : data.end,
384                            'language'      : data.language,
385                            'filters'       : data.filters,
386                            'slotsNo'       : slotsNo,
387                            'rategroup'     : $(this).data('rate'),
388                            'slotsArray'    : slotsArray, 
389                            'total'         : newTotal
390                        };
391                       $.when(ajax2()).done(function(a1){});
392                       function ajax2() {
393                          $('.timeCell').each(function (e){
394                            $(this).addClass('no-click');
395                            $(this).prop('disabled', true);
396                          });
397
398                          return $.ajax({
399                              url: app_url + '/webapp/ajax/offers' ,
400                              data: {myData:JSON.stringify(data2)},
401                              dataType:"json",
402                              cache: false,
403                              type: "POST",
404                               success: function(json) { 
405                                $('#slots-'+self2.data("date")).val(JSON.stringify(slotsArray));
406                                $('#rategroup-id-'+self2.data("date")).val(json.rategroup);
407                                $('#slotValue-'+self2.data("date")).val(self2.data('encrypt-value'));
408                                if (json.appliedOffers) {
409                                  total = json.appliedOffers.new_value;
410                                  // $('#total-'+self.data("date")).val($appliedOffers );
411                                } else {
412                                  total = newTotal;
413                                }
414                                $('.btn-slot').prop('disabled', true); 
415                                $('#button-'+self2.data("date")).prop("disabled", false);
416                                if (total > 0) {
417                                    $('#total-price-'+self2.data("date")).text(currency + total);
418                                } else {
419                                   $('#no-charge-'+self2.data("date")).text('');
420                                }
421
422                                
423                                $('#total-'+self2.data("date")).val(total);
424                                $('.timeCell').each(function (e){
425                                  $(this).removeClass('no-click');
426                                  $(this).prop('disabled', false);
427                                });
428                            }
429                          });
430                        }
431                     
432                  });
433                }
434            },
435            error: function (request, status, error) {
436                console.log('-----------error-----------');
437                $('#selectDatesModal').modal('hide');
438            } 
439        });
440    }
441  });
442
443  $(document).on("click", ".no-auth", function(e) {
444    $this = $(this);
445    formelement = $this.closest("form");
446    target = $this.data('target');
447    e.preventDefault();
448
449
450    if ( formelement.length){
451      formelement.submit();
452      return;
453    }
454    
455    $('#selectDatesModal').modal('hide');
456   
457    $('#signinModal').modal('show');
458    if ($(this).hasClass('signin')) {
459      $('.login').trigger('click');
460     } else {
461        $('.register').trigger('click');
462     }
463  });
464
465  $('.show-signin-modal').on('click touchend',function(){
466    $('#signinModal').modal('show');
467  })
468
469  // Make a new search for next release date
470  $(document).on("click", ".service-book-next-release a", function(e) {
471      e.preventDefault();
472      startDate = $(this).data('start');
473      endDate   = $(this).data('end');
474      nextRelease = $(this).data('next-date');
475      var startParts = String(startDate).split(' ');
476      var endParts = String(endDate).split(' ');
477      var startDay = startParts[0];
478      var startTime = startParts[1] || '';
479      var endDay = endParts[0];
480      var endTime = endParts[1] || '';
481
482      $('#pickup_range').val(startDate + ' to ' + endDate);
483      $('#pickup_range_no_time').val(startDay + ' to ' + endDay);
484      $('#pickup_time').val(startTime);
485      $('#return_time').val(endTime);
486      $('#pickup_datetime').val(startDate);
487      $('#return_datetime').val(endDate);
488      $('#nextRelease').val(nextRelease);
489      // $('#group_id').val($(this).data('service-id'));
490      $('.booking-form form').submit();
491  });
492
493
494//Check page background scroll when a modal is open
495  if ($('#selectDatesModal').length){
496    $('#selectDatesModal').on('hidden.bs.modal', function(){
497      if ($('#signinModal').length){
498        if ($('#signinModal').hasClass('in')) {
499          $('body').addClass('modal-open');
500        } 
501      } else {
502         $('body').removeClass('modal-open');
503      }
504    });
505  };
506
507
508  $('.errorHandler').addClass('hidden');
509  $('.successHandler').addClass('hidden');
510  $(document).on("click", ".btn-login", function(e) {
511    e.preventDefault();
512    
513    var $routeUrl = app_url + '/login' ;
514    $.when(ajax1()).done(function(a1){
515       $('.btn-login').button('reset');
516    });
517    function ajax1() {
518        return $.ajax({
519            url: $routeUrl ,
520            data:  $('#login-form').serialize(),
521            cache: false,
522            type: "POST",
523            success: function(json) {
524                console.log('-----------logged in -----------');
525                if (json.say === "ok") {
526                   if (typeof formelement !== 'undefined' && formelement.length) {
527                     formelement.submit();
528                   } else if (typeof target !== 'undefined' && target != null ) {
529                      window.location.href = target;
530                   } else {
531                    location.reload();
532
533                   }
534                   delete target;
535                   $('#signinModal').modal('hide');
536                } else {
537                   $('.box-login .successHandler').addClass('hidden');
538                   $('.box-login .errorHandler').removeClass('hidden');
539                   $('.box-login #message-fail').html(json.message);
540                   $('.btn-login').button('reset');
541                }
542            },
543            error: function (request, status, error) {
544                console.log('-----------error-----------');
545
546                console.log(request);
547            } 
548        });
549    }
550  });
551
552
553
554   // Flatpickr prevents the first outside click while closing an open picker.
555   // Close it during capture so the same click can continue to submit the form.
556   document.addEventListener('click', function(event) {
557      var submitButton = $(event.target).closest('.booking-form button[type="submit"]')[0];
558      if (!submitButton) {
559        return;
560      }
561
562      $(submitButton.form).find('.flatpickr-input').each(function() {
563        if (this._flatpickr && this._flatpickr.isOpen) {
564          this._flatpickr.close();
565        }
566      });
567   }, true);
568
569   $('.btn:not(.add-row)').on('click touchend' , function() {
570      var $this = $(this);
571      $this.addClass('running');
572      $this.addClass('no-click');
573        setTimeout(function() {
574         // $this.button('reset');
575          $this.removeClass('running');
576         $this.removeClass('no-click');
577      }, 9000);
578    });
579
580
581  jQuery(document).on('click', '.control', function(event) {
582    event.preventDefault();
583    var amountControl = jQuery(this).siblings('.amount-control');
584    var calcPriceAmount = amountControl.data('calc');
585    var calcPrice = jQuery(this).siblings('.extras-price').find('span');
586    var currentVal = parseInt(amountControl.val(), 10);
587    var extra = amountControl.data('reflect');
588    var description = $("#row-"+extra).find('.extra-name').text();
589    var minamount = jQuery(this).data('minamount');
590    if (typeof minamount === undefined) {
591      minamount = false;
592    }
593
594    var maxamount = jQuery(this).data('maxamount');
595    if (typeof maxamount === undefined) {
596      maxamount = false;
597    }
598
599    if (jQuery(this).hasClass('minus-control') && (currentVal > 0)) {
600      amountControl.val(currentVal - 1);
601      amountControl.trigger('change');
602      extraTotal = (amountControl.val() * calcPriceAmount);
603      if ((minamount) && (extraTotal < minamount )) {
604        extraTotal = minamount;
605      }
606      if ((maxamount) && (extraTotal > maxamount )) {
607        extraTotal = maxamount;
608      }
609      addExtraLine(extra, calcPriceAmount, amountControl.val()+' x '+description , amountControl.val(), extraTotal);
610      if (amountControl.val() == 0 ){
611        $('#'+extra).remove();
612      } 
613     
614    } 
615
616    var maxvalue = jQuery(this).data('maxvalue');
617    if (typeof maxvalue === undefined || maxvalue === undefined) {
618      maxvalue = 10;
619    }
620  
621    if ((jQuery(this).hasClass('plus-control'))  && (currentVal < maxvalue)) {
622      amountControl.val(currentVal + 1);
623      amountControl.trigger('change');
624      extraTotal = (amountControl.val() * calcPriceAmount);
625       if ((minamount) && (extraTotal < minamount )) {
626          extraTotal = minamount;
627        }
628
629        if ((maxamount) && (extraTotal > maxamount )) {
630          extraTotal = maxamount;
631        }
632        if ($('#'+extra).length > 0 ){
633          $('#'+extra).remove();
634        } 
635        $('#extras-section').append('<div class="extra-item" id="'+extra+'""></div>');
636        addExtraLine(extra, calcPriceAmount, amountControl.val()+' x '+description, amountControl.val() , extraTotal);
637    }
638    addExtraToFom();
639  });
640
641  $(document).ready(function(){
642  jQuery(document).on('click touchend', '.btn-facebook', function(event, clickType) {
643     event.preventDefault();
644     var alias = $(this).data('alias');
645     FB.login(function(response){
646        if (response.authResponse) {
647          console.log('facebook loggedin');
648           facebookSignin(response.authResponse.accessToken, 'facebook', alias);
649           return 'success';
650            
651        }
652      }, {scope: 'email,public_profile', return_scopes: true});
653  });
654  });
655
656
657  jQuery(document).on('click', '.extra-switch, .extra-required', function(event, clickType) {
658    // event.preventDefault();
659    selectionTrigger($(this));
660  });
661
662  function selectionTrigger(element) {
663    var calcPriceAmount =element.data('calc');
664    calcPriceAmount = calcPriceAmount.toString();
665    var calcPrice = jQuery(element).siblings('.extras-price').find('span');
666    var currentVal = $(element).val();
667    var extra = $(element).data('reflect');
668    var old = parseFloat($('#initial-price').text());
669    var priceAfter = parseFloat($('.total-price .price-amount').text());
670    var priceType = $(element).data('pricetype');
671    var description = $("#row-"+extra).find('.extra-name').text();
672
673    var minamount = jQuery(element).data('minamount');
674    if (typeof minamount === undefined) {
675      minamount = false;
676    }
677
678    var maxamount = jQuery(element).data('maxamount');
679    if (typeof maxamount === undefined) {
680      maxamount = false;
681    }
682
683    var days = jQuery(element).data('days');
684    if (typeof days === undefined) {
685      days = 1;
686    }
687
688     if (($(element).prop("checked") == true) || ($(element).hasClass('extra-required'))) {
689       $('#extras-section').append('<div class="extra-item" id="'+extra+'""></div>');
690       if (calcPriceAmount.includes('%')) {
691          stringNumber = calcPriceAmount.substring(0, calcPriceAmount.lastIndexOf('%'));
692          amount = parseFloat(stringNumber);
693
694          if (priceType) {
695              extrasTotalAmount = priceAfter * (amount/100);
696            } else {
697              extrasTotalAmount = old * (amount/100);
698            }
699        
700          extrasTotalAmount =  extrasTotalAmount.toFixed(2);
701
702          if ((minamount) && (extrasTotalAmount < minamount)) {
703            extrasTotalAmount = minamount;
704          }
705
706          if ((maxamount) && (extrasTotalAmount > maxamount)) {
707             extrasTotalAmount = maxamount;
708          }
709          addExtraLine(extra, calcPriceAmount, description, 1, extrasTotalAmount, days,amount, priceType);
710       } else {
711          calcPriceAmount = parseFloat(calcPriceAmount).toFixed(2);
712           
713          if ((minamount) && (calcPriceAmount < minamount)) {
714            calcPriceAmount = minamount;
715          }
716
717          if ((maxamount) && (calcPriceAmount > maxamount)) {
718             calcPriceAmount = maxamount;
719          }
720
721          addExtraLine(extra, calcPriceAmount+currency, description, 1, calcPriceAmount, days);
722       }
723       
724    } else {
725      if (!$(element).hasClass('extra-required')) {
726        console.log('remove');
727        $('#'+extra).remove();
728           var netTotal = 0;
729           netTotal = cartCalulate(old);
730            $('.price-amount').text(netTotal+old);
731      } 
732    }
733    addExtraToFom();
734  }
735
736  jQuery(document).on('click', '#coupon_btn', function(event) {
737    event.preventDefault();
738    var extra = $('.extra-coupon').data('reflect');
739    var coupon = $('.extra-coupon').val();
740    var rategroupid = $('.extra-coupon').data('rategroup-id');
741     var old = parseFloat($('#initial-price').text());
742    var description = $("#row-"+extra).find('.extra-name').text();
743    extrasTotalAmount = old * (20/100);
744    $('#extras-section').append('<div class="extra-item" id="'+extra+'""></div>');
745    
746    return $.ajax({
747        url:  app_url +'/webapp/'+company_alias+'/offers/coupon',
748        data:  {"coupon": coupon, "rategroupId": rategroupid},
749        dataType:"json",
750        cache: false,
751        type: "POST",
752        success: function(json) {
753          if (json.value !== null) {
754              if (json.value.includes('%')) {
755                  stringNumber = json.value.substring(0, json.value.lastIndexOf('%'));
756                  amount = parseFloat(stringNumber);
757                  extrasTotalAmount = old * (amount/100);
758                  extrasTotalAmount =  extrasTotalAmount.toFixed(2);
759                  addExtraLine(extra, json.value, json.title+description, 1, extrasTotalAmount, 0);
760                  addExtraToFom();
761               } else {
762                  json.value = parseFloat(json.value).toFixed(2);
763                  extrasTotalAmount = old + parseFloat(json.value);
764                  addExtraLine(extra, json.value+currency, json.title+description, 1, json.value, 0);
765                  addExtraToFom();
766               }
767               $('#tags').val(json.title);
768
769            } else {
770              $('#'+extra).remove();
771               var netTotal = 0;
772               netTotal = cartCalulate(old);
773                $('.price-amount').text(netTotal+old);
774                $('#tags').val('');
775            }
776        },
777        error: function (request, status, error) {
778            console.log('-----------error-----------');
779            console.log(request);
780        } 
781      });
782
783 
784   
785});
786
787  // if ($('.extra-required').length > 0 ) {
788  //   console.log('clicked required');
789  //   if (!$('.extra-required').prop('disabled'))
790  //   {
791  //     selectionTrigger($('.extra-required'));
792  //     $('.extra-required').prop('disabled', true);
793  //     $('.extra-required').attr('checked','checked')
794  //   }
795  // }
796
797   if ($('.extra-switch').length > 0 ) {
798      $('.extra-switch').each(function (e){
799        if ($(this).prop('checked') && !$(this).hasClass('extra-required'))
800        {
801          selectionTrigger($(this));
802          $(this).attr('checked','checked');
803        } else {
804          if ($('.extra-required').length > 0 ) {
805            if (!$('.extra-required').prop('disabled'))
806              {
807                selectionTrigger($('.extra-required'));
808                $('.extra-required').prop('disabled', true);
809                $('.extra-required').attr('checked','checked')
810              }
811          }
812        }
813      });
814  }
815
816  // Process required add-ons (display_as 300) that show as "Included" - not switch-based
817  $('.extra-included.extra-required').each(function () {
818    selectionTrigger($(this));
819  });
820
821  function addExtraLine (extra, amount,  description, quantity, total, totaldays = 1, amountPercent=false, priceType=false) {
822    var html = $('<hr>\
823              <div class="row ">\
824                <span class="extra-amount hidden">' + quantity +'</span>\
825                <div class="col-md-8">\
826                  <div class="description">'+description+'</div>\
827                </div>\
828                <div class="col-md-4 text-right">\
829                  <strong>'+currency+ '<span class="extra-price" id="extra-price-'+extra+'" data-pricePercent="'+ amountPercent +'" data-priceType="'+priceType+'">'+total +'</span></strong>\
830                    </div>\
831                </div>');
832    var old = parseFloat($('#initial-price').text());
833   
834   
835    $('#'+extra).html(html);
836
837    var netTotal = cartCalulate(old);
838    $('.price-amount').text(netTotal+old);
839  }
840
841  function addExtraToFom() {
842      var extrasArr = {};
843      $('.extra-item').each(function (e){
844          var temp = {};
845          temp['description'] = $(this).find('.description').text();
846          temp['quantity'] = parseInt($(this).find('.extra-amount').text());
847          temp['price'] = parseFloat($(this).find('.extra-price').text());
848          extrasArr[$(this).attr('id')] = temp;
849      });
850      
851      $('#extras').val(JSON.stringify(extrasArr));
852      $('#total').val($('.price-amount').text());
853    }
854
855});
856
857function cartCalulate(old) {
858    var netTotal = 0;
859    var pricePercent = false;
860    $('.extra-price').each(function (e){
861        if ($(this).data('pricetype') != 201) {
862           netTotal = netTotal + parseFloat($(this).text());
863         } else {
864            pricePercent = $(this).data('pricepercent');
865            priceElement = $(this);
866         }
867    });
868    
869    if (pricePercent) {
870      priceElement.text((netTotal+old)*pricePercent/100);
871      netTotal = netTotal + (netTotal+old)*pricePercent/100;
872    } 
873    
874   return netTotal;
875}
876
877function attachSignin(element) {
878  console.log(element.id);
879  auth2.attachClickHandler(element, {},
880      function(googleUser) {
881        googleSignin(googleUser);
882      }, function(error) {
883        alert(JSON.stringify(error, undefined, 2));
884      });
885  }
886
887//Googe custom sign in callback
888function googleSignin(authResult) {
889
890  var authResponse = authResult.getAuthResponse();
891  var token = authResponse.access_token;
892  if (token) {
893    var alias = $('.btn-google').data('alias');
894    // var $routeUrl = 'https://reservit-staging.azurewebsites.net/login/google/callback' ;
895    var $routeUrl = app_url +'/login/google/callback' ;
896
897    console.log(token);
898    $.when(ajax1()).done(function(){
899        $('#signinModal').modal('hide');
900       $('.btn-google').button('reset');
901    });
902    function ajax1() {
903      return $.ajax({
904          url: $routeUrl ,
905          data:  {"token": token, "provider": 'google', "alias": alias},
906          dataType:"json",
907          cache: false,
908          crossDomain: true,
909          type: "GET",
910          success: function(json) {
911            console.log('-----------logged in -----------');
912             console.log('-----------'+ google +' -----------');
913            if (json.say == "ok") {
914              if (typeof formelement !== 'undefined' && formelement.length) {
915                     formelement.submit();
916                  } else if (typeof target !== 'undefined' && target != null ) {
917                    window.location.href = target;
918                 } else {
919                    location.reload();
920                   }
921               delete target;
922              
923            } else {
924              $('.errorHandler').removeClass('hidden');
925              $('#error-message').html(json.message);
926              $('.btn-login').button('reset');
927            }
928          },
929          error: function (request, status, error) {
930              console.log('-----------error-----------');
931
932              console.log(request);
933          } 
934      });
935    };
936  }
937};
938
939//Googe custom sign in callback
940function facebookSignin(token, provider, alias) {
941  // var $routeUrl = 'https://reservit-staging.azurewebsites.net/login/'+provider+'/callback' ;
942  var $routeUrl = app_url +'/login/'+provider+'/callback' ;
943
944  $.when(ajax1()).done(function(a1){
945     $('#signinModal').modal('hide');
946     $('.btn-login').button('reset');
947  });
948  function ajax1() {
949    return $.ajax({
950        url: $routeUrl ,
951        data:  {"token": token, "provider": provider, "alias": alias},
952        dataType:"json",
953        cache: false,
954        crossDomain: true,
955        type: "GET",
956        success: function(json) {
957          console.log('-----------logged in -----------');
958           console.log('-----------'+ provider +' -----------');
959          if (json.say == "ok") {
960            if (typeof formelement !== 'undefined' && formelement.length) {
961                 formelement.submit();
962             } else if (typeof target !== 'undefined' &&  target != null ) {
963                window.location.href = target;
964             } else {
965                location.reload();
966               }
967            delete target;
968            
969          } else {
970            $('.errorHandler').removeClass('hidden');
971            $('#error-message').html(json.message);
972            $('.btn-login').button('reset');
973          }
974        },
975        error: function (request, status, error) {
976            console.log('-----------error-----------');
977
978            console.log(request);
979        } 
980    });
981  };
982}
983
984// Login modal buttons functionality 
985  var el = $('.box-login');
986  if (getParameterByName('box').length) {
987    switch(getParameterByName('box')) {
988      case "register" :
989        el = $('.box-register');
990        break;
991      case "forgot" :
992        el = $('.box-forgot');
993        break;
994      default :
995        el = $('.box-login');
996        break;
997    }
998  }
999
1000  $('.forgot').on('click touchend', function() {
1001    $('.box-login').hide().removeClass("animated fadeOutRight");
1002    $('.box-forgot').show().addClass("animated fadeInLeft").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
1003      $(this).show().removeClass("animated fadeInLeft");
1004    });
1005  });
1006
1007  $('.register').on('click touchend', function() {
1008    $('.modal-box').hide().removeClass("animated fadeOutRight");
1009    $('.box-register').show().addClass("animated fadeInRight").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
1010      $(this).show().removeClass("animated fadeInRight");
1011
1012    });
1013  });
1014
1015
1016
1017
1018  $('.go-back,.go-signin').on('click touchend',function() {
1019    // hide all boxes
1020    $('.modal-box').hide().removeClass("animated fadeOutRight");
1021    //  show login box
1022    $('.box-login').show().addClass("animated fadeInRight").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
1023      $(this).show().removeClass("animated fadeInRight");
1024    });
1025  });
1026
1027
1028
1029  $('.terms').on('click touchend', function() {
1030      $('.box-login').hide();
1031      $('.box-terms').show().addClass("animated bounceInRight").on('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
1032        $(this).show().removeClass("animated bounceInRight");
1033
1034      });
1035  });
1036
1037
1038$('#forgot').on("click touchend", function (e) {
1039  e.preventDefault();
1040  var email = $('.box-forgot input[name="email"]').val();
1041  // get the url from the form
1042  var $routeUrl =  $(this).closest('form').attr('action');
1043
1044  $.when(ajax11()).done(function (a1) {
1045    $('.btn-login').button('reset');
1046  });
1047
1048  function ajax11() {
1049    return $.ajax({
1050      url: $routeUrl,
1051      data: {"email": email},
1052      dataType: "json",
1053      cache: false,
1054      type: "POST",
1055      success: function (response) {
1056        console.log('.........');
1057        $('.box-login .errorHandler').addClass('hidden');
1058        $('.box-login .successHandler').removeClass('hidden');
1059        $('.box-login #message-success').text(response.status);
1060      },error: function (response) {
1061            $('.box-login .successHandler').addClass('hidden');
1062            $('.box-login .errorHandler').removeClass('hidden');
1063
1064            if (response.status === 422 && response.responseJSON && response.responseJSON.message) {
1065                $('.box-login #message-fail').html(response.responseJSON.message);
1066            } else {
1067                $('.box-login #message-fail').text("An error occurred, please try again later.");
1068            }
1069        }
1070    });
1071  };
1072});
1073
1074//------------- end of login modal -------------------------
1075
1076//------------------------ START TRANSLATABLE ---------------------
1077$(document).on("click", ".translate-row", function(e) {
1078    e.preventDefault();
1079    row    = $(this).data('id');
1080    model  = $(this).data('model');
1081    field  = $(this).data('field');
1082    var company_id = $(this).data('company');
1083
1084    var data = {
1085        "id"            : row ,
1086        "model"         : model,
1087        "field"         : field,
1088        "company_id"    : company_id,
1089    };
1090    console.log(data);
1091
1092    var $routeUrl = app_url + '/webapp/tranlation' ;
1093    
1094    $.when(ajax1()).done(function(a1){
1095       $('#translateModal').modal('show');
1096    });
1097
1098    function ajax1() {
1099        return $.ajax({
1100            url: $routeUrl ,
1101            dataType: 'json',
1102            data: data,
1103            cache: false,
1104            type: "POST",
1105            success: function(json) {
1106                console.log('-----------Success-----------');
1107                if (json.say == "ok") {
1108                    $.each(json.tranlations, function(key, val) {
1109                        console.log('#translateModal input[name="'+key+'"]');
1110                        $('#translateModal input[name="'+key+'"]').val(val);
1111                        $('#translateModal input[name="'+key+'"]').attr('data-field', field);
1112                        $('#translateModal input[name="'+key+'"]').attr('data-model', model);
1113                        $('#translateModal input[name="'+key+'"]').attr('data-id', row);
1114                    });
1115                } else {
1116                    if (json.message == "100") {
1117                        // toastr.error("You should save it first in order to setup translations!");
1118                    }
1119                }
1120            },
1121            error: function (request, status, error) {
1122                console.log('-----------error-----------');
1123                $('#translateModal').modal('hide');
1124                console.log(request);
1125            } 
1126        });
1127    }
1128    
1129});
1130
1131$(document).on("click", "#translateModal .add-row", function(e) {
1132    e.preventDefault();
1133    var translations = {};
1134    var field;
1135    var model;
1136    var id;
1137    $('#translateModal input').each(function(obj) {
1138        translations[$(this).attr('name')]=$(this).val();
1139        field = $(this).data('field');
1140        model = $(this).data('model');
1141        id     = $(this).data('id');
1142    });
1143
1144    var data = {
1145        "field"         : field,
1146        "translations"  : translations,
1147        "model"         : model,
1148        "id"            : id,
1149    };
1150    // console.log(rategroups);
1151    var $routeUrl = app_url + '/user/settranlations' ;
1152    
1153    $.when(ajax1()).done(function(a1){
1154      
1155    });
1156
1157    function ajax1() {
1158        return $.ajax({
1159            url: $routeUrl ,
1160            dataType: 'json',
1161            data: data,
1162            cache: false,
1163            type: "POST",
1164            success: function(json) {
1165                console.log('-----------Success-----------');
1166                if (json.say == "ok") {
1167                    $('#translateModal').modal('hide');
1168                }
1169            },
1170
1171            error: function (request, status, error) {
1172                console.log('-----------error-----------');
1173                console.log(request);
1174            } 
1175        });
1176    }
1177});
1178
1179//----------------------------------------------------
1180
1181$(".zone-switch").click( function() {
1182    $('#zone').toggleClass("hidden");
1183});
1184
1185$(".new-service-switch").click( function() {
1186    $('#new-service').toggleClass("hidden");
1187    $('#select-service').toggleClass('hidden');
1188    if ($('input[name="prediction-input"').prop('required') == false) {
1189       $('.search-select').prop('required',false); 
1190      $('input[name="title"').prop('required',true); 
1191      $('input[name="prediction-input"').prop('required',true); 
1192      $('input[name="newService"').val('true'); 
1193    } else {
1194      $('.search-select').prop('required',true); 
1195       $('input[name="title"').prop('required',false); 
1196       $('input[name="prediction-input"').prop('required',false); 
1197       $('input[name="newService"').val('false');
1198    }
1199
1200});
1201
1202
1203$("#serviceID").on("change click", function(e){
1204  var href = app_url + '/webapp/'+company_alias+'/service/id/'+$(this).val()+'/l/'+language;
1205  $('#selected-service a').attr("href", href);
1206  $('#selected-service').removeClass('hidden');
1207
1208});
1209//--------- editable attributes
1210$(function() {
1211    //defaults
1212    var $routeUrl = app_url;
1213    var routeUrl = $routeUrl + '/provider/service/attributes/update';
1214    console.log(routeUrl);
1215    if (($('.editableAttributes').length) ||  ($('.assignOrders').length)) {
1216        $.fn.editable.defaults.url = routeUrl;
1217        var empty = $('.editableAttributes').data('empty');
1218        //editables
1219        $('.editableAttributes').editable({
1220            url: routeUrl,
1221            emptytext: empty, 
1222        });
1223    }
1224});
1225// ----------------------------
1226
1227
1228//  Pricing actions at add listing process
1229$('#interval-radio').on("change click ", function(e) {
1230    $('#add-minutes').removeClass('hidden');
1231});
1232$('#daily-radio').on("change click ", function(e) {
1233    $('#add-minutes').addClass('hidden');
1234});
1235
1236$(function() {
1237  if ($("#select-days").length) {
1238      _selectRange = false;
1239      _deselectQueue = [];
1240      $("#select-days").selectable({
1241         filter: ".daysCell",
1242         cancel: "a,.switch",
1243         disabled: false,
1244         lasso: {
1245            border: '1px solid #3498db',
1246            backgroundColor: 'rgba(52, 152, 219, 0.2)',
1247        },
1248        selecting: function (event, ui) {
1249            if (event.detail == 0) {
1250                _selectRange = true;
1251                return true;
1252            }
1253            if ($(ui.selecting).hasClass('ui-selected')) {
1254                _deselectQueue.push(ui.selecting);
1255            }
1256        },
1257        unselecting: function (event, ui) {
1258            $(ui.unselecting).addClass('ui-selected');
1259        },
1260        stop: function () {
1261            if (!_selectRange) {
1262                console.log(_deselectQueue);
1263                $.each(_deselectQueue, function (ix, de) {
1264                    $(de)
1265                        .removeClass('ui-selecting')
1266                        .removeClass('ui-selected');
1267                });
1268            }
1269            _selectRange = false;
1270            _deselectQueue = [];
1271        }   
1272    });
1273  };
1274});
1275
1276$('#out-of-hours-switch').on("change click", function(e) {
1277    // e.preventDefault();
1278    $('#out-of-hours').toggleClass('hidden');
1279
1280});
1281
1282$(document).on("selectablestop", "#select-days", function(event, ui) {
1283    var interval = $('#inteval_value').val();
1284    var target   = $('.add-row').data('route');
1285    var route    = $(this).data('target');
1286    if (!interval>0) {
1287         $('#inteval_value').val(60);
1288        interval = 60;
1289    }
1290    $('#select-days').selectable( "option", "disabled", false);
1291    $("input[name='providerScheduleToggle']").attr('checked','checked');
1292
1293    var data = {
1294        "interval": interval,
1295    };
1296    var $routeUrl = app_url + '/provider/services/timecuncks';
1297    $.when(ajax1()).done(function(a1){
1298     
1299    });
1300    function ajax1() {
1301        return $.ajax({
1302            url: $routeUrl ,
1303            dataType: 'json',
1304            data: data,
1305            cache: false,
1306            async:false,
1307            type: "POST",
1308            success: function(json) {
1309                console.log('-----------Success----------')
1310                console.log(json.timeShedule);
1311                var timeChunks = json.timeShedule;
1312                var index;
1313                var a = timeChunks['morning'];
1314                var appendDiv;
1315                $('#morning').html('');
1316                for (index = 0; index < a.length; ++index) {
1317                    appendDiv = '<div class="timeCell ui-selectee" data-timeValue="'+a[index]+'">'+a[index]+'</div>';
1318                    $('#morning').append(appendDiv);
1319                }
1320                a = timeChunks['noon'];
1321                $('#noon').html('');
1322                if (a !== undefined) {
1323                    for (index = 0; index < a.length; ++index) {
1324                        appendDiv = '<div class="timeCell ui-selectee" data-timeValue="'+a[index]+'">'+a[index]+'</div>';
1325                        $('#noon').append(appendDiv);
1326                    }
1327                }
1328               
1329                a = timeChunks['afternoon'];
1330                $('#afternoon').html('');
1331                if (a !== undefined) {
1332                    for (index = 0; index < a.length; ++index) {
1333                        appendDiv = '<div class="timeCell ui-selectee" data-timeValue="'+a[index]+'">'+a[index]+'</div>';
1334                        $('#afternoon').append(appendDiv);
1335                    }
1336                }
1337
1338                array = timeChunks['outofhours'];
1339                var i,j,temparray, chunckNo = 1,chunk = 6;
1340                if (array !== undefined) {
1341                    for (i=0,j=array.length; i<j; i+=chunk) {
1342                        temparray = array.slice(i,i+chunk);
1343                        $('#chunk'+chunckNo).html('');
1344                        a =  temparray;
1345                        for (index = 0; index < a.length; ++index) {
1346                            appendDiv = '<div class="timeCell ui-selectee" data-timeValue="'+a[index]+'">'+a[index]+'</div>';
1347                            $('#chunk'+chunckNo).append(appendDiv);
1348                        }
1349                        chunckNo++;
1350                    }
1351                }
1352                $('#timeSchedule').selectable( "option", "disabled", false );
1353                
1354            }
1355        });
1356    }
1357    $('#inteval_value').val(interval);
1358    $('#timeScheduleModal').modal('show');
1359    $('#timeScheduleModal').on('shown.bs.modal', function() {
1360        if (target == 'companyadmin/provider/pricelist/update') {
1361            $('#price-area').addClass("hidden");
1362            $('#enableday').removeClass("padd20t");
1363        } else {
1364            $('#price-area').removeClass("hidden");
1365            $('#enableday').addClass("padd20t");
1366            $('#price_value').focus();
1367        }
1368    });
1369});
1370
1371$("#timeSchedule .ui-widget-content").click( function() {
1372    $(this).toggleClass("ui-selected");
1373});
1374$("#rateTimeSchedule .ui-widget-content").click( function() {
1375    $(this).toggleClass("ui-selected");
1376});
1377
1378if ($("#timeSchedule").length) {
1379    _selectRange = false;
1380    _deselectQueue = [];
1381
1382    $("#timeSchedule").selectable({
1383         filter: ".timeCell",
1384         cancel: "a,.switch",
1385         disabled: false,
1386         lasso: {
1387            border: '1px solid #3498db',
1388            backgroundColor: 'rgba(52, 152, 219, 0.2)',
1389        },
1390        selecting: function (event, ui) {
1391            if (event.detail == 0) {
1392                _selectRange = true;
1393                return true;
1394            }
1395            if ($(ui.selecting).hasClass('ui-selected')) {
1396                _deselectQueue.push(ui.selecting);
1397            }
1398        },
1399        unselecting: function (event, ui) {
1400            $(ui.unselecting).addClass('ui-selected');
1401        },
1402        stop: function () {
1403            if (!_selectRange) {
1404                console.log(_deselectQueue);
1405                $.each(_deselectQueue, function (ix, de) {
1406                    $(de)
1407                        .removeClass('ui-selecting')
1408                        .removeClass('ui-selected');
1409                });
1410            }
1411            _selectRange = false;
1412            _deselectQueue = [];
1413        }   
1414    });
1415}
1416
1417$(document).on("click", "#timeScheduleModal .add-row", function(e) {
1418    e.preventDefault();
1419    var result = 0;
1420    var values = [];
1421    var validDays = [];
1422    var validTimes = [];
1423    var availability = [];
1424    var rategroups = [];
1425    var servicesIds = [];
1426    var actor    = $('#select-days').data('actor');
1427    if ($('#servicesIds').length) {
1428     var servicesIds = [$('#servicesIds').val()];
1429    } 
1430    var disableDays = $("input[name='enabledayToggle']").is(':checked');
1431    var days = $("#select-days");
1432    var interval = $("#inteval_value").val();
1433    var price = $("#price_value").val();
1434    var rateType = $("input[name='rate_type']:checked").val();
1435    var resources = $("#fleet").val();
1436    var service_id;
1437    var view =  $("input[name='view']").val();
1438
1439    $(".ui-selected", days).each(function() {
1440        validDays.push($(this).attr('data-day'));
1441        service_id = $(this).attr('data-service');
1442        rategroup_id = $(this).attr('data-rategroup')
1443    });
1444    
1445    $("#timeSchedule .ui-selected").each(function() {
1446        validTimes.push($(this).attr('data-timeValue'));
1447    });
1448     $("#rateTimeSchedule .ui-selected").each(function() {
1449        validTimes.push($(this).attr('data-timeValue'));
1450    });
1451
1452    var data = {
1453        "selectedDays"  : validDays,
1454        "selectedTimes" : validTimes,
1455        "interval"      : interval, 
1456        "price"         : price,
1457        "rateType"      : rateType,
1458        "resources"     : resources,
1459        "service_id"    : service_id,
1460        "rategroup_id"  : rategroup_id,
1461        'disable_days'  : disableDays,
1462        'servicesIds'   : servicesIds,
1463        'actor'         : actor,
1464        'view'          : view,
1465    };
1466 
1467    var $routeUrl = app_url + '/' + $(this).data('route');
1468    console.log($routeUrl);
1469    $.when(ajax1()).done(function(a1){
1470
1471    });
1472
1473    function ajax1() {
1474        return $.ajax({
1475            url: $routeUrl ,
1476            dataType: 'json',
1477            // contentType: "application/json",
1478            data: data,
1479            cache: false,
1480            type: "POST",
1481            success: function(json) {
1482                console.log('-----------Success-----------');
1483                if (json.say == "ok") {
1484                    $('#pricelist-updated').toggleClass('hidden');
1485                    $('#day-rates-reload').replaceWith(json.returnStatus.view);
1486                    $('[data-toggle="tooltip"]').tooltip({
1487                      html: true
1488                    });
1489                    _selectRange = false;
1490                    _deselectQueue = [];
1491                    $("#select-days").selectable({
1492                         filter: ".daysCell",
1493                         cancel: "a,.switch",
1494                         disabled: false,
1495                         lasso: {
1496                            border: '1px solid #3498db',
1497                            backgroundColor: 'rgba(52, 152, 219, 0.2)',
1498                        },
1499                        selecting: function (event, ui) {
1500                            if (event.detail == 0) {
1501                                _selectRange = true;
1502                                return true;
1503                            }
1504                            if ($(ui.selecting).hasClass('ui-selected')) {
1505                                _deselectQueue.push(ui.selecting);
1506                            }
1507                        },
1508                        unselecting: function (event, ui) {
1509                            $(ui.unselecting).addClass('ui-selected');
1510                        },
1511                        stop: function () {
1512                            if (!_selectRange) {
1513                                console.log(_deselectQueue);
1514                                $.each(_deselectQueue, function (ix, de) {
1515                                    $(de)
1516                                        .removeClass('ui-selecting')
1517                                        .removeClass('ui-selected');
1518                                });
1519                            }
1520                            _selectRange = false;
1521                            _deselectQueue = [];
1522                        }   
1523                    });
1524                }
1525            },
1526            error: function (request, status, error) {
1527                console.log('-----------error-----------');
1528                console.log(request);
1529            } 
1530        });
1531    }
1532    $('#timeScheduleModal').modal('hide');
1533
1534});
1535
1536$('#enabledayToggle').on("change click ", function(e) {
1537    $('#price_value').toggleClass('hidden');
1538    $('#timeSchedule').toggleClass('hidden');
1539    $('#rateExplanation').toggleClass('hidden');
1540});
1541
1542$( document ).ready(function() {
1543       if ( $('.editableRateMM').length ) {
1544        var route = app_url;
1545        $('.editableRateMM').editable({
1546            url: route + '/provider/service/mm/update'
1547        });
1548    }
1549
1550  var cookie = getCookie('workadu-webapp'+webapp);
1551   if (cookie != 1) {
1552      setTimeout(function () {
1553          $("#cookieConsent").fadeIn(200);
1554       }, 4000);
1555    }
1556    $("#closeCookieConsent, .cookieConsentOK").click(function() {
1557        $("#cookieConsent").fadeOut(200);
1558        var cookie_string ='';
1559        var expiration_date = new Date();
1560        expiration_date.setFullYear(expiration_date.getFullYear()+1);
1561        cookie_string = 'workadu-webapp' + webapp + '=1; path=/; expires='+ expiration_date.toUTCString();
1562        document.cookie = cookie_string;
1563    }); 
1564  });
1565
1566  $('.extra-switch').on('click', function(){
1567    $('#selectedExtras').val($('#selectedExtras').val() + ','+ $(this).data('reflect'));
1568  });
1569
1570  if ($('.search-select').length) {
1571    $(".search-select").select2({
1572        
1573    });
1574}
1575
1576
1577// --------------------------------------
1578
1579// Drop down list box dynamicaly loaded 
1580$(document).on("change", "#categoryId", function(e) {
1581    e.preventDefault();
1582   $('#serviceID').addClass("disabled");
1583    var id = $(this).val();
1584    // console.log(rategroups);
1585    var $routeUrl = app_url + '/'+company_alias+'/user/get-services' ;
1586    
1587    $.when(ajax1()).done(function(a1){
1588      if (id != '' ) {
1589        $('#add-new-service').removeClass('hidden');
1590      }
1591    });
1592
1593    function ajax1() {
1594        return $.ajax({
1595            url: $routeUrl ,
1596            dataType: 'json',
1597            data: {'id' : id},
1598            cache: false,
1599            type: "POST",
1600            success: function(json) {
1601                console.log('-----------Success subelement-----------');
1602                if (json.say == "ok") {
1603                    console.log(json.options);
1604                    $('#serviceID').select2('destroy').empty().select2({data: json.options });
1605                    $('#serviceID').removeClass("disabled")
1606                    var href = app_url + '/webapp/'+company_alias+'/service/id/'+json.options[0].id+'/l/'+language;
1607                    $('#selected-service a').attr("href", href);
1608                } else {
1609                   $('#serviceID').select2('destroy').empty().select2();
1610                    $('#serviceID').addClass('disabled');
1611                }
1612
1613            },
1614            error: function (request, status, error) {
1615                console.log('-----------error-----------');
1616                console.log(request);
1617            } 
1618        });
1619    }
1620});
1621// ------------------------------
1622
1623jQuery('#my-awesome-dropzone').each(function(index, el) {
1624    $("div#my-awesome-dropzone").dropzone();
1625});
1626
1627
1628
1629$('.add-section').on('click touchend', function(e) {
1630     e.preventDefault();
1631     var id = $(this).data('id');
1632     var type = $(this).data('type');
1633     var pos = $(this).data('pos');
1634     console.log('#'+type+'-after-'+id);
1635     $('#'+type+'-'+pos+'-'+id).toggleClass('hidden');
1636  });
1637
1638$('.editable-refresh .close').on('click touchend', function(e) {
1639     e.preventDefault();
1640     $(this).parent().toggleClass('hidden');
1641});
1642
1643// Lightbox modal js 
1644function openModal() {
1645  document.getElementById('lightbox').style.display = "block";
1646}
1647
1648function closeModal() {
1649  document.getElementById('lightbox').style.display = "none";
1650}
1651if ($('.mySlides').length) {
1652  var slideIndex = 1;
1653  showSlides(slideIndex);
1654}
1655
1656function plusSlides(n) {
1657  showSlides(slideIndex += n);
1658}
1659
1660function currentSlide(n) {
1661  showSlides(slideIndex = n);
1662}
1663
1664$('a[data-toggle="collapse"]').on('click touchend', function(e) {
1665    e.preventDefault();
1666    target = $(this).data('target');
1667    $('#'+target).toggleClass('in');
1668});
1669
1670function showSlides(n) {
1671  var i;
1672  var className = "mySlides";
1673  var slides = document.getElementsByClassName(className);
1674  var dots = document.getElementsByClassName("demo");
1675  var captionText = document.getElementById("caption");
1676  if (n > slides.length) {slideIndex = 1}
1677  if (n < 1) {slideIndex = slides.length}
1678  for (i = 0; i < slides.length; i++) {
1679    slides[i].style.display = "none";
1680  }
1681
1682  for (i = 0; i < dots.length; i++) {
1683    dots[i].className = dots[i].className.replace(" active", "");
1684  }
1685  slides[slideIndex-1].style.display = "block";
1686  if (dots[slideIndex-1] !== undefined) {
1687    dots[slideIndex-1].className += " active";
1688  }
1689  //captionText.innerHTML = dots[slideIndex-1].alt;
1690}
1691
1692//------------end of lightbox
1693  //function to return the querystring parameter with a given name.
1694  function getParameterByName() {
1695    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
1696    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search);
1697    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
1698  };
1699
1700
1701
1702
1703//Credit card 
1704
1705$('#cardNumber').on('keyup', function(event) {
1706  var cardNumber = $(this).val();
1707  var cardType = detectCardType(cardNumber);
1708  if (cardType !== undefined) {
1709    if (cardType == "visa") {
1710       $('#cardRight').removeAttr('class');
1711       $('#cardRight').attr('class', "fa fa-cc-visa card-right");
1712       cardType = 'CB_VISA_MASTERCARD';
1713    } else if(cardType == "mastercard") {
1714       $('#cardRight').removeAttr('class');
1715       $('#cardRight').attr('class', "fa fa-cc-mastercard card-right");
1716       cardType = 'CB_VISA_MASTERCARD';
1717    }else if(cardType == "amex") {
1718         $('#cardRight').removeAttr('class');
1719       $('#cardRight').attr('class', "fa fa-cc-amex card-right");
1720       cardType = 'CB_VISA_MASTERCARD';
1721     }else if(cardType == "diners") {
1722         $('#cardRight').removeAttr('class');
1723       $('#cardRight').attr('class', "fa fa-cc-diners-club card-right");
1724       cardType = 'DINERS';
1725    }else if(cardType == "discover") {
1726      $('#cardRight').removeAttr('class');
1727       $('#cardRight').attr('class', "fa fa-cc-discover card-right");
1728       cardType = 'CB_VISA_MASTERCARD';
1729     }else if(cardType == "jcb") {
1730      $('#cardRight').removeAttr('class');
1731      $('#cardRight').attr('class', "fa fa-cc-jcb card-right");
1732      cardType = 'CB_VISA_MASTERCARD';
1733    } else {
1734       $('#cardRight').removeAttr('class');
1735      $('#cardRight').attr('class', "fa fa-cc card-right");
1736      cardType = 'CB_VISA_MASTERCARD';
1737    }
1738    $('.card-right').removeClass('hidden');
1739  } else {
1740    $('.card-right').addClass('hidden');
1741  }
1742  console.log(cardType);
1743});
1744
1745$('#cc-expDate').on('keyup', function(event) {
1746  $('#expDate').val($(this).val().replace('/', ''));
1747});
1748
1749$('#cardLinkButton').on('click touchend', function(e){
1750    var $routeUrl = window.location.origin  + '/webapp/cardlink';
1751   $('#payment-form').attr('action', $routeUrl).submit();
1752});
1753
1754$('#winbankButton').on('click touchend', function(e){
1755   // var apiurl = $('#winbankURL').val();
1756   var paymethod = $('input[name="payMethod"]').val();
1757   // $('#digest') = 
1758    var $routeUrl = app_url + '/webapp/winbank' ;
1759   $('#payment-form').attr('action', $routeUrl).submit();
1760
1761});
1762
1763$('#ethnikiButton').on('click touchend', function(e){
1764  var paymethod = $('input[name="payMethod"]').val();
1765   var $routeUrl = app_url + '/webapp/ethniki' ;
1766  $('#payment-form').attr('action', $routeUrl).submit();
1767
1768});
1769
1770$('#vivaButton').on('click touchend', function(e){
1771   $('#loading').removeClass('hidden');
1772    $('#vivawallet-snippet').addClass('hidden');
1773});
1774
1775function getCookie(cname) {
1776  var name = cname + "=";
1777  var decodedCookie = decodeURIComponent(document.cookie);
1778  var ca = decodedCookie.split(';');
1779  for(var i = 0; i <ca.length; i++) {
1780    var c = ca[i];
1781    while (c.charAt(0) == ' ') {
1782      c = c.substring(1);
1783    }
1784    if (c.indexOf(name) == 0) {
1785      return c.substring(name.length, c.length);
1786    }
1787  }
1788  return "";
1789}
1790
1791function detectCardType(cardNumber) {
1792    var re = {
1793        electron: /^(4026|417500|4405|4508|4844|4913|4917)\d+$/,
1794        maestro: /^(5018|5020|5038|5612|5893|6304|6759|6761|6762|6763|0604|6390)\d+$/,
1795        dankort: /^(5019)\d+$/,
1796        interpayment: /^(636)\d+$/,
1797        unionpay: /^(62|88)\d+$/,
1798        visa: /^4[0-9]{12}(?:[0-9]{3})?$/,
1799        mastercard: /^5[1-5][0-9]{14}$/,
1800        amex: /^3[47][0-9]{13}$/,
1801        diners: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
1802        discover: /^6(?:011|5[0-9]{2})[0-9]{12}$/,
1803        jcb: /^(?:2131|1800|35\d{3})\d{11}$/
1804    }
1805
1806    for(var key in re) {
1807        if(re[key].test(cardNumber)) {
1808            return key
1809        }
1810    }
1811}
1812
1813$(document).on("click touchend", "#booking-pax", function(e) {
1814  $('#booking-pax-modal').removeClass('hidden');
1815});
1816
1817$(document).on("click touchend", "#booking-pax-cancel", function(e) {
1818  $('#booking-pax-modal').addClass('hidden');
1819});
1820
1821$(document).on("click touchend", "#booking-pax-end", function(e) {
1822  var adults = parseInt($('input[name="adults"]').val());
1823  var children = parseInt($('input[name="children"]').val());
1824  var infants = parseInt($('input[name="infants"]').val());
1825  var pax = adults + children + infants;
1826
1827  $('#booking-pax-number').text(pax);
1828  $('#booking-pax-modal').addClass('hidden');
1829});
1830
1831
1832$(function(){
1833
1834  // add a cookie for popup
1835  // 
1836  if(typeof page_has_popup != 'undefined' && page_popup_show_onload == true){
1837
1838    if(page_popup_show_once == true){
1839      if( document.cookie.indexOf('popupshown=') === -1){
1840        window.location.hash = page_popup_id;
1841        var date = new Date();
1842        date.setTime(date.getTime() + 7*24*60*60*1000);
1843        document.cookie = "popupshown=true; expires="+date.toGMTString();
1844      }
1845    }else{
1846        window.location.hash = page_popup_id;
1847    }
1848
1849  }
1850
1851
1852})

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.