$(function() {

// TO MAKE RADIO TOGGLE    
$('input[type="radio"]').click(function(){
  var $radio = $(this);
  // if this was previously checked
  if ($radio.data('waschecked') == true){
      $radio.prop('checked', false);
      $radio.data('waschecked', false);
  }
  else
      $radio.data('waschecked', true);
  // remove was checked from other radios
  $radio.siblings('input[type="radio"]').data('waschecked', false);
  });

$('.req').hide(); 
$("form[name='contact-enq']").validate({
// Specify validation rules
rules: {
vb_name: { required: true },
vb_email:{ required:true, email:true },
vb_phone: { required: true, digits:true},      
vb_message:{ required:true },
},

// Specify validation error messages
messages: {
vb_name: { required: "Please provide name" },
vb_email:{ email: "Please enter a valid email address" },
vb_phone: { required: "Please provide mobile no",
digits: "Mobile no must be numeric"},
vb_message:{ required: "Please provide message detail" },
},

submitHandler: function(form) {
form.submit();
}
});

$("form[name='popup-enq']").validate({
// Specify validation rules
rules: {
vb_name: { required: true },
vb_email:{ required:true, email:true },
vb_phone: { required: true, digits:true},      
vb_message:{ required:true },
},

// Specify validation error messages
messages: {
vb_name: { required: "Please provide name" },
vb_email:{ email: "Please enter a valid email address" },
vb_phone: { required: "Please provide mobile no",
digits: "Mobile no must be numeric"},
vb_message:{ required: "Please provide message detail" },
},

submitHandler: function(form) {
form.submit();
}
});

});

subscription = ()=>{
var subscriber_email = $('#subscriber_email').val();
if(subscriber_email!=""){
 if(!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(subscriber_email)){
  alert('Please enter a valid email!');
  $('#subscriber_email').focus();
 }else{
  $.ajax({
    url: site_url+"/subscription.php",
    type:"post",
    data:{subscriber_email:subscriber_email},
    success:function(res){
      alert(res)
      $('#subscriber_email').val("");
    },error:function(res){
      console.log(res)
    }
  });
 }  
}else{
  alert('Please enter your email!');
  $('#subscriber_email').focus();
}
}



