var CurrentData = [];
var secondStepData = [];

function valid(fid, fmsg) {
    var id = fid;
    var msg = fmsg;
    $(".span_err").html("");
    $("input").removeClass("input_err");
    $("textarea").removeClass("input_err");
    $("select").removeClass("input_err");
    $("#" + id + "_err").html(msg);
    $("#" + id).focus().addClass("input_err");
}

function addData() {
    var name_of_shareholder = $("#name_of_shareholder").val();
    var shareholding_percentage = $("#shareholding_per").val();
    var company_detail_id= '';
    if ( name_of_shareholder == "" || shareholding_percentage == "") {
        // $("#name_of_shareholder").focus();
		$(".errmsg").html("Please enter name of shareholder or shareholding percentage  ");
		$(".errmsg").slideDown("slow").delay(3000).slideUp();
        return false;
    } 
    else{
    secondStepData.push({
        "company_detail_id": company_detail_id,
        "Name_Of_Shareholder": name_of_shareholder,
        "Shareholding_In_Percentage": shareholding_percentage,
        "record_type":'2'
    });
    }
    display_data_second_step();
     $("#name_of_shareholder").val("");
     $("#shareholding_per").val("");
}

// function addData2() {

//     var name_of_shareholder = $("#name_of_shareholder2").val();
//     var shareholding_per = $("#shareholding_per2").val();
//     var type_of_concern = $("#type_of_concern").val();
//     var list_of_concern = $("#list_of_concern").val();
//     CurrentData.push({
//         "Name_Of_Shareholder": name_of_shareholder,
//         "List_Of_Concern": list_of_concern,
//         "Type_Of_Concern": type_of_concern,
//         "Shareholding_per": shareholding_per
//     });
//     console.log(CurrentData);
//     display_data_third_step();
//     $("#name_of_shareholder2").val("");
//     $("#shareholding_per2").val("");
//     $("#type_of_concern").val("");
//     $("#list_of_concern").val("");
    
// }

$("#nextBtn").click(function() {
    var step = parseInt($("#step").val());
    var company_detail_id = $("#company_detail_id").val();
    var company_select = $("#company-select").val().trim();
    var financ_year = $("#finan-year").val();
    var substantial_interest = $("#substantial_interest").val();
    var other = $("#other_company_name").val();
    var total_alert = $("#area_total").text(); 
    var datepicker = $("#date").val().trim();
    var name_of_shareholder = [];
    var shareholding_per = [];
    var table = $("#shareholding_details_table tbody");
    var name_of_shareholder2 = [];
    var list_of_concern = [];
    var type_of_concern = [];
    var shareholding_per2 = [];
    var entity2=[];
    var table2 = $("#type_of_concern_table tbody");
     if(step==1)
    {
			if(company_select=="others")
			{
			    if(other==""){
				$("#other_company_name").focus();
				$(".errmsg").html("Please Enter company name");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}  
			}
			if(financ_year==""){
				$("#finan-year").focus();
				$(".errmsg").html("Please Select Finance Year");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(datepicker==""){
				$("#date").focus();
				$(".errmsg").html("Please Select Cut_off Date");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			
			
    }
   else if(step==2)
    {
			
			if(step==2 && secondStepData.length==0){
				$("#excel_file").focus();
				$(".errmsg").html("Please upload excel or add input");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			if(total_alert != 100)
			{
		    $("#area_total").focus();
			$(".errmsg").html("Total Shareholding Percentage Should Be 100");
			$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 
    }
    else if(step==3)
    {
			
			if(step==2 && CurrentData.length==0){
				$("#excel_file2").focus();
				$(".errmsg").html("Please upload excel or add input");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 
    }
    
   var ctk =step; 
    var formdata = new FormData();
    table.find('tr').each(function(i) {
        var $tds = $(this).find('td'),
            productId = $tds.eq(1);
            var input_name = productId.find("input"); 
            var in_name = input_name.val();
            product = $tds.eq(2);
            var input_val = product.find("input"); 
            var in_val = input_val.val();
            
            name_of_shareholder.push(in_name);
            shareholding_per.push(in_val);
    });

    table2.find('tr').each(function(i) {
        var $tds = $(this).find('td'),
        productId = $tds.eq(0).text();
        var product = $tds.eq(1);
        var input_product = product.find("input"); 
        var input_product1 = input_product.val();
        product1 = $tds.eq(2);
        var selectObject = product1.find("select"); 
    var selCntry = selectObject.val();
         product2 = $tds.eq(3);
            var input_val1 = product2.find("input"); 
            var in_val1 = input_val1.val();
        
    var inputValue = $("#thirdentity_type"+i).val();
         name_of_shareholder2.push(productId);
        list_of_concern.push(input_product1);
        type_of_concern.push(selCntry);
        shareholding_per2.push(in_val1);
       
        entity2.push(inputValue);
    
    });
  
    formdata.append('step', step);
    formdata.append('company_detail_id', company_detail_id);
    formdata.append('name_of_shareholder', name_of_shareholder);
    formdata.append('shareholding_per', shareholding_per);
    formdata.append('name_of_shareholder2', name_of_shareholder2);
    formdata.append('list_of_concern', list_of_concern);
    formdata.append('type_of_concern', type_of_concern);
    formdata.append('shareholding_per2', shareholding_per2);
    formdata.append('entity2', entity2);
    formdata.append('company-select', company_select);
    formdata.append('finan-year', financ_year);
    formdata.append('substantial_interest', substantial_interest);
    formdata.append('other_company_name', other);
    formdata.append('date', datepicker);
    formdata.append('type', "section");

    $.ajax({
        type: "post",
        data: formdata,
        processData: false,
        contentType: false,
        url: "ajax/section_22e_action.php",
        success: function(msg) {
        msg = msg.trim();
            var res = JSON.parse(msg);
            if (res.third_step != undefined) {
              
                CurrentData = res.third_step;
                display_data_third_step();
            }
            if (res.second_step != undefined) {
                secondStepData=res.second_step;
                display_data_second_step();
            }

            if (res['n'] == 1) {

                $('#second-section-yes').modal('show');

            } else if (res['n'] == 3) {
               
                $('#second-section-no').modal('show');

            } else{

            }
             nextPrev(ctk);
        }
    });

    if(step == 1)
    {
      step +=1;
      $("#step").val(step);
      
    }
    else if(step == 2)
    {
      step +=1;
      $("#step").val(step);  
    }
});

$("#proceed").click(function() {
   
    var section = $("#section").val().trim();
    var company = $("#company").val().trim();
    var maker = $("#maker").val().trim();
    var checker = $("#checker").val().trim();
    
		    if(section==""){
				$("#section").focus();
				$(".errmsg").html("Please Select Section name");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			} 

			if(company==""){
				$("#company").focus();
				$(".errmsg").html("Please Select Company Name");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}  
			
			if(maker==""){
				$("#maker").focus();
				$(".errmsg").html("Please Enter Maker Name");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(checker==""){
				$("#checker").focus();
				$(".errmsg").html("Please Enter Checker Name");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}

    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);
            if (res['n'] == 1 && res['section_id'] == 1) {
                location.href = "section-a.php";
            }  
            if (res['n'] == 1 && res['section_id'] == 2) {
                location.href = "section-list-2(22)(e).php";
            } else {

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

 $("#drftBtn").click(function(){
  
var step = parseInt($("#step").val());
    var company_detail_id = $("#company_detail_id").val();
    var company_select = $("#company-select").val().trim();
    var financ_year = $("#finan-year").val();
    var substantial_interest = $("#substantial_interest").val();
    var other = $("#other_company_name").val();
    var total_alert = $("#area_total").text(); 
    var datepicker = $("#date").val().trim();
    var name_of_shareholder = [];
    var shareholding_per = [];
    var table = $("#shareholding_details_table tbody");
    var name_of_shareholder2 = [];
    var list_of_concern = [];
    var type_of_concern = [];
    var shareholding_per2 = [];
    var entity2=[];
    var table2 = $("#type_of_concern_table tbody");
//      if(step==1)
//     {
// 			if(company_select=="others")
// 			{
// 			    if(other==""){
// 				$("#other_company_name").focus();
// 				$(".errmsg").html("Please Enter company name");
// 				$(".errmsg").slideDown("slow").delay(3000).slideUp();
// 				return false;
// 			}  
// 			}
// 			if(financ_year==""){
// 				$("#finan-year").focus();
// 				$(".errmsg").html("Please Select Finance Year");
// 				$(".errmsg").slideDown("slow").delay(3000).slideUp();
// 				return false;
// 			}
// 			 if(datepicker==""){
// 				$("#date").focus();
// 				$(".errmsg").html("Please Select Cut_off Date");
// 				$(".errmsg").slideDown("slow").delay(3000).slideUp();
// 				return false;
// 			}
			
			
//     }
//   else if(step==2)
//     {
			
// 			if(step==2 && secondStepData.length==0){
// 				$("#excel_file").focus();
// 				$(".errmsg").html("Please upload excel or add input");
// 				$(".errmsg").slideDown("slow").delay(3000).slideUp();
// 				return false;
// 			}
// 			if(total_alert != 100)
// 			{
// 		    $("#area_total").focus();
// 			$(".errmsg").html("Total Shareholding Percentage Should Be 100");
// 			$(".errmsg").slideDown("slow").delay(3000).slideUp();
// 				return false;
// 			}
			 
//     }
//     else if(step==3)
//     {
			
// 			if(step==2 && CurrentData.length==0){
// 				$("#excel_file2").focus();
// 				$(".errmsg").html("Please upload excel or add input");
// 				$(".errmsg").slideDown("slow").delay(3000).slideUp();
// 				return false;
// 			}
			 
//     }
    
   var ctk =step; 
    var formdata = new FormData();
    table.find('tr').each(function(i) {
        var $tds = $(this).find('td'),
            productId = $tds.eq(1);
            var input_name = productId.find("input"); 
            var in_name = input_name.val();
            product = $tds.eq(2);
            var input_val = product.find("input"); 
            var in_val = input_val.val();
            
            name_of_shareholder.push(in_name);
            shareholding_per.push(in_val);
    });

    table2.find('tr').each(function(i) {
        var $tds = $(this).find('td'),
        productId = $tds.eq(0).text();
        var product = $tds.eq(1);
        var input_product = product.find("input"); 
        var input_product1 = input_product.val();
        product1 = $tds.eq(2);
        var selectObject = product1.find("select"); 
    var selCntry = selectObject.val();
         product2 = $tds.eq(3);
            var input_val1 = product2.find("input"); 
            var in_val1 = input_val1.val();
        
    var inputValue = $("#thirdentity_type"+i).val();
         name_of_shareholder2.push(productId);
        list_of_concern.push(input_product1);
        type_of_concern.push(selCntry);
        shareholding_per2.push(in_val1);
       
        entity2.push(inputValue);
    
    });
  
    formdata.append('step', step);
    formdata.append('company_detail_id', company_detail_id);
    formdata.append('name_of_shareholder', name_of_shareholder);
    formdata.append('shareholding_per', shareholding_per);
    formdata.append('name_of_shareholder2', name_of_shareholder2);
    formdata.append('list_of_concern', list_of_concern);
    formdata.append('type_of_concern', type_of_concern);
    formdata.append('shareholding_per2', shareholding_per2);
    formdata.append('entity2', entity2);
    formdata.append('company-select', company_select);
    formdata.append('finan-year', financ_year);
    formdata.append('substantial_interest', substantial_interest);
    formdata.append('other_company_name', other);
    formdata.append('date', datepicker);
    formdata.append('type', "section");

    $.ajax({
        type: "post",
        data: formdata,
        processData: false,
        contentType: false,
        url: "ajax/section_22e_action.php",

  success:function(msg){
   msg=msg.trim();   
   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(){ 
              }, 1000);                                                        
              $(".errmsg").addClass("alert-success");
              $(".errmsg").removeClass("alert-danger");
 
   if(res['n'] == 1)
   {
    $('#second-section-yes').modal('show');
    
   }
   else if(res['n'] == 3)
   {
    $('#second-section-no').modal('show');
    
   }else if(res['n'] == 2)
   {
   $('#drftBtn').attr('disabled', false);
              $('#drftBtn').html('Save as draft');
              $(".errmsg").html("Data save successfully !!");
              setTimeout(function(){ 
              }, 2000);                                                        
              $(".errmsg").addClass("alert-success");
              $(".errmsg").removeClass("alert-danger");
              $(".errmsg").slideDown("slow").delay(5000).slideUp();

   }
  else{
} 
}
}
});
});  
$(".sub-one").click(function() {
    var step = $("#step").val();
     var company_detail_id = $("#company_detail_id").val();
    var company_select = $("#company-select").val();
    var substantial_interest = $("#substantial_interest").val();
    var financial_year = $("#finan-year").val();
    var other = $("#other_company_name").val();
    var cut_off_date = $("#date").val();
            if(company_select==""){
				$("#company-select").focus();
				$(".errmsg").html("Please Select A Company");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
            if(company_select=="others")
			{
    			    if(other==""){
    				$("#other_company_name").focus();
    				$(".errmsg").html("Please Enter company name");
    				$(".errmsg").slideDown("slow").delay(3000).slideUp();
    				return false;
    			    }  
			}
			
			if(substantial_interest==""){
				$("#substantial_interest").focus();
				$(".errmsg").html("Please Select Substantial Interest");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			if(financial_year==""){
				$("#finan-year").focus();
				$(".errmsg").html("Please Select Finance Year");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
			 if(cut_off_date==""){
				$("#date").focus();
				$(".errmsg").html("Please Select Cut_off Date");
				$(".errmsg").slideDown("slow").delay(3000).slideUp();
				return false;
			}
        var formdata = new FormData();
        formdata.append('company_detail_id', company_detail_id);
        formdata.append('company-select', company_select);
        formdata.append('substantial_interest', substantial_interest);
        formdata.append('finan-year', financial_year);
        formdata.append('other_company_name', other);
        formdata.append('date', cut_off_date);
        $.ajax({
            type: "post",
            data: formdata,
            processData: false,
            contentType: false,
            url: "ajax/section_22e_action1.php",
            success: function(msg) {
                msg = msg.trim();
                var res = JSON.parse(msg);
                if(res['n'] == 1)
                   {
                    $('#second-section-yes').modal('show');
                    
                   }
                   else if(res['n'] == 3)
                   {
                    $('#second-section-no').modal('show');
                    
                   } else {
                }
            }
        });
        return false;
    
});

function valid(fid, fmsg) {
    var id = fid;
    var msg = fmsg;
    $(".span_err").html("");
    $("input").removeClass("input_err");
    $("textarea").removeClass("input_err");
    $("select").removeClass("input_err");
    $("#" + id + "_err").html(msg);
    $("#" + id).focus().addClass("input_err");
}

$('#excel_file').on('change', function() {
    var reader = new FileReader();
    reader.readAsArrayBuffer(event.target.files[0]);
    reader.onload = function(event) {
        var data = new Uint8Array(reader.result);
        var work_book = XLSX.read(data, {
         type: 'array'
        });
        var sheet_name = work_book.SheetNames;
        var sheet_data = XLSX.utils.sheet_to_json(work_book.Sheets[sheet_name[0]], {
            header: 0
        });
            
           $.each(sheet_data, function(i, val) {
                   var company_detail_id= "";
                    var TempData1 = {
                        "company_detail_id": company_detail_id,
                        "Name_Of_Shareholder": val.Name_Of_Shareholder,
                        "Shareholding_In_Percentage": val.Shareholding_In_Percentage,
                        "record_type": '2'
                    };
                    secondStepData.push(TempData1);
            });
        display_data_second_step();
        	$("#excel_file").val("");
        
    }
});

$('#excel_file_2').on('change', function() {
    var reader = new FileReader();
    reader.readAsArrayBuffer(event.target.files[0]);
    reader.onload = function(event) {
    var data = new Uint8Array(reader.result);
    var work_book = XLSX.read(data, {
        type: 'array'
    });
        var sheet_name = work_book.SheetNames;
        var sheet_data = XLSX.utils.sheet_to_json(work_book.Sheets[sheet_name[0]], { 
            header: 0
        });
        $.each(sheet_data, function(i, val) {
            for (var i = 0; i < CurrentData.length; i++) {
                if (CurrentData[i].Name_Of_Shareholder == val.Names_Of_Shareholders_Of_Company) {
                    var TempData = {
                        "Name_Of_Shareholder": val.Names_Of_Shareholders_Of_Company,
                        "Shareholding_per": val.Shareholding,
                        "Name_Of_Concern": val.Name_Of_Concern,
                        "Type_Of_Concern": val.Type_Of_Concern,
                        "record_type":'3'
                    };
                    CurrentData.push(TempData);
                    break;
                    
                }
            }
        });
        display_data_third_step();
        $("#excel_file_2").val("");
    }
});

function delete_item(i) {
var result = confirm("Want to delete this record?");
    if (result) {
       var name_of_shareholder = secondStepData[i].Name_Of_Shareholder;
       var shareholding_per = secondStepData[i].Shareholding_In_Percentage;
       var company_detail_id = secondStepData[i].company_detail_id;
       var formdata= new FormData();
       formdata.append('company_detail_id',company_detail_id);
       formdata.append('shareholding_per',shareholding_per);
       formdata.append('name_of_shareholder',name_of_shareholder);
       secondStepData.splice(i, 1);
       display_data_second_step();
        $.ajax({
        type:"post",
        data: formdata,
        processData: false,
        contentType: false,
        url:"ajax/delete_records.php",
        success:function(msg)
        {
             msg=msg.trim();
            var res = JSON.parse(msg);

            if(res['n'] == 1)
            {
              display_data_second_step();
            }
            
            else
            {
              return false;
            }

          },
          error:function(b)
          {
            console.log("error");  
            return false; 
          }
        });
    }
}

function delete_item2(i) {
    CurrentData.splice(i, 1);
    display_data_third_step();
}

function display_data_third_step() {
    $("#type_of_concern_table tbody").empty();
    CurrentData.sort(function(a, b) {
        let x = a.Name_Of_Shareholder.toLowerCase();
    let y = b.Name_Of_Shareholder.toLowerCase();
    if (x < y) {return -1;}
    if (x > y) {return 1;}
     return 0;
    });
    console.log(CurrentData);
    for (var i = 0; i < CurrentData.length; i++) {
        // if (parseInt(CurrentData[i].Shareholding_per) >= 10) {
            var markup = `<tr id="row_`+i+`"><td>` + nullEmptyUndefinedreplacespace(CurrentData[i].Name_Of_Shareholder) + `</td><td><input type="text" id="list_concern_`+i+`" value=""></td><td> <select id="type_of_concern_`+i+`" class="js-states form-control step3-select">               
                   <option value=" ">Select</option>
                   <option value="Company">Company</option>
                   <option value="Partnership Firm">Partnership Firm</option>                
                   <option value="Limited Liability Partnership">Limited Liability Partnership (LLP)</option>     
                   <option value="Body Of Individuals">Body of Individuals (BOI)</option> 

                   <option value="Association Of Persons">Association of Persons (AOP)</option>

                   <option value="Hindu Undivided Family">Hindu Undivided Family (HUF)</option>
                   <option value="Others">Others</option>                 
                 </select></td><td><input type="text" maxlength="3" id="share_per2_`+i+`" class="numbers"></td><td id="row_btn_`+i+`" class="add_more_shareholder pl-0"></td><td><input type="hidden" id="thirdentity_type`+i+`" value="`+CurrentData[i].record_type+`"></td><td id="delete_btn_`+i+`"></td></tr>`;
                  $("#type_of_concern_table tbody").append(markup);
                  $("#type_of_concern_"+i).val(CurrentData[i].Type_Of_Concern);
                  $("#list_concern_"+i).val(CurrentData[i].List_Of_Concern);
                  $("#share_per2_"+i).val(CurrentData[i].Shareholding_per);
                  var test= $("#type_of_concern_"+i).val();
                  if((test == "Partnership Firm" || test == "Limited Liability Partnership") && (CurrentData[i].record_type =='2'))
                  {
                      var markup1= "<button type='button' class='addentities' onclick='addentities("+i+");'>+</button>";
                      $("#row_btn_"+i).html(markup1);
                  }
                  if(CurrentData[i].record_type=='3')
                  {
                     var markup1=  "<button type='button' class='btndeleterowadded1 btn' onclick='delete_item2(" + i + ");'>x</button>";
                     
                     $("#row_btn_"+i).html(markup1);
                    
                  }
                  $("#share_per2_"+i).on('change', function()
                  {
                    var myArr = $(this).attr('id').split('_');
                    var share_value = $(this).val();
                     CurrentData[myArr[myArr.length-1]].Shareholding_per = share_value;
                     display_data_third_step();
                  });
                  $("#list_concern_"+i).on('change', function()
                  {
                    var myArr = $(this).attr('id').split('_');
                    var list_of_concern_value = $(this).val();
                     CurrentData[myArr[myArr.length-1]].Name_Of_Concern = list_of_concern_value;
                     display_data_third_step();
                  });
                  
                  $("#type_of_concern_"+i).on('change', function()
                   {
                        var myArr = $(this).attr('id').split('_');
                        var type_of_concern_value = $(this).val();
                        CurrentData[myArr[myArr.length-1]].Type_Of_Concern = type_of_concern_value;
                         display_data_third_step();
                       var a=  CurrentData[myArr[myArr.length-1]].record_type;
                       ;
                       if ((type_of_concern_value == "Partnership Firm" || type_of_concern_value == "Limited Liability Partnership") && (a == "2"))
                       {
                       
                          var markup1= "<button type='button' class='addentities' onclick='addentities("+myArr[myArr.length-1]+");'>+</button>";
                        
                             var markup2=  "<td><button type='button' class='btndeleterowadded1 btn' onclick='delete_item2(" + i + ");'>x</button></td>";
                        
                         $("#row_btn_"+myArr[myArr.length-1]).html(markup1);
                       }
                       else
                       {
                           $("#row_btn_"+myArr[myArr.length-1]).html(markup2);
                       }
                   });
        // }
    }
} 
 
function display_data_second_step() {
    var totalPer = 0;
    $("#shareholding_details_table tbody").empty();
    
    for (var i = 0; i < secondStepData.length; i++) {
        var markup = "<tr><td style='display:none'><input type='hidden' id='company_id_"+i+"' value=''></td><td data-gramm='false' data-gramm_editor='false' data-enable-grammarly='false'  ><input type='text' id='share_name_"+i+"' value='' class='txtOnly'></td><td id='total_change_"+i+"'  ><input type='text' id='share_per_"+i+"' class='numbers'> </td><td><button type='button' class='btndeleterowadded1 btn' onclick='delete_item(" + i + ");'>x</button></td><td style='display:none'><input type='hidden' id='entity_type"+i+"' value=''></td></tr>";
        $("#shareholding_details_table tbody").append(markup);
        $("#share_name_"+i).val(secondStepData[i].Name_Of_Shareholder);
        $("#share_per_"+i).val(secondStepData[i].Shareholding_In_Percentage);
        $("#entity_type"+i).val(secondStepData[i].record_type);
        console.log(secondStepData);
        totalPer += parseInt(secondStepData[i].Shareholding_In_Percentage);
        $("#company_id_"+i).val(secondStepData[i].company_detail_id);
        $('#share_per_'+i).on('keyup',function(){
              
        var myArr = $(this).attr('id').split('_');
        var changed_value = $("#share_per_"+myArr[myArr.length-1]).val();
          secondStepData[myArr[myArr.length-1]].Shareholding_In_Percentage = changed_value;
        display_data_second_step();
         $('#share_per_'+myArr[myArr.length-1]).focus();
         });
         $('#share_name_'+i).on('keyup',function(){
              
        var myArr = $(this).attr('id').split('_');
        var changed_name = $("#share_name_"+myArr[myArr.length-1]).val();
          secondStepData[myArr[myArr.length-1]].Name_Of_Shareholder = changed_name;
        display_data_second_step();
         $('#share_name_'+myArr[myArr.length-1]).focus();
         });
     
    }
    $("#area_total").html(totalPer); 

}


function func1()
{
	$("#warning").html("Total shareholding percentage should be equal to 100");
    func2();
    }

function func2()
{
        $('#nextBtn').attr('disabled', true); 

}

function nullEmptyUndefinedreplacespace(value) {
    if (value == null || value == "" || value == undefined || value== 0)
        return "";
    return value;
}

$(".numbers").keypress(function (e) {
    if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
        return false;
    }
});
$('.txtOnly').keydown(function (e) {
    var key = e.keyCode;
    if (!((key == 8) || (key == 9) || (key == 32) || (key == 16) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90))) {
        e.preventDefault();
    }

})

 function addentities(index)
{

         CurrentData.splice(index+1, 0, {
        "Name_Of_Shareholder": CurrentData[index].Name_Of_Shareholder,
        "Shareholding_per":'',
        "Name_Of_Concern": '',
        "Type_Of_Concern":'',
        "record_type":'3'
    });
         display_data_third_step();
}
