<style>
    #mira-house-list{
        border: 2px solid #dddddd;
    }
    #mira-house-list > thead > tr > th,
    #mira-house-list > tbody > tr > th,
    #mira-house-list > tfoot > tr > th,
    #mira-house-list > thead > tr > td,
    #mira-house-list > tbody > tr > td,
    #mira-house-list > tfoot > tr > td {
        border: 2px solid #dddddd;

    }
    #mira-house-list{
        width: 100%;
        overflow-x: scroll;
    }
    

</style>

<script>
    var baseUrl = "<?php echo base_url(); ?>";
</script>

<?php
$ashaName = 'Testing';
$level = $this->session->userdata('level');
$anmselected=$this->session->userdata('anmregionId');
$ashaselected=$this->session->userdata('asharegionId');
$start_date=$this->session->userdata('start_date');
$end_date=$this->session->userdata('end_date');

?>
<div class="panel"> 
    <div class="row">
        <div class="col col-xs-6 text-left">
            <h3 class="text-info"><strong>Registered&nbsp;House&nbsp;List</strong></h3>
        </div>
    </div>

    <div class="panel-body" style="margin-top: -16px">
        <table id="mira-house-list" class="table table-bordred table-striped table-hover">
            <thead>
               <?php if($level==1){ ?>
                    <tr>
                        <th colspan="10">
                            <div class="row">
                                <div class="col-md-4">
                                    <div class="form-group">
                                        <div class="input-group">
                                            <span class="input-group-addon"><i aria-hidden="true"></i><strong>Select ANM</strong></span>
                                            <select name="anm_region_code" id="anm_region_code" class="form-control">
                                                <option value="0" selected="true" disabled=""> Select ANM</option>
                                                <?php
                                                for ($i = 0; $i < count($anmList); $i++) {
                                                    if (isset($regionCode)) {
                                                        if ($anmselected == $anmList[$i]['region_code']) {
                                                            ?>
                                                            <option selected="true" value=<?= $anmList[$i]['region_code'] ?> ><strong><?= $anmList[$i]['user_name'] ?></strong></option>
                                                        <?php } else { ?>
                                                            <option value=<?= $anmList[$i]['region_code'] ?>><strong><?= $anmList[$i]['user_name'] ?></strong></option>
                                                            <?php
                                                        }
                                                    } else {
                                                        ?>
                                                        <option value=<?= $anmList[$i]['region_code'] ?>><strong><?= $anmList[$i]['user_name'] ?></strong></option>
                                                        <?php
                                                    }
                                                }
                                                ?>
                                            </select>
                                            <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                                        </div>                    
                                    </div>   
                                </div>
                            </div>
                            
                   <div class="row" style="margin-top: 10px">
                       <?php  if (isset($miraList) and $miraList and $level==1) { ?>
                       <div class="col-md-4">
                        <div class="form-group">
                            <div class="input-group">
                                <span class="input-group-addon"><i aria-hidden="true"></i><strong>Select Asha</strong></span>
                                <select name="region_code" id="region_code" class="form-control">
                                    <option value=0 selected="true" disabled=""> Select Asha</option>
                                    <?php
                                    for ($i = 0; $i < count($miraList); $i++) {
                                        if (isset($regionCode)) {
                                            if ($ashaselected == $miraList[$i]['region_code']) {
                                                ?>
                                                <option selected="true" value=<?= $miraList[$i]['region_code'] ?> ><strong><?= $miraList[$i]['user_name'] ?></strong></option>
                                            <?php } else { ?>
                                                <option value=<?= $miraList[$i]['region_code'] ?>><strong><?= $miraList[$i]['user_name'] ?></strong></option>
                                                <?php
                                            }
                                        } else {
                                            ?>
                                            <option value=<?= $miraList[$i]['region_code'] ?>><strong><?= $miraList[$i]['user_name'] ?></strong></option>
                                            <?php
                                        }
                                    }
                                    ?>
                                </select>
                                <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                            </div>                    
                        </div> 
                       </div>
                      <?php  }else {?> 
                    <div class="col-md-4">
                        <div class="form-group">
                            <div class="input-group">
                                <span class="input-group-addon"><i aria-hidden="true"></i><strong>Select Asha</strong></span>
                                <select name="region_code" id="region_code" class="form-control">
                                    <option value="0" selected="true" disabled=""> Select Asha</option>
                                   
                                </select>
                                <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                            </div>                    
                        </div> 
                    </div>
                        <?php }?>
                    <div class="col-lg-1 col-lg-push-3" id="asha_list_update_spinner" style="display: none;margin-left: -10px;margin-top: 6px">
                        <i class="fa fa-spinner fa-spin"></i>
                    </div>
                     <div class="col-md-4">
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon"><i aria-hidden="true"></i><strong>Search By</strong></span>
                            <select name="searchbydate" id="searchbydate" required class="form-control">
                                <option value="0" disabled="true" selected="true"> Select Option</option>
                                <option value="1"> <strong>By Mobile Date</strong></option>
                                <option value="2"> <strong>By Actual Date</strong></option>
                                <option value="3"><strong>By Server Date</strong></option>
                            </select>
                            <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                        </div>                    
                    </div> 
                </div>
                    
                    <div class="col-md-2-push-2" id="trdspan" style="display: none;"> 
                        <label ><b>Total Records:</b><span id="trd" ></span></label>
                    </div>
                    <div class="col-md-2-push-2" style="display: none;" id="frdspan"> 
                        <label><b>Filtered Records:</b><span id="frd" ></span></label>
                    </div>
                </div>
             
                 <div class="row">
                 <div class="col-lg-4">   
                 
                    <div class="form-group">
                        <div class="input-group date" id="st_date" data-date-fromat="dd-mm-yyyy" style="color: white">
                            <span class="input-group-addon"><strong>Start Date</strong></span>
                            <input class="form-control" type="text" name="st_date" id="st_date_input"   required placeholder="dd-mm-yyyy">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>                    
                    </div>
          
                     </div>
                     <div class="col-lg-4">   
                 
                    <div class="form-group">
                        <div class="input-group date" id="en_date" data-date-fromat="dd-mm-yyyy" style="color: white">
                            <span class="input-group-addon"><strong>End Date</strong></span>
                            <input class="form-control" type="text" name="en_date" id="en_date_input"  required placeholder="dd-mm-yyyy">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>                    
                    </div>
          
                     </div>
                      
                     <div class="col-lg-4">
                    <input type="button" class="btn btn-primary" id="btnsearch" value="Submit">
                       </div>
                                
                 </div>
                </th>
                </tr>
                             <?php } ?>
                
                <?php  if (isset($miraList) and $miraList and $level>1) { ?>
                    <tr>
                        <th colspan="10">
                   <div class="row" style="margin-top: 10px">
                    <div class="col-md-4">
                        <div class="form-group">
                            <div class="input-group">
                                <span class="input-group-addon"><i aria-hidden="true"></i><strong>Select Asha</strong></span>
                                <select name="region_code" id="region_code" class="form-control">
                                    <option value="0" selected="true" disabled=""> Select Asha</option>
                                    <?php
                                    for ($i = 0; $i < count($miraList); $i++) {
                                        if (isset($regionCode)) {
                                            if ($regionCode == $miraList[$i]['region_code']) {
                                                ?>
                                                <option selected="true" value=<?= $miraList[$i]['region_code'] ?> ><strong><?= $miraList[$i]['user_name'] ?></strong></option>
                                            <?php } else { ?>
                                                <option value=<?= $miraList[$i]['region_code'] ?>><strong><?= $miraList[$i]['user_name'] ?></strong></option>
                                                <?php
                                            }
                                        } else {
                                            ?>
                                            <option value=<?= $miraList[$i]['region_code'] ?>><strong><?= $miraList[$i]['user_name'] ?></strong></option>
                                            <?php
                                        }
                                    }
                                    ?>
                                </select>
                                <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                            </div>                    
                        </div> 
                    </div>
                    <div class="col-lg-1 col-lg-push-3" id="house_list_update_spinner" style="display: none;margin-left: -10px;margin-top: 6px">
                        <i class="fa fa-spinner fa-spin"></i>
                    </div>
                     <div class="col-md-4">
                    <div class="form-group">
                        <div class="input-group">
                            <span class="input-group-addon"><i aria-hidden="true"></i><strong>Search By</strong></span>
                            <select name="searchbydate" id="searchbydate" required class="form-control">
                                <option value="0" disabled="true" selected="true"> Select Option</option>
                                <option value="1"> <strong>By Mobile Date</strong></option>
                                <option value="2"> <strong>By Actual Date</strong></option>
                                <option value="3"><strong>By Server Date</strong></option>
                            </select>
                            <span class="input-group-addon"><i class="fa fa-level-down"aria-hidden="true"></i></span>
                        </div>                    
                    </div> 
                </div>
                    
                    <div class="col-md-2-push-2" id="trdspan" style="display: none;"> 
                        <label ><b>Total Records:</b><span id="trd" ></span></label>
                    </div>
                    <div class="col-md-2-push-2" style="display: none;" id="frdspan"> 
                        <label><b>Filtered Records:</b><span id="frd" ></span></label>
                    </div>
                </div>
             
                 <div class="row">
                 <div class="col-lg-4">   
                 
                    <div class="form-group">
                        <div class="input-group date" id="st_date" data-date-fromat="dd-mm-yyyy" style="color: white">
                            <span class="input-group-addon"><strong>Start Date</strong></span>
                            <input class="form-control" type="text" name="st_date" id="st_date_input" required placeholder="dd-mm-yyyy">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>                    
                    </div>
          
                     </div>
                     <div class="col-lg-4">   
                 
                    <div class="form-group">
                        <div class="input-group date" id="en_date" data-date-fromat="dd-mm-yyyy" style="color: white">
                            <span class="input-group-addon"><strong>End Date</strong></span>
                            <input class="form-control" type="text" name="en_date" id="en_date_input" required placeholder="dd-mm-yyyy">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>                    
                    </div>
          
                     </div>
                      
                     <div class="col-lg-4">
                    <input type="button" class="btn btn-primary" id="btnsearch" value="Submit">
                       </div>
                                
                 </div>
                </th>
                </tr>
               
                
            <?php } ?>
            <tr>
                <th class="text-center">#</th>
                <th class="text-center">House&nbsp;ID</th>
                <th class="text-center">House&nbsp;No.</th>
                <th class="text-center">Actual&nbsp;Registration&nbsp;Date</th>
                <th class="text-center">House&nbsp;Head</th>
                <th class="text-center">Total&nbsp;Member</th>
                <th class="text-center">Married&nbsp;Women</th>
                <th class="text-center">Unmarried&nbsp;Women</th>
                <th class="text-center">Adolence&nbsp;Girl</th>
                <th class="text-center">Child</th>
<!--                <th class="text-center">Delete</th>-->
            </tr>
            </thead>
            <tbody>
                <?php
                if (isset($houseList) and $houseList) {
                    for ($i = 0; $i < count($houseList); $i++) {
                       //  $ashaName=$this->session->userdata('ashaName');
                        ?>
                        <tr id="<?= 'h' . $houseList[$i]['auto_id'] ?>">
                            <td class="text-center"><?= ($i + 1) ?></td>
                            <td class="text-center"><a href="<?php echo base_url('registrationhousewomenchild/getWomenListByRegionIDFromHouseList/'.$houseList[$i]['auto_id'].'/'. $ashaName) ?>"><?php echo "MR" . $houseList[$i]['auto_id'] ?></a></td>
                            <td class="text-center"><?= $houseList[$i]['house_number'] ?></td>
                            <td class="text-center"><?= date('d-m-Y', strtotime($houseList[$i]['actual_register_date'])); ?></td>
                            <td class="text-center"><?= str_replace(' ', '&nbsp;', $houseList[$i]['house_head_name']) ?></td>
                            <td class="text-center"><?= $houseList[$i]['total_family_member'] ?></td>
                            <td class="text-center"><?= $houseList[$i]['married_women'] ?></td>
                            <td class="text-center"><?= $houseList[$i]['unmarried_women'] ?></td>
                            <td class="text-center"><?= $houseList[$i]['total_adolenc_girl'] ?></td>
                            <td class="text-center"><?= $houseList[$i]['total_child'] ?></td>
<!--                            <td class="text-center"><p style="margin: 0" data-placement="top" data-toggle="tooltip" title="Duplicate house data delete."><button style="margin: 0" type="button" class="btn btn-danger btn-xs house-delete-data" data-title="houseDelete" data-toggle="modal" data-target="#houseDelete"  value="<?= $houseList[$i]['auto_id'] ?>"><span class="glyphicon glyphicon-trash"></span></button></p></td>-->


                        </tr>
                        <?php
                    }
                }
                ?>

            </tbody>
        </table>
    </div>
    <div class="panel-footer" style="margin-top: -36px">
        <div class="row">
            <div class="col-lg-12">
                <ul class="pagination pagination-large" id="pagination">
                    <?php
                    if (isset($totalPage) and $totalPage and $totalPage > 1) {
                        for ($i = 0; $i < $totalPage; $i++) {
                            if ($i == 0) {
                                if ($activePage == 1) {
                                    ?>
                                    <li class="disabled"><span>«</span></li>
                                    <?php
                                } else {
                                    if (isset($regionCode)) {
                                        ?>
                                        <li class="page"><a href =<?= base_url('house_list_view/' . ($activePage - 1) . '/' . $regionCode) ?>><span><i class="fa fa-angle-double-left" aria-hidden="true"></i></span></a></li>
                                    <?php } else { ?>
                                        <li class="page" value="<?= ($activePage - 1) ?>"><a href="<?= base_url('house_list_view/' . ($activePage - 1)) ?>"><span><i class="fa fa-angle-double-left" aria-hidden="true"></i></span></a></li>
                                        <?php
                                    }
                                }
                            }
                            if (($i + 1) == $activePage) {
                                ?>
                                <li class="active page"><span><?= ($i + 1) ?></span></li>
                                <?php
                            } else {
                                if (isset($regionCode)) {
                                    ?>
                                    <li class="page"><a href =<?= base_url('house_list_view/' . ($i + 1) . '/' . $regionCode) ?>><span><?= ($i + 1) ?></span></a></li>
                                <?php } else { ?>
                                    <li class="page"><a href="<?= base_url('house_list_view/' . ($i + 1)) ?>"><span><?= ($i + 1) ?></span></a></li>
                                    <?php
                                }
                            }
                            if (($i + 1) == $totalPage) {
                                if ($totalPage == $activePage) {
                                    ?>
                                    <li class="disabled page"><span>Next</span></li>
                                    <?php
                                } else {
                                    if (isset($regionCode)) {
                                        ?>
                                        <li class="page"><a href =<?= base_url('house_list_view/' . ($activePage + 1) . '/' . $regionCode) ?>><span>Next</span></a></li>
                                    <?php } else { ?>
                                        <li class="page"><a href="<?= base_url('house_list_view/' . ($activePage + 1)) ?>"><span>Next</span></a></li>
                                        <?php
                                    }
                                }
                            }
                        }
                    }
                    ?>
                </ul>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="houseDelete" tabindex="-1" role="dialog" aria-labelledby="Delete" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close btn-danger" data-dismiss="modal" aria-hidden="true"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></button>
                <h4 class="modal-title custom_align text-center" id="Heading">Delete House</h4>
            </div>
            <div class="modal-body">
                <input id="auto_id_house" type="hidden" name="auto_id_house" value="">
                <h4 class="text-center text-danger"><strong>Are you sure you want to delete this Record?</strong></h4>
            </div>
            <div class="modal-footer ">
                <button id="yes_house" type="button" class="btn btn-success" ><span class="glyphicon glyphicon-ok-sign"></span> Yes</button>
                <button id="no_house" type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> No</button>
            </div>
        </div>

    </div>

</div>

<script type="text/javascript">
    bootstrap_alert = function () {
    }
    bootstrap_alert.warning = function (message) {
        $('#alert_placeholder').html('<div class="alert"><a class="close" data-dismiss="alert">×</a><span>' + message + '</span></div>')
    }





    $(document).ready(function () {

        //**********************************************//
        $('.house-delete-data').click(function () {
            $('#auto_id_house').val($(this).val());
           
           var posY = $(this).position().top;
            $('#houseDelete').css({'margin-top' :300});
            $('#houseDelete').css({'margin-left' :530});
            

        });
        //***********************************************//
        $('#yes_house').click(function () {
            var houseId = $('#auto_id_house').val();

            $.ajax({
                url: '<?= base_url('house-delete') ?>',
                data: {
                    auto_id: houseId
                },
                type: "POST",
                success: function (data, textStatus, jqXHR) {
                    var house_update_data = JSON.parse(data);
                    if (house_update_data['status']) {
                        $('#h' + house_update_data['house_id']).remove();
                        $('#houseDelete').modal('hide');
                        bootstrap_alert.warning('Your text goes here');
                    }
                }
            });
        });

        //*************************************************//
        $('#region_code').change(function () {
            var region_code = parseInt($('#region_code').val());
            var _name = $('#region_code option:selected').text();
            var anm_region_code=0;
            if(<?php echo $level; ?>==1)
            {
              anm_region_code=parseInt($('#anm_region_code').val());  
            }
            // anm_region_code:anm_region_code
            $('#house_list_update_spinner').css('display', 'block');
            $('#mira-house-list tbody tr').remove();
            $('#pagination li').remove();
            $.ajax({
                url: '<?= base_url('house_list_view_jquery') ?>',
                data: {
                    region_code: region_code,
                    anm_region_code:anm_region_code
                },
                type: "POST",
                success: function (data, textStatus, jqXHR) {
                    $('#house_list_update_spinner').css('display', 'none');
                    var house_data = JSON.parse(data);
                    if (house_data['houseList']) {
                        $("#trd").text(house_data['houseList'].length);
                        $('#trdspan').css('display', 'block');
                        for (var i = 0; i < house_data['houseList'].length; i++) {
                            $("#mira-house-list tbody").append('<tr></tr>');
                            var date_string = getDateFormat(house_data['houseList'][i]['actual_register_date']);
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + (parseInt(i) + 1) + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center"><a href="' + baseUrl + 'registrationhousewomenchild/getWomenListByRegionIDFromHouseList/' + house_data['houseList'][i]['auto_id'] +'/'+encodeURIComponent(_name) + '">' + "MR" + house_data['houseList'][i]['auto_id'] + '</a></td>');
                            
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['house_number'] + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + date_string + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['house_head_name'] + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['total_family_member'] + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['married_women'] + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['unmarried_women'] + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['total_adolenc_girl'] + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['total_child'] + '</td>');
                        }
                    }
                    // This block is working for pagination.
                    if (house_data['totalPage'] && parseInt(house_data['totalPage']) > 1) {
                        var current_page = parseInt(house_data['activePage']);
                        var total_page = parseInt(house_data['totalPage']);
                        var region_code = parseInt(house_data['regionCode']);
                        previousPage(current_page, region_code, 'pagination');
                        forLoop(current_page, total_page, region_code, 'pagination');
                        nextPage(current_page, total_page, region_code, 'pagination');
                    }
                }
            });
        });
        
        $('#btnsearch').click(function(){
        let stdate=$('#st_date_input').val();
        let endate=$('#en_date_input').val();
        let rcode=parseInt($('#region_code').val());
        let searchby=parseInt($('#searchbydate').val());
       // alert('hi   .....==='+searchby);
         var _name = $('#region_code option:selected').text();           
           $('#house_list_update_spinner').css('display', 'block');
            $('#mira-house-list tbody tr').remove();
            $('#pagination li').remove();
           
        $.ajax({
                url: '<?= base_url('getHouseListByRegionIDJqueryV2')?>',
                data: {
                    region_code: rcode,
                    start_date: stdate,
                    end_date: endate,
                    search_by: searchby,
              
                },
                type: "POST",
                success: function (data, textStatus, jqXHR) {
                    $('#house_list_update_spinner').css('display', 'none');
                    $("#frd").text('0');
                    var house_data = JSON.parse(data);
                    if (house_data['houseList']) {
                        if(house_data['houseList'].length>0)
                        {
                       $("#frd").text(house_data['houseList'].length);
                        }
                        else
                        {
                           $("#frd").text('0');  
                        }
                       $('#frdspan').css('display', 'block');
                        for (var i = 0; i < house_data['houseList'].length; i++) {
                            $("#mira-house-list tbody").append('<tr></tr>');
                            var date_string = getDateFormat(house_data['houseList'][i]['actual_register_date']);
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + (parseInt(i) + 1) + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center"><a href="' + baseUrl + 'registrationhousewomenchild/getWomenListByRegionIDFromHouseList/' + house_data['houseList'][i]['auto_id'] +'/'+encodeURIComponent(_name) + '">' + "MR" + house_data['houseList'][i]['auto_id'] + '</a></td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['house_number'] + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + date_string + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['house_head_name'] + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['total_family_member'] + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['married_women'] + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['unmarried_women'] + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['total_adolenc_girl'] + '</td>');
                            $('#mira-house-list tbody tr:last').append('<td class="text-center">' + house_data['houseList'][i]['total_child'] + '</td>');
                        }
                    }
                    // This block is working for pagination.
                    if (house_data['totalPage'] && parseInt(house_data['totalPage']) > 1) {
                        var current_page = parseInt(house_data['activePage']);
                        var total_page = parseInt(house_data['totalPage']);
                        var region_code = parseInt(house_data['regionCode']);
                        previousPage(current_page, region_code, 'pagination');
                        forLoop(current_page, total_page, region_code, 'pagination');
                        nextPage(current_page, total_page, region_code, 'pagination');
                    }
                }
            });
        
        
        
        });
        $('#st_date').datepicker({autoclose: true, format: 'dd-mm-yyyy'});
        $('#en_date').datepicker({autoclose: true, format: 'dd-mm-yyyy'});
    });
    
    
    
     $('#anm_region_code').change(function () {
            var region_code = parseInt($('#anm_region_code').val());
            $('#region_code').children('option:not(:first)').remove();
            $('#region_code').css('display', 'block');
            $.ajax({
                url: '<?= base_url('getAshalistByANMId') ?>',
                data: {
                   region_code: region_code
                },
                type: "POST",
                success: function (json) {
                    var states = $.parseJSON(json);
                    for (var i = 0; i < states['miraList'].length; i++) {
                        $("#region_code").append($("<option></option>").val(states['miraList'][i]['region_code']).html(states['miraList'][i]['user_name']));
                    }
                    $('#asha_list_update_spinner').css('display', 'none');
                },
                error: function (xhr, status, errorThrown) {
                    $('#asha_list_update_spinner').css('display', 'none');
                },
                complete: function (xhr, status) {
                    $('#asha_list_update_spinner').css('display', 'none');
                }
            });

        });

    function nextDoubleClick(startingindex, regioncode, selectorid) {
        $('#' + selectorid).append('<li class ="disabled"><span>. .. ...</span></li>');
        $('#' + selectorid).append('<li class="page"><a href =' + '<?= base_url('house_list_view') ?>' + '/' + (startingindex + 5) + '/' + regioncode + '><span><i class="fa fa-angle-double-right" aria-hidden="true"></i><i class="fa fa-angle-double-right" aria-hidden="true"></i></span></a></li>');
    }
    function previousDoubleClick(startingindex, regioncode, selectorid) {

        $('#' + selectorid).append('<li class="page"><a href =' + '<?= base_url('house_list_view') ?>' + '/' + (startingindex - 5) + '/' + regioncode + '><span><i class="fa fa-angle-double-left" aria-hidden="true"></i><i class="fa fa-angle-double-left" aria-hidden="true"></i></span></a></li>');
        $('#' + selectorid).append('<li class ="disabled"><span>... .. .</span></li>');

    }
    function previousPage(startingindex, regioncode, selectorid) {

        $('#' + selectorid).append('<li class ="disabled"><span><i class="fa fa-angle-double-left" aria-hidden="true"></i></span></li>');

    }
    function nextPage(startingindex, lastindex, regioncode, selectorid) {

        $('#' + selectorid).append('<li class="page"><a href =' + '<?= base_url('house_list_view') ?>' + '/' + (startingindex + 1) + '/' + regioncode + '><span>Next</span></a></li>');



    }
    function forLoop(startingindex, lastindex, regioncode, selectorid) {
        for (var i = 1; i <= lastindex; i++) {
            if (i === startingindex) {
                $('#' + selectorid).append('<li class="active page"><span>' + i + '</span></li>');
            } else {
                $('#' + selectorid).append('<li class="page"><a href=' + '<?= base_url('house_list_view') ?>' + '/' + i + '/' + regioncode + '><span>' + i + '</span></a></li>');
            }

        }
    }
    function getDateFormat(date) {
        var split_date_array1 = date.split('-');
        var split_date_array2 = split_date_array1[2].split(' ');
        return (split_date_array2[0] + '-' + split_date_array1[1] + '-' + split_date_array1[0]);
    }
</script>

