
$(document).ready(function () {
  var navListItems = $('ul#progressbar li a'),
          allWells = $('.setup-content'),
          allNextBtn = $('.nextBtn'),
          allPrevBtn = $('.prevBtn');

  allWells.hide();

  navListItems.click(function (e) {
      e.preventDefault();
      var $target = $($(this).attr('href')),
              $item = $(this);

      if (!$item.hasClass('disabled')) {
          navListItems.removeClass('btnprimary').addClass('btndefault');
          $item.addClass('btnprimary');
          allWells.hide();
          $target.show();
          $target.find('input:eq(0)').focus();
      }
  });
  
  allPrevBtn.click(function(){
      var curStep = $(this).closest(".setup-content"),
          curStepBtn = curStep.attr("id"),
          prevStepWizard = $('ul#progressbar li a[href="#' + curStepBtn + '"]').parent().prev().children("a");

          prevStepWizard.removeAttr('disabled').trigger('click');
  });

  allNextBtn.click(function(){
      let curStep = $(this).closest(".setup-content"),
          curStepBtn = curStep.attr("id"),
          nextStepWizard = $('ul#progressbar li a[href="#' + curStepBtn + '"]').parent().next().children("a"),
          curInputs = curStep.find("input[type='radio'],input[type='url']"),
          isValid = true;
          
      $(".form-group").removeClass("has-error");
      for(var i=0; i<curInputs.length; i++){
          if (!curInputs[i].validity.valid){
              isValid = false;
              $(curInputs[i]).closest(".form-group").addClass("has-error");
          }
      }

          /*added by bishnu on Nov 26 2019*/

    const travelDate=$("input[name='travelDate']:checked").val();
      $("input[name='travelDate']").click(e=>{
         $('#datePickingButton').removeAttr("disabled");
      });
      if(travelDate==1){
          const startDate=$("input[name='start_date']").val();
          const endDate=$("input[name='end_date']").val();

          if(startDate && endDate){
              var CurrentDate = Date.parse(new Date());

                       if(Date.parse(startDate)>=CurrentDate && Date.parse(startDate)<=Date.parse(endDate)){
                    
                              isValid=true;
                            
                            }
                          
                       
                       else{
                            $('.listplanmessage').remove();
                            $('#listplanactive').before('<p class="text-danger listplanmessage"> please select the valid return and departure date</p>');
                          isValid = false;
                       }
  
          }
          else{
              $('.listplanmessage').remove();
              $('#listplanactive').before('<p class="text-danger listplanmessage"> please select the return and departure date</p>');
              isValid = false;

          }
      }
         if(travelDate==2){
        const start_date=$("#selMon option:selected" ).text();
        const duration=$("input[name='no_days']").val();
            if(start_date){
                isValid=true;
            }
            else{
                isValid=false;
            }
            
        }   
         
         
          if($("a[href='#step-3']").hasClass( 'btnprimary' )){
              let requiredPlans=[];
           
            
              $('.text-danger').remove();
              const select_plan=$("input[name='age']:checked").val();
              const activity=$("input[name='activity[]']:checked").val();
              const destination_id=$("input[name='destination_id[]']:checked").val();
              const trip_type=$("input[name='trip_type']:checked").val();
               const currency=$("select[name='currency']").val();
               const expected_cost=$("input[name='expected_cost']").val();
               const budget_flexible=$("select[name='budget_flexible']").val();
              if(typeof select_plan === 'undefined'){
                  requiredPlans.push("select_plan");
                  $('.a1').before('<span class="text-danger">please select the group of adults</span>');
              }
              if(typeof activity === 'undefined'){
                  requiredPlans.push("activity");
                  $('.a2').before('<span class="text-danger">please select the activities you intrested</span>');
              }
              if(typeof destination_id === 'undefined'){
                  requiredPlans.push("destination_id");
                  $('.a3').before('<span class="text-danger">please select the destination you intrested</span>');
              }
              if(typeof trip_type === 'undefined'){
                  requiredPlans.push("trip_type");
                  $('.a4').before('<span class="text-danger">please select the accmodartion you like</span>');
              }
              if(currency==='0'){
                   requiredPlans.push("currency");
                  $('.a5').before('<span class="text-danger">please select the Currency</span>');
              }
              if(budget_flexible==='0'){
                   requiredPlans.push("budget_flexible");
                  $('.a6').before('<span class="text-danger">please put your expected price</span>');
              }
              if(!expected_cost){
                   requiredPlans.push("expected_cost");
                  $('.a7').before('<span class="text-danger">please select you budget choice</span>');
              }
             if(!requiredPlans.length){
                 isValid=true;
             }else{
                isValid=false;
             }
              
          }
          
           
        
      if (isValid)
          nextStepWizard.removeAttr('disabled').trigger('click');
  });
  
//   const termsAndCondition=$( "#termsAndCondition" ).prop( "checked" ).val();


    
  function validatePassword() {
        var validator = $("#loginForm").validate({
            rules: {
                password: "required",
                confirmpassword: {
                    equalTo: "#password"
                }
            },
            messages: {
                password: " Enter Password",
                confirmpassword: " Enter Confirm Password Same as Password"
            }
        });
        if (validator.form()) {
            alert('Sucess');
        }
    }
    
  

  $('ul#progressbar li a.btnprimary').trigger('click');
  
$('#termsAndCondition').click(function() {
    $("#submitButton").prop('disabled', false);
});
 
if($('#signupExample').length){
 $('#customize-form').submit(e=>{
     e.preventDefault();
     let errors=[];
     $('.text-danger').remove();
     const firstName= $("input[name=first_name]").val(),
     lastName=$("input[name=last_name]").val(),
     email=$("#email").val(),
     country=$("#country:selected").val(),
     phone=$("input[name=phone]").val(),
     password=$("#password").val(),
     confirmpassword=$("#confirmpassword").val();
     if(firstName<=3){
         $("input[name=first_name]").before('<span class="text-danger"><br/><small>First name is required and need to be more than 3 characters</small></span>');
          errors.push("first_name");
     }
     if(lastName<=3){
         $("input[name=last_name]").before('<span class="text-danger"><br/><small>Last name is required and need to be more than 3 characters</small></span>');
          errors.push("last_name");
     }
     if(!email){
         $("#email").before('<span class="text-danger"><br/><small>Please enter an email</small></span>');
          errors.push("email");
     }
     if(!phone){
         $("input[name=phone]").before('<span class="text-danger"><br/><small>Please enter your phone number</small></span>');
          errors.push("phone");
     }
     if(password<=8){
         $("#password").before('<span class="text-danger"><br/><small>Please enter a password and mustbe more than 8 character</small></span>');
          errors.push("password");
     }
     if(password!==confirmpassword){
         $("#confirmpassword").before('<span class="text-danger"><br/><small>Password must match</small></span>');
          errors.push("password");
     }
     if(!errors.length){
         console.log(errors.length);
         $('#customize-form').unbind().submit();
     }
    
 })
}
 
  
$("input:radio[name='travelNo']").click(e=>{
    $('.trvSty').attr('disabled',false);
});
  $("input:radio[name='travelDate']").click(e=>{
   const checked=$("input:radio[name='travelDate']:checked").val();
   
   if(checked>=2){
      $('.listplanmessage').remove();
   }
});
  
});