var Step1={max_height:'',min_once_amount:'',max_once_amount:'',min_regular_amount:'',max_regular_amount:'',adapted_height:false,lang:'fr_FR',payment_modes_once:{},payment_modes_regular:{},current_donation:'',amount_equivalences:{'once':[],'regular':[]},init_done:false,init:function(){$(document).trigger($.Event("ira_step1_init_before"));Step1.lang=$('html').attr('lang');var currency_field=$('input[name=currency],select[name=currency]');var famount_once=$('#famount-once');var famount_regular=$('#famount-regular');var amount_once=$('#once input[type="radio"]');var amount_regular=$('#regular input[type="radio"]');amount_regular.each(function(){$(this).attr('data-amount',$(this).val());});amount_once.each(function(){$(this).attr('data-amount',$(this).val());});Step1.min_once_amount_err_template=DntErrors.errorMsg.min_once_amount;Step1.max_once_amount_err_template=DntErrors.errorMsg.max_once_amount;Step1.min_regular_amount_err_template=DntErrors.errorMsg.min_regular_amount;Step1.max_regular_amount_err_template=DntErrors.errorMsg.max_regular_amount;Step1.hideReductionInfo();Step1.hideEquivalence();Step1.initValues();Step1.init_done=true;Step1.current_donation=Step1.getDonation();famount_once.change(function(){Step1.set_donation_from_element($(this));});famount_once.keyup(function(){setTimeout(function(){},100);Step1.set_donation_from_element($(this));});famount_regular.change(function(){Step1.set_donation_from_element($(this));});famount_regular.keyup(function(){setTimeout(function(){},100);Step1.set_donation_from_element($(this));});amount_once.click(function(){Step1.set_donation_from_element($(this));});amount_regular.click(function(){Step1.set_donation_from_element($(this));});currency_field.change(function(){$('body').trigger($.Event("change_amount"));Common.applyCurrency();});$("#famount-once, #famount-regular").irPriceInput({'decimal_sep':Step1.decimal_sep});$('#step-1 [data-ira-check] > input,#step-1 input[data-ira-check]').blur(function(){Common.check_input($(this));});try{var donation=Step1.getDonation();Common.fillField('input[name=currency],select[name=currency]',donation.currency);if(typeof Step3!='undefined'){Step1.payment_modes_once=$('#payment_modes_once').detach();Step1.payment_modes_regular=$('#payment_modes_regular').detach();Step3.showPaymentModes(donation.frequency);}
if(donation&&typeof(donation)!='undefined'&&donation.amount>0){Step1.set_donation_from_element(donation.element);}
$('form#form-steps').append('');$('input[name=private_stats_config]').val(JSON.stringify(Step1.get_user_params()));}catch(err){}},set_donation:function(donation){var elem=Step1.initValues(donation);Step1.set_donation_from_element(elem,donation);},set_donation_from_element:function(elem,donation){Step1.hideReductionInfo();Step1.hideEquivalence();var id_elem=elem.attr('id');$('#step-1 [id^=famount-], #step-1 [id^=amount-]').each(function(){if($(this).attr('id')!=id_elem){if($(this).attr('type')=='text')$(this).val('');else{$(this).removeAttr("selected");$(this).attr('checked',false);}}});var donation=donation||Step1.getDonation();Common.applyCurrency(donation.currency);var frequency=donation.frequency;if(frequency=='once'){if(typeof Step3!='undefined'){Step3.showPaymentModes('once');Step3.hidePaymentModes('regular');Step3.regularFrequenciesHide();}
Step1.regularBlocksHide();Step1.onceBlocksShow();if(typeof showWalletWidgetOnce=='undefined'){$('#fielset-amazon').hide();}else{if(typeof accessToken!='undefined'){showWalletWidgetOnce(accessToken);}else{$('#fielset-amazon').show();if((typeof showAmazonPayButtonOnce!='undefined')&&(typeof(OffAmazonPayments)!="undefined")&&($('#AmazonPayButton > .amazonpay-button-inner-image').length)==0){showAmazonPayButtonOnce();}}}
$('#amazon-submit-once').hide();}else{if(typeof Step3!='undefined'){Step3.showPaymentModes('regular');Step3.hidePaymentModes('once');Step3.regularFrequenciesShow();}
Step1.regularBlocksShow();Step1.onceBlocksHide();if(typeof showWalletWidgetRegular=='undefined'){$('#fielset-amazon').hide();}else{if(typeof accessToken!='undefined'){showWalletWidgetRegular(accessToken);}else{$('#fielset-amazon').show();if((typeof showAmazonPayButtonRegular!='undefined')&&(typeof(OffAmazonPayments)!="undefined")&&($('#AmazonPayButton > .amazonpay-button-inner-image').length)==0){showAmazonPayButtonRegular();}}}
$('#amazon-submit-regular').hide();}
$('#regular input, #once input').each(function(){$(this).prop('tabindex',100);});elem.prop('tabindex',0);$('#form-steps').change();Step1.showReductionInfo(donation.amount_donation,donation.amount_tip,frequency);Step1.showEquivalence(donation.amount_donation||donation.donation,frequency);Step1.adaptHeight();var amount_changed=(Step1.current_donation.frequency!=donation.frequency||Step1.current_donation.amount!=donation.amount);Step1.current_donation=donation;if(amount_changed)$('body').trigger($.Event("change_amount"));$('body').trigger($.Event("init_done"));},get_user_params:function(){var e=0,t=0;var ratio=window.devicePixelRatio||1;try{"number"==typeof window.innerWidth?(e=window.innerWidth,t=window.innerHeight):document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)?(e=document.documentElement.clientWidth,t=document.documentElement.clientHeight):document.body&&(document.body.clientWidth||document.body.clientHeight)&&(e=document.body.clientWidth,t=document.body.clientHeight)}catch(n){console.log(n.message)}
var i={"visitor_resolution_width":screen.width*ratio,"visitor_resolution_height":screen.height*ratio,"visitor_color":screen.colorDepth,"visitor_java_enabled":navigator.javaEnabled(),"visitor_langage":navigator.language,"visitor_screen_height":screen.height,"visitor_screen_width":screen.width,"user_agent":navigator.userAgent,"visitor_timezone":new Date().getTimezoneOffset(),"window_width":e,"window_height":t};return i},submit:function(){$('#form-steps').submit(function(){if(!Step1.check()){console.log('Step 1 checking failed');return false;}});},check:function(){var donation=Step1.getDonation();var ok=true;if(donation.amount==0){DntErrors.addError('choose_amount');ok=false;}else{DntErrors.removeError('choose_amount');}
var min_amount=Step1.min_once_amount*100;var max_amount=Step1.max_once_amount*100;if(donation.frequency=='regular'){min_amount=Step1.min_regular_amount*100;max_amount=Step1.max_regular_amount*100;}
DntErrors.removeError('min_once_amount');DntErrors.removeError('min_regular_amount');if(min_amount!=''&&donation.amountmax_amount){DntErrors.errorMsg['max_'+donation.frequency+'_amount']=Step1['max_'+donation.frequency+'_amount_err_template'].replace('{max_amount_with_currency}',Common.get_price(max_amount,donation.currency));DntErrors.addError('max_'+donation.frequency+'_amount');ok=false;}
if(!Common.check_qualification('step1'))ok=false;if(ok==false){DntErrors.displayErrors();}
return ok;},unCheckRadio:function(frequency){var selector='';if(frequency!=''){selector+='#'+frequency;}
selector+=' input[type="radio"]';$(selector).each(function(){this.checked=false;});},hideEquivalence:function(){$('.amount-equivalences').hide();$('.amount-equivalences-description').html('');Step1.adaptHeight();},showEquivalence:function(value,frequency){var equivalences=Step1.amount_equivalences[frequency];if(!equivalences||!value||!frequency||(!equivalences.length)){Step1.hideEquivalence();return;}
var equivalence={'image':null,'description':''};for(var i in equivalences){if(value');img.attr('src',equivalence['image']).attr('id',id).hide();$('#'+frequency+' .amount-equivalences-img').append(img);img.hide().fadeIn('fast',function(){setTimeout(function(){img.parent().css('min-height','');var height=Math.max(img.height()||0,img.parent().height()||0);if(height){img.parent().css('min-height',height);}else{img.parent().height('auto');}},10);})}}else{$('#'+frequency+' .amount-equivalences-img').html('').css('height','');}
$('#'+frequency+' .amount-equivalences').show();Step1.adaptHeight();},hideReductionInfo:function(){if(Step1.active_tax_reduction==0)return;$('p.tax-info').hide();Step1.adaptHeight();},showReductionInfo:function(donation_amount_original,donation_amount_tip,frequency){var body_id=$('body').attr('id');var value=donation_amount_original;if(!Step1.is_tipping_campaign){value+=donation_amount_tip;}
if(Step1.active_tax_reduction==0||value==0)return;if(frequency=='regular'){value*=12;}
var tax_text='';if(value>0&&value!=''){var company=$('#company').val();var is_company=$('#iscompany').prop('checked');var tax_info=Step1.tax_info;var tax_notice='';var real_value;var deduction;var real_values={"ir":0,"isf":0,"corp":0,"custom1":0,"custom2":0};var deductions={"ir":0,"isf":0,"corp":0,"custom1":0,"custom2":0};for(var key in real_values){real_values[key]=Step1.computeReduction(value,Step1.tax_reduction_rates[key],Step1.tax_reduction_ceils[key],Step1.tax_reduction_triggers[key]);deductions[key]=value/100-real_values[key];if(frequency=='regular'){real_values[key]/=12;deductions[key]/=12;}}
if((body_id=='type-b'||body_id=='type-c')&&is_company){if(Step1.tax_reduction_notices["corp"]!='')tax_notice=' '+Step1.tax_reduction_notices["corp"];real_value=real_values["corp"];deduction=deductions["corp"];}else{if(Step1.is_french_isf==1){if(Step1.tax_reduction_notices["isf"]!='')tax_notice=' '+Step1.tax_reduction_notices["isf"];real_value=real_values["isf"];deduction=deductions["isf"];}else{if(Step1.tax_reduction_notices["ir"]!='')tax_notice=' '+Step1.tax_reduction_notices["ir"];real_value=real_values["ir"];deduction=deductions["ir"];}}
if(!isNaN(deduction)&&!isNaN(real_value)&&deduction>0){tax_text=tax_info.replace('[notice]',tax_notice).replace(/\[(amount|deduction) ([^\]]*)\]/g,function(match,$1,$2){if($1=='amount')
return Common.number_format(real_values[$2],2,Step1.decimal_sep).replace(Step1.decimal_sep+"00","");else
return Common.number_format(deductions[$2],2,Step1.decimal_sep).replace(Step1.decimal_sep+"00","");}).replace('%s',Common.number_format(real_value,2,Step1.decimal_sep).replace(Step1.decimal_sep+"00","")).replace('%d',Common.number_format(deduction,2,Step1.decimal_sep).replace(Step1.decimal_sep+"00",""));}}
var tax_text_dom=$(''+tax_text+'
');$('.price_currency',tax_text_dom).html(Common.price_currencies[Common.getCurrency()]);tax_text=tax_text_dom.html();$('#'+frequency+' p.tax-info').html(tax_text).show();Step1.adaptHeight();},initValues:function(amount_values){var amount=Common.getDonation();var currency=Common.price_default_currency;if(typeof amount!='undefined'&&!!amount&&typeof amount.currency!='undefined'&&!!amount.currency){currency=amount.currency;}else{amount.currency=currency;}
if(amount_values&&amount_values.amount&&!amount_values.amount_donation&&amount.amount==amount_values.amount){amount_values.amount_donation=amount.amount_donation;}
Common.checkDonation(amount_values);amount=Object.assign({},{'amount':0,'frequency':Common.campaign_default_frequency,'currency':Common.price_default_currency,},amount,amount_values);Common.setCurrency(amount.currency);Common.applyCurrency(amount.currency);Common.checkDonation(amount,true);var result=null;$('input[id^=famount-]').val('');$('input[id^=amount-]').attr('checked',false);if(!amount){return null;}
try{if(amount!=null&&amount.amount_donation!=undefined&&amount.frequency!=undefined){result=$('input[name="amount-'+amount.frequency+'"][value="'+amount.amount_donation+'"]');if(!!result&&result.length==1){result.attr('checked','checked');result.click();Step1.showReductionInfo(amount.amount_donation,amount.amount_tip,amount.frequency);Step1.showEquivalence(amount.amount_donation,amount.frequency);return result;}}
result=$('input#famount-'+amount.frequency);result.val(String(amount.amount_donation/100).replace('.',Step1.decimal_sep));result.irPriceInput({'decimal_sep':Step1.decimal_sep});result.keyup();Step1.showReductionInfo(amount.amount_donation,amount.amount_tip,amount.frequency);Step1.showEquivalence(amount.amount_donation,amount.frequency);}catch(err){console.warn(err);}
return result;},saveHeightTempo:0,adaptHeight:function(){var rand=Math.floor(Math.random()*1000000);var self=this;self.saveHeightTempo=rand;setTimeout(function(){if(self.saveHeightTempo==rand){return self.adaptHeight_();}},100);},adaptHeight_:function(){if(Step1.adapt_tax_bloc){if(!Step1.adapted_height){$('#once').children().wrapAll('');$('#regular').children().wrapAll('');}
Step1.adapted_height=true;Step1.max_height=Math.max($('#adapt_once').height(),$('#adapt_regular').height());$('#once').height(Step1.max_height);$('#regular').height(Step1.max_height);}
var body_id=$('body').attr('id');if(body_id=='type-b'||body_id=='type-c'){if(typeof Steps!="undefined"){Steps.adaptHeight();}}},getDonation:function(){var famount_once_element=$('#famount-once');var famount_regular_element=$('#famount-regular');var amount_once_element=$('#once input[type="radio"]:checked');var amount_regular_element=$('#regular input[type="radio"]:checked');var famount_once=famount_once_element.val();var famount_regular=famount_regular_element.val();var amount_once=amount_once_element.val();var amount_regular=amount_regular_element.val();var donation={};donation.amount=0;donation.frequency=$('#step-1 #regular,#step-1 #once').first().attr('id');if(donation.frequency=='once')donation.element=famount_once_element;else donation.element=famount_regular_element;if(famount_once==undefined&&famount_regular==''){donation.frequency='regular';donation.element=famount_regular_element;}
if(amount_once!=undefined){donation.amount=parseFloat(amount_once);donation.frequency='once';donation.element=amount_once_element;}else if(famount_once!=''&&famount_once!=undefined){donation.amount=Math.round(parseFloat(famount_once.replace(',','.'))*100);donation.frequency='once';donation.element=famount_once_element;}else if(amount_regular!=undefined){donation.amount=parseFloat(amount_regular);donation.frequency='regular';donation.element=amount_regular_element;}else if(famount_regular!=''&&famount_regular!=undefined){donation.amount=Math.round(parseFloat(famount_regular.replace(',','.'))*100);donation.frequency='regular';donation.element=famount_regular_element;}
donation.currency=Common.getCurrency();donation.amount_donation=donation.amount;donation.amount_tip=Common.tip_value(donation.amount_donation);donation.amount=donation.amount_donation+donation.amount_tip;if(Step1.init_done){var dnt_amount_json=JSON.stringify({'amount':donation.amount,'frequency':donation.frequency,'currency':donation.currency,'amount_donation':donation.amount_donation,'amount_tip':donation.amount_tip});$.cookie('dnt_amount',dnt_amount_json,{'path':'/'});}
return donation;},changeGridAmount:function(id,newval){$('#'+id).val(newval);$('#value_of_'+id).find('.price_amount').html(Common.number_format(Math.round(newval/100),2,Step1.decimal_sep).replace(Step1.decimal_sep+"00",""));},applyRate:function(value,currency,round){var newval=value/Common.price_rates[Common.price_campaign_currency||Common.price_default_currency||'EUR']*Common.price_rates[currency];if(!round){return Math.round(newval);}
if(newval<1000){newval=Math.round(Math.ceil(newval/100)*100);}else if(newval<10000){newval=Math.round(Math.ceil(newval/500)*500);}else if(newval<50000){newval=Math.round(Math.ceil(newval/1000)*1000);}else if(newval<100000){newval=Math.round(Math.ceil(newval/5000)*5000);}else{var precision=Math.pow(10,Math.floor(Math.log10(newval))-1);newval=Math.round(Math.round(newval/precision)*precision);}
return newval;},applyCurrencyRateToGrid:function(currency){$('#once input[type="radio"][data-amount], #regular input[type="radio"][data-amount]').each(function(){var newval=$(this).attr('data-amount');if(currency!=(Common.price_campaign_currency||Common.price_default_currency||'EUR')){newval=Step1.applyRate(newval,currency,true);}
Step1.changeGridAmount($(this).attr('id'),newval);});},computeReduction:function(value,rates,ceils,trigger){if(valuei&&ceils[i]>0)amount=Math.min(remain,ceils[i]*100-last_ceil*100);deduction+=amount*rates[i]/100;remain-=amount;last_ceil=ceils[i];}
deduction=Math.round(deduction/100)*100;return(value-deduction)/100;},onceAmountSelected:function onceAmountSelected(){var donation=Step1.getDonation();return(donation.frequency=='once');},regularBlocksHide:function(){$('.regularblock').hide();$('.regularblock input, .regularblock select, .regularblock textarea').prop('disabled',true);},regularBlocksShow:function(){$('.regularblock').show();$('.regularblock input, .regularblock select, .regularblock textarea').prop('disabled',false);},onceBlocksHide:function(){$('.onceblock').hide();$('.onceblock input, .onceblock select, .onceblock textarea').prop('disabled',true);},onceBlocksShow:function(){$('.onceblock').show();$('.onceblock input, .onceblock select, .onceblock textarea').prop('disabled',false);}};