/*dashboard pagination*/

$(document).ready(function() {
     $(".next").click(function() {
      $(".pagination")
      .find(".pageNumber.active")
      .next()
      .addClass("active");
      $(".pagination")
      .find(".pageNumber.active")
      .prev()
      .removeClass("active");
     });
     $(".prev").click(function() {
      $(".pagination")
      .find(".pageNumber.active")
      .prev()
      .addClass("active");
      $(".pagination")
      .find(".pageNumber.active")
      .next()
      .removeClass("active");
     });
      $(".drft").click(function() {
      $(".pagination")
      .find(".pageNumber.active")
      .prev()
      .addClass("active");
      $(".pagination")
      .find(".pageNumber.active")
      .next()
      .removeClass("active");
     });
    });


/*step form js*/

  var currentTab = 0; // Current tab is set to be the first tab (0)
      showTab(currentTab); // Display the current tab

      function showTab(n) {
        // This function will display the specified tab of the form...
        var x = document.getElementsByClassName('tab');
        // var company_id = document.getElementsById('company-select');
        // alert(company_id);
        x[n].style.display = 'block';
        //... and fix the Previous/Next buttons:
        if (n == 0) {
          document.getElementById('prevBtn').style.display = 'none';
        } else {
          document.getElementById('prevBtn').style.display = 'inline';
        }
        if (n == x.length - 1) {
          document.getElementById('nextBtn').innerHTML = 'Submit';
        } else {
          document.getElementById('nextBtn').innerHTML = 'Next';
        }
        //... and run a function that will display the correct step indicator:
        fixStepIndicator(n);
      }

      function nextPrev_185(n) {
        // This function will figure out which tab to display
        var x = document.getElementsByClassName('tab');
        var company = document.getElementById("company-select").value;
        
        if (n == 1 && !validateForm()) return false;
        
        x[currentTab].style.display = 'none';
        
        console.log(currentTab);
        currentTab =  n;
        
         //alert(currentTab);
        
         //alert(company);
        
        if(company != "Private Company" && currentTab==1)
        {
              currentTab = currentTab + n;

        }
          
       
        if (currentTab >= x.length) {
          // ... the form gets submitted:
          document.getElementById('regForm').submit();
          currentTab=currentTab-1;
          return false;
        }
        // Otherwise, display the correct tab:
         if(currentTab!=4)
        showTab(currentTab);
      }

      
      function draft_185(n) {
        // This function will figure out which tab to display
        var x = document.getElementsByClassName('tab');
       
        x[currentTab].style.display = 'none';
        // Increase or decrease the current tab by 1:
        console.log(currentTab);
        currentTab;
      
        // currentTab = currentTab + n;
    
        // if(company != "Private Company" && currentTab==1)
        // {
        //       currentTab = currentTab + n;

        //   }
          
       
        if (currentTab >= x.length) {
          // ... the form gets submitted:
          document.getElementById('regForm').submit();
          currentTab;
          return false;
        }
       
        showTab(currentTab);
      }
      
     function prev_185(n) {
         // This function will figure out which tab to display
        var x = document.getElementsByClassName('tab');
        var company = document.getElementById("company-select").value;
         var step1= parseInt($("#step1").val());
         var prev =$("#prev").val();
        var formdata= new FormData();
        formdata.append('prev',prev);
         $.ajax({
  type:"post",
  data: formdata,
  processData: false,
  contentType: false,

  url:"ajax/section_185_action.php",

  success:function(msg){
      msg=msg.trim();
      //alert(msg);
  }
  });
          
          
          
      if (n == 1 && !validateForm()) 
      {
          //alert('hii');
       return false;}
        
        x[currentTab].style.display = 'none';
        
        console.log(currentTab);
        //alert(currentTab);
        
        if(currentTab == 3)
      {
         var result = confirm("Going back to previous step will delete the existing data entered, Want to delete this information?");
         
        if(result)
        {
           
        }
        else
        {
            //alert('in else ');
            currentTab =3;
            showTab(currentTab);
            return false;
          
        }
      }
        
          if(company != "Private Company" && parseInt(currentTab)==2)
        {
            //alert('in company');
              currentTab =0;
              //alert(currentTab);
              step1 =1;
             $("#step1").val(step1);
        }
        else
        {
            currentTab = currentTab + n;
            step1 -=1;
            $("#step1").val(step1);
            //alert(currentTab);
        }
      
         //alert(company);
      
        
          
       
         
        showTab(currentTab);
      }
  


      function validateForm() {
        // This function deals with validation of the form fields
        var x,
        y,
        i,
        valid = true;
        x = document.getElementsByClassName('tab');
        y = x[currentTab].getElementsByTagName('input');
        h = x[currentTab].getElementsByTagName('select');
        // A loop that checks every input field in the current tab:
    //   console.log(y);
    
// for (i = 0; i < y.length; i++) {
//     // If a field is empty...
//     if (y[i].value == "") {
//       // add an "invalid" class to the field:
//       y[i].className += " invalid";
//       // and set the current valid status to false
//       valid = false;
//     }
//   }

//   for (i = 0; i < h.length; i++) {
//     // If a field is empty...
//     if (h[i].value == "") {
//       // add an "invalid" class to the field:
//       h[i].className += " invalid";
//       // and set the current valid status to false
//       valid = false;
//     }
//   }
        // If the valid status is true, mark the step as finished and valid:
        if (valid) {
          document.getElementsByClassName('step')[currentTab].className +=
          ' finish';
        }
        return valid; // return the valid status
      }

      function fixStepIndicator(n) {
        // This function removes the "active" class of all steps...
        var i,
        x = document.getElementsByClassName('step');
        for (i = 0; i < x.length; i++) {
          x[i].className = x[i].className.replace(' active', '');
        }
        //... and adds the "active" class on the current step:
        x[n].className += ' active';
      }

/*hidde n input box for dropdown company*/
// $('#nextBtn').click(function() {
  

// });


function changeFunc() {
  var selectBox = document.getElementById("company-select");
  var selectedValue = selectBox.options[selectBox.selectedIndex].value;
  if (selectedValue == "others") {
    $('#hidden-input').show();
  } else {
    $('#hidden-input').hide();
  }
  if (selectedValue == "private-company") {
    $('#private-div-show').hide();
  } else {
    $('#private-div-show').show();
  }
}


$(function(){
  $(".sub-one").show();
  $("#company-select").change(function(){
      if(($("#company-select").val() == "private-company") || ($("#company-select").val() == "public-company")){
          $(".sub-one").hide();
      }
      else{
          $(".sub-one").show();
      }
  });
});


$(function(){
  $(".next-one").hide();
  $("#company-select").change(function(){
      if(($("#company-select").val() == "private-company") || ($("#company-select").val() == "public-company")){
          $(".next-one").show();
      }
      else{
          $(".next-one").hide();
      }
  });
});

$(function(){
  $("#tab-2").hide();
  $("#company-select").change(function(){
      if(($("#company-select").val() == "private-company")){
          $("#tab-2").show();
      }
      else{
          $("#tab-2").hide();
      }
  });
});




$(document).ready(function() {
   
    var selectBox = document.getElementById("lending");
    var selectedValue = selectBox.options[selectBox.selectedIndex].value;
    var selectBox1 = document.getElementById("share-holding");
   var selectedValue1 = selectBox.options[selectBox1.selectedIndex].value;
    if (selectedValue == "Yes") {
        $('#hidden-dd').show();
    } 
    if(selectedValue1 == "Yes")
    {
      $('#hidden-shareholding').show();  
    }


});


$('#lending').change(function()  {
   var lending= $(this).val();
  if (lending == "Yes") {
    $('#hidden-dd').show();
    
  } else {
    $('#hidden-dd').hide();
  }
});

$('#share-holding').change(function()  {
   var share= $(this).val();
  if (share == "Yes") {
    $('#hidden-shareholding').show();
    
  } else {
    $('#hidden-shareholding').hide();
  }
});



// function changeFuncsh() {
//   var selectBox = document.getElementById("share-holding");
//   var selectedValue = selectBox.options[selectBox.selectedIndex].value;
  
//   if (selectedValue =='Yes') {
    
//     $('#hidden-shareholding').show();
//   } else {
//     $('#hidden-shareholding').hide();
//   }
// }


/*input tags*/

var tags = [];
var $container = document.querySelector('div');
var $input = document.querySelector('input');
var $tags = document.querySelector('.js-tags');

$container.addEventListener('click', function() {
  $input.focus();
});

$container.addEventListener('keydown', function(evt) {
  if ( !evt.target.matches('.js-tag-input') ) {
    return;
  }
  
  if ( evt.keyCode !== 13 ) {
    return;
  }
  
  var value = String(evt.target.value);
  
  if ( !value.length || value.length > 20 || tags.length === 5 ) {
    return;
  }
  
  tags.push(evt.target.value);
  $input.value = '';
  render(tags, $tags);
});

$container.addEventListener('keydown', function(evt) {
  if ( !evt.target.matches('.js-tag-input') ) {
    return;
  }
  
  if ( evt.keyCode !== 8 ) {
    return;
  }
  
  if ( String(evt.target.value).length ) {
    return;
  }
  
  tags = tags.slice(0, tags.length - 1);
  $input.value = '';
  render(tags, $tags);
});

$container.addEventListener('click', function(evt) {
  if ( evt.target.matches('.js-tag-close') || evt.target.matches('.js-tag') ) {
    tags = tags.filter(function(tag, i) {
      return i != evt.target.getAttribute('data-index');
    });
    render(tags, $tags);
  }
}, true);
 

function render(tags, el) {
  el.innerHTML = tags.map(function(tag, i) {
    return (
      '<div class="tag js-tag" data-index="' + i + '">' +
        tag +
        '<span class="tag-close js-tag-close" data-index="' + i + '">×</span>' +
      '</div>'
   );
  }).join('') + (tags.length === 5 ? '' : '<input placeholder="Type here..." class="js-tag-input">')
  ;
  
  $container.querySelector('.js-tag-input').focus();
    $("#textInput").css("width","100%")

}

