;(function($,_,undefined){"use strict";ips.controller.register('forms.front.submission.form',{initialize:function(){this.on('click','[data-action="changeLUG"]',this.changeLUG);this.on('click','[data-action="changeAddress"]',this.changeAddress);this.on('click','[data-action="revertAddress"]',this.revertAddress);this.on('forms.stopLogic',this.checkStoppedQuestions);this.on('change','#elSelect_form_club_id',this.changeClub);this.on('submit',this.submitForm);this.setup();this.changeClub();},setup:function(){this._modifiedAddress=false;this._noAddress=false;this._noPhone=false;this._noEmail=false;this._noName=false;if(this.scope.find('[data-role="existingShippingDetails"]').length){if(this.scope.find('[data-role="noShippingAddress"]').length){this._noAddress=true;}
if(this.scope.find('[data-role="noShippingPhone"]').length){this._noPhone=true;}
if(this.scope.find('[data-role="noShippingEmail"]').length){this._noEmail=true;}
if(this.scope.find('[data-role="noShippingName"]').length){this._noName=true;}}
this._interval=setInterval(this._heartbeat,180000);},submitForm:function(e){if(!(this.scope.find('[data-role="shippingAddress"]').length||this.scope.find('input[type="hidden"][name="custom_shipping_address"]').length)){return;}
var usingCustomShipping=this.scope.find('input[type="hidden"][name="custom_shipping_address"]').length;var addressFirstLine=this.scope.find('input[name="shipping_address[address][]"]');var email=this.scope.find('input[name="shipping_email"]');var phone=this.scope.find('input[name="shipping_phone"]');var name=this.scope.find('input[name="shipping_name"]');if(usingCustomShipping&&$.trim(addressFirstLine.val())==''){ips.ui.alert.show({type:'alert',message:ips.getString('addressErrorNoText')});e.preventDefault();return false;}else if(!usingCustomShipping&&this._noAddress){ips.ui.alert.show({type:'alert',message:ips.getString('addressErrorNoClub')});e.preventDefault();return false;}else if((usingCustomShipping&&$.trim(phone.val())=='')||(!usingCustomShipping&&this._noPhone)){ips.ui.alert.show({type:'alert',message:ips.getString('addressErrorNoPhone')});e.preventDefault();return false;}else if((usingCustomShipping&&$.trim(email.val())=='')||(!usingCustomShipping&&this._noEmail)){ips.ui.alert.show({type:'alert',message:ips.getString('addressErrorNoEmail')});e.preventDefault();return false;}else if((usingCustomShipping&&$.trim(name.val())=='')||(!usingCustomShipping&&this._noName)){ips.ui.alert.show({type:'alert',message:ips.getString('addressErrorNoName')});e.preventDefault();return false;}},changeLUG:function(e){e.preventDefault();this.scope.find('[data-role="clubName"], [data-action="changeLUG"]').hide();this.scope.find('[data-role="chooseClub"]').slideDown();},changeAddress:function(e){e.preventDefault();this.scope.find('[data-role="existingShippingDetails"], [data-action="changeAddress"]').hide();this.scope.find('[data-role="changeShippingAddress"]').slideDown();this.scope.prepend("<input type='hidden' name='custom_shipping_address' value='1' />");},revertAddress:function(e){e.preventDefault();var self=this;this.scope.find('[data-role="changeShippingAddress"]').slideUp(function(){self.scope.find('[data-role="existingShippingDetails"], [data-action="changeAddress"]').show();})
this.scope.find('input[type="hidden"][name="custom_shipping_address"]').remove();},changeClub:function(e){var shippingDetails=this.scope.find('[data-role="existingShippingDetails"]');var shippingAddress=this.scope.find('[data-role="shippingAddress"]');var shippingEmail=this.scope.find('[data-role="shippingEmail"]');var shippingPhone=this.scope.find('[data-role="shippingPhone"]');var shippingName=this.scope.find('[data-role="shippingName"]');var id=(this.scope.find('#elSelect_form_club_id').val()?this.scope.find('#elSelect_form_club_id').val():this.scope.find('[name="form_club_id"]').val());if(typeof id=='undefined'){return;}
var self=this;shippingAddress.html("<span class='ipsType_light'>Loading...</span>");shippingPhone.html("<span class='ipsType_light'>Loading...</span>");shippingEmail.html("<span class='ipsType_light'>Loading...</span>");shippingName.html("<span class='ipsType_light'>Loading...</span>");ips.getAjax()(ips.getSetting('baseURL')+'index.php?app=forms&module=forms&controller=forms&do=getClubLocation&id='+id,{type:'post'}).done(function(response){var addressPieces=[];if(_.isArray(response.address.addressLines)&&response.address.addressLines.length){for(var i=0;i<response.address.addressLines.length;i++){if(response.address.addressLines[i]!==null){addressPieces.push(response.address.addressLines[i]);}}}
if(response.address.city){addressPieces.push(response.address.city);}
if(response.address.region){addressPieces.push(response.address.region);}
if(response.address.country){addressPieces.push(response.address.country);}
if(response.address.postalCode){addressPieces.push(response.address.postalCode);}
if(addressPieces.length){self._noAddress=false;shippingAddress.html(addressPieces.join('<br>'));}else{self._noAddress=true;shippingAddress.html("<span class='ipsType_light'>No address specified</span>");}
if(response.phone){shippingPhone.text(response.phone);self._noPhone=false;}else{shippingPhone.html("<span class='ipsType_light'>No phone number specified</span>");self._noPhone=true;}
if(response.email){shippingEmail.text(response.email);self._noEmail=false;}else{shippingEmail.html("<span class='ipsType_light'>No email address specified</span>");self._noEmail=true;}
if(response.name){shippingName.text(response.name);self._noName=false;}else{shippingName.html("<span class='ipsType_light'>No recipient name specified</span>");self._noName=true;}}).fail(function(){self._noAddress=true;shippingDetails.html("<span class='ipsType_light'>Couldn't load an address</span>");});},checkStoppedQuestions:function(){const stoppedQuestions=this.scope.find('[data-stopped]');if(stoppedQuestions.length){this.scope.find('button[type="submit"]').prop('disabled',true);}else{this.scope.find('button[type="submit"]').prop('disabled',false);}},_heartbeat:function(){ips.getAjax()(ips.getSetting('baseURL')+'index.php?app=forms&module=forms&controller=submission&do=ping');}});}(jQuery,_));;
;(function($,_,undefined){"use strict";ips.controller.register('forms.front.submission.question',{initialize:function(){this.on('change','input[type="radio"], input[type="checkbox"]',this.selectableFieldChange);this.on('change','input[type="date"]',this.dateFieldChange);this.setup();},setup:function(){const initialSelected=this.scope.find('input[type="radio"]:checked, input[type="checkbox"]:checked');if(initialSelected.length){this._checkForStopLogic(initialSelected);}},dateFieldChange:function(e){this._checkForValidDate($(e.currentTarget));},selectableFieldChange:function(e){this._checkForStopLogic();},_checkForValidDate:function(field){const question=field.attr('name');const message=this.scope.find('[data-role="fieldStopMessage"]');if(_.isUndefined(dateFields)||_.isUndefined(dateFields[question])){return;}
const secondsInDays=dateFields[question]*24*60*60;const nowDate=Date.now()/ 1000;const thenDate=Date.parse(field.val())/ 1000;console.log(nowDate);console.log(thenDate);if(nowDate-thenDate<secondsInDays){message.text(`This date must be at lease ${dateFields[ question ]} days in the past`).show();this.scope.attr('data-stopped',true);}else{message.text('').hide();this.scope.removeAttr('data-stopped');}
this.trigger('forms.stopLogic');},_checkForStopLogic:function(){let question;let idx;const fields=this.scope.find('input[type="radio"], input[type="checkbox"]');const message=this.scope.find('[data-role="fieldStopMessage"]');const messages=[];fields.each(function(){const field=$(this);if(field.attr('type')==='radio'){question=field.attr('name');idx=parseInt(field.attr('value'));}else if(field.attr('type')==='checkbox'){const pieces=field.attr('name').match(/(.+)\[(.+)\]/);question=pieces[1];idx=parseInt(pieces[2]);}
if(field.is(':checked')){if(!_.isUndefined(stopLogic)&&!_.isUndefined(stopLogic[question])&&stopLogic[question][idx].enabled){messages.push(stopLogic[question][idx].message);}}});if(messages.length){message.html(messages.join('<br>')).show();this.scope.attr('data-stopped',true);}else{message.html('').hide();this.scope.removeAttr('data-stopped');}
this.trigger('forms.stopLogic');}});}(jQuery,_));;
;(function($,_,undefined){"use strict";ips.controller.register('forms.front.submission.slider',{initialize:function(){this.on('input','[data-role="slider"]',this.changeSlider);this.setup();},setup:function(){this.changeSlider();var max=parseInt(this.scope.find('[data-role="slider"]').attr('max'));this.scope.find('[data-role="answerMax"]').text(max);},changeSlider:function(){var val=this.scope.find('[data-role="slider"]').val();this.scope.find('[data-role="answerValue"]').text(val);}});}(jQuery,_));;