/*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");
     });
     $(function() {
      $('#sub-one').hide(); 
      var selectedValue = $("#company-select").val();
      if((selectedValue == "private-company") || (selectedValue == "public-company")) {
        $('.next-one').show();
        $('.sub-one').hide();
      } else {
        $('.next-one').hide();
        $('.sub-one').show();
        $('#private-div-show').show();
      }
      if(selectedValue == "others"){
         $('#hidden-input').show();
         $('#private-div-show').show();
      } else {
         $('#hidden-input').hide();
      }
    //   if(selectedValue != "private-company") {
    //      $('#private-div-show').show();
    //   } else {
    //      $('#private-div-show').hide();
    //   }
     });
     
    //   $(function() {
    //   var selectedValue = $("#company-select").val();
    //   if(selectedValue == "public-company") {
    //   $('#private-div-show').show();
    //   } else {
    //      $('#private-div-show').hide();
    // }
    //  });
    });


/*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');
        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(n) {
        // This function will figure out which tab to display
        var x = document.getElementsByClassName('tab');
        // Exit the function if any field in the current tab is invalid:
        if (n == 1 && !validateForm()) return false;
        // Hide the current tab:
        x[currentTab].style.display = 'none';
        // Increase or decrease the current tab by 1:
        currentTab = n;
        // if you have reached the end of the form...
        if (currentTab >= x.length) {
          // ... the form gets submitted:
          document.getElementById('regForm').submit();
        //   currentTab=currentTab-1;
          return false;
        }
        // Otherwise, display the correct tab:
        // $('#step').val(currentTab);
        if(currentTab!=3)
        showTab(currentTab);
      }
      
      function draft(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(n) {
         // This function will figure out which tab to display
        var x = document.getElementsByClassName('tab');
        var company = document.getElementById("company-select").value;
        var step= parseInt($("#step").val());
        //alert(step1);
      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(parseInt(currentTab)==2)
        // {
        //     //alert('in company');
        //       currentTab =1;
        //       //alert(currentTab);
        //       step1 =1;
        //      $("#step").val(step1);
        // }
        // else
        // {
            currentTab = currentTab + n;
            step -=1;
            $("#step").val(step);
            //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:

        // 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*/


// 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').show();
// 	} else {
// 		$('#private-div-show').hide();
// 	}
// }

$('#company-select').change(function() {
    var selectBoxvalue = $("#company-select").val();
   if(selectBoxvalue == "private-company") {
		$('#private-div-show').hide();
		$(".sub-one").hide();
	} else  {
		$('#private-div-show').show();
		$(".sub-one").show();
	}
	if (selectBoxvalue == "others") {
		$('#hidden-input').show();
	} else {
		$('#hidden-input').hide();
	}
});


// $(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();
          $(".sub-one").hide();
      }
      else{
          $(".next-one").hide();
          $(".sub-one").show();
      }
  });
});

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




function changeFuncdd() {
	var selectBox = document.getElementById("object-clause");
	var selectedValue = selectBox.options[selectBox.selectedIndex].value;
	if (selectedValue == "yes") {
		$('#hidden-dd').show();
	} else {
		$('#hidden-dd').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%")

}

