function monetizationInit(channel){$.post('/monetization/get_creator_monetization/',{'csrfmiddlewaretoken':Cookies.get('csrftoken'),'channel':channel},function(result){if(result.success){$('#main-content').append(result.html);$('.creator-monetization').off('click.monetization').on('click.monetization',function(){monetizationModalShow()});themeSetMode();if(result.monetized)monetizationModalInit();}else{console.log('Failed to check creator monetization state');}});}
function monetizationModalInit(){$('#on-usd-id').removeClass('hidden');$('#off-usd-id').addClass('hidden').addClass('remove');setTimeout(monetizationUnshake,10000);$('.monetization-provider').off('click.monetization').on('click.monetization',function(){var elem=$(this);$('#select-monetization-provider').addClass('hidden');$('#'+elem.data('target')).removeClass('hidden');});$('#coinpayments-form').on('submit',function(){$('#monetization-coinpayments').addClass('hidden');$('#support-bitchute').removeClass('hidden')});$("#coinpayments-amount").on("change keyup paste click",function(){tip=$(this).val();if(tip===0||typeof tip=='undefined'||tip.length===0){$('#coinpayments-submit').attr('disabled','disabled');return;}else{$('#coinpayments-submit').removeAttr('disabled');}
if(tip.endsWith("\.0"))return;tip=Math.round(tip*100)/100;$(this).val(tip);});$('#paypal-monthly-form').on('submit',function(){$('#monetization-paypal').addClass('hidden');$('#support-bitchute').removeClass('hidden')});$('#paypal-tip-form').on('submit',function(){$('#monetization-paypal').addClass('hidden');$('#support-bitchute').removeClass('hidden')});$("#paypal-amount").on("change keyup paste click",function(){tip=$(this).val();if(tip===0||typeof tip=='undefined'||tip.length===0){$('#paypal-monthly-submit').attr('disabled','disabled');$('#paypal-tip-submit').attr('disabled','disabled');return;}else{$('#paypal-monthly-submit').removeAttr('disabled');$('#paypal-tip-submit').removeAttr('disabled');}
if(tip.endsWith("\.0"))return;tip=Math.round(tip*100)/100;$(this).val(tip);$('#paypal-monthly-amount').val(tip);$('#paypal-tip-amount').val(tip);});$('#paypal-recurring').on('change.bootstrapSwitch',function(e){if(e.target.checked){$('#paypal-tip').addClass("hidden");$('#paypal-monthly').removeClass("hidden");}else{$('#paypal-monthly').addClass("hidden");$('#paypal-tip').removeClass("hidden");}});}
function monetizationModalShow(){$('#select-monetization-provider').removeClass('hidden');$('#monetization-coinpayments').addClass('hidden');$('#monetization-paypal').addClass('hidden');$('#support-bitchute').addClass('hidden');$('#monetization-modal').modal('show');}
function monetizationUnshake(){$('#on-usd-id').addClass('hidden');$('#off-usd-id').removeClass('hidden');}
function monetizationAdvertInit(){$('.panel-heading input').off('click.monetization').on('click.monetization',function(){$('#region-'+$(this).data('region')+' input').prop('checked',$(this).prop('checked'));});$('.panel-body input').off('click.monetization').on('click.monetization',function(){monetizationAdvertCheckRegion($(this).data('region'));});$('.panel-heading input').each(function(){monetizationAdvertCheckRegion($(this).data('region'));});}
function monetizationAdvertCheckRegion(region){$('#region-'+region+'-toggle').prop('checked',$('#region-'+region+' input:checked').length>0);}
function monetizationAdvertState(advert,action){$.post('/monetization/advert/'+advert+'/state/',{'action':action,'csrfmiddlewaretoken':Cookies.get('csrftoken')},function(result){$('#advert-error').addClass('hidden').text('');if(result.success){$('#advert-state-change-action').attr('href',result.target);if(useSPA)$('#advert-state-change-action').click();else window.location.href=$('#advert-state-change-action').attr('href');}else if(typeof result.error=='undefined'){$('#error_modal').modal('show');}else{toastr.error('Please resolve errors then resubmit');$('#advert-error').removeClass('hidden').text(result.error);}});}
function monetizationAdvertSave(advert){$.post('/monetization/advert/'+advert+'/save/',$('#save-advert').serialize(),function(result){$('#save-advert [id^="advert-error"]').addClass('hidden').text('');if(result.success){toastr.success('Your changes have been saved');$('#advert-title').text(result.title);$('#advert-url').attr('href',result.url);if(result.url.length>0){$('#advert-url').removeClass('hidden');$('#advert-url-disabled').addClass('hidden');}else{$('#advert-url').addClass('hidden');$('#advert-url-disabled').removeClass('hidden');}}else{toastr.error('Please resolve errors then resubmit');for(i=0;i<result.errors.length;i++){if(result.errors[i][0]=='__all__'){$('#advert-error').removeClass('hidden').text(result.errors[i][1]);}else{$('#advert-error-'+result.errors[i][0]).removeClass('hidden').text(result.errors[i][1]);}}}});}