text: $( document ).ready(function() {
    var check_lease=$("#lease").prop("checked");
    var check_sale=$("#sale").prop("checked");
    var check_property_management=$("#property_management").prop("checked");
    if (check_lease == true) {$('.lease').show();}else{$('.lease').hide();}
    if (check_sale == true) {$('.sale').show();}else{$('.sale').hide();}
    if (check_property_management == true) {$('.property_management').show();}else{$('.property_management').hide();}
    get_unit();
        
  });
   $(function () {
          $('input').iCheck({
              checkboxClass: 'icheckbox_square-green',
              radioClass: 'iradio_square-blue',
              increaseArea: '20%' // optional
          });
      });
  $('#lease').on('ifChecked', function(event){
  
       $('.lease').show();
       $('#lease').val(1);
  
  }); 
  $('#lease').on('ifUnchecked', function(event){
       $('.lease').hide();
       $('#lease').val(0);
  
  });
  $('#sale').on('ifUnchecked', function(event){
   $('.sale').hide();
   $('#sale').val(0);
  });
  
  $('#sale').on('ifChecked', function(event){
  $('.sale').show();
  $('#sale').val(1);
  });
  $('#property_management').on('ifChecked', function(event){
  $('.property_management').show();
  $('#property_management').val(1);
  });  
  $('#property_management').on('ifUnchecked', function(event){
  $('.property_management').hide();
  $('#property_management').val(0);
  });  
  
  // PROPERTY FEATURES
  $('#balcony').on('ifChecked', function(event){
  $('#balcony').val(1);
  });  
  $('#balcony').on('ifUnchecked', function(event){
  $('#balcony').val(0);
  }); 
  $('#basemet_parking').on('ifChecked', function(event){
  $('#basemet_parking').val(1);
  });  
  $('#basemet_parking').on('ifUnchecked', function(event){
  $('#basemet_parking').val(0);
  }); 
  $('#central_air_conditionning').on('ifChecked', function(event){
  $('#central_air_conditionning').val(1);
  });  
  $('#central_air_conditionning').on('ifUnchecked', function(event){
  $('#central_air_conditionning').val(0);
  }); 
  
  $('#gymnasium').on('ifChecked', function(event){
  $('#gymnasium').val(1);
  });  
  $('#gymnasium').on('ifUnchecked', function(event){
  $('#gymnasium').val(0);
  }); 
  $('#kitchen_white_goods').on('ifChecked', function(event){
  $('#kitchen_white_goods').val(1);
  });  
  $('#kitchen_white_goods').on('ifUnchecked', function(event){
  $('#kitchen_white_goods').val(0);
  }); 
  $('#pets_allowed').on('ifChecked', function(event){
  $('#pets_allowed').val(1);
  });  
  $('#pets_allowed').on('ifUnchecked', function(event){
  $('#pets_allowed').val(0);
  }); 
  $('#shared_swimming_poolg').on('ifChecked', function(event){
  $('#shared_swimming_poolg').val(1);
  });  
  $('#shared_swimming_poolg').on('ifUnchecked', function(event){
  $('#shared_swimming_poolg').val(0);
  }); 
  $('#view_of_parkland').on('ifChecked', function(event){
  $('#view_of_parkland').val(1);
  });  
  $('#view_of_parkland').on('ifUnchecked', function(event){
  $('#view_of_parkland').val(0);
  }); 
  $('#bank').on('ifChecked', function(event){
  $('#bank').val(1);
  });  
  $('#bank').on('ifUnchecked', function(event){
  $('#bank').val(0);
  }); 
  $('#business_center').on('ifChecked', function(event){
  $('#business_center').val(1);
  });  
  $('#business_center').on('ifUnchecked', function(event){
  $('#business_center').val(0);
  }); 
  $('#childrens_play_area').on('ifChecked', function(event){
  $('#childrens_play_area').val(1);
  });  
  $('#childrens_play_area').on('ifUnchecked', function(event){
  $('#childrens_play_area').val(0);
  }); 
  $('#concierge_service').on('ifChecked', function(event){
  $('#concierge_service').val(1);
  });  
  $('#concierge_service').on('ifUnchecked', function(event){
  $('#concierge_service').val(0);
  }); 
  $('#fitness_center').on('ifChecked', function(event){
  $('#fitness_center').val(1);
  });  
  $('#fitness_center').on('ifUnchecked', function(event){
  $('#fitness_center').val(0);
  }); 
  $('#metro_station').on('ifChecked', function(event){
  $('#metro_station').val(1);
  });  
  $('#metro_station').on('ifUnchecked', function(event){
  $('#metro_station').val(0);
  }); 
  $('#public_park').on('ifChecked', function(event){
  $('#public_park').val(1);
  });  
  $('#public_park').on('ifUnchecked', function(event){
  $('#public_park').val(0);
  }); 
  $('#recreational_facilities').on('ifChecked', function(event){
  $('#recreational_facilities').val(1);
  });  
  $('#recreational_facilities').on('ifUnchecked', function(event){
  $('#recreational_facilities').val(0);
  }); 
  $('#schools').on('ifChecked', function(event){
  $('#schools').val(1);
  });  
  $('#schools').on('ifUnchecked', function(event){
  $('#schools').val(0);
  }); 
  $('#covered_parking').on('ifChecked', function(event){
  $('#covered_parking').val(1);
  });  
  $('#covered_parking').on('ifUnchecked', function(event){
  $('#covered_parking').val(0);
  }); 
  $('#shops').on('ifChecked', function(event){
  $('#shops').val(1);
  });  
  $('#shops').on('ifUnchecked', function(event){
  $('#shops').val(0);
  }); 
  $('#walking_trails').on('ifChecked', function(event){
  $('#walking_trails').val(1);
  });  
  $('#walking_trails').on('ifUnchecked', function(event){
  $('#walking_trails').val(0);
  }); 
  $('#built_in_wardrobes').on('ifChecked', function(event){
  $('#built_in_wardrobes').val(1);
  });  
  $('#built_in_wardrobes').on('ifUnchecked', function(event){
  $('#built_in_wardrobes').val(0);
  }); 
  $('#central_heating').on('ifChecked', function(event){
  $('#central_heating').val(1);
  });  
  $('#central_heating').on('ifUnchecked', function(event){
  $('#central_heating').val(0);
  }); 
  $('#fully_fitted_kitchen').on('ifChecked', function(event){
  $('#fully_fitted_kitchen').val(1);
  });  
  $('#fully_fitted_kitchen').on('ifUnchecked', function(event){
  $('#fully_fitted_kitchen').val(0);
  }); 
  $('#intercom').on('ifChecked', function(event){
  $('#intercom').val(1);
  });  
  $('#intercom').on('ifUnchecked', function(event){
  $('#intercom').val(0);
  });  
  $('#on_high_floor').on('ifUnchecked', function(event){
  $('#on_high_floor').val(0);
  }); 
  $('#on_high_floor').on('ifChecked', function(event){
  $('#on_high_floor').val(1);
  });  
  $('#satellite').on('ifUnchecked', function(event){
  $('#satellite').val(0);
  }); 
  $('#satellite').on('ifChecked', function(event){
  $('#satellite').val(1);
  });  
  $('#strorage_room').on('ifUnchecked', function(event){
  $('#strorage_room').val(0);
  }); 
  $('#strorage_room').on('ifChecked', function(event){
  $('#strorage_room').val(1);
  });  
  $('#twentyfour_hours_maintenance').on('ifUnchecked', function(event){
  $('#twentyfour_hours_maintenance').val(0);
  }); 
  $('#twentyfour_hours_maintenance').on('ifChecked', function(event){
  $('#twentyfour_hours_maintenance').val(1);
  });  
  $('#childrens_nursery').on('ifUnchecked', function(event){
  $('#childrens_nursery').val(0);
  }); 
  $('#childrens_nursery').on('ifChecked', function(event){
  $('#childrens_nursery').val(1);
  });  
  $('#bus_service').on('ifUnchecked', function(event){
  $('#bus_service').val(0);
  }); 
  $('#bus_service').on('ifChecked', function(event){
  $('#bus_service').val(1);
  });  
  $('#communal_garden').on('ifUnchecked', function(event){
  $('#communal_garden').val(0);
  }); 
  $('#communal_garden').on('ifChecked', function(event){
  $('#communal_garden').val(1);
  });  
  $('#cycling_track').on('ifUnchecked', function(event){
  $('#cycling_track').val(0);
  }); 
  $('#cycling_track').on('ifChecked', function(event){
  $('#cycling_track').val(1);
  });  
  $('#laundry_service').on('ifUnchecked', function(event){
  $('#laundry_service').val(0);
  }); 
  $('#laundry_service').on('ifChecked', function(event){
  $('#laundry_service').val(1);
  });  
  $('#mosque').on('ifUnchecked', function(event){
  $('#mosque').val(0);
  }); 
  $('#mosque').on('ifChecked', function(event){
  $('#mosque').val(1);
  });  
  $('#public_parking').on('ifUnchecked', function(event){
  $('#public_parking').val(0);
  }); 
  $('#public_parking').on('ifChecked', function(event){
  $('#public_parking').val(1);
  });  
  $('#restaurants').on('ifUnchecked', function(event){
  $('#restaurants').val(0);
  }); 
  $('#restaurants').on('ifChecked', function(event){
  $('#restaurants').val(1);
  });  
  $('#shopping_mall').on('ifUnchecked', function(event){
  $('#shopping_mall').val(0);
  }); 
  $('#shopping_mall').on('ifChecked', function(event){
  $('#shopping_mall').val(1);
  });  
  $('#sports_academics').on('ifChecked', function(event){
  $('#sports_academics').val(1);
  }); 
  $('#sports_academics').on('ifUnchecked', function(event){
  $('#sports_academics').val(0);
  }); 
  $('#property_description').on('ifUnchecked', function(event){
  $('#property_description').val(0);
  }); 
  $('#property_description').on('ifChecked', function(event){
  $('#property_description').val(1);
  });  
  // $('#lease_villa').on('ifUnchecked', function(event){
  // $('#lease_villa').val(0);
  // }); 
  // $('#vlease_illa').on('ifChecked', function(event){
  // $('#lease_villa').val(1);
  // }); 
  // $('#lease_appartment').on('ifUnchecked', function(event){
  // $('#lease_appartment').val(0);
  // }); 
  // $('#lease_appartment').on('ifChecked', function(event){
  // $('#lease_appartment').val(1);
  // });
  // $('#lease_commercial').on('ifUnchecked', function(event){
  // $('#lease_commercial').val(0);
  // }); 
  // $('#lease_commercial').on('ifChecked', function(event){
  // $('#lease_commercial').val(1);
  // });
  // $('#lease_vecant').on('ifUnchecked', function(event){
  // $('#lease_vecant').val(0);
  // }); 
  // $('#lease_vecant').on('ifChecked', function(event){
  // $('#lease_vecant').val(1);
  // });
  // $('#lease_rented').on('ifUnchecked', function(event){
  // $('#lease_rented').val(0);
  // }); 
  // $('#lease_rented').on('ifChecked', function(event){
  // $('#lease_rented').val(1);
  // });
  // $('#lease_furnished').on('ifUnchecked', function(event){
  // $('#lease_furnished').val(0);
  // }); 
  // $('#lease_furnished').on('ifChecked', function(event){
  // $('#lease_furnished').val(1);
  // });
  // $('#lease_unfurnished').on('ifUnchecked', function(event){
  // $('#lease_unfurnished').val(0);
  // }); 
  // $('#lease_unfurnished').on('ifChecked', function(event){
  // $('#lease_unfurnished').val(1);
  // });
  
  
  
  
  // $('#villa').on('ifUnchecked', function(event){
  // $('#villa').val(0);
  // }); 
  // $('#villa').on('ifChecked', function(event){
  // $('#villa').val(1);
  // }); 
  // $('#appartment').on('ifUnchecked', function(event){
  // $('#appartment').val(0);
  // }); 
  // $('#appartment').on('ifChecked', function(event){
  // $('#appartment').val(1);
  // });
  // $('#commercial').on('ifUnchecked', function(event){
  // $('#commercial').val(0);
  // }); 
  // $('#commercial').on('ifChecked', function(event){
  // $('#commercial').val(1);
  // });
  // $('#vecant').on('ifUnchecked', function(event){
  // $('#vecant').val(0);
  // }); 
  // $('#vecant').on('ifChecked', function(event){
  // $('#vecant').val(1);
  // });
  // $('#rented').on('ifUnchecked', function(event){
  // $('#rented').val(0);
  // }); 
  // $('#rented').on('ifChecked', function(event){
  // $('#rented').val(1);
  // });
  // $('#furnished').on('ifUnchecked', function(event){
  // $('#furnished').val(0);
  // }); 
  // $('#furnished').on('ifChecked', function(event){
  // $('#furnished').val(1);
  // });
  // $('#unfurnished').on('ifUnchecked', function(event){
  // $('#unfurnished').val(0);
  // }); 
  // $('#unfurnished').on('ifChecked', function(event){
  // $('#unfurnished').val(1);
  // });
  
  
  function get_unit(){
      var property_usage=$("#property_usage").val();
      var building_name=$("#building_name").val();
      var plote_no=$("#plote_no").val();
      var unit_no=$("#unit_no").val();
      var unit_type=$("#unit_type").val();
      var manageTable = $('#unt-table').DataTable();
      manageTable.destroy();
      manageTable= $("#unt-table").DataTable({
        "ajax": {
                  "url": 'fetchUnit',
                  'type': "GET",
                  'data':{property_usage:property_usage,building_name:building_name,plote_no:plote_no,unit_no:unit_no,unit_type:unit_type},
                 },
        lengthMenu: [
                  [10, 25, 50, 100, -1],
                  ['10', '25', '50', '100', 'All']],
                  "responsive": false, "lengthChange": true, "autoWidth": true,
       "order": [[0, 'asc']],
         dom: "<'row'<'col-sm-4'l><'col-sm-4 text-center'B><'col-sm-4'f>>" +
                      "<'row'<'col-sm-12'tr>>" +
                      "<'row'<'col-sm-6'i><'col-sm-6'p>>",
              buttons: [{
                      extend: 'copy',
                      exportOptions: {
                          columns: ':visible:not(:eq(11))'
                      }
                  },
                  {
                      extend: 'csv',
                      exportOptions: {
                          columns: ':visible:not(:eq(11))'
                      }
                  },
                  {
                      extend: 'print',
                      exportOptions: {
                          columns: ':visible:not(:eq(11))',
                      }
  
                  },
                  {
                      extend: 'excel',
                      exportOptions: {
                          columns: ':visible:not(:eq(11))'
                      }
                  },
                  {
                      extend: 'pdf',
                      exportOptions: {
                          columns: ':visible:not(:eq(11))'
                      }
                  }],
  
                
        });
  }
  
  $(document).on('click', '#delete', function (e) {
  
      e.preventDefault();
      var id = $(this).data('id');
      
          swal({
            title: "Are you sure?",
            icon: "warning",
            buttons: true,
            dangerMode: true,
          })
          .then((willDelete) => {
            if (willDelete) {
              $.ajaxSetup({
              headers: {
              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
              }
              });
              $.ajax({
                  type: "POST",
                  url: 'deleteUnit/' + id,
                  success: function (data) {
                  get_unit();   
                  swal("Successfully deleted!", {
                  icon: "success",
                  });
                  }         
              });
            
          } 
           // location.reload();
          });
   
  });
  
  