',};$querySelector('.lightbox #frm-email-subscribe').addEventListener('submit', function(e){e.preventDefault();var first_name = this.querySelector('input[name="first_name"]');var email_address = this.querySelector('input[name="email_address"]');if( first_name.value == '' ){this.querySelector('.response').text('Please provide your first name.');this.querySelector('.response').addClass('active','error');first_name.focus();return form_error( first_name );}this.querySelector('.response').html('');this.querySelector('.response').removeClass('active','error');if( !is_valid_email_address(email_address.value) ){this.querySelector('.response').append( icons.warning );this.querySelector('.response').append('Please enter a valid email address.');this.querySelector('.response').addClass('active','error');email_address.focus();return form_error( email_address );}this.querySelector('.btn-submit').addClass('working');this.querySelector('.btn-submit').disabled = true;xhr('/ajax/subscribe/', {method:'POST',responseType:'json',data:{first_name:first_name.value,email_address:email_address.value,post_id:MoneySavingPro.post_id,vertical_name:MoneySavingPro.vertical_name,carrier_interest:MoneySavingPro.carrier_interest,network_interest:MoneySavingPro.network_interest,provider_interest:MoneySavingPro.provider_interest,device_interest:MoneySavingPro.device_interest,},success:function( response ){if( response.status == MoneySavingPro.STATUS_ERROR ){$querySelector('.lightbox #frm-email-subscribe .response').append( response.error_message );$querySelector('.lightbox #frm-email-subscribe .response').addClass('active','error');$querySelector('.lightbox #frm-email-subscribe .btn-submit').removeClass('working');$querySelector('.lightbox #frm-email-subscribe .btn-submit').disabled = false;}else{$querySelector('.lightbox #frm-email-subscribe').removeClass('active');$querySelector('.lightbox #frm-sms-subscribe .response').append( icons.check );$querySelector('.lightbox #frm-sms-subscribe .response').append('You\'ve successfully subcribed to our newsletter!');$querySelector('.lightbox #frm-sms-subscribe .response').addClass('active', 'success');$ID('frm-sms-subscribe').addClass('active');}},error:function(){$querySelector('.lightbox #frm-email-subscribe .response').append( response.error_message );$querySelector('.lightbox #frm-email-subscribe .response').append('An internal error has occurred.');$querySelector('.lightbox #frm-email-subscribe .response').addClass('active', 'error');}});});$querySelector('.lightbox #frm-sms-subscribe').addEventListener('submit', function(e){e.preventDefault();var phone_number = this.querySelector('input[name="phone_number"]');var phone_number_value = phone_number.value.replace(/[^0-9]/g,'');if( phone_number_value.length == 11 && phone_number_value.substr(0,1) == 1 ){phone_number_value = phone_number_value.substr(1);}this.querySelector('.response').html('');this.querySelector('.response').removeClass('active', 'success', 'error');if( phone_number_value.length != 10 ){this.querySelector('.response').append( icons.warning );this.querySelector('.response').append('Please enter a valid phone number.');this.querySelector('.response').addClass('active', 'error');phone_number.focus();return form_error( phone_number );}this.querySelector('.btn-submit').addClass('working');this.querySelector('.btn-submit').disabled = true;xhr('/ajax/subscribe/', {method:'POST',responseType:'json',data:{phone_number:phone_number.value,post_id:MoneySavingPro.post_id,vertical_name:MoneySavingPro.vertical_name,carrier_interest:MoneySavingPro.carrier_interest,network_interest:MoneySavingPro.network_interest,provider_interest:MoneySavingPro.provider_interest,device_interest:MoneySavingPro.device_interest,},success:function( response ){if( response.status == MoneySavingPro.STATUS_ERROR ){$querySelector('.lightbox #frm-sms-subscribe .response').append( icons.warning );$querySelector('.lightbox #frm-sms-subscribe .response').append( response.error_message );$querySelector('.lightbox #frm-sms-subscribe .response').addClass('active', 'error');$querySelector('.lightbox #frm-sms-subscribe .btn-submit').removeClass('working');$querySelector('.lightbox #frm-sms-subscribe .btn-submit').disabled = false;}else{$querySelector('.lightbox #frm-sms-subscribe').removeClass('active');$querySelector('.lightbox #subscribe-complete').addClass('active');}},error:function(){$querySelector('.lightbox #frm-sms-subscribe .response').append( icons.warning );$querySelector('.lightbox #frm-sms-subscribe .response').append('An internal error has occurred.');$querySelector('.lightbox #frm-sms-subscribe .response').addClass('active', 'error');}});});$querySelector('.lightbox #frm-sms-subscribe input[name="phone_number"]').addEventListener('blur', function(){var num = this.value.replace(/[^0-9]/g,'');if( num.length == 11 && num.substr(0,1) == 1 ){num = num.substr(1);}if( num.length == 10 ){this.value = '+1 ('+num.substr(0,3)+') '+num.substr(3,3)+'-'+num.substr(6);}});})();