$.fn.saasfeeRangepicker=function(options){let settings=$.extend({dateFrom:null,dateTo:null},options);if(settings.dateFrom===null){console.error('DateFrom has to be set');return}
if(settings.dateTo===null){console.error('DateTo has to be set');return}
return $(this).mobiscroll().range({theme:'saasfee-relaunch',lang:'de',showOverlay:!1,display:'bubble',yearChange:!1,showSelector:!1,months:'auto',min:new Date(new Date().setDate(new Date().getDate())),dayNamesMin:['So','Mo','Di','Mi','Do','Fr','Sa'],onSet:function(event,instance){$(settings.dateFrom).val(instance.startVal);$(settings.dateTo).val(instance.endVal)},onSetDate:function(event,instance){if(instance.startVal!==""&&instance.endVal!==""&&instance.startVal!==$(settings.dateFrom).val()&&instance.endVal!==$(settings.dateTo).val()){instance.select()}}}).mobiscroll('getInst')};$.fn.saasfeeDateTimepicker=function(){return $(this).mobiscroll().calendar({theme:'saasfee-relaunch',controls:['calendar','time'],lang:'de',cssClass:'mbsc-datetimerpicker',showOverlay:!1,display:'bubble',yearChange:!1,dayNamesMin:['So','Mo','Di','Mi','Do','Fr','Sa'],buttons:['set','clear','cancel']}).mobiscroll('getInst')};$.fn.saasfeeDatepicker=function(){return $(this).mobiscroll().calendar({theme:'saasfee-relaunch',controls:['calendar'],lang:'de',cssClass:'mbsc-datetimerpicker',showOverlay:!1,display:'bubble',yearChange:!1,dayNamesMin:['So','Mo','Di','Mi','Do','Fr','Sa'],buttons:['set','clear','cancel'],onSetDate:function(event,instance){if(instance.getVal()!=null&&instance.getVal().getTime()!==instance.getVal(!0).getTime()){instance.select()}}}).mobiscroll('getInst')};$(document).ready(function(){$('.powermail_form:not(.powermail_form_3) .mbsc_powermail_date').each(function(){let $that=$(this);if($that.data('datepicker-settings')==='date'){let instance=$(this).saasfeeDatepicker();let $calendarIcon=$that.next('.icon.icon-calendar');$calendarIcon.on('click',function(event){instance.show();return!1})}else{let instance=$(this).saasfeeDateTimepicker();let $calendarIcon=$that.next('.icon.icon-calendar');$calendarIcon.on('click',function(event){instance.show();return!1})}})});$.fn.saasfeeDatepicker_reservation=function(){let options={theme:'saasfee-relaunch',controls:['calendar'],lang:'de',cssClass:'mbsc-datetimerpicker',showOverlay:!1,display:'bubble',yearChange:!1,dayNamesMin:['So','Mo','Di','Mi','Do','Fr','Sa'],buttons:['set','clear','cancel'],onSetDate:function(event,instance){if(instance.getVal()!=null&&instance.getVal().getTime()!==instance.getVal(!0).getTime()){instance.select()}},invalid:INVALID_DATES,min:RESERVATION_MINDATE};return $(this).mobiscroll().calendar(options).mobiscroll('getInst')};$(document).ready(function(){if(document.documentElement.lang==='de-CH'){moment.locale('de')}
if(document.documentElement.lang==='fr-CH'){moment.locale('fr')}
let vonInstance=undefined;let bisInstance=undefined;let vonValue=undefined;let bisValue=undefined;function extracted(element){let $that=$(element);let instance=$(element).saasfeeDatepicker_reservation();let $calendarIcon=$that.next('.icon.icon-calendar');$calendarIcon.on('click',function(event){instance.show();return!1});return instance}
let $vonInput=$('.powermail_form_3 [name="tx_powermail_pi1[field][aufenthalt_von]"]');$vonInput.each(function(){vonInstance=extracted(this)});let $bisInput=$('.powermail_form_3 [name="tx_powermail_pi1[field][aufenthalt_bis]"]');$bisInput.each(function(){bisInstance=extracted(this,vonInstance)});displayFields=()=>{if(typeof vonValue!=='undefined'&&typeof bisValue!=='undefined'){$('.powermail_fieldwrap_type_saasfee-reservation').each(function(){let $field=$(this);$field.hide();$field.find('.__date input').val('');$field.find('.__date .__dummy').html('')});let diff=parseInt(moment(bisValue).diff(moment(vonValue),'days'));for(let i=0;i<=diff;i++){$('#powermail_field_res'+(i+1)+',#powermail_field_reservierung'+(i+1)).each(function(){let $field=$(this);$field.show();let value=moment(vonValue).add(i,'days').format('YYYY-MM-DD');let html=moment(vonValue).add(i,'days').format('L');$field.find('.__date input').val(value);$field.find('.__date .__dummy').html(html)})}}}
vonValue=vonInstance.getVal();bisValue=bisInstance.getVal();displayFields();vonInstance.option({onSet:function(event,inst){vonValue=inst.getVal();let min=RESERVATION_MINDATE;bisInstance.option({min:min,max:moment(inst.getVal()).add(13,'days').toDate()});$vonInput.parsley().validate();$bisInput.parsley().validate();displayFields()}});bisInstance.option({onSet:function(event,inst){bisValue=inst.getVal();$vonInput.parsley().validate();$bisInput.parsley().validate();displayFields()}})})