
console.log('in section 185');
var givendata = [];
var given_id = [];


  $(document).ready(function(){
      
  $('.btnrowAddDelete').unbind().click(function(){
     
      var table  = $("#given_loan tbody"); 
      var txtTeamAddDelete = $('.txtTeamAddDelete option:selected').text();
      var txtCricketerAddDelete = $('.txtCricketerAddDelete').val();
      
      var id=16;
      var flag=0;
      
      table.find('tr').each(function (i) {//iterate through rows
       
         var $tds = $(this).find('td'),
            productId = $tds.eq(0).text();
            product   = $tds.eq(1).text();
            
        if ((txtTeamAddDelete == productId) && (txtCricketerAddDelete == product)) {
           
            flag = 1; 
        }
    });
    
      if (flag == 1) {
          
        	$(".TableAddDelete").focus();
				$(".errmsg").html("Company already Added in table");
				$(".TableAddDelete").val("");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false; 
      } 
      else 
      {
         if(txtTeamAddDelete !="" && txtCricketerAddDelete !="" )
      {
        //  $('.TableAddDelete').append("<tr><td>"+txtTeamAddDelete+"</td><td>"+txtCricketerAddDelete+"</td><td><button type='button' class='btndeleterowadded btn'>x</button></td></tr>");
        
          givendata.push({"sub_company_type_name": txtTeamAddDelete, "sub_company_transaction_relation":txtCricketerAddDelete,sub_company_type_id: '16' });
         display_fourth_step_data();
         
      }
      else
      {
        	$(".TableAddDelete").focus();
				$(".errmsg").html("Please Select user input for given loan");
				$(".TableAddDelete").val("");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false; 
      }
      
       
      }
      
     
      
  });
    $(document).on('click', 'button.btndeleterowadded', function(){
      $(this).closest('tr').remove();
      return false;
  });
});

$(document).ready(function(){
  $('.btnrowAddDelete1').unbind().click(function(){
      
       var table1 = $("#loan tbody");
       
      var txtTeamAddDelete1 = $('.txtTeamAddDelete1 option:selected').text();
      var txtCricketerAddDelete1 = $('.txtCricketerAddDelete1').val();
       var id=17;
      var flag=0;
       table1.find('tr').each(function (i) {//iterate through rows
       
         var $tds = $(this).find('td'),
            productId = $tds.eq(0).text();
            product   = $tds.eq(1).text();
        if ((txtTeamAddDelete1 == productId) && (txtCricketerAddDelete1 == product)) {
           
            flag = 1; 
        }
    });
        
             if (flag == 1) {
        	$(".TableAddDelete1").focus();
				$(".errmsg").html("Company already Added in table");
				$(".TableAddDelete1").val("");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false; 
           } 
           else 
          {
         if(txtTeamAddDelete1 !="" && txtCricketerAddDelete1 !="" )
         {
        // $('.TableAddDelete1').append("<tr><td>"+txtTeamAddDelete1+"</td><td>"+txtCricketerAddDelete1+"</td><td><button type='button' class='btndeleterowadded btn'>x</button></td></tr>");
          givendata.push({"sub_company_type_name": txtTeamAddDelete1, "sub_company_transaction_relation":txtCricketerAddDelete1,sub_company_type_id: '17' });
         display_fourth_step_data();
         
         }
         else
         {
        	$(".TableAddDelete1").focus();
				$(".errmsg").html("Please Select user input for loan Represented as Book dept");
				$(".TableAddDelete1").val("");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false; 
      }
      } 
      
  });
  
    $(document).on('click', 'button.btndeleterowadded', function(){
      $(this).closest('tr').remove();
      return false;
  });
});

$(document).ready(function(){
  $('.btnrowAddDelete2').unbind().click(function(){
      
       var table2 = $("#guarantee_loan tbody");
       
      var txtTeamAddDelete2 = $('.txtTeamAddDelete2 option:selected').text();
      var txtCricketerAddDelete2 = $('.txtCricketerAddDelete2').val();
       var id=18;
      var flag=0;
       table2.find('tr').each(function (i) {//iterate through rows
       
         var $tds = $(this).find('td'),
            productId = $tds.eq(0).text();
            product   = $tds.eq(1).text();
        if ((txtTeamAddDelete2 == productId) && (txtCricketerAddDelete2 == product)) {
           
            flag = 1; 
        }
    });
        
             if (flag == 1) {
        	$(".TableAddDelete2").focus();
				$(".errmsg").html("Company already Added in table");
				$(".TableAddDelete2").val("");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false; 
           } 
           else 
          {
         if(txtTeamAddDelete2 !="" && txtCricketerAddDelete2 !="" )
         {
        // // $('.TableAddDelete2').append("<tr><td>"+txtTeamAddDelete2+"</td><td>"+txtCricketerAddDelete2+"</td><td><button type='button' class='btndeleterowadded btn'>x</button></td></tr>");
        
        //  givenuserinput.push(productId);
         givendata.push({"sub_company_type_name": txtTeamAddDelete2, "sub_company_transaction_relation":txtCricketerAddDelete2,sub_company_type_id: '18' });
         display_fourth_step_data();
         
         }
         else
         {
        	$(".TableAddDelete2").focus();
				$(".errmsg").html("Please Select user input for loan Represented as Book dept");
				$(".TableAddDelete2").val("");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false; 
      }
      } 
      
  });
  
    $(document).on('click', 'button.btndeleterowadded', function(){
      $(this).closest('tr').remove();
      return false;
  });
});

$(document).ready(function(){
  $('.btnrowAddDelete3').unbind().click(function(){
      
       var table3 = $("#security_loan tbody");
       
      var txtTeamAddDelete3 = $('.txtTeamAddDelete3 option:selected').text();
      var txtCricketerAddDelete3 = $('.txtCricketerAddDelete3').val();
       var id=19;
      var flag=0;
       table3.find('tr').each(function (i) {//iterate through rows
       
         var $tds = $(this).find('td'),
            productId = $tds.eq(0).text();
            product   = $tds.eq(1).text();
        if ((txtTeamAddDelete3 == productId) && (txtCricketerAddDelete3 == product)) {
           
            flag = 1; 
        }
    });
        
             if (flag == 1) {
        	$(".TableAddDelete3").focus();
				$(".errmsg").html("Company already Added in table");
				$(".TableAddDelete3").val("");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false; 
           } 
           else 
          {
         if(txtTeamAddDelete3 !="" && txtCricketerAddDelete3 !="" )
         {
        // $('.TableAddDelete3').append("<tr><td>"+txtTeamAddDelete3+"</td><td>"+txtCricketerAddDelete3+"</td><td><button type='button' class='btndeleterowadded btn'>x</button></td></tr>");
         
          givendata.push({"sub_company_type_name": txtTeamAddDelete3, "sub_company_transaction_relation":txtCricketerAddDelete3,sub_company_type_id: '19' });
         display_fourth_step_data();
         }
         else
         {
        	$(".TableAddDelete3").focus();
				$(".errmsg").html("Please Select user input for loan Represented as Book dept");
				$(".TableAddDelete3").val("");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false; 
      }
      } 
      
  });
  
    $(document).on('click', 'button.btndeleterowadded', function(){
      $(this).closest('tr').remove();
      return false;
  });
});

// $(function(){
//   $('#banks, #nbfc,#financ_inst,#indian_comp,#llp,#foreign,#datepicker').keyup(function(){
//   var banks = parseFloat($('#banks').val().replaceAll(',', '')) || 0;
//     var banks1 =  banks.replace(/,/g,'');
    
//   var nbfc = parseFloat($('#nbfc').val()) || 0;
//   var nbfc1 =  nbfc1.replace(/,/g,'');
//   var financ_inst = parseFloat($('#financ_inst').val()) || 0;
//      var financ_inst1 =  financ_inst1.replace(/,/g,'');
     
     
//   var indian_comp = parseFloat($('#indian_comp').val()) || 0;
//      var indian_comp1 =  indian_comp1.replace(/,/g,'');
//   var llp = parseFloat($('#llp').val()) || 0;
//      var llp1 =  llp1.replace(/,/g,'');
   
//   var foreign = parseFloat($('#foreign').val()) || 0;
//     var foreign1 = foreign1.replace(/,/g,'');
// //   var cut_off = $('#datepicker').val()|| 0;
// //  var cut_off1 = cut_off1.replace(/,/g,'');

//  var formatted = inrFormat(banks);
//  var formatted1 = inrFormat(nbfc);
//  var formatted2 = inrFormat(financ_inst);
//  var formatted3 = inrFormat(indian_comp);
//  var formatted4 = inrFormat(llp);
//  var formatted5 = inrFormat(foreign);
//     if (formatted.indexOf('.') > 0) {
//       var split = formatted.split('.');
//       formatted = split[0] + '.' + split[1].substring(0, 2);
//     }
//      if (formatted1.indexOf('.') > 0) {
//       var split = formatted1.split('.');
//       formatted1 = split[0] + '.' + split[1].substring(0, 2);
//     }
//      if (formatted2.indexOf('.') > 0) {
//       var split = formatted2.split('.');
//       formatted2 = split[0] + '.' + split[1].substring(0, 2);
//     }
//      if (formatted3.indexOf('.') > 0) {
//       var split = formatted3.split('.');
//       formatted3 = split[0] + '.' + split[1].substring(0, 2);
//     }
//      if (formatted4.indexOf('.') > 0) {
//       var split = formatted4.split('.');
//       formatted4 = split[0] + '.' + split[1].substring(0, 2);
//     }
//      if (formatted5.indexOf('.') > 0) {
//       var split = formatted5.split('.');
//       formatted5 = split[0] + '.' + split[1].substring(0, 2);
//     }
    
//      $(this).val(formatted);
//      $(this).val(formatted1);
//      $(this).val(formatted2);
//      $(this).val(formatted3);
//     $(this).val(formatted4);
//      $(this).val(formatted5);
    

//   $('#total').html((banks1 + nbfc1 +financ_inst1+indian_comp1+llp+foreign1).toLocaleString("en-IN"));
   
//  });
// });


$(function(){
  $('#banks, #nbfc,#financ_inst,#indian_comp,#llp,#foreign,#datepicker').keyup(function(){
   var banks = parseFloat($('#banks').val()) || 0;
   
   
   var nbfc = parseFloat($('#nbfc').val()) || 0;
   var financ_inst = parseFloat($('#financ_inst').val()) || 0;
   var indian_comp = parseFloat($('#indian_comp').val()) || 0;
   var llp = parseFloat($('#llp').val()) || 0;
   var foreign = parseFloat($('#foreign').val()) || 0;

   $('#total').html((banks + nbfc +financ_inst+indian_comp+llp+foreign).toLocaleString("en-IN"));
   
 });
});


function inrFormat(val) {
  var x = val;
  x = x.toString();
  var afterPoint = '';
  if (x.indexOf('.') > 0)
    afterPoint = x.substring(x.indexOf('.'), x.length);
  x = Math.floor(x);
  x = x.toString();
  var lastThree = x.substring(x.length - 3);
  var otherNumbers = x.substring(0, x.length - 3);
  if (otherNumbers != '')
    lastThree = ',' + lastThree;
  var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree + afterPoint;
  return res;
}


$(function(){
  $('#equity,#capital').keyup(function(){
   var equity = parseInt($('#equity').val()) || 0;
   var capital = parseInt($('#capital').val()) || 0;

   $('#total_cap').html((equity + capital).toLocaleString("en-IN"));
   $('#twice_cap').html(((equity + capital)* 2).toLocaleString("en-IN"));
 });
});



function assign_relation(n,name)
{
  
    if(n=='1' )
  {
    $('#'+name).val('holding company');
   
  }
  if(n=='2')
  {
   $('#'+name).val('Subsidiary Companies');
  }
  
   if(n=='3')
  {
    $('#'+name).val('Wholly Owned Subidiary Companies');
   
  }
  if(n=='4' )
  {
   $('#'+name).val('Managing Director');
  
  }
  if(n=='5' )
  {
   $('#'+name).val('Whole time directors');
    
  }
  if(n=='6')
  {
   
   $('#'+name).val('Director of an Company');
  
  }
   if(n=='7' )
  {
    $('#'+name).val('Relative of directors');
    
  }
  if(n=='8')
  {
   $('#'+name).val('Partner of directors in any firm (incl. LLP)');
   
  }
    if(n=='9')
  {
    $('#'+name).val('Firm (incl. LLP) in which director is a partner');
   
  }
  if(n=='10')
  {
   $('#'+name).val('Firm (incl. LLP) in which relative of director is a partner');
  
  }
   if(n=='11')
  {
    $('#'+name).val('Private Companies in which director is a director');
   
  }
  if(n=='12')
  {
   $('#'+name).val('Private Companies in which director is a Member');
  
  }
  if(n=='13')
  {
    $('#'+name).val('Director of holding company');
   
  }
  if(n=='14')
  {
   $('#'+name).val('Companies / LLPs wherein director either singly or jointly with other directors of lending company has 25%');
  
  }
   if(n=='15')
  {
    $('#'+name).val('any directors of lending company');
  }
  
}


$('#sub_company').on('change',function(){
  var sub= $('#sub_company option:selected').val();
  var sub1 = $('option:selected', this).attr('test');
  
//   var sub1= $("#sub_company").val($("#sub_company option:selected").attr("test"));
 
  assign_relation(sub,'relation');
 
 });
 
 $('#loan_represent').on('change',function(){
 
  var loan= $('#loan_represent option:selected').val();
   var loan1 = $('option:selected', this).attr('test');
   assign_relation(loan,'relation1');
  
 });
  $('#guarantee').on('change',function(){
 
  var guarantee= $('#guarantee option:selected').val();
   var  guarantee1 = $('option:selected', this).attr('test');
   assign_relation(guarantee,'relation2');
  
 });
  $('#security').on('change',function(){
    var security= $('#security option:selected').val();
    var  security1 = $('option:selected', this).attr('test');
  assign_relation(security,'relation3');
  
 });

// function formatRows(main, prefer) {
//   return '<tr><td class="col-xs-3"><input type="text" value="' +main+ '" class="form-control editable" /></td>' +
//          '<td class="col-xs-3"><input type="text" value="' +prefer+ '" class="form-control editable" /></td>' +   
//          '<td class="col-xs-1 text-center"><a href="#" onClick="deleteRow(this)">' +
//          '<i class="fa fa-trash-o" aria-hidden="true"></a></td></tr>';
// };
// function deleteRow(trash) {
//   $(trash).closest('tr').remove();
// };

// function addRow() {
//   var main = $('.addMain option:selected').text();

//   var preferred = $('.addPrefer').val();
 
//   $(formatRows(main,preferred)).insertAfter('#addRow');
//    // $(input).val('');  
// }
// $('.addBtn').click(function() {
//   addRow();
//   // addloan();
// });



console.log('1852');
$("#nextBtn").click(function(){
    
  var letters = /^[A-Za-z]+$/;
  var step1= parseInt($("#step1").val());
  var company_edit_id=$("#company_edit_id").val();
  var company_select= $("#company-select").val();
  var other= $("#other").val().trim();
  var financ_year= $("#financ_year").val();
  var datepicker= $("#cut_off_date_step_1").val().trim(); 
  var lending= $("#lending").val();
  var format = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/;
  var prevailing= $("#prevailing").val();
  var borrow_date= $("#cut_off_date_step_2").html();
  var banks= $("#banks").val().trim();
  var nbfc= $("#nbfc").val().trim();
  var foreign= $("#foreign").val().trim(); 
  var indian_comp= $("#indian_comp").val().trim();
  var llp= $("#llp").val().trim();
  var financ_inst= $("#financ_inst").val().trim();
    
  var total1= $("#total").html();
  var total =  total1.replace(/,/g,'');
   
  var equity= $("#equity").val().trim();
  var capital= $("#capital").val().trim();
  var total_cap1= $("#total_cap").html();
   var total_cap =  total_cap1.replace(/,/g,'');
  
  var twice_cap1= $("#twice_cap").html();
  var twice_cap =  twice_cap1.replace(/,/g,'');
  
  
  var repayment= $("#repayment").val().trim();
  var shareholders= $("#share-holding").val().trim(); 
  var specify= $("#specify").val().trim(); 
  var hold_comp= $("#hold_comp").val().trim();
  var subs_comp= $("#subs_comp").val().trim();
  var wholl_own= $("#wholl_own").val().trim();
  var form_dir= $("#form_dir").val().trim();
  var whole_time= $("#whole_time").val().trim();
  var direc_comp= $("#direc_comp").val().trim();
  var relat_direct= $("#relat_direct").val().trim();
  var part_dirc= $("#part_dirc").val().trim();
  var dirc_part= $("#dirc_part").val().trim();
  var rel_dirc= $("#rel_dirc").val().trim();
  var priv_comp= $("#priv_comp").val().trim();
  var direc_mem= $("#direc_mem").val().trim();
  var direc_hold_comp= $("#direc_hold_comp").val().trim();
  var llp_comp= $("#llp_comp").val().trim();
  var llp_comp_lead= $("#llp_comp_lead").val().trim();
  var givenuserinput = [];
  var givenrelation =[];
  var loanuserinput = [];
  var loanrelation  =[];
  var guaranteeuserinput = [];
  var guaranteerelation  =[];
  var securityuserinput = [];
  var securityrelation =[];

  var table  = $("#given_loan tbody"); 
  var table1 = $("#loan tbody");
  var table2 = $("#guarantee_loan tbody");
  var table3 = $("#security_loan tbody");
  

    table.find('tr').each(function (i) {
        var $tds = $(this).find('td'),
            productId = $tds.eq(0).text();
            product   = $tds.eq(1).text();
             
           
    givenuserinput.push(productId);
    givenrelation.push(product);
   
    });

     table1.find('tr').each(function (i) {
        var $tds = $(this).find('td'),
            productId = $tds.eq(0).text();
            product = $tds.eq(1).text();

          
    loanuserinput.push(productId);
    loanrelation.push(product);

    });


      table2.find('tr').each(function (i) {
        var $tds = $(this).find('td'),
            productId = $tds.eq(0).text();
            product = $tds.eq(1).text();

    guaranteeuserinput.push(productId);
    guaranteerelation.push(product);

    });

   
       table3.find('tr').each(function (i) {
        var $tds = $(this).find('td'),
            productId = $tds.eq(0).text();
            product = $tds.eq(1).text();
             
    securityuserinput.push(productId);
    securityrelation.push(product);

    });
     
    // alert(step1);
  if(step1==1)
 {
  if (company_select=="" ){
				$("#company_select").focus();
				$(".errmsg").html("Please Select Type of Company");
				$("#company_select").val("");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			if(company_select=="others")
			{
			     if(other==""){
				$("#other").focus();
				$(".errmsg").html("Please Enter company name");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}  
			}
			else
     
			if(financ_year==""){
				$("#financ_year").focus();
				$(".errmsg").html("Please Select Finance Year");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(datepicker==""){
				$("#datepicker").focus();
				$(".errmsg").html("Please Select Cut_off Date");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(lending=="Select"){
				$("#lending").focus();
				$(".errmsg").html("Please Select Company undertakes lending operations");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			if(lending=="Yes")
			{
		     if(prevailing=="Select"){
				$("#prevailing").focus();
				$(".errmsg").html("Please Select Option About Interest charged ");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			} 
			}
 }
 else if(step1==2)
 {
        if(banks=="" ){
				$("#lending").focus();
				$(".errmsg").html("Please Enter Borrowings from bank");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			} 
	        if(banks!="" && format.test(banks)){
				$("#lending").focus();
				$(".errmsg").html("Speacial character not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(banks!=""  && letters.test(banks)){
				$("#lending").focus();
				$(".errmsg").html("Letters not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
		     if(nbfc==""){
				$("#nbfc").focus();
				$(".errmsg").html("Please Enter Borrowings from NBFC");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			if(nbfc!="" && format.test(nbfc)){
				$("#nbfc").focus();
				$(".errmsg").html("Speacial character not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			if(nbfc!="" && letters.test(nbfc)){
				$("#nbfc").focus();
				$(".errmsg").html("Letters not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
				if(financ_inst==""){
				$("#financ_inst").focus();
				$(".errmsg").html("Please Enter Borrowings from any other Financial");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
				if(financ_inst!="" && format.test(nbfc)){
				$("#financ_inst").focus();
				$(".errmsg").html("Speacial character not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
				if(financ_inst!="" && letters.test(financ_inst) ){
				$("#financ_inst").focus();
				$(".errmsg").html("Letters not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
		     if(indian_comp==""){
				$("#indian_comp").focus();
				$(".errmsg").html("Borrowings from Indian Company");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			if(indian_comp!="" && format.test(indian_comp) ){
				$("#indian_comp").focus();
				$(".errmsg").html("Speacial character not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			if(indian_comp!="" && letters.test(indian_comp)){
				$("#indian_comp").focus();
				$(".errmsg").html("Letters not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			
				 if(llp==""){
				$("#llp").focus();
				$(".errmsg").html("Please Enter Borrowings from LLP");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(llp!="" && format.test(llp)){
				$("#llp").focus();
				$(".errmsg").html("Speacial character not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(llp!="" && letters.test(llp)){
				$("#llp").focus();
				$(".errmsg").html("Letters not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
		     if(foreign==""){
				$("#foreign").focus();
				$(".errmsg").html("Borrowings from Foreign company");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(foreign!="" && format.test(foreign) ){
				$("#foreign").focus();
				$(".errmsg").html("Speacial character not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(foreign!="" && letters.test(foreign)){
				$("#foreign").focus();
				$(".errmsg").html("Letters not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
				 if(equity==""){
				$("#equity").focus();
				$(".errmsg").html("Please Enter Equity Share Capital");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			if(equity!="" && format.test(equity)){
				$("#equity").focus();
				$(".errmsg").html("Speacial character not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			if(equity!="" && letters.test(equity)){
				$("#equity").focus();
				$(".errmsg").html("Letters not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
		     if(capital==""){
				$("#capital").focus();
				$(".errmsg").html("Preference share capital");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(capital!="" && format.test(capital)){
				$("#capital").focus();
				$(".errmsg").html("Speacial character not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(capital!="" && letters.test(capital)){
				$("#capital").focus();
				$(".errmsg").html("Letters not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			  if(repayment=="Select"){
				$("#capital").focus();
				$(".errmsg").html("Please Select Whether default in repayment");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(shareholders=="Select"){
				$("#capital").focus();
				$(".errmsg").html("Please Select Whether shareholders include any Body Corporate");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			if(shareholders=="Yes")
			{
			 if(specify==""){
				$("#capital").focus();
				$(".errmsg").html("Specify Shareholders Names ");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}   
			}
				
 }else if(step1==3)
 {
  if(direc_comp==""){
				$("#lending").focus();
				$(".errmsg").html("Please Enter Director of an Company");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
			
				return false;
			}
		     if(relat_direct==""){
				$("#relat_direct").focus();
				$(".errmsg").html("Please Enter Relative of directors");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				
				return false;
			}  
			
 }
              
 
  var ctk =step1;   
  
var formdata= new FormData();

formdata.append('step1',step1);
formdata.append('company_edit_id',company_edit_id);
formdata.append('given_loan',givenuserinput);
formdata.append('given_relation',givenrelation);
formdata.append('loan',loanuserinput);
formdata.append('loan_relation',loanrelation);
formdata.append('guarantee_loan',guaranteeuserinput);
formdata.append('guarantee_relation',guaranteerelation);
formdata.append('security_loan',securityuserinput);
formdata.append('security_relation',securityrelation);

formdata.append('company-select',company_select);
formdata.append('other',other);
formdata.append('financ_year',financ_year);

formdata.append('datepicker',datepicker);
 
formdata.append('lending',lending);
formdata.append('prevailing',prevailing);
formdata.append('cut',borrow_date);
formdata.append('banks',banks);
formdata.append('nbfc',nbfc);
formdata.append('foreign',foreign);
formdata.append('indian_comp',indian_comp);
formdata.append('llp',llp);
formdata.append('financ_inst',financ_inst);
formdata.append('nbfc',nbfc);
formdata.append('total',total);

formdata.append('equity',equity);
formdata.append('capital',capital);
formdata.append('total_cap',total_cap);
formdata.append('twice_cap',twice_cap);
formdata.append('repayment',repayment);
formdata.append('share-holding',shareholders);
formdata.append('specify',specify);

formdata.append('hold_comp',hold_comp);
formdata.append('wholl_own',wholl_own);  
formdata.append('whole_time',whole_time);          
formdata.append('relat_direct',relat_direct);
formdata.append('dirc_part',dirc_part);
formdata.append('priv_comp',priv_comp);
formdata.append('subs_comp',subs_comp);
formdata.append('form_dir',form_dir);
formdata.append('direc_comp',direc_comp);
formdata.append('part_dirc',part_dirc);
formdata.append('direc_hold_comp',direc_hold_comp);
formdata.append('direc_mem',direc_mem);
formdata.append('rel_dirc',rel_dirc);
formdata.append('llp_comp',llp_comp);
formdata.append('llp_comp_lead',llp_comp_lead);

 formdata.append('type',"section");
  
 $.ajax({
  type:"post",
  data: formdata,
  processData: false,
  contentType: false,

  url:"ajax/section_185_action.php",

  success:function(msg){
   msg=msg.trim();
  //alert(msg);
   
   var res = JSON.parse(msg);
   
  var companiesArray =  res.data;
  $.each(companiesArray , function (index, valueObj){
  var compId = valueObj.sub_company_id;
 
  
});
   
   console.log(res);
  
  if (res.data != undefined) {
            //   alert('undefined');
                given_id = res.data;
               
    } 
     if(res['n'] == '3')
   {
 
    $('#first-section-no').modal('show');
    
   }
   else if(res['n'] == '1')
   {
  
    $('#first-section-yes').modal('show');
    
   }
   
  else{
 
} 

 nextPrev_185(ctk);
 
  var table  = $("#given_loan tbody"); 
  var table1 = $("#loan tbody");
  var table2 = $("#guarantee_loan tbody");
  var table3 = $("#security_loan tbody");
 
  $('#sub_company').find('option').remove();
  $("input[id='relation']").val("");
  $('#loan_represent').find('option').remove();
  $("input[id='relation1']").val("");
  $('#guarantee').find('option').remove();
  $("input[id='relation2']").val("");
  $('#security').find('option').remove();
  $("input[id='relation3']").val("");
    
    $("#given_loan tbody").empty();
     $("#loan tbody").empty();
    $("#guarantee_loan tbody").empty();
     $("#security_loan tbody").empty();
     
    for(var i=0; i< res.data.length; i++){
         
    $('#sub_company').append($("<option></option>").attr("value","").text('select user input'));
    
    // $('#sub_company').append($("<option></option>").attr("value",res.data[i].sub_company_type_id).text(res.data[i].sub_company_type_name));
    
    $('#sub_company').append($("<option></option>").attr({"value":res.data[i].sub_company_type_id,'test':res.data[i].sub_company_id}).text(res.data[i].sub_company_type_name));
    
    
    
    $('#loan_represent').append($("<option></option>").attr("value","").text('select user input'));
     $('#loan_represent').append($("<option></option>").attr("value",res.data[i].sub_company_type_id).text(res.data[i].sub_company_type_name));
   
   
     $('#guarantee').append($("<option></option>").attr("value","").text('select user input'));
     $('#guarantee').append($("<option></option>").attr("value",res.data[i].sub_company_type_id).text(res.data[i].sub_company_type_name));
   
   
     $('#security').append($("<option></option>").attr("value","").text('select user input'));
     $('#security').append($("<option></option>").attr("value",res.data[i].sub_company_type_id).text(res.data[i].sub_company_type_name));
    // $('#relation3').append($("<option></option>").attr("value",res.data[i].sub_company_type_name).text(res.data[i].sub_company_type_name));
   
    }
    
     if (res.fourth != undefined) {
               //alert('undefined');
                givendata = res.fourth;
                display_fourth_step_data();
    } 
     var date =res.data[0].date;
 
    $("#cut_off_date_step_2").html(date);
    
   
}

});

if(step1)
{
  //alert(company_select);
  if(company_select == "Private Company")
{
  step1 +=1;
   //alert('in if');
  $("#step1").val(step1);
}
else if(step1 ==3)
{
  step1 +=1;
   //alert('in 1');
  $("#step1").val(step1);  
}
else
{
 step1 +=2;
   //alert('in 2');
  $("#step1").val(step1);   
}
  
}


console.log(step1);
});


$("#proceed").click(function(){
               
              var section = $("#section").val();
              var company = $("#company").val();
              var maker = $("#maker").val().trim();
              var checker = $("#checker").val().trim();
             var format = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]+/;
             
              	if (section==""){
				$("#section").focus();
				$(".errmsg").html("Please Select Section");
				$("#section").val("");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			else if(company==""){
				$("#company").focus();
				$(".errmsg").html("Please Select Company");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			else if(maker==""){
				$("#maker").focus();
				$(".errmsg").html("Please Enter your name");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
		  else if(maker!="" && format.test(maker)){
				$("#checker").focus();
				$(".errmsg").html("Speacial character not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			else if(checker!="" && format.test(checker)){
				$("#checker").focus();
				$(".errmsg").html("Speacial character not accepted");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
		
			else{
               
              var formdata= new FormData();
              formdata.append('section',section);
              formdata.append('company',company);  
              formdata.append('maker',maker);
              formdata.append('checker',checker);  
              formdata.append('type',"proceed");
              
              $.ajax({
                type:"post",
                data: formdata,
                processData: false,
                contentType: false,
                url:"ajax/proceed_action.php",
                success:function(msg){
                
                 msg=msg.trim();
                // alert(msg);
                 var res = JSON.parse(msg);
                 
                      console.log(res);

                        //   if(res['n'] == 1)
                        //   {
                        //       //alert('in if');
                              
                        //       location.href="section-a.php";
                        //     }
                        //     else{

                        //       $(".alert").removeClass("hide");
                        //     }   
                        
                        if(res['n'] == 1 && res['section_id'] == 1)
                          {
                              //alert('in if');
                              
                              location.href="section-a.php";
                            }
                          else if(res['n'] == 1 && res['section_id'] == 2)
                            {
                              location.href="section-list-222E.php";
                            } 
                             else{

 

                              $(".alert").removeClass("hide");
                            }         
                            
                          }
                        });
              return false;
		     	}
             });


 $("#drftBtn").click(function(){
  
  var step1= parseInt($("#step1").val());
  //alert(step1);
  var company_detail_id=$("#company_detail_id").val();
  var company_select= $("#company-select").val();
  var other= $("#other").val().trim();
  var financ_year= $("#financ_year").val();
  var datepicker= $("#cut_off_date_step_1").val().trim(); 
  var lending= $("#lending").val();
  var prevailing= $("#prevailing").val();
  var borrow_date= $("#cut").val();
  var banks= $("#banks").val().trim();
  var nbfc= $("#nbfc").val().trim();
  var foreign= $("#foreign").val().trim(); 
  var indian_comp= $("#indian_comp").val().trim();
  var llp= $("#llp").val().trim();
  var financ_inst= $("#financ_inst").val().trim();
  var total= $("#total").val().trim();
  var equity= $("#equity").val().trim();
  var capital= $("#capital").val().trim();
  var total_cap= $("#total_cap").val().trim();
  var twice_cap= $("#twice_cap").val().trim();
  var repayment= $("#repayment").val().trim();
  var shareholders= $("#share-holding").val().trim(); 
  var specify= $("#specify").val().trim(); 
  var hold_comp= $("#hold_comp").val().trim();
  var wholl_own= $("#wholl_own").val().trim();
  var whole_time= $("#whole_time").val().trim();
  var relat_direct= $("#relat_direct").val().trim();
  var dirc_part= $("#dirc_part").val().trim();
  var priv_comp= $("#priv_comp").val().trim();
  var subs_comp= $("#subs_comp").val().trim();
  var form_dir= $("#form_dir").val().trim();
  var direc_comp= $("#direc_comp").val().trim();
  var part_dirc= $("#part_dirc").val().trim();
  var direc_hold_comp= $("#direc_hold_comp").val().trim();
  var direc_mem= $("#direc_mem").val().trim();
  var rel_dirc= $("#rel_dirc").val().trim();
  var llp_comp= $("#llp_comp").val().trim();

  var llp_comp_lead= $("#llp_comp_lead").val().trim();
  var givenuserinput = [];
  var givenrelation =[];
  var loanuserinput = [];
  var loanrelation  =[];
  var guaranteeuserinput = [];
  var guaranteerelation  =[];
  var securityuserinput = [];
  var securityrelation =[];

  var table  = $("#given_loan tbody"); 
  var table1 = $("#loan tbody");
  var table2 = $("#guarantee_loan tbody");
  var table3 = $("#security_loan tbody");

  
  
    table.find('tr').each(function (i) {
        var $tds = $(this).find('td'),
            productId = $tds.eq(0).text();
            product   = $tds.eq(1).text();
          
    givenuserinput.push(productId);
    givenrelation.push(product);

    });

     table1.find('tr').each(function (i) {
        var $tds = $(this).find('td'),
            productId = $tds.eq(0).text();
            product = $tds.eq(1).text();

          
    loanuserinput.push(productId);
    loanrelation.push(product);

    });

      table2.find('tr').each(function (i) {
        var $tds = $(this).find('td'),
            productId = $tds.eq(0).text();
            product = $tds.eq(1).text();

   guaranteeuserinput.push(productId);
   guaranteerelation.push(product);

    });

       table3.find('tr').each(function (i) {
        var $tds = $(this).find('td'),
            productId = $tds.eq(0).text();
          
    securityuserinput.push(productId);
    securityrelation.push(productId);

    });
    

var formdata= new FormData();
formdata.append('step1',step1);
formdata.append('company_detail_id',company_detail_id);
formdata.append('given_loan',givenuserinput);
formdata.append('given_relation',givenrelation);
formdata.append('loan',loanuserinput);
formdata.append('loan_relation',loanrelation);
formdata.append('guarantee_loan',guaranteeuserinput);
formdata.append('guarantee_relation',guaranteerelation);
formdata.append('security_loan',securityuserinput);
formdata.append('security_relation',securityrelation);

formdata.append('company-select',company_select);
formdata.append('other',other);
formdata.append('financ_year',financ_year);

formdata.append('datepicker',datepicker);
 
formdata.append('lending',lending);

formdata.append('prevailing',prevailing);
formdata.append('cut',borrow_date);

formdata.append('banks',banks);
formdata.append('nbfc',nbfc);
formdata.append('foreign',foreign);
formdata.append('indian_comp',indian_comp);
formdata.append('llp',llp);
formdata.append('financ_inst',financ_inst);
formdata.append('nbfc',nbfc);
formdata.append('total',total);

formdata.append('equity',equity);
formdata.append('capital',capital);
formdata.append('total_cap',total_cap);
formdata.append('twice_cap',twice_cap);
formdata.append('repayment',repayment);
formdata.append('share-holding',shareholders);
formdata.append('specify',specify);

formdata.append('hold_comp',hold_comp);
formdata.append('wholl_own',wholl_own);  
formdata.append('whole_time',whole_time);          
formdata.append('relat_direct',relat_direct);
formdata.append('dirc_part',dirc_part);
formdata.append('priv_comp',priv_comp);
formdata.append('subs_comp',subs_comp);
formdata.append('form_dir',form_dir);
formdata.append('direc_comp',direc_comp);
formdata.append('part_dirc',part_dirc);
formdata.append('direc_hold_comp',direc_hold_comp);
formdata.append('direc_mem',direc_mem);
formdata.append('rel_dirc',rel_dirc);
formdata.append('llp_comp',llp_comp);
formdata.append('llp_comp_lead',llp_comp_lead);

 formdata.append('type',"section");
  
 $.ajax({
  type:"post",
  data: formdata,
  processData: false,
  contentType: false,

  url:"ajax/section_185_action.php",

  success:function(msg){
   msg=msg.trim();
   //sub_company_type_id=sub_company_type_id.trim();
   
   //alert(msg);
   //return false;
   var res = JSON.parse(msg);
   
    if(res['n'] == 2)
   {
      
    $('#drftBtn').attr('disabled', false);
                           $('#drftBtn').html('Save as draft');
							$(".errmsg").html("Data save successfully !!");
							setTimeout(function(){ 
								// window.location.reload(1);
							}, 2000);                                                        
							$(".errmsg").addClass("alert-success");
							$(".errmsg").removeClass("alert-danger");
							$(".errmsg").slideDown("slow").delay(5000).slideUp();
							 
    
   }
   else if(res['n'] == 1)
   {
      
    $('#drftBtn').attr('disabled', false);
                           $('#drftBtn').html('Save as draft');
							$(".errmsg").html("Data save successfully !!");
							setTimeout(function(){ 
								// window.location.reload(1);
							}, 2000);                                                        
							$(".errmsg").addClass("alert-success");
							$(".errmsg").removeClass("alert-danger");
							$(".errmsg").slideDown("slow").delay(5000).slideUp();
							 
    
   }
   else if(res['n'] == 3)
   {
      
    $('#drftBtn').attr('disabled', false);
                           $('#drftBtn').html('Save as draft');
							$(".errmsg").html("Data save successfully !!");
							setTimeout(function(){ 
								// window.location.reload(1);
							}, 2000);                                                        
							$(".errmsg").addClass("alert-success");
							$(".errmsg").removeClass("alert-danger");
							$(".errmsg").slideDown("slow").delay(5000).slideUp();
							 
    
   }
   console.log(res); 
   
   

}
});
// if(step1)
// {
//   //alert(company_select);
//   if(company_select == "Private Company")
// {
//   step1 +=1;
//   //alert('in if');
//   $("#step1").val(step1);
// }
// else if(step1 ==3)
// {
//   step1 +=1;
//   //alert('in 1');
//   $("#step1").val(step1);  
// }
// else
// {
//  step1 +=2;
//   //alert('in 2');
//   $("#step1").val(step1);   
// }
  
// }



});   

function display_fourth_step_data()
{
    $("#given_loan tbody").empty();
     $("#loan tbody").empty();
    $("#guarantee_loan tbody").empty();
     $("#security_loan tbody").empty();
    
    for(var i=0; i<givendata.length; i++)
    {
        if(givendata[i].sub_company_type_id=='16')
        {
          var markup = "<tr><td>" + givendata[i].sub_company_type_name + "</td><td>" + givendata[i].sub_company_transaction_relation + "</td><td><button type='button' class='btndeleterowadded btn' onclick='delete_item2(" + i + ");'>x</button></td></tr>";  
            
            $("#given_loan tbody").append(markup);
      
        }
         if(givendata[i].sub_company_type_id=='17')
        {
          var markup = "<tr><td>" + givendata[i].sub_company_type_name + "</td><td>" + givendata[i].sub_company_transaction_relation + "</td><td><button type='button' class='btndeleterowadded btn' onclick='delete_item2(" + i + ");'>x</button></td></tr>";  
            
            $("#loan tbody ").append(markup);
      
        }
         if(givendata[i].sub_company_type_id=='18')
        {
          var markup = "<tr><td>" + givendata[i].sub_company_type_name + "</td><td>" + givendata[i].sub_company_transaction_relation + "</td><td><button type='button' class='btndeleterowadded btn' onclick='delete_item2(" + i + ");'>x</button></td></tr>";  
            
            $("#guarantee_loan tbody").append(markup);
      
        }
         if(givendata[i].sub_company_type_id=='19')
        {
          var markup = "<tr><td>" + givendata[i].sub_company_type_name + "</td><td>" + givendata[i].sub_company_transaction_relation + "</td><td><button type='button' class='btndeleterowadded btn' onclick='delete_item2(" + i + ");'>x</button></td></tr>";  
            
            $("#security_loan tbody").append(markup);
      
        }
    }
}

 function delete_item2(i) {
    givendata.splice(i, 1);
    display_fourth_step_data();
}        

console.log('185 nsan');

