<!-- basic scripts -->

<!--[if !IE]> -->

<script type="text/javascript">
    window.jQuery || document.write("<script src='<?php echo $base_url; ?>assets/js/jquery-2.0.3.min.js'>" + "<" + "/script>");
</script>

<!-- <![endif]-->

<!--[if IE]>
<script type="text/javascript">
window.jQuery || document.write("<script src='<?php echo $base_url; ?>assets/js/jquery-1.10.2.min.js'>"+"<"+"/script>");
</script>
<![endif]-->

<script type="text/javascript">
    if ("ontouchend" in document)
        document.write("<script src='<?php echo $base_url; ?>assets/js/jquery.mobile.custom.min.js'>" + "<" + "/script>");
</script>
<script src="<?php echo $base_url; ?>assets/js/bootstrap.min.js"></script>
<script src="<?php echo $base_url; ?>assets/js/typeahead-bs2.min.js"></script>

<!-- page specific plugin scripts -->

<!--[if lte IE 8]>
  <script src="<?php echo $base_url; ?>assets/js/excanvas.min.js"></script>
<![endif]-->

<script src="<?php echo $base_url; ?>assets/js/jquery-ui-1.10.3.custom.min.js"></script>
<script src="<?php echo $base_url; ?>assets/js/jquery.ui.touch-punch.min.js"></script>
<script src="<?php echo $base_url; ?>assets/js/jquery.slimscroll.min.js"></script>
<script src="<?php echo $base_url; ?>assets/js/jquery.easy-pie-chart.min.js"></script>
<script src="<?php echo $base_url; ?>assets/js/jquery.sparkline.min.js"></script>
<script src="<?php echo $base_url; ?>assets/js/flot/jquery.flot.min.js"></script>
<script src="<?php echo $base_url; ?>assets/js/flot/jquery.flot.pie.min.js"></script>
<script src="<?php echo $base_url; ?>assets/js/flot/jquery.flot.resize.min.js"></script>
<script src="<?php echo $base_url; ?>assets/js/jquery.validate.min.js"></script>
<!-- ace scripts -->

<script src="<?php echo $base_url; ?>assets/js/ace-elements.min.js"></script>
<script src="<?php echo $base_url; ?>assets/js/ace.min.js"></script>

<script src="<?php echo $base_url; ?>assets/js/date-time/moment.min.js"></script>
<script src="<?php echo $base_url; ?>assets/js/date-time/daterangepicker.min.js"></script>

<!-- inline scripts related to this page -->

<script type="text/javascript">
	$('.daterangepicker').daterangepicker();
    jQuery(function ($) {



        var d6 = [];
        for (var i = 0; i < 14; i += 0.5 + Math.random()) {
            d6.push([i, Math.sqrt(2 * i + Math.sin(i) + 5)]);
        }

        var traffix_charts = $('#traffix-charts').css({'width': '100%', 'height': '320px'});
        $.plot("#traffix-charts", [
            {data: d6, lines: {show: true}, step: {show: true}},
        ]);

        //Android's default browser somehow is confused when tapping on label which will lead to dragging the task
        //so disable dragging when clicking on label
        var agent = navigator.userAgent.toLowerCase();
        if ("ontouchstart" in document && /applewebkit/.test(agent) && /android/.test(agent))
            $('#tasks').on('touchstart', function (e) {
                var li = $(e.target).closest('#tasks li');
                if (li.length == 0)
                    return;
                var label = li.find('label.inline').get(0);
                if (label == e.target || $.contains(label, e.target))
                    e.stopImmediatePropagation();
            });

        $('#tasks').sortable({
            opacity: 0.8,
            revert: true,
            forceHelperSize: true,
            placeholder: 'draggable-placeholder',
            forcePlaceholderSize: true,
            tolerance: 'pointer',
            stop: function (event, ui) {//just for Chrome!!!! so that dropdowns on items don't appear below other items after being moved
                $(ui.item).css('z-index', 'auto');
            }
        }
        );
        $('#tasks').disableSelection();
        $('#tasks input:checkbox').removeAttr('checked').on('click', function () {
            if (this.checked)
                $(this).closest('li').addClass('selected');
            else
                $(this).closest('li').removeClass('selected');
        });


    });

    function show_box(id) {
        jQuery('.widget-box.visible').removeClass('visible');
        jQuery('#' + id).addClass('visible');
    }

    $('#register-button').click(function () {
        $('#modal-login').modal('show')
    })

    $('#validation-edit-form').validate({
        errorElement: 'label',
        errorClass: 'help-block',
        focusInvalid: true,
        rules: {
            password: {
                required: true,
            },
            username: {
                required: true
            }
        },
        messages: {
            username: {
                required: "Vui lòng nhập tài khoản !",
            },
            password: {
                required: "Vui lòng nhập mật khẩu !",
            }
        },
        highlight: function (e) {
            $(e).closest('label').removeClass('has-info').addClass('has-error');
        },
        success: function (e) {
            $(e).closest('label').removeClass('has-error').addClass('has-info');
            $(e).remove();
        },
    });

</script>
<?php
if (isset($adminjs)) {
    foreach ($adminjs as $file) {
        ?>
        <script type="text/javascript" src="<?php echo $base_url; ?><?php echo $file ?>"></script>
        <?php
    }
}
?>
<script>
    $('#validation-add-form').validate({
        errorElement: 'label',
        errorClass: 'help-block',
        focusInvalid: true,
        rules: {
            password: {
                required: true,
            },
            username: {
                required: true
            }
        },
        messages: {
            username: {
                required: "Vui lòng nhập tài khoản !",
            },
            password: {
                required: "Vui lòng nhập mật khẩu !",
            }
        },
        /*
         highlight: function (e) {
         $(e).closest('label').removeClass('has-info').addClass('has-error');
         },
         
         success: function (e) {
         $(e).closest('label').removeClass('has-error').addClass('has-info');
         $(e).remove();
         },*/
    });
    var last_time=0;
    $(document).ajaxStart(function () {
       if ($.now()>(last_time+60000))
       {
            $.ajax({
                url: "<?php echo $base_url; ?>admin/home/is_timeout",
                type: "POST",
                data: $("#package_register").serialize(),
                success: function (data, textStatus, jqXHR)
                {
                    var results = jQuery.parseJSON(data);
                    if (results.login==0)
                    {
                    window.location.href = "<?php echo $base_url; ?>admin/home";
                    }
                },
            });
            last_time=$.now();
        }
    });
</script>
</body>
</html>