$(function(){$(document).on('click','.j-customer-logout',function(e){$.get('/api-customer/apicustomerlogout',function(response){if(typeof response.redirect!=='undefined'){window.location.href=response.redirect;return}
window.location.href=window.location.href})})
$(document).on('submit','#j-login-form',function(e){e.preventDefault();po_details={};po_details.resetform=!0;po_details.redirect='/my-details';updateform($(this),po_details)});$(document).on('submit','#j-register-form',function(e){e.preventDefault();po_details={};po_details.resetform=!0;po_details.redirect='/my-details';updateform($(this),po_details)});$(document).on('submit','#j-forgot-password-form',function(e){e.preventDefault();po_details={};po_details.resetform=!0;updateform($(this),po_details);$('[data-label] input').each(function(){$(this).parent().removeClass('j-label')})});$(document).on('click','.j-remove-saved-card',function(){$('#j-saved-card-list .s-error, #j-saved-card-list .s-success').html('').addClass('is-hidden');if(!confirm('Are you sure you want to delete this saved card?')){return!1}
var cardid=$(this).data('id');var token=$('#j-saved-card-list').find('#csrftoken').val();var _this=$(this);$.post('/saved-cards?a=removecard',{i:cardid,k:token},function(po_data){if(po_data.success){_this.parent().parent().remove();var count=$('.s-list-group__item').length;$('.j-card-count').text(count);$('#j-saved-card-list .s-success').html(po_data.message).removeClass('is-hidden')}else{$('#j-saved-card-list .s-error').html(po_data.message).removeClass('is-hidden')}},'json')});$(document).on('submit','#j-update-details-form',function(e){e.preventDefault();po_details={};po_details.resetform=!1;updateform($(this),po_details)});$(document).on('submit','#j-update-password-form',function(e){e.preventDefault();po_details={};po_details.resetform=!0;po_details.redirect=!1;updateform($(this),po_details)});$(document).on('click','.j-view-all-orders',function(){$('.order-history-table .order-row').removeClass('is-hidden');$(this).addClass('is-hidden')});$(document).on('submit','.j-register-card',function(e){e.preventDefault();po_details={};po_details.resetform=!0;po_details.redirect='/my-gift-cards';updateform($(this),po_details)});$(document).on('submit','.j-email-preference-form',function(e){e.preventDefault();po_details={};po_details.resetform=!1;updateform($(this),po_details)});$(document).on('submit','.j-gift-voucher-form',function(e){e.preventDefault();po_details={};po_details.resetform=!1;po_details.subscribetimer=!1;updateform($(this),po_details)});$(document).on('change','#upload-avatar',function(){var form=$('form.s-menu-profile__edit');var formdata=new FormData(form[0]);$.ajax({type:'POST',url:'/ajax-upload-avatar',data:formdata,processData:!1,enctype:'multipart/form-data',contentType:!1}).done(function(resp){$('.s-menu-profile__avatar.s-avatar--image > img, .account-nav__icon.s-image > img').each(function(){$(this).attr('src',resp.src);$(this).attr('srcset',resp.srcset)});$('.s-menu-profile__avatar.s-avatar--initials, .account-nav__icon.s-avatar--initials').addClass('is-hidden');$('.s-menu-profile__avatar.s-avatar--image, .account-nav__icon.s-image').removeClass('is-hidden')})});"use strict";function updateform(po_form){var po_details=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};if(typeof po_details.resetform==='undefined'){po_details.resetform=!0}
if(typeof po_details.redirect==='undefined'){po_details.redirect=!1}
if(typeof po_details.subscribetimer==='undefined'){po_details.subscribetimer=!0}
var formdata=po_form.serializeArray();var formAction=po_form.attr('action');var _form=po_form;_form.find('.s-success, .s-error').html('').addClass('is-hidden');_form.find('.s-input-error').html('').addClass('is-hidden');_form.find('.s-input.s-error--validation').removeClass('s-error--validation');$.ajax({url:formAction,type:'post',dataType:'json',data:formdata,success:function success(po_data){if(po_data.success){_form.find('.s-success').html(po_data.message).removeClass('is-hidden');if(po_details.subscribetimer){subscribeTimer=setTimeout(function(){_form.find('.s-success, .s-error').html('').addClass('is-hidden');if(po_details.resetform){_form[0].reset()}
if(typeof po_data.redirect!=='undefined'){window.location.href=po_data.redirect}},800)}}else{lo_errors=po_data.errors;if(!$.isEmptyObject(lo_errors)){$.each(lo_errors,function(name,value){if(name=='recaptcha'){_form.find('.recaptcha-error').html(value).removeClass('is-hidden')}else if(name=='gender'){_form.find('.gender-error').html(value).removeClass('is-hidden')}else{_form.find('input[name="'+name+'"]').parent('.s-input').addClass('s-error--validation');_form.find('input[name="'+name+'"]').nextAll('.s-input-error').html(value).removeClass('is-hidden')}})}
if(po_data.message){_form.find('.s-message-error').html(po_data.message).removeClass('is-hidden')}}},error:function error(){}})}})