1document.addEventListener('DOMContentLoaded',function(){jQuery(document).on('click','input.gform-datepicker',function(){jQuery(this).closest('.ginput_container_date').find('button.gform-datepicker-toggle').trigger('click')});jQuery('form').each(function(){var form=jQuery(this);var formId=parseInt(form.data('formid'));switch(formId){case 27:initializeForm27();break;case 48:initializeForm48();break;case 49:initializeForm49();break;case 50:initializeForm50();break;case 51:initializeForm51();break;case 52:initializeForm52();break;case 57:initializeForm57();break;case 53:initializeForm53();break}})});function initializeForm27(){const pricingTable=starkupEauLicensesData.pricingTable;const dateInput=document.getElementById('input_27_24');const feePanel=document.querySelector('.fee-panel');const currentSum=document.querySelector('.license-price');const currentPeriod=document.querySelector('.license-period');const licenseBillingNotice=document.querySelector('.license-future-cost');initializeForm27QuarterPicker();jQuery(document).on('gform_post_render',function(event,formId){if(parseInt(formId,10)===27){initializeForm27QuarterPicker()}});window.form27Calculate=debounce(function(){const fee=calculateFee();updateDisplay(fee)},250);jQuery(document).on('submit','#gform_27',function(event){updateDisplay();setTimeout(function(){jQuery(this).submit()},100)});function calculateFee(){let totalMonthlyFee=0;const isIndefiniteLicense=jQuery('#choice_27_11_0').is(':checked');const isTimePeriodLicense=jQuery('#choice_27_11_1').is(':checked');const paymentFrequency=jQuery('input[name="input_6"]:checked').val();jQuery('input[id^="input_27_2012"]').each(function(){const areaInput=jQuery(this);if(areaInput.closest('.gfield_repeater_template').length){return} 2if(jQuery.trim(areaInput.val())===''){return} 3const index=areaInput.attr('id').split('-')[1];const choiceInput=jQuery(`#choice_27_2013_0-${index}`);let monthlyFee=0;if(areaInput.length>0){const area=parseInt(areaInput.val(),10)||0;if(area>7000){monthlyFee=110+Math.ceil((area-7000)/1000)*11}else{for(const[maxArea,cost]of Object.entries(pricingTable)){if(area<=parseInt(maxArea)){monthlyFee=parseFloat(cost);break}}} 4if(choiceInput.is(':checked')){monthlyFee+=8} 5totalMonthlyFee+=monthlyFee}});const formattedStartDate=convertDate(dateInput.value);const startDate=new Date(formattedStartDate);let totalFee=0;if(isDateNearPeriodEnd(startDate,paymentFrequency)){const additionalFee=calculateAdditionalFee(totalMonthlyFee,paymentFrequency);totalFee+=additionalFee} 6if(isIndefiniteLicense){if(!isNaN(startDate.getDate())){const daysInStartMonth=new Date(startDate.getFullYear(),startDate.getMonth()+1,0).getDate();const remainingDaysInStartMonth=daysInStartMonth-startDate.getDate()+1;const proratedFeeForStartMonth=(totalMonthlyFee/daysInStartMonth)*remainingDaysInStartMonth;totalFee+=proratedFeeForStartMonth;const endDate=getEndDate(startDate,paymentFrequency);let currentMonth=startDate.getMonth()+1;while(currentMonth<=endDate.getMonth()){totalFee+=totalMonthlyFee;currentMonth++}}}else if(isTimePeriodLicense){const endDateInput=document.getElementById('input_27_26');const formattedEndDate=convertDate(endDateInput.value);const endDate=new Date(formattedEndDate);if(!isNaN(startDate.getDate())&&!isNaN(endDate.getDate())){totalFee=calculateSeasonalFee(startDate,endDate,totalMonthlyFee);const minSeasonalFee=totalMonthlyFee*3;if(totalFee<minSeasonalFee){totalFee=minSeasonalFee}}} 7return{totalFee,totalMonthlyFee}} 8function updateDisplay(fee){var forEAU=0;var futureFeeStartDate='';const isTimePeriodLicense=jQuery('#choice_27_11_1').is(':checked');const date=dateInput.value;const paymentFrequency=jQuery('input[name="input_6"]:checked').val();const isContractTypeSelected=jQuery('#field_27_11 input[type="radio"]:checked').length>0;if(!isContractTypeSelected){jQuery(feePanel).slideUp();return} 9if(date===''){jQuery(feePanel).slideUp();return} 10let isAreaFilled=!1;jQuery('input[id^="input_27_2012"]').each(function(){const areaValue=jQuery(this).val();if(areaValue!==''){isAreaFilled=!0;return!1}});
10if(!isAreaFilled){jQuery(feePanel).slideUp();return} 11const formattedStartDate=convertDate(date);const startDate=new Date(formattedStartDate);const addExtraPeriod=startDate.getDate()>=15;const endDate=getEndDate(startDate,paymentFrequency,addExtraPeriod);const{totalFee,totalMonthlyFee}=calculateFee();forAuthors=totalFee*0.80;forEAU=totalFee*0.20;feeVAT=forEAU*0.24;const displayTotalFee=totalFee<0?0:totalFee;const displayFeeVAT=feeVAT<0?0:feeVAT;const displayForAuthors=forAuthors<0?0:forAuthors;const displayForEAU=forEAU<0?0:forEAU;const displayTotalFeeInclVAT=displayTotalFee+displayFeeVAT;currentSum.innerHTML=`<p>Tasu: <span style="float: right;"><strong>${displayTotalFee.toFixed(2)} â¬</strong></span><br> 12 <span style="color: #797979;">sh autoritasu</span><span style="float: right; color: #797979;">${displayForAuthors.toFixed(2)} â¬</span><br> 13 <span style="color: #797979;">sh vahendustasu</span><span style="float: right; color: #797979;">${displayForEAU.toFixed(2)} â¬</span></p>`;currentSum.innerHTML+=`<p style="margin-top: 10px;"><span class="license-vat">Käibemaks vahendustasult</span> <span style="float: right;"><strong>${displayFeeVAT.toFixed(2)} â¬</strong></span></p>`;currentSum.innerHTML+=`<hr><p><strong>Kokku <span style="float: right;">${displayTotalFeeInclVAT.toFixed(2)} â¬</span></strong></p>`;jQuery(feePanel).slideDown();const isSecondOptionChecked=jQuery('#choice_27_11_1').is(':checked');const displayStartDate=formatDateToDDMMYYYY(startDate);var displayEndDate;if(!isSecondOptionChecked){displayEndDate=formatDateToDDMMYYYY(endDate)}else{seasonalEndDate=document.getElementById('input_27_26').value;if(!seasonalEndDate){displayEndDate='...'}else{displayEndDate=seasonalEndDate}} 14currentPeriod.innerHTML=`Periood: <span style="float: right;"><strong>${displayStartDate} - ${displayEndDate}</strong></span>`;if(!isSecondOptionChecked){endDate.setDate(endDate.getDate()+1);futureFeeStartDate=formatDateToDDMMYYYY(endDate);let paymentFrequencyDisplay=paymentFrequency;if(paymentFrequency==="Aasta"||paymentFrequency==="Poolaasta"){paymentFrequencyDisplay=paymentFrequency.charAt(0).toLowerCase()+paymentFrequency.slice(1)}else if(paymentFrequency==="Kvartal"){paymentFrequencyDisplay="kvartali"} 15licenseBillingNotice.innerHTML=`Alates ${futureFeeStartDate} edastatakse teile automaatselt arve iga ${paymentFrequencyDisplay} eest sel hetkel kehtiva hinnakirja alusel.`;jQuery('.license-future-cost').slideDown();jQuery.ajax({url:my_ajax_obj.ajax_url,type:'POST',data:{'action':'store_license_future_fee','future_fee_start_date':futureFeeStartDate,'future_fee_payment_frequency':paymentFrequency,},})}else{jQuery('.license-future-cost').slideUp()} 16var inputElement=document.getElementById('input_27_5');inputElement.value=totalFee.toFixed(2);var inputElement=document.getElementById('input_27_29');inputElement.value=futureFeeStartDate} 17var debouncedCalculateAndDisplay=debounce(function(){const fee=calculateFee();updateDisplay(fee)},250);jQuery('#input_27_26').on("change",function(){if(jQuery('#input_27_26').val()!==''&&jQuery('#input_27_26').is(':visible')){debouncedCalculateAndDisplay()}});jQuery('.gform_wrapper').on('input change','input[id^="input_27_2012"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#input_27_24',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','.gfield-choice-input[type="radio"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_27_15_1',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_27_28_1',debouncedCalculateAndDisplay);var observerCallback=function(mutationsList,observer){for(var mutation of mutationsList){if(mutation.type==='childList'){debouncedCalculateAndDisplay();break}}};var observer=new MutationObserver(observerCallback);var targetNode=document.querySelector('.gform_wrapper');observer.observe(targetNode,{childList:!0,subtree:!0})} 18function initializeForm27QuarterPicker(){const FORM_ID=27;const startInput=document.getElementById('input_27_24');const endInput=document.getElementById('input_27_26');const startField=document.getElementById('field_27_24');const endField=document.getElementById('field_27_26');if(!startInput||!endInput||!startField||!endField)return;if(document.getElementById('field_27_quarter'))return;const START_QUARTERS_AHEAD=4;const MAX_QUARTERS=4;const isEnglish=document.documentElement.lang==='en-US';const t=isEnglish?{legend:'Seasonal licence period',start:'First quarter',end:'Last quarter',choose:'- choose -',quarter:'quarter',description:'A seasonal licence can only be issued for whole calendar quarters (Q1 January-March, Q2 April-June, Q3 July-September, Q4 October-December). The contract start and end dates are filled
18in automatically from your selection.'}:{legend:'Hooajalise litsentsi periood',start:'Alguskvartal',end:'Lõppkvartal',choose:'- vali -',quarter:'kvartal',description:'Hooajalise litsentsi saab vormistada ainult täiskvartaliteks (I kv jaanuar-märts, II kv aprill-juuni, III kv juuli-september, IV kv oktoober-detsember). Lepingu alguse ja lõpu kuupäevad täidetakse valiku järgi automaatselt.'};const ROMAN=['I','II','III','IV'];function quarterIndex(date){return date.getFullYear()*4+Math.floor(date.getMonth()/3)} 19function quarterStart(index){return new Date(Math.floor(index/4),(index%4)*3,1)} 20function quarterEnd(index){return new Date(Math.floor(index/4),(index%4)*3+3,0)} 21function quarterLabel(index){const q=index%4,y=Math.floor(index/4);const name=isEnglish?'Q'+(q+1)+' '+y:ROMAN[q]+' '+t.quarter+' '+y;return name+' ('+formatDateToDDMMYYYY(quarterStart(index))+' - '+formatDateToDDMMYYYY(quarterEnd(index))+')'} 22function sameDay(a,b){return a&&b&&a.getTime()===b.getTime()} 23function parseInputDate(value){const d=new Date(convertDate(value));return isNaN(d.getTime())?null:d} 24const picker=document.createElement('div');picker.id='field_27_quarter';picker.className='gfield gfield--type-select gfield--width-full field_sublabel_below field_description_below eau-quarter-picker';picker.innerHTML='<label class="gfield_label gform-field-label" for="eau_quarter_start"><span class="gform-field-label__text">'+t.legend+'</span><span class="gfield_required"><span class="gfield_required gfield_required_asterisk">*</span></span></label>'+'<div class="ginput_container ginput_container_select eau-quarter-picker__row">'+'<div class="eau-quarter-picker__col"><label class="gform-field-label gform-field-label--type-sub" for="eau_quarter_start">'+t.start+'</label><select id="eau_quarter_start" class="large gfield_select"></select></div>'+'<div class="eau-quarter-picker__col"><label class="gform-field-label gform-field-label--type-sub" for="eau_quarter_end">'+t.end+'</label><select id="eau_quarter_end" class="large gfield_select" disabled></select></div>'+'</div>'+'<div class="gfield_description">'+t.description+'</div>';startField.parentNode.insertBefore(picker,startField);const startSelect=picker.querySelector('#eau_quarter_start');const endSelect=picker.querySelector('#eau_quarter_end');function fillSelect(select,fromIndex,toIndex,selectedIndex){select.innerHTML='';const placeholder=document.createElement('option');placeholder.value='';placeholder.textContent=t.choose;select.appendChild(placeholder);for(let i=fromIndex;i<=toIndex;i++){const option=document.createElement('option');option.value=String(i);option.textContent=quarterLabel(i);if(i===selectedIndex)option.selected=!0;select.appendChild(option)}} 25const currentQuarter=quarterIndex(new Date());const existingStart=parseInputDate(startInput.value);const existingEnd=parseInputDate(endInput.value);let selectedStart=null,selectedEnd=null;if(existingStart&&sameDay(existingStart,quarterStart(quarterIndex(existingStart)))){selectedStart=quarterIndex(existingStart)} 26if(selectedStart!==null&&existingEnd&&sameDay(existingEnd,quarterEnd(quarterIndex(existingEnd)))){const endIndex=quarterIndex(existingEnd);if(endIndex>=selectedStart&&endIndex<selectedStart+MAX_QUARTERS)selectedEnd=endIndex} 27fillSelect(startSelect,Math.min(currentQuarter,selectedStart===null?currentQuarter:selectedStart),currentQuarter+START_QUARTERS_AHEAD,selectedStart);if(selectedStart!==null){fillSelect(endSelect,selectedStart,selectedStart+MAX_QUARTERS-1,selectedEnd===null?selectedStart:selectedEnd);endSelect.disabled=!1} 28function setDateValue(input,date){const value=date?formatDateToDDMMYYYY(date):'';if(input.value===value)return;input.value=value;jQuery(input).trigger('change')} 29function applyQuartersToDates(){const startIndex=startSelect.value===''?null:parseInt(startSelect.value,10);const endIndex=endSelect.value===''?null:parseInt(endSelect.value,10);setDateValue(startInput,startIndex===null?null:quarterStart(startIndex));setDateValue(endInput,endIndex===null?null:quarterEnd(endIndex))}
30function lockDateFields(locked){[startField,endField].forEach(function(field){field.classList.toggle('eau-quarter-locked',locked)});[startInput,endInput].forEach(function(input){if(locked){input.setAttribute('readonly','readonly');input.setAttribute('tabindex','-1')}else{input.removeAttribute('readonly');input.removeAttribute('tabindex')}});[startField,endField].forEach(function(field){const toggle=field.querySelector('button.gform-datepicker-toggle');if(toggle)toggle.disabled=locked})} 31function isSeasonal(){const seasonal=document.getElementById('choice_27_11_1');return!!(seasonal&&seasonal.checked)} 32function applyMode(){if(isSeasonal()){picker.style.display='';lockDateFields(!0);if(startSelect.value==='')setDateValue(startInput,null);if(endSelect.value==='')setDateValue(endInput,null);applyQuartersToDates()}else{picker.style.display='none';lockDateFields(!1)}} 33startSelect.addEventListener('change',function(){if(startSelect.value===''){fillSelect(endSelect,0,-1,null);endSelect.disabled=!0}else{const startIndex=parseInt(startSelect.value,10);const previousEnd=endSelect.value===''?null:parseInt(endSelect.value,10);const keepEnd=previousEnd!==null&&previousEnd>=startIndex&&previousEnd<startIndex+MAX_QUARTERS?previousEnd:startIndex;fillSelect(endSelect,startIndex,startIndex+MAX_QUARTERS-1,keepEnd);endSelect.disabled=!1} 34applyQuartersToDates()});endSelect.addEventListener('change',applyQuartersToDates);jQuery(document).on('change','#gform_'+FORM_ID+' input[name="input_11"]',function(){setTimeout(applyMode,50)});applyMode()} 35function initializeForm49(){const pricingTable=starkupEauLicensesData.pricingTable;const dateInput=document.getElementById('input_49_24');const feePanel=document.querySelector('.fee-panel');const currentSum=document.querySelector('.license-price');const currentPeriod=document.querySelector('.license-period');const licenseBillingNotice=document.querySelector('.license-future-cost');jQuery(document).on('submit','#gform_49',function(event){updateDisplay();setTimeout(function(){jQuery(this).submit()},100)});function calculateFee(){let totalMonthlyFee=0;const isIndefiniteLicense=jQuery('#choice_49_11_0').is(':checked');const isTimePeriodLicense=jQuery('#choice_49_11_1').is(':checked');const paymentFrequency=jQuery('input[name="input_6"]:checked').val();jQuery('input[id^="input_49_2012"]').each(function(){const areaInput=jQuery(this);if(areaInput.closest('.gfield_repeater_template').length){return} 36if(jQuery.trim(areaInput.val())===''){return} 37const index=areaInput.attr('id').split('-')[1];const choiceInput=jQuery(`#choice_49_2013_0-${index}`);let monthlyFee=0;if(areaInput.length>0){const area=parseInt(areaInput.val(),10)||0;if(area){isAreaFilled=!0;if(area<=0){monthlyFee=277}else if(area<=20){monthlyFee=19}else if(area<=50){monthlyFee=24}else if(area<=100){monthlyFee=43}else if(area<=150){monthlyFee=55}else if(area<=200){monthlyFee=83}else if(area<=300){monthlyFee=108}else if(area<=400){monthlyFee=129}else if(area<=1000){var extraHundreds=Math.floor((area-300)/100);monthlyFee=129+21*extraHundreds}else{monthlyFee=277}} 38if(choiceInput.is(':checked')){monthlyFee+=7} 39const isDiscountApplied=jQuery('#choice_49_15_1').is(':checked');if(isDiscountApplied){monthlyFee*=0.93} 40totalMonthlyFee+=monthlyFee}});const formattedStartDate=convertDate(dateInput.value);const startDate=new Date(formattedStartDate);let totalFee=0;if(isDateNearPeriodEnd(startDate,paymentFrequency)){const additionalFee=calculateAdditionalFee(totalMonthlyFee,paymentFrequency);totalFee+=additionalFee} 41if(isIndefiniteLicense){if(!isNaN(startDate.getDate())){const daysInStartMonth=new Date(startDate.getFullYear(),startDate.getMonth()+1,0).getDate();const remainingDaysInStartMonth=daysInStartMonth-startDate.getDate()+1;const proratedFeeForStartMonth=(totalMonthlyFee/daysInStartMonth)*remainingDaysInStartMonth;totalFee+=proratedFeeForStartMonth;const endDate=getEndDate(startDate,paymentFrequency);let currentMonth=startDate.getMonth()+1;while(currentMonth<=endDate.getMonth()){totalFee+=totalMonthlyFee;currentMonth++}}}else if(isTimePeriodLicense){const endDateInput=document.getElementById('input_49_26');const formattedEndDate=convertDate(endDateInput.value);const endDate=new Date(formattedEndDate);
41if(!isNaN(startDate.getDate())&&!isNaN(endDate.getDate())){totalFee=calculateSeasonalFee(startDate,endDate,totalMonthlyFee)}} 42return{totalFee,totalMonthlyFee}} 43function updateDisplay(fee){var forEAU=0;var futureFeeStartDate='';const isTimePeriodLicense=jQuery('#choice_49_11_1').is(':checked');const date=dateInput.value;const paymentFrequency=jQuery('input[name="input_6"]:checked').val();const isContractTypeSelected=jQuery('#field_49_11 input[type="radio"]:checked').length>0;if(!isContractTypeSelected){jQuery(feePanel).slideUp();return} 44if(date===''){jQuery(feePanel).slideUp();return} 45let isAreaFilled=!1;jQuery('input[id^="input_49_2012"]').each(function(){const areaValue=jQuery(this).val();if(areaValue!==''){isAreaFilled=!0;return!1}});if(!isAreaFilled){jQuery(feePanel).slideUp();return} 46const formattedStartDate=convertDate(date);const startDate=new Date(formattedStartDate);const addExtraPeriod=startDate.getDate()>=15;const endDate=getEndDate(startDate,paymentFrequency,addExtraPeriod);const{totalFee,totalMonthlyFee}=calculateFee();forAuthors=totalFee*0.80;forEAU=totalFee*0.20;feeVAT=forEAU*0.24;const displayTotalFee=totalFee<0?0:totalFee;const displayFeeVAT=feeVAT<0?0:feeVAT;const displayForAuthors=forAuthors<0?0:forAuthors;const displayForEAU=forEAU<0?0:forEAU;const displayTotalFeeInclVAT=displayTotalFee+displayFeeVAT;currentSum.innerHTML=`<p>Tasu: <span style="float: right;"><strong>${displayTotalFee.toFixed(2)} â¬</strong></span><br> 47 <span style="color: #797979;">sh autoritasu</span><span style="float: right; color: #797979;">${displayForAuthors.toFixed(2)} â¬</span><br> 48 <span style="color: #797979;">sh vahendustasu</span><span style="float: right; color: #797979;">${displayForEAU.toFixed(2)} â¬</span></p>`;currentSum.innerHTML+=`<p style="margin-top: 10px;"><span class="license-vat">Käibemaks vahendustasult</span> <span style="float: right;"><strong>${displayFeeVAT.toFixed(2)} â¬</strong></span></p>`;currentSum.innerHTML+=`<hr><p><strong>Kokku <span style="float: right;">${displayTotalFeeInclVAT.toFixed(2)} â¬</span></strong></p>`;jQuery(feePanel).slideDown();const isSecondOptionChecked=jQuery('#choice_49_11_1').is(':checked');const displayStartDate=formatDateToDDMMYYYY(startDate);var displayEndDate;if(!isSecondOptionChecked){displayEndDate=formatDateToDDMMYYYY(endDate)}else{seasonalEndDate=document.getElementById('input_49_26').value;if(!seasonalEndDate){displayEndDate='...'}else{displayEndDate=seasonalEndDate}} 49currentPeriod.innerHTML=`Periood: <span style="float: right;"><strong>${displayStartDate} - ${displayEndDate}</strong></span>`;if(!isSecondOptionChecked){endDate.setDate(endDate.getDate()+1);futureFeeStartDate=formatDateToDDMMYYYY(endDate);let paymentFrequencyDisplay=paymentFrequency;if(paymentFrequency==="Aasta"||paymentFrequency==="Poolaasta"){paymentFrequencyDisplay=paymentFrequency.charAt(0).toLowerCase()+paymentFrequency.slice(1)}else if(paymentFrequency==="Kvartal"){paymentFrequencyDisplay="kvartali"} 50licenseBillingNotice.innerHTML=`Alates ${futureFeeStartDate} edastatakse teile automaatselt arve iga ${paymentFrequencyDisplay} eest sel hetkel kehtiva hinnakirja alusel.`;jQuery('.license-future-cost').slideDown();jQuery.ajax({url:my_ajax_obj.ajax_url,type:'POST',data:{'action':'store_license_future_fee','future_fee_start_date':futureFeeStartDate,'future_fee_payment_frequency':paymentFrequency,},})}else{jQuery('.license-future-cost').slideUp()} 51var inputElement=document.getElementById('input_49_5');if(inputElement){inputElement.value=totalFee.toFixed(2)} 52var futureDateInputElement=document.getElementById('input_49_29');if(futureDateInputElement){futureDateInputElement.value=futureFeeStartDate}} 53var debouncedCalculateAndDisplay=debounce(function(){const fee=calculateFee();updateDisplay(fee)},250);jQuery('#input_49_26').on("change",function(){if(jQuery('#input_49_26').val()!==''&&jQuery('#input_49_26').is(':visible')){debouncedCalculateAndDisplay()}});jQuery('.gform_wrapper').on('input change','input[id^="input_49_2012"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#input_49_24',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','.gfield-choice-input[type="radio"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_49_15_1',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_49_28_1',debouncedCalculateAndDisplay);var observerCallback=function(mutationsList,observer){for(var mutation of mutationsList){if(mutation.type==='childList'){debouncedCalculateAndDisplay();break}}};var observer=new MutationObserver(observerCallback);var targetNode=document.querySelector('.gform_wrapper');if(targetNode){observer.observe(targetNode,{childList:!0,subtree:!0})}} 54function initializeForm50(){const dateInput=document.getElementById('input_50_24');const feePanel=document.querySelector('.fee-panel');const currentSum=document.querySelector('.license-price');const currentPeriod=document.querySelector('.license-period');const licenseBillingNotice=document.querySelector('.license-future-cost');jQuery(document).on('submit','#gform_50',function(event){updateDisplay();setTimeout(function(){jQuery(this).submit()},100)});function calculateFee(){let totalMonthlyFee=0;const isIndefiniteLicense=jQuery('#choice_50_11_0').is(':checked');const isTimePeriodLicense=jQuery('#choice_50_11_1').is(':checked');const paymentFrequency=jQuery('input[name="input_6"]:checked').val();jQuery('input[id^="input_50_2012"]').each(function(){const areaInput=jQuery(this);if(areaInput.closest('.gfield_repeater_template').length){return} 55if(jQuery.trim(areaInput.val())===''){return} 56const index=areaInput.attr('id').split('-')[1];
56var extraDays=parseInt(jQuery(`#input_50_2013-${index}`).val(),10);let monthlyFee=0;if(areaInput.length>0){const area=parseInt(areaInput.val(),10)||0;var baseFee=0;var extraDayFee=0;if(area<=50){baseFee=53;extraDayFee=14}else if(area<=100){baseFee=106;extraDayFee=27}else if(area<=200){baseFee=141;extraDayFee=36}else if(area<=300){baseFee=176;extraDayFee=45}else if(area<=400){baseFee=211;extraDayFee=53}else if(area<=500){baseFee=281;extraDayFee=71}else if(area<=600){baseFee=298;extraDayFee=75}else{var extraHundreds=Math.floor((area-600)/100);baseFee=298+28*extraHundreds;extraDayFee=75+8*extraHundreds} 57if(extraDays===1||extraDays===2){extraDays=0}else if(extraDays===3){extraDays=1}else if(extraDays===4){extraDays=2}else if(extraDays===5){extraDays=3}else if(extraDays===6){extraDays=4}else if(extraDays===7){extraDays=5}else{extraDays=0} 58monthlyFee=baseFee+extraDayFee*extraDays;const isDiscountApplied=jQuery('#choice_50_15_1').is(':checked');if(isDiscountApplied){monthlyFee*=0.93} 59totalMonthlyFee+=monthlyFee}});const formattedStartDate=convertDate(dateInput.value);const startDate=new Date(formattedStartDate);let totalFee=0;if(isDateNearPeriodEnd(startDate,paymentFrequency)){const additionalFee=calculateAdditionalFee(totalMonthlyFee,paymentFrequency);totalFee+=additionalFee} 60if(isIndefiniteLicense){if(!isNaN(startDate.getDate())){const daysInStartMonth=new Date(startDate.getFullYear(),startDate.getMonth()+1,0).getDate();const remainingDaysInStartMonth=daysInStartMonth-startDate.getDate()+1;const proratedFeeForStartMonth=(totalMonthlyFee/daysInStartMonth)*remainingDaysInStartMonth;totalFee+=proratedFeeForStartMonth;const endDate=getEndDate(startDate,paymentFrequency);let currentMonth=startDate.getMonth()+1;while(currentMonth<=endDate.getMonth()){totalFee+=totalMonthlyFee;currentMonth++}}}else if(isTimePeriodLicense){const endDateInput=document.getElementById('input_50_26');const formattedEndDate=convertDate(endDateInput.value);const endDate=new Date(formattedEndDate);if(!isNaN(startDate.getDate())&&!isNaN(endDate.getDate())){totalFee=calculateSeasonalFee(startDate,endDate,totalMonthlyFee)}} 61return{totalFee,totalMonthlyFee}} 62function updateDisplay(fee){var forEAU=0;var futureFeeStartDate='';const isTimePeriodLicense=jQuery('#choice_50_11_1').is(':checked');const date=dateInput.value;const paymentFrequency=jQuery('input[name="input_6"]:checked').val();const isContractTypeSelected=jQuery('#field_50_11 input[type="radio"]:checked').length>0;if(!isContractTypeSelected){jQuery(feePanel).slideUp();return} 63if(date===''){jQuery(feePanel).slideUp();return} 64let isAreaFilled=!1;jQuery('input[id^="input_50_2012"]').each(function(){const areaValue=jQuery(this).val();if(areaValue!==''){isAreaFilled=!0;return!1}});if(!isAreaFilled){jQuery(feePanel).slideUp();return} 65const formattedStartDate=convertDate(date);const startDate=new Date(formattedStartDate);const addExtraPeriod=startDate.getDate()>=15;const endDate=getEndDate(startDate,paymentFrequency,addExtraPeriod);const{totalFee,totalMonthlyFee}=calculateFee();forAuthors=totalFee*0.80;forEAU=totalFee*0.20;feeVAT=forEAU*0.24;const displayTotalFee=totalFee<0?0:totalFee;const displayFeeVAT=feeVAT<0?0:feeVAT;const displayForAuthors=forAuthors<0?0:forAuthors;const displayForEAU=forEAU<0?0:forEAU;const displayTotalFeeInclVAT=displayTotalFee+displayFeeVAT;currentSum.innerHTML=`<p>Tasu: <span style="float: right;"><strong>${displayTotalFee.toFixed(2)} â¬</strong></span><br> 66 <span style="color: #797979;">sh autoritasu</span><span style="float: right; color: #797979;">${displayForAuthors.toFixed(2)} â¬</span><br> 67 <span style="color: #797979;">sh vahendustasu</span><span style="float: right; color: #797979;">${displayForEAU.toFixed(2)} â¬</span></p>`;currentSum.innerHTML+=`<p style="margin-top: 10px;"><span class="license-vat">Käibemaks vahendustasult</span> <span style="float: right;"><strong>${displayFeeVAT.toFixed(2)} â¬</strong></span></p>`;currentSum.innerHTML+=`<hr><p><strong>Kokku <span style="float: right;">${displayTotalFeeInclVAT.toFixed(2)} â¬</span></strong></p>`;jQuery(feePanel).slideDown();const isSecondOptionChecked=jQuery('#choice_50_11_1').is(':checked');const displayStartDate=formatDateToDDMMYYYY(startDate);var displayEndDate;if(!isSecondOptionChecked){displayEndDate=formatDateToDDMMYYYY(endDate)}else{seasonalEndDate=document.getElementById('input_50_26').value;if(!seasonalEndDate){displayEndDate='...'}else{displayEndDate=seasonalEndDate}} 68currentPeriod.innerHTML=`Periood: <span style="float: right;"><strong>${displayStartDate} - ${displayEndDate}</strong></span>`;if(!isSecondOptionChecked){endDate.setDate(endDate.getDate()+1);futureFeeStartDate=formatDateToDDMMYYYY(endDate);let paymentFrequencyDisplay=paymentFrequency;if(paymentFrequency==="Aasta"||paymentFrequency==="Poolaasta"){paymentFrequencyDisplay=paymentFrequency.charAt(0).toLowerCase()+paymentFrequency.slice(1)}else if(paymentFrequency==="Kvartal"){paymentFrequencyDisplay="kvartali"} 69licenseBillingNotice.innerHTML=`Alates ${futureFeeStartDate} edastatakse teile automaatselt arve iga ${paymentFrequencyDisplay} eest sel hetkel kehtiva hinnakirja alusel.`;jQuery('.license-future-cost').slideDown();jQuery.ajax({url:my_ajax_obj.ajax_url,type:'POST',data:{'action':'store_license_future_fee','future_fee_start_date':futureFeeStartDate,'future_fee_payment_frequency':paymentFrequency,},})}else{jQuery('.license-future-cost').slideUp()} 70var inputElement=document.getElementById('input_50_5');
70inputElement.value=totalFee.toFixed(2);var inputElement=document.getElementById('input_50_29');inputElement.value=futureFeeStartDate} 71var debouncedCalculateAndDisplay=debounce(function(){const fee=calculateFee();updateDisplay(fee)},250);jQuery('#input_50_26').on("change",function(){if(jQuery('#input_50_26').val()!==''&&jQuery('#input_50_26').is(':visible')){debouncedCalculateAndDisplay()}});jQuery('.gform_wrapper').on('input change','input[id^="input_50_2012"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','select[id^="input_50_2013"]',function(){debouncedCalculateAndDisplay()});jQuery('.gform_wrapper').on('change','#input_50_24',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','.gfield-choice-input[type="radio"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_50_15_1',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_50_28_1',debouncedCalculateAndDisplay);var observerCallback=function(mutationsList,observer){for(var mutation of mutationsList){if(mutation.type==='childList'){debouncedCalculateAndDisplay();break}}};var observer=new MutationObserver(observerCallback);var targetNode=document.querySelector('.gform_wrapper');observer.observe(targetNode,{childList:!0,subtree:!0})};function initializeForm51(){const dateInput=document.getElementById('input_51_24');const feePanel=document.querySelector('.fee-panel');const currentSum=document.querySelector('.license-price');const currentPeriod=document.querySelector('.license-period');const licenseBillingNotice=document.querySelector('.license-future-cost');jQuery(document).on('submit','#gform_51',function(event){updateDisplay();setTimeout(function(){jQuery(this).submit()},100)});function calculateFee(){let totalMonthlyFee=0;const paymentFrequency=jQuery('input[name="input_6"]:checked').val();jQuery('input[id^="input_51_2012"]').each(function(){const lessonInput=jQuery(this);if(lessonInput.closest('.gfield_repeater_template').length){return} 72if(jQuery.trim(lessonInput.val())===''){return} 73let monthlyFee=0;if(lessonInput.length>0){const lesson=parseInt(lessonInput.val(),10)||0;if(lesson<=0){monthlyFee=37}else if(lesson<=15){monthlyFee=10}else if(lesson<=30){monthlyFee=15}else if(lesson<=60){monthlyFee=30}else if(lesson<=90){monthlyFee=37}else{var extraHundreds=Math.floor((lesson-60)/30);monthlyFee=37+10*extraHundreds} 74totalMonthlyFee+=monthlyFee}});const formattedStartDate=convertDate(dateInput.value);const startDate=new Date(formattedStartDate);let totalFee=0;if(isDateNearPeriodEnd(startDate,paymentFrequency)){const additionalFee=calculateAdditionalFee(totalMonthlyFee,paymentFrequency);totalFee+=additionalFee} 75if(!isNaN(startDate.getDate())){const daysInStartMonth=new Date(startDate.getFullYear(),startDate.getMonth()+1,0).getDate();const remainingDaysInStartMonth=daysInStartMonth-startDate.getDate()+1;const proratedFeeForStartMonth=(totalMonthlyFee/daysInStartMonth)*remainingDaysInStartMonth;totalFee+=proratedFeeForStartMonth;const endDate=getEndDate(startDate,paymentFrequency);let currentMonth=startDate.getMonth()+1;while(currentMonth<=endDate.getMonth()){totalFee+=totalMonthlyFee;currentMonth++}} 76return{totalFee,totalMonthlyFee}} 77function updateDisplay(fee){var forEAU=0;var futureFeeStartDate='';const date=dateInput.value;const paymentFrequency=jQuery('input[name="input_6"]:checked').val();if(date===''){jQuery(feePanel).slideUp();return} 78let islessonFilled=!1;jQuery('input[id^="input_51_2012"]').each(function(){const lessonValue=jQuery(this).val();if(lessonValue!==''){islessonFilled=!0;return!1}});if(!islessonFilled){jQuery(feePanel).slideUp();return} 79const formattedStartDate=convertDate(date);const startDate=new Date(formattedStartDate);const addExtraPeriod=startDate.getDate()>=15;const endDate=getEndDate(startDate,paymentFrequency,addExtraPeriod);const{totalFee,totalMonthlyFee}=calculateFee();forAuthors=totalFee*0.80;forEAU=totalFee*0.20;feeVAT=forEAU*0.24;const displayTotalFee=totalFee<0?0:totalFee;const displayFeeVAT=feeVAT<0?0:feeVAT;const displayForAuthors=forAuthors<0?0:forAuthors;
79const displayForEAU=forEAU<0?0:forEAU;const displayTotalFeeInclVAT=displayTotalFee+displayFeeVAT;currentSum.innerHTML=`<p>Tasu: <span style="float: right;"><strong>${displayTotalFee.toFixed(2)} â¬</strong></span><br> 80 <span style="color: #797979;">sh autoritasu</span><span style="float: right; color: #797979;">${displayForAuthors.toFixed(2)} â¬</span><br> 81 <span style="color: #797979;">sh vahendustasu</span><span style="float: right; color: #797979;">${displayForEAU.toFixed(2)} â¬</span></p>`;currentSum.innerHTML+=`<p style="margin-top: 10px;"><span class="license-vat">Käibemaks vahendustasult</span> <span style="float: right;"><strong>${displayFeeVAT.toFixed(2)} â¬</strong></span></p>`;currentSum.innerHTML+=`<hr><p><strong>Kokku <span style="float: right;">${displayTotalFeeInclVAT.toFixed(2)} â¬</span></strong></p>`;jQuery(feePanel).slideDown();const displayStartDate=formatDateToDDMMYYYY(startDate);var displayEndDate;displayEndDate=formatDateToDDMMYYYY(endDate);currentPeriod.innerHTML=`Periood: <span style="float: right;"><strong>${displayStartDate} - ${displayEndDate}</strong></span>`;let nextDay=new Date(endDate);nextDay.setDate(nextDay.getDate()+1);futureFeeStartDate=formatDateToDDMMYYYY(nextDay);var inputField29=document.getElementById('input_51_29');if(inputField29){inputField29.value=futureFeeStartDate} 82if(licenseBillingNotice){licenseBillingNotice.innerHTML=`Alates ${futureFeeStartDate} edastatakse teile automaatselt arve iga ${formatPaymentFrequencyDisplay(paymentFrequency)} eest sel hetkel kehtiva hinnakirja alusel.`;jQuery(licenseBillingNotice).slideDown()} 83var inputElement=document.getElementById('input_51_5');inputElement.value=totalFee.toFixed(2);if(typeof my_ajax_obj!=='undefined'){jQuery.ajax({url:my_ajax_obj.ajax_url,type:'POST',data:{'action':'store_license_future_fee','future_fee_start_date':futureFeeStartDate,'future_fee_payment_frequency':paymentFrequency,},})}} 84var debouncedCalculateAndDisplay=debounce(function(){const fee=calculateFee();updateDisplay(fee)},250);jQuery('#input_51_26').on("change",function(){if(jQuery('#input_51_26').val()!==''&&jQuery('#input_51_26').is(':visible')){debouncedCalculateAndDisplay()}});jQuery('.gform_wrapper').on('input change','input[id^="input_51_2012"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#input_51_24',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','.gfield-choice-input[type="radio"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_51_15_1',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_51_28_1',debouncedCalculateAndDisplay);var observerCallback=function(mutationsList,observer){for(var mutation of mutationsList){if(mutation.type==='childList'){debouncedCalculateAndDisplay();break}}};var observer=new MutationObserver(observerCallback);var targetNode=document.querySelector('.gform_wrapper');observer.observe(targetNode,{childList:!0,subtree:!0})};function initializeForm48(){const dateInput=document.getElementById('input_48_24');const feePanel=document.querySelector('.fee-panel');const currentSum=document.querySelector('.license-price');const currentPeriod=document.querySelector('.license-period');const licenseBillingNotice=document.querySelector('.license-future-cost');jQuery(document).on('submit','#gform_48',function(event){updateDisplay();setTimeout(function(){jQuery(this).submit()},100)});function calculateFee(){let totalMonthlyFee=0;const paymentFrequency=jQuery('input[name="input_6"]:checked').val();jQuery('input[id^="input_48_2012"]').each(function(){const areaInput=jQuery(this);if(areaInput.closest('.gfield_repeater_template').length){return} 85if(jQuery.trim(areaInput.val())===''){return} 86let monthlyFee=0;if(areaInput.length>0){const area=parseInt(areaInput.val(),10)||0;if(area>100){monthlyFee=34}else{monthlyFee=10} 87totalMonthlyFee+=monthlyFee}});const formattedStartDate=convertDate(dateInput.value);const startDate=new Date(formattedStartDate);let totalFee=0;if(isDateNearPeriodEnd(startDate,paymentFrequency)){const additionalFee=calculateAdditionalFee(totalMonthlyFee,paymentFrequency);totalFee+=additionalFee} 88if(!isNaN(startDate.getDate())){const daysInStartMonth=new Date(startDate.getFullYear(),startDate.getMonth()+1,0).getDate();const remainingDaysInStartMonth=daysInStartMonth-startDate.getDate()+1;const proratedFeeForStartMonth=(totalMonthlyFee/daysInStartMonth)*remainingDaysInStartMonth;totalFee+=proratedFeeForStartMonth;const endDate=getEndDate(startDate,paymentFrequency);let currentMonth=startDate.getMonth()+1;while(currentMonth<=endDate.getMonth()){totalFee+=totalMonthlyFee;currentMonth++}} 89return{totalFee,totalMonthlyFee}} 90function updateDisplay(fee){var forEAU=0;var futureFeeStartDate='';const date=dateInput.value;const paymentFrequency=jQuery('input[name="input_6"]:checked').val();
90if(date===''){jQuery(feePanel).slideUp();return} 91let isAreaFilled=!1;jQuery('input[id^="input_48_2012"]').each(function(){const areaValue=jQuery(this).val();if(areaValue!==''){isAreaFilled=!0;return!1}});if(!isAreaFilled){jQuery(feePanel).slideUp();return} 92const formattedStartDate=convertDate(date);const startDate=new Date(formattedStartDate);const addExtraPeriod=startDate.getDate()>=15;const endDate=getEndDate(startDate,paymentFrequency,addExtraPeriod);const{totalFee,totalMonthlyFee}=calculateFee();forAuthors=totalFee*0.80;forEAU=totalFee*0.20;feeVAT=forEAU*0.24;const displayTotalFee=totalFee<0?0:totalFee;const displayFeeVAT=feeVAT<0?0:feeVAT;const displayForAuthors=forAuthors<0?0:forAuthors;const displayForEAU=forEAU<0?0:forEAU;const displayTotalFeeInclVAT=displayTotalFee+displayFeeVAT;currentSum.innerHTML=`<p>Tasu: <span style="float: right;"><strong>${displayTotalFee.toFixed(2)} â¬</strong></span><br> 93 <span style="color: #797979;">sh autoritasu</span><span style="float: right; color: #797979;">${displayForAuthors.toFixed(2)} â¬</span><br> 94 <span style="color: #797979;">sh vahendustasu</span><span style="float: right; color: #797979;">${displayForEAU.toFixed(2)} â¬</span></p>`;currentSum.innerHTML+=`<p style="margin-top: 10px;"><span class="license-vat">Käibemaks vahendustasult</span> <span style="float: right;"><strong>${displayFeeVAT.toFixed(2)} â¬</strong></span></p>`;currentSum.innerHTML+=`<hr><p><strong>Kokku <span style="float: right;">${displayTotalFeeInclVAT.toFixed(2)} â¬</span></strong></p>`;jQuery(feePanel).slideDown();const displayStartDate=formatDateToDDMMYYYY(startDate);var displayEndDate;displayEndDate=formatDateToDDMMYYYY(endDate);currentPeriod.innerHTML=`Periood: <span style="float: right;"><strong>${displayStartDate} - ${displayEndDate}</strong></span>`;let nextDay=new Date(endDate);nextDay.setDate(nextDay.getDate()+1);futureFeeStartDate=formatDateToDDMMYYYY(nextDay);var inputField29=document.getElementById('input_48_29');if(inputField29){inputField29.value=futureFeeStartDate} 95if(licenseBillingNotice){licenseBillingNotice.innerHTML=`Alates ${futureFeeStartDate} edastatakse teile automaatselt arve iga ${formatPaymentFrequencyDisplay(paymentFrequency)} eest sel hetkel kehtiva hinnakirja alusel.`;jQuery(licenseBillingNotice).slideDown()} 96var inputElement=document.getElementById('input_48_5');if(inputElement){inputElement.value=totalFee.toFixed(2)} 97if(typeof my_ajax_obj!=='undefined'){jQuery.ajax({url:my_ajax_obj.ajax_url,type:'POST',data:{'action':'store_license_future_fee','future_fee_start_date':futureFeeStartDate,'future_fee_payment_frequency':paymentFrequency,},})}} 98var debouncedCalculateAndDisplay=debounce(function(){const fee=calculateFee();updateDisplay(fee)},250);jQuery('#input_48_26').on("change",function(){if(jQuery('#input_48_26').val()!==''&&jQuery('#input_48_26').is(':visible')){debouncedCalculateAndDisplay()}});jQuery('.gform_wrapper').on('input change','input[id^="input_48_2012"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#input_48_24',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','.gfield-choice-input[type="radio"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_48_15_1',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_48_28_1',debouncedCalculateAndDisplay);var observerCallback=function(mutationsList,observer){for(var mutation of mutationsList){if(mutation.type==='childList'){debouncedCalculateAndDisplay();break}}};var observer=new MutationObserver(observerCallback);var targetNode=document.querySelector('.gform_wrapper');if(targetNode){observer.observe(targetNode,{childList:!0,subtree:!0})}};function initializeForm52(){const dateInput=document.getElementById('input_52_24');const feePanel=document.querySelector('.fee-panel');const currentSum=document.querySelector('.license-price');const currentPeriod=document.querySelector('.license-period');const licenseBillingNotice=document.querySelector('.license-future-cost');jQuery(document).on('submit','#gform_52',function(event){updateDisplay();setTimeout(function(){jQuery(this).submit()},100)});function calculateFee(){let totalMonthlyFee=0;const paymentFrequency=jQuery('input[name="input_6"]:checked').val();jQuery('input[id^="input_52_2012"]').each(function(){const areaInput=jQuery(this);if(areaInput.closest('.gfield_repeater_template').length){return} 99if(jQuery.trim(areaInput.val())===''){return} 100const index=areaInput.attr('id').split('-')[1];const choiceInput=jQuery(`#choice_52_2013_0-${index}`);let monthlyFee=0;
100if(areaInput.length>0){const area=parseInt(areaInput.val(),10)||0;if(area<=0){monthlyFee=41.56}else if(area<=100){monthlyFee=6.39}else if(area<=500){monthlyFee=12}else if(area<=2000){monthlyFee=22.37}else if(area<=4000){monthlyFee=28.76}else if(area<=5000){monthlyFee=35.15}else if(area<=6000){monthlyFee=41.54}else{var extraThousands=Math.floor((area-5000)/1000);monthlyFee=41.54+6.39*extraThousands} 101if(choiceInput.is(':checked')){monthlyFee+=2.11} 102totalMonthlyFee+=monthlyFee}});const formattedStartDate=convertDate(dateInput.value);const startDate=new Date(formattedStartDate);let totalFee=0;if(isDateNearPeriodEnd(startDate,paymentFrequency)){const additionalFee=calculateAdditionalFee(totalMonthlyFee,paymentFrequency);totalFee+=additionalFee} 103if(!isNaN(startDate.getDate())){const daysInStartMonth=new Date(startDate.getFullYear(),startDate.getMonth()+1,0).getDate();const remainingDaysInStartMonth=daysInStartMonth-startDate.getDate()+1;const proratedFeeForStartMonth=(totalMonthlyFee/daysInStartMonth)*remainingDaysInStartMonth;totalFee+=proratedFeeForStartMonth;const endDate=getEndDate(startDate,paymentFrequency);let currentMonth=startDate.getMonth()+1;while(currentMonth<=endDate.getMonth()){totalFee+=totalMonthlyFee;currentMonth++}} 104return{totalFee,totalMonthlyFee}} 105function updateDisplay(fee){var forEAU=0;var futureFeeStartDate='';const date=dateInput.value;const paymentFrequency=jQuery('input[name="input_6"]:checked').val();if(date===''){jQuery(feePanel).slideUp();return} 106let isAreaFilled=!1;jQuery('input[id^="input_52_2012"]').each(function(){const areaValue=jQuery(this).val();if(areaValue!==''){isAreaFilled=!0;return!1}});if(!isAreaFilled){jQuery(feePanel).slideUp();return} 107const formattedStartDate=convertDate(date);const startDate=new Date(formattedStartDate);const addExtraPeriod=startDate.getDate()>=15;const endDate=getEndDate(startDate,paymentFrequency,addExtraPeriod);const{totalFee,totalMonthlyFee}=calculateFee();forAuthors=totalFee*0.80;forEAU=totalFee*0.20;feeVAT=forEAU*0.24;const displayTotalFee=totalFee<0?0:totalFee;const displayFeeVAT=feeVAT<0?0:feeVAT;const displayForAuthors=forAuthors<0?0:forAuthors;const displayForEAU=forEAU<0?0:forEAU;const displayTotalFeeInclVAT=displayTotalFee+displayFeeVAT;currentSum.innerHTML=`<p>Tasu: <span style="float: right;"><strong>${displayTotalFee.toFixed(2)} â¬</strong></span><br> 108 <span style="color: #797979;">sh autoritasu</span><span style="float: right; color: #797979;">${displayForAuthors.toFixed(2)} â¬</span><br> 109 <span style="color: #797979;">sh vahendustasu</span><span style="float: right; color: #797979;">${displayForEAU.toFixed(2)} â¬</span></p>`;currentSum.innerHTML+=`<p style="margin-top: 10px;"><span class="license-vat">Käibemaks vahendustasult</span> <span style="float: right;"><strong>${displayFeeVAT.toFixed(2)} â¬</strong></span></p>`;currentSum.innerHTML+=`<hr><p><strong>Kokku <span style="float: right;">${displayTotalFeeInclVAT.toFixed(2)} â¬</span></strong></p>`;jQuery(feePanel).slideDown();const displayStartDate=formatDateToDDMMYYYY(startDate);var displayEndDate;displayEndDate=formatDateToDDMMYYYY(endDate);currentPeriod.innerHTML=`Periood: <span style="float: right;"><strong>${displayStartDate} - ${displayEndDate}</strong></span>`;const isSecondOptionChecked=(()=>{const choice15=jQuery('#choice_52_15_1');const choice28=jQuery('#choice_52_28_1');if(choice15.length&&choice15.is(':checked'))return!0;if(choice28.length&&choice28.is(':checked'))return!0;const pf=jQuery('input[name="input_6"]');if(pf.length>=2&&pf.eq(1).is(':checked'))return!0;return!1})();if(!isSecondOptionChecked){endDate.setDate(endDate.getDate()+1);futureFeeStartDate=formatDateToDDMMYYYY(endDate);let paymentFrequencyDisplay=paymentFrequency;if(paymentFrequency==="Aasta"||paymentFrequency==="Poolaasta"){paymentFrequencyDisplay=paymentFrequency.charAt(0).toLowerCase()+paymentFrequency.slice(1)}else if(paymentFrequency==="Kvartal"){paymentFrequencyDisplay="kvartali"} 110licenseBillingNotice.innerHTML=`Alates ${futureFeeStartDate} edastatakse teile automaatselt arve iga ${paymentFrequencyDisplay} eest sel hetkel kehtiva hinnakirja alusel.`;jQuery('.license-future-cost').slideDown();jQuery.ajax({url:my_ajax_obj.ajax_url,type:'POST',data:{'action':'store_license_future_fee','future_fee_start_date':futureFeeStartDate,'future_fee_payment_frequency':paymentFrequency,},})}else{jQuery('.license-future-cost').slideUp()} 111var inputElement=document.getElementById('input_52_5');inputElement.value=totalFee.toFixed(2);var inputElement=document.getElementById('input_52_29');inputElement.value=futureFeeStartDate} 112var debouncedCalculateAndDisplay=debounce(function(){const fee=calculateFee();updateDisplay(fee)},250);jQuery('#input_52_26').on("change",function(){if(jQuery('#input_52_26').val()!==''&&jQuery('#input_52_26').is(':visible')){debouncedCalculateAndDisplay()}});jQuery('.gform_wrapper').on('input change','input[id^="input_52_2012"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','select[id^="input_50_2013"]',function(){debouncedCalculateAndDisplay()});jQuery('.gform_wrapper').on('change','#input_52_24',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','.gfield-choice-input[type="radio"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_52_15_1',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_52_28_1',debouncedCalculateAndDisplay);var observerCallback=function(mutationsList,observer){for(var mutation of mutationsList){if(mutation.type==='childList'){debouncedCalculateAndDisplay();break}}};var observer=new MutationObserver(observerCallback);var targetNode=document.querySelector('.gform_wrapper');observer.observe(targetNode,{childList:!0,subtree:!0})};function initializeForm57(){const dateInput=document.getElementById('input_57_24');const feePanel=document.querySelector('.fee-panel');const currentSum=document.querySelector('.license-price');const currentPeriod=document.querySelector('.license-period');const licenseBillingNotice=document.querySelector('.license-future-cost');jQuery(document).on('submit','#gform_57',function(event){updateDisplay();setTimeout(function(){jQuery(this).submit()},100)});function calculateFee(){let totalMonthlyFee=0;const isIndefiniteLicense=jQuery('#choice_57_11_0').is(':checked');const isTimePeriodLicense=jQuery('#choice_57_11_1').is(':checked');const paymentFrequency=jQuery('input[name="input_6"]:checked').val();jQuery('input[id^="input_57_2012"]').each(function(){const areaInput=jQuery(this);if(areaInput.closest('.gfield_repeater_template').length){return} 113if(jQuery.trim(areaInput.val())===''){return} 114const index=areaInput.attr('id').split('-')[1];const choiceInput=jQuery(`#choice_57_2013_0-${index}`);let monthlyFee=0;const pricingTable=[{maxArea:100,cost:6},{maxArea:300,cost:9},{maxArea:600,cost:12}];if(areaInput.length>0){const area=parseInt(areaInput.val(),10)||0;if(area>600){monthlyFee=12+Math.ceil((area-600)/300)*3}else{for(const{maxArea,cost}of pricingTable){if(area<=parseInt(maxArea)){monthlyFee=parseFloat(cost);break}}} 115if(choiceInput.is(':checked')){monthlyFee+=5} 116totalMonthlyFee+=monthlyFee}});const formattedStartDate=convertDate(dateInput.value);const startDate=new Date(formattedStartDate);let totalFee=0;if(isDateNearPeriodEnd(startDate,paymentFrequency)){const additionalFee=calculateAdditionalFee(totalMonthlyFee,paymentFrequency);totalFee+=additionalFee} 117if(isIndefiniteLicense){if(!isNaN(startDate.getDate())){const daysInStartMonth=new Date(startDate.getFullYear(),startDate.getMonth()+1,0).getDate();const remainingDaysInStartMonth=daysInStartMonth-startDate.getDate()+1;const proratedFeeForStartMonth=(totalMonthlyFee/daysInStartMonth)*remainingDaysInStartMonth;totalFee+=proratedFeeForStartMonth;const endDate=getEndDate(startDate,paymentFrequency);let currentMonth=startDate.getMonth()+1;while(currentMonth<=endDate.getMonth()){totalFee+=totalMonthlyFee;currentMonth++}}}else if(isTimePeriodLicense){const endDateInput=document.getElementById('input_57_26');const formattedEndDate=convertDate(endDateInput.value);const endDate=new Date(formattedEndDate);
117if(!isNaN(startDate.getDate())&&!isNaN(endDate.getDate())){totalFee=calculateSeasonalFee(startDate,endDate,totalMonthlyFee)}} 118return{totalFee,totalMonthlyFee}} 119function updateDisplay(fee){var forEAU=0;var futureFeeStartDate='';const isTimePeriodLicense=jQuery('#choice_57_11_1').is(':checked');const date=dateInput.value;const paymentFrequency=jQuery('input[name="input_6"]:checked').val();const isContractTypeSelected=jQuery('#field_57_11 input[type="radio"]:checked').length>0;if(!isContractTypeSelected){jQuery(feePanel).slideUp();return} 120if(date===''){jQuery(feePanel).slideUp();return} 121let isAreaFilled=!1;jQuery('input[id^="input_57_2012"]').each(function(){const areaValue=jQuery(this).val();if(areaValue!==''){isAreaFilled=!0;return!1}});if(!isAreaFilled){jQuery(feePanel).slideUp();return} 122const formattedStartDate=convertDate(date);const startDate=new Date(formattedStartDate);const addExtraPeriod=startDate.getDate()>=15;const endDate=getEndDate(startDate,paymentFrequency,addExtraPeriod);const{totalFee,totalMonthlyFee}=calculateFee();forAuthors=totalFee*0.80;forEAU=totalFee*0.20;feeVAT=forEAU*0.24;const displayTotalFee=totalFee<0?0:totalFee;const displayFeeVAT=feeVAT<0?0:feeVAT;const displayForAuthors=forAuthors<0?0:forAuthors;const displayForEAU=forEAU<0?0:forEAU;const displayTotalFeeInclVAT=displayTotalFee+displayFeeVAT;currentSum.innerHTML=`<p>Tasu: <span style="float: right;"><strong>${displayTotalFee.toFixed(2)} â¬</strong></span><br> 123 <span style="color: #797979;">sh autoritasu</span><span style="float: right; color: #797979;">${displayForAuthors.toFixed(2)} â¬</span><br> 124 <span style="color: #797979;">sh vahendustasu</span><span style="float: right; color: #797979;">${displayForEAU.toFixed(2)} â¬</span></p>`;currentSum.innerHTML+=`<p style="margin-top: 10px;"><span class="license-vat">Käibemaks vahendustasult</span> <span style="float: right;"><strong>${displayFeeVAT.toFixed(2)} â¬</strong></span></p>`;currentSum.innerHTML+=`<hr><p><strong>Kokku <span style="float: right;">${displayTotalFeeInclVAT.toFixed(2)} â¬</span></strong></p>`;jQuery(feePanel).slideDown();const isSecondOptionChecked=jQuery('#choice_57_11_1').is(':checked');const displayStartDate=formatDateToDDMMYYYY(startDate);var displayEndDate;if(!isSecondOptionChecked){displayEndDate=formatDateToDDMMYYYY(endDate)}else{seasonalEndDate=document.getElementById('input_57_26').value;if(!seasonalEndDate){displayEndDate='...'}else{displayEndDate=seasonalEndDate}} 125currentPeriod.innerHTML=`Periood: <span style="float: right;"><strong>${displayStartDate} - ${displayEndDate}</strong></span>`;if(!isSecondOptionChecked){endDate.setDate(endDate.getDate()+1);futureFeeStartDate=formatDateToDDMMYYYY(endDate);let paymentFrequencyDisplay=paymentFrequency;if(paymentFrequency==="Aasta"||paymentFrequency==="Poolaasta"){paymentFrequencyDisplay=paymentFrequency.charAt(0).toLowerCase()+paymentFrequency.slice(1)}else if(paymentFrequency==="Kvartal"){paymentFrequencyDisplay="kvartali"} 126licenseBillingNotice.innerHTML=`Alates ${futureFeeStartDate} edastatakse teile automaatselt arve iga ${paymentFrequencyDisplay} eest sel hetkel kehtiva hinnakirja alusel.`;jQuery('.license-future-cost').slideDown();jQuery.ajax({url:my_ajax_obj.ajax_url,type:'POST',data:{'action':'store_license_future_fee','future_fee_start_date':futureFeeStartDate,'future_fee_payment_frequency':paymentFrequency,},})}else{jQuery('.license-future-cost').slideUp()} 127var inputElement=document.getElementById('input_57_5');inputElement.value=totalFee.toFixed(2);var inputElement=document.getElementById('input_57_29');inputElement.value=futureFeeStartDate} 128var debouncedCalculateAndDisplay=debounce(function(){const fee=calculateFee();updateDisplay(fee)},250);jQuery('#input_57_26').on("change",function(){if(jQuery('#input_57_26').val()!==''&&jQuery('#input_57_26').is(':visible')){debouncedCalculateAndDisplay()}});jQuery('.gform_wrapper').on('input change','input[id^="input_57_2012"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#input_57_24',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','.gfield-choice-input[type="radio"]',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_57_15_1',debouncedCalculateAndDisplay);jQuery('.gform_wrapper').on('change','#choice_57_28_1',debouncedCalculateAndDisplay);var observerCallback=function(mutationsList,observer){for(var mutation of mutationsList){if(mutation.type==='childList'){debouncedCalculateAndDisplay();break}}};var observer=new MutationObserver(observerCallback);var targetNode=document.querySelector('.gform_wrapper');observer.observe(targetNode,{childList:!0,subtree:!0})} 129function initializeForm53(){const currentSum=document.querySelector('.license-price');const feePanel=document.querySelector('.fee-panel');function calculateFee(){let totalMovies=0;const pricePerMovie=3;let isFilled=!1;jQuery('input[id^="input_53_2015"]').each(function(){const value=parseInt(this.value,10);if(!isNaN(value)&&value>0){totalMovies+=value;isFilled=!0}});if(!isFilled){return{totalFee:0,hasValue:!1}} 130return{totalFee:totalMovies*pricePerMovie,hasValue:!0}} 131function updateDisplay(){const{totalFee,hasValue}=calculateFee();
131if(!hasValue){jQuery(feePanel).slideUp();return} 132const forAuthors=totalFee*0.80;const forEAU=totalFee*0.20;const feeVAT=forEAU*0.24;const totalInclVAT=totalFee+feeVAT;currentSum.innerHTML=` 133 <p> 134 Tasu: 135 <span style="float:right;"><strong>${totalFee.toFixed(2)} â¬</strong></span><br> 136 <span style="color:#797979;">sh autoritasu</span> 137 <span style="float:right; color:#797979;">${forAuthors.toFixed(2)} â¬</span><br> 138 <span style="color:#797979;">sh vahendustasu</span> 139 <span style="float:right; color:#797979;">${forEAU.toFixed(2)} â¬</span> 140 </p> 141 <p style="margin-top:10px;"> 142 <span class="license-vat">Käibemaks vahendustasult</span> 143 <span style="float:right;"><strong>${feeVAT.toFixed(2)} â¬</strong></span> 144 </p> 145 <hr> 146 <p><strong>Kokku <span style="float:right;">${totalInclVAT.toFixed(2)} â¬</span></strong></p> 147 `;jQuery(feePanel).slideDown();const hidden=document.getElementById('input_53_7');if(hidden){hidden.value=totalFee.toFixed(2)}} 148const debouncedUpdate=debounce(updateDisplay,200);jQuery('.gform_wrapper').on('input change','input[id^="input_53_2015"]',debouncedUpdate);jQuery('.gform_wrapper').on('click','.add_repeater_item, .remove_repeater_item',debouncedUpdate);const observer=new MutationObserver(function(mutations){for(const mutation of mutations){if(mutation.type==='childList'){debouncedUpdate();break}}});observer.observe(document.querySelector('.gform_wrapper'),{childList:!0,subtree:!0})} 149function convertDate(inputDate){const parts=inputDate.split('.');if(parts.length===3){return parts[1]+'/'+parts[0]+'/'+parts[2]}else{return null}} 150function getEndDate(startDate,paymentFrequency,addExtraPeriod=!1){const year=startDate.getFullYear();let month=startDate.getMonth();let day=0;switch(paymentFrequency){case 'Poolaasta':month=month<6?6:12;break;case 'Aasta':month=12;break;default:month=Math.floor(month/3)*3+3;break} 151if(addExtraPeriod){const isNearPeriodEnd=isDateNearPeriodEnd(startDate,paymentFrequency);switch(paymentFrequency){case 'Poolaasta':if(isNearPeriodEnd){month+=6} 152break;case 'Aasta':if(isNearPeriodEnd){month+=12} 153break;default:if(isNearPeriodEnd){month+=3} 154break}} 155return new Date(year,month,day)} 156function isDateNearPeriodEnd(startDate,paymentFrequency){const month=startDate.getMonth()+1;const day=startDate.getDate();switch(paymentFrequency){case 'Poolaasta':return(month===6||month===12)&&day>=15;case 'Aasta':return month===12&&day>=15;default:return(month===3||month===6||month===9||month===12)&&day>=15}} 157function formatDateToDDMMYYYY(date){const day=('0'+date.getDate()).slice(-2);const month=('0'+(date.getMonth()+1)).slice(-2);const year=date.getFullYear();return `${day}.${month}.${year}`} 158function calculateSeasonalFee(startDate,endDate,totalMonthlyFee){const monthDiff=(endDate.getFullYear()-startDate.getFullYear())*12+(endDate.getMonth()-startDate.getMonth());const isStartFirstDay=startDate.getDate()===1;const isEndLastDay=endDate.getDate()===new Date(endDate.getFullYear(),endDate.getMonth()+1,0).getDate();if(isStartFirstDay&&isEndLastDay&&monthDiff>=0){return totalMonthlyFee*(monthDiff+1)} 159if(startDate.getDate()===endDate.getDate()&&monthDiff>0){return totalMonthlyFee*monthDiff} 160const daysInPeriod=Math.round((endDate.getTime()-startDate.getTime())/(1000*3600*24));return(totalMonthlyFee/30)*daysInPeriod} 161function formatPaymentFrequencyDisplay(paymentFrequency){if(paymentFrequency==="Kvartal"){return"kvartali"} 162if(paymentFrequency==="Aasta"||paymentFrequency==="Poolaasta"){return paymentFrequency.charAt(0).toLowerCase()+paymentFrequency.slice(1)} 163return paymentFrequency} 164function calculateAdditionalFee(monthlyFee,paymentFrequency){let additionalFee=monthlyFee;if(paymentFrequency==='Kvartal'){additionalFee*=3} 165if(paymentFrequency==='Poolaasta'){additionalFee*=6} 166if(paymentFrequency==='Aasta'){additionalFee*=12} 167return additionalFee} 168function debounce(func,wait,immediate){let timeout;return function(){const context=this,args=arguments;const later=function(){timeout=null;if(!immediate)func.apply(context,args)};const callNow=immediate&&!timeout;clearTimeout(timeout);timeout=setTimeout(later,wait);if(callNow)func.apply(context,args)}}
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.