var channelCountsRefreshed=false;function channelResetRefresh(){channelCountsRefreshed=false;}
function channelRefreshCounts(id,name){if(window.location.pathname.toLowerCase().indexOf(id.toLowerCase())!==-1||window.location.pathname.toLowerCase().indexOf(name.toLowerCase())!==-1){if(!channelCountsRefreshed||document.visibilityState=='visible'){$.post({url:'/channel/'+id+'/counts/',data:{'csrfmiddlewaretoken':Cookies.get('csrftoken')},success:function(result){if(result.success){$('#subscriber_count').html(result.subscriber_count);$('#about-subscriber-count').html(result.about_subscriber_count);$('#about-view-count').html(result.about_view_count);channelCountsRefreshed=true;}},complete:function(){setTimeout(channelRefreshCounts,60000,id,name);}});}else{setTimeout(channelRefreshCounts,60000,id,name);}}}
function channelSaveSettings(channel){$.post('/channel/'+channel+'/save/',$('#save-settings').serialize(),function(result){$('#save-settings [id^="settings_error"]').addClass('hidden').text('');if(result.success){toastr.success('Your changes have been saved');$('#channel-title').text(result.display_name);$('#id_url_slug').val(result.url_slug);$('#channel-description').html(result.description);if(result.category_locked){$('#id_category').attr('readonly',true);$('#id_category').find('option').not(':selected').remove();$('#id_category_locked').removeClass('hidden');}
if(result.sensitivity_locked){$('#id_sensitivity').attr('readonly',true);$('#id_sensitivity').find('option').not(':selected').remove();$('#id_sensitivity_locked').removeClass('hidden');}}else{toastr.error('Please resolve errors then resubmit');for(i=0;i<result.errors.length;i++){if(result.errors[i][0]=='__all__'){$('#settings_error').removeClass('hidden').text(result.errors[i][1]);}else{$('#settings_error_'+result.errors[i][0]).removeClass('hidden').text(result.errors[i][1]);}}
$('.nav-tabs a[href="#channel-settings"]').tab('show');}});}
function channelExtend(extend,showall){var more=$('#channel-tabs .active .show-more');if(!more.hasClass('hidden')){more.addClass('hidden');var count=$('.channel-videos-list').children('.channel-videos-container').length;var url=window.location.href;url=url+'extend/';if(showall)url=url+'?showall=1';$.post(url,{'csrfmiddlewaretoken':Cookies.get('csrftoken'),'name':name,'offset':count},function(result){if(result.success){$('.channel-videos-list').append(result.html);spaAttachEvents();playlistAttachEvents();$('[data-toggle="tooltip"]').tooltip({container:'body',trigger:'hover'});if($('.channel-videos-list').children('.channel-videos-container').length==count+extend)more.removeClass('hidden');}});}}
function setChannelState(channel,action){$.post('/channel/'+channel+'/state/',{'action':action,'csrfmiddlewaretoken':Cookies.get('csrftoken')},function(result){if(result.success){$('#channel-state-change-action').attr('href',result.target);if(useSPA)$('#channel-state-change-action').click();else window.location.href=$('#channel-state-change-action').attr('href');}else{$('#error_modal').modal('show');}});}
function channelCreateAttach(){$('.channel-create').off('click.channel').on('click.channel',function(){$('.channel-create').addClass('hidden');$('.channel-mine').removeClass('hidden');$('.channel-upload').removeClass('hidden');});}