var authNextPage='#';function authShowModal(url){authNextPage=url;$('#auth_modal').modal('show');}
function authNext(){if(authNextPage.length>0){if(authNextPage[0]=='#'){window.location.reload();}else{window.location.href=authNextPage;}}else{window.location.reload();}}
$('#auth_submit').off('click.authenication').on('click.authenication',function(e){var elem=$(this);var tab=$('#auth_modal form:visible').closest('.tab-pane');elem.prop('disabled',true);if(tab.attr('id')=='auth_login'){$.post(tab.attr('data-target'),$('#auth_login_form').serialize(),function(result){$('#auth_login_form [id^="auth_login_error"]').addClass('hidden').text('');if(result.success){$('#auth_modal').modal('hide');authNext();}else{if(result.otc)$('#auth_login_one_time_code').removeClass('hidden');for(i=0;i<result.errors.length;i++){if(result.errors[i][0]=='__all__'){$('#auth_login_error').removeClass('hidden').html(result.errors[i][1]);}else{$('#auth_login_error_'+result.errors[i][0]).removeClass('hidden').text(result.errors[i][1]);}}
toastr.error('Please resolve errors and try again');}}).fail(function(){toastr.error('Please refresh the page and repeat the action. If the issue persists please raise a support ticket.','Unexpected Error Occurred',{timeOut:2500});}).always(function(){elem.prop('disabled',false);});}else if(tab.attr('id')=='auth_reset'){$.post(tab.attr('data-target'),$('#auth_reset_form').serialize(),function(result){$('#auth_reset_form [id^="auth_reset_error"]').addClass('hidden').text('');if(result.success){$('#auth_modal').modal('hide');authNextPage='/accounts/reset/done/';authNext();}else{for(i=0;i<result.errors.length;i++){if(result.errors[i][0]=='__all__'){$('#auth_reset_error').removeClass('hidden').text(result.errors[i][1]);}else{$('#auth_reset_error_'+result.errors[i][0]).removeClass('hidden').text(result.errors[i][1]);}}
toastr.error('Please resolve errors and try again');}}).fail(function(){toastr.error('Please refresh the page and repeat the action. If the issue persists please raise a support ticket.','Unexpected Error Occurred',{timeOut:2500});}).always(function(){elem.prop('disabled',false);});}});