<style>
    .hasDatepicker {
        margin-top: 5px !important;
    }

    #renew-flash-msg .alert {
        width: 475px !important;
    }

</style>
<?php $this->widget('bootstrap.widgets.TbAlert'); ?>


<div id="renew-flash-msg">
    <br>
    <?php $this->widget('bootstrap.widgets.TbAlert'); ?>
</div>

<div id="vehicleDiv" style="display: none">
    <?php
    echo Yii::t('default', 'Vehicle Book Expiry Date');

    echo "<br/>";
    $this->widget('yiiwheels.widgets.datepicker.WhDatePicker', array(
        'name' => 'vehicle',
        'id' => 'Asset_vehicle_book_expiry_date',
        'pluginOptions' => array(
            'format' => 'yyyy-mm-dd'
        )
    ));
    ?>

</div>

<div id="radioactiveDiv"  style="display: none">
    <?php
    echo Yii::t('default', 'Radioactive License Expiry Date');

    echo "<br/>";

    $this->widget('yiiwheels.widgets.datepicker.WhDatePicker', array(
        'name' => 'radioactive',
        'id' => 'Asset_radioactive_license_expiry_date',
        'pluginOptions' => array(
            'format' => 'yyyy-mm-dd'
        )
    ));
    ?>

</div>


<script type="text/javascript">




    $(document).ready(function() {
        hide_column();
        $('#Asset_vehicle_book_expiry_date').datepicker({'showAnim': 'fold', 'dateFormat': 'yy-mm-dd'});
        $('#Asset_radioactive_license_expiry_date').datepicker({'showAnim': 'fold', 'dateFormat': 'yy-mm-dd'});

    });



    function checkTypeOfAssetModal(data) {
        var vehicle_id = '<?php echo Setting::getVehicleTypeOfAsset(); ?>';
        var radio_active_id = '<?php echo Setting::getRadioActiveTypeOfAsset(); ?>';
        if (data == vehicle_id) {
            $('#vehicleDiv').attr('style', 'display:block');
            $('#radioactiveDiv').attr('style', 'display:none');
        }
        else
        if (data == radio_active_id) {
            $('#vehicleDiv').attr('style', 'display:none');
            $('#radioactiveDiv').attr('style', 'display:block');
        }
        else
        {
            $('#vehicleDiv').attr('style', 'display:none');
            $('#radioactiveDiv').attr('style', 'display:none');
        }

        if (vehicle_id == '')
            $('#vehicleDiv').attr('style', 'display:none');
        if (radio_active_id == '')
            $('#radioactiveDiv').attr('style', 'display:none');

    }


    $('.close').click(function() {
        $('#renew-form').removeClass('in');
    });


    function hide_column() {
        grid = $('#asset-grid');
        $('tr', grid).each(function() {
            $('td:eq(0), th:eq(0)', this).hide();
        });
    }

    function save_changes() {
        var vehicle_expiry_date = $("#Asset_vehicle_book_expiry_date").val();
        var radioactive_expiry_date = $("#Asset_radioactive_license_expiry_date").val();
        $.ajax({
            type: "POST",
            data: {
                'model_id': model_id,
                'vehicle_expiry_date': vehicle_expiry_date,
                'radioactive_expiry_date': radioactive_expiry_date

            },
            url: "<?php echo Yii::app()->createAbsoluteUrl("asset/renew"); ?>",
            success: function(data) {
                if (data.indexOf("error") != -1) {
                    $("#renew-flash-msg").html(data);
                }
                else {
                    $("#renew-flash-msg").html("");
                    $("#flash-msg").html(data);
                    $.fn.yiiGridView.update('asset-grid', {
                    });
                    $('#renew-form').removeClass('in');
                    hide_column();
                    $("#asset-flash-msg").html(data);
                    $("#Asset_vehicle_book_expiry_date").val("");
                    $("#Asset_radioactive_license_expiry_date").val("");
                }
            },
            error: function(data) { // if error occured
                $("#renew-flash-msg").html(data);
            }
        });
    }

</script>





