text: $(document).ready(function () {
      datashow();
      getadvisor();
      function getadvisor() {
          $.ajax({
              type: "POST",
              url: base_url + "Sub_Broker/getadvisor",
              data: {
                  table_name: 'financial_advisor'
              },
              dataType: "JSON",
              async: false,
              success: function (data) {
                  html = '';
                  var name = '';
                  html += '<option selected disabled value="" >Select</option>';
                  for (i = 0; i < data.length; i++) {
                      var id = '';
                      name = data[i].a_name;
                      id = data[i].id;
                      html += '<option value="' + id + '">' + name + '</option>';
                  }
                  $('#advisor').html(html);
              },
              error: function () {
              }
  
          });
      }
      /*------------------- Form Submit --------------------------------*/
      $(document).on('submit', "#budgethead_form", function (e) {
          e.preventDefault();
          //alert(table_name);
          //console.log("everything is fine");
          var id = $('#saveupdate').val();
          var name = $('#name').val();
          var advisor = $('#advisor').val();
          var code = $('#code').val();
          console.log(id + " : " + name + " / " + advisor + " / " + code);
          $.ajax({
              type: "POST",
              url: base_url + "Sub_Broker/addData",
              data: {
                  id: id,
                  name: name,
                  advisor: advisor,
                  code: code,
                  table_name: table_name
              },
              dataType: "JSON",
              async: false,
              success: function (data) {
                  console.log(data);
                  $(".tablehideshow").hide();
                  $(".formhideshow").show();
                  successTost("Saved..", "success");
                  $('#budgethead_form')[0].reset();
                  $('#saveupdate').val('');
                  datashow()
              },
              error: function (data) {
                  //console.log(data);
                  //alert("Error...");
              }
          });
      });
  
      /*---------------------Data show function----------------------*/
      function datashow() {
          var isModify = true;
          $.ajax({
              type: "POST",
              url: base_url + "Employee/getUserRights",
              data: {
                  mid: 5,
                  sid: 14
              },
              dataType: "JSON",
              async: false,
              success: function(data) {
                  console.log(data);
                  var data=eval(data);
                  if(data[0].u_right==0 || data[0].u_right=="0" ){
                      isModify = false;
                  }else{
                      $(".btnhideshow").show();
                  }
                  // console.log(data);
              },
              error:function(){
                  console.log('problem in getUserRights - employee');
              }
          });
          $.ajax({
              type: "POST",
              url: base_url + "Sub_Broker/showdata",
              data: {
                  table_name: 'sub_broker'
              },
              dataType: "JSON",
              async: false,
              success: function (data) {
                  // successTost("Success..","success");
                  console.log(data);
                  var data = eval(data);
                  var table = ''; var index = 1;
                  $('#tbody').html('');
                  var table = ''; index = 1;
                  for (var i = 0; i < data.length; i++) {
                      table += '<tr>' +
                          '<td>' + index + '</td>' +
                          '<td id="name_' + data[i].id + '">' + data[i].a_name + '</td>' +
                          '<td hidden id="advisor_' + data[i].id + '">' + data[i].advisor + '</td>' +//
                          '<td>' + data[i].a_name + '</td>' +
                          '<td id="code_' + data[i].id + '">' + data[i].code + '</td>' ;
                          if(isModify)
                          {table+=
                          '<td><button type="button" class="btn btn-success btn-xs edit_data" id="' + data[i].id + '" style="margin-right:16px;"><span class="fa fa-pencil" aria-hidden="true"></span></button><button type="button" class="btn btn-danger btn-xs delete_data" id="' + data[i].id + '"><span class="fa fa-trash" aria-hidden="true"></span></button></td>' +
                          '</tr>';  $(".btnhideshow").show();
                      }else{
                          $(".btnhideshow").hide();
                          table +='<td>Not Allowed</td></tr>';
                      } index++;
                  }
                  $('#tbody').html(table);
              },
              error: function () {
                  //errorTost("Error...");
              }
          });
      }
  
      /*------------------------- Edit data ------------------------------*/
      $(document).on('click', '.edit_data', function () {
          // alert("HII");
          $(".tablehideshow").show();
          $(".formhideshow").hide();
          var id = $(this).attr('id');
          $('#saveupdate').val(id);
          $('#name').val($('#name_' + id).html());////
          $('#advisor').val($('#advisor_' + id).html());
          $('#code').val($('#code_' + id).html());
      });
  
      /*-------------------------- Delete Data --------------------------------*/
      $(document).on('click', '.delete_data', function () {
          var id1 = $(this).attr('id');
          if (id1 != "") {
              swal({
                  title: "Are you sure to delete ?",
                  text: "You will not be able to recover this Data !!",
                  type: "warning",
                  showCancelButton: true,
                  confirmButtonColor: "#DD6B55",
                  confirmButtonText: "Yes, delete it !!",
                  closeOnConfirm: false
              },
                  function () {
                      $.ajax({
                          type: "POST",
                          url: base_url + "Sub_Broker/deletedata",
                          dataType: "JSON",
                          data: {
                              id: id1,
                              table_name: 'sub_broker',
                          },
                          success: function (data) {
                              datashow();
                              swal("Deleted !!", "Hey, your Data has been deleted !!", "success");
                          },
                          error: function () {
                              alert("Error");
                          }
                      });
                  });
          }
      });
      $('.closehideshow').on('click', function () {
          $('#budgethead_form')[0].reset();
          $('#saveupdate').val('');
      });
  });