<script>
    $(document).ready(function(){
        if ($.ui && $.ui.dialog && $.ui.dialog.prototype._allowInteraction) {
            var ui_dialog_interaction = $.ui.dialog.prototype._allowInteraction;
            $.ui.dialog.prototype._allowInteraction = function(e) {
                if ($(e.target).closest('.select2-dropdown').length) return true;
                return ui_dialog_interaction.apply(this, arguments);
            };
        }

        clockUpdate();
        setInterval(clockUpdate, 1000);

        $('#toggle-btn').on('click', function () {
            $('.left_side').slideToggle('slow').css({'zIndex': 2, 'width' : '180px'});
        });

        $('#hints-section').load(encodeURI('/activate-hints/'+ <?php echo e(auth()->user()->id); ?>));
        $('#clock-section').load(encodeURI('/activate-clock/'+ <?php echo e(auth()->user()->id); ?>));
        $('#notification-section').load(encodeURI('/activate-notifications/'+ <?php echo e(auth()->user()->id); ?>));

        $('#perform-calculations').click(function (){
            alert('Which calculations to perform?');
        });

    });

    /**ADD NEW POLICY FUNCTION**/
    function addNewPolicy(module){
        var route_link = '/add-policy-step-one/'+module;

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>');
        $('#edit_dialog_content').load(encodeURI(route_link));
        $('#edit_dialog_content').dialog({
            modal: true,
            minWidth: 850,
            title: "Add New Project - Step One",
            buttons: [
                {
                    text: "Save Project Details",
                    icon: "ui-icon-check",
                    id: "my-button-1",
                    click: function(e) {
                        if(confirm('Are you sure to open Project File with displayed Details?')){
                            e.preventDefault();
                            $("#my-button-1").attr('disabled', true);
                            $("#my-button-1").text('Please Wait....');
                            var datas = $('#add-policy-step-one').serializeArray();

                            $.ajax({
                                method: "POST",
                                url: route_link,
                                data: datas,
                                success: function (res){
                                    //alert(res);
                                    //$("#my-button-1").attr('disabled', false);
                                    if(res == 'empty client'){
                                        alert('Please Select a Client to Proceed');
                                        $("#my-button-1").attr('disabled', false);
                                        $("#my-button-1").text('Save Premium Computations');
                                    }else if(res == 'empty insured'){
                                        alert('Please provide name of the Insured Person to Proceed');
                                        $("#my-button-1").attr('disabled', false);
                                        $("#my-button-1").text('Save Premium Computations');
                                    }else if(res == 'empty insurer'){
                                        alert('Select an Insurance Company taking this Risk');
                                        $("#my-button-1").attr('disabled', false);
                                        $("#my-button-1").text('Save Premium Computations');
                                    }else if(res == 'empty st'){
                                        alert('Please Provide the Start Date of this Policy');
                                        $("#my-button-1").attr('disabled', false);
                                        $("#my-button-1").text('Save Premium Computations');
                                    }else if(res == 'empty ed'){
                                        alert('Please enter the End Date for this particular policy');
                                        $("#my-button-1").attr('disabled', false);
                                        $("#my-button-1").text('Save Premium Computations');
                                    }else if(res == 'empty trans type'){
                                        alert('Please Specify the Type of Transaction as either New or Renewal');
                                        $("#my-button-1").attr('disabled', false);
                                        $("#my-button-1").text('Save Premium Computations');
                                    }else if(res == 'empty renewal option'){
                                        alert('Please specify if this Policy is Renewable or NOT');
                                        $("#my-button-1").attr('disabled', false);
                                        $("#my-button-1").text('Save Premium Computations');
                                    }else if(res == 'empty product'){
                                        alert('Please select a Product or Class of Insurance to Proceed');
                                        $("#my-button-1").attr('disabled', false);
                                        $("#my-button-1").text('Save Premium Computations');
                                    }else if(res == 'empty product type'){
                                        alert('Please select the Type of Product being Underwritten');
                                        $("#my-button-1").attr('disabled', false);
                                        $("#my-button-1").text('Save Premium Computations');
                                    }else if(res == 'empty sum insured'){
                                        alert('Please enter the Total Sum Insured to Proceed');
                                        $("#my-button-1").attr('disabled', false);
                                        $("#my-button-1").text('Save Premium Computations');
                                    }else if(res == 'empty premium'){
                                        alert('Please enter Annual Premium Rate/Amount to proceed');
                                        $("#my-button-1").attr('disabled', false);
                                        $("#my-button-1").text('Save Premium Computations');
                                    }else if(res == 'error'){
                                        alert('System Encountered an Error. Please Try again');
                                        location.reload();
                                    }else if($.isNumeric(res)){
                                        window.location = '/add-policy-step-two/'+res;
                                    }else{
                                        alert('System Encountered an Error. Please Contact System Admin');
                                        location.reload();
                                    }
                                }
                            });
                            return false;
                        }
                    }
                }
            ],
            open: function() {
                $(this).parent().css({'top': 50});
            },
            beforeClose: function() {
                if(confirm('Are you sure to close this Window of adding a New Project?')){
                    location.reload();
                }
                return false;
            }
        });
    }

    /**Create a Function to View My Notifications**/
    function viewMyNotifications(){
        var route_link = '/view-my-notifications';

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
            .load(encodeURI(route_link))
            .dialog({
                modal: true,
                width: 900,
                title: "View My Notifications List",
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
    }
    /**Function to Run for getting the count of Notifications**/
    function myNotifications() {
        /**Make an Ajax Call**/
        $.ajax({
            method: "GET",
            url: '/get-my-notifications',
            success: function (res){
                if(res != ""){
                    $('#my-notifications').html(res);
                }
            }
        });
        setTimeout(myNotifications, 5000);
    }
    myNotifications();

    //PREMIUM CALCULATOR
    function premiumCalc(){
        var url_link = '/premium-calculators';

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>');
        $('#edit_dialog_content').load(encodeURI(url_link));
        $('#edit_dialog_content').dialog({
            modal: true,
            width: 700,
            title: "Standard Calculator",
            open: function() {
                $(this).parent().css({'top': 50});
            }
        });
    }

    //SEARCH CLIENT FUNCTION
    function searchClient(){
        var url_link = '/search-client';

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
        .load(encodeURI(url_link))
        .dialog({
            modal: true,
            width: 600,
            title: "Search Client",
            buttons: [
                {
                    text: "Open Client's File ",
                    icon: "ui-icon-check",
                    id: 'submit-button',
                    click: function(e) {
                        e.preventDefault();
                        //$('#submit-button').text("Please wait...").attr('disabled', true).css('backgroundColor', 'gray');
                        var type = $('input[name="search-parameter"]:checked').val();

                        var selected,details;
                        if(type == 1){
                             selected = $('#select-list').val();
                             details = "Please Select a Client to Search";
                        }else if(type == 2){
                             selected = $('#select-file-no').val();
                             details = "Please Select Client File Number to perform the Search";
                        }else if(type == 3){
                             selected = $('#select-phone-no').val();
                             details = "Please Select Client Phone Number to perform the Search";
                        }else if(type == 4){
                             selected = $('#select-id-no').val();
                             details = "Please Select Client ID Number to perform the Search";
                        }

                        if(selected == "" ||  null){
                            alert(details);
                        }else{
                            $(location).attr('href','/client/'+selected+'?type=summary');
                        }

                    }
                }
            ],
            open: function() {
                $(this).parent().css({'top': 50});
            }
        });
    }

    
    function managePasswords(){
        var route_link = '/edit-user-passwords';

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
        .load(encodeURI(route_link))
        .dialog({
            modal: true,
            width: 500,
            title: "Update your Password(s)",
            buttons: [
                {
                    text: "Continue & Update",
                    icon: "ui-icon-check",
                    click: function(e) {
                        if(confirm('Are you sure to Perform this Request?')){
                            e.preventDefault();
                            var datas = $('#edit-user-passwords').serializeArray();

                            $.ajax({
                                method: "POST",
                                url: route_link,
                                data: datas,
                                success: function (res){
                                    if(res == 'empty password'){
                                        alert('Please Provide your New Password to Continue');
                                    }else if(res == 'empty confirm'){
                                        alert('Please Provide Confirm Password to Continue');
                                    }else if(res == 'not match'){
                                        alert('Entered New password and Confirm password does not match');
                                    }else if(res == 'empty smtp email'){
                                        alert('Please Provide your Company Email Address to Continue');
                                    }else if(res == 'empty smtp password'){
                                        alert('Please Provide your Company Email SMTP Password to Continue');
                                    }else if(res == 'error'){
                                        alert('There was an error updating your password. Try again later');
                                    }else if(res == 'success'){
                                        alert('Password Changed Successfully. Thank you.');
                                        location.reload();
                                    }else if(res == 'smtp success'){
                                        alert('Email SMTP Settings Updated Successfully. Thank you.');
                                        $('#edit_dialog_content').dialog('close');
                                    }else{
                                        alert('System Encountered unexpected Error. Please contact Developers');
                                        location.reload();
                                    }
                                }
                            });
                        }
                        return false;
                    }
                }
            ],
            open: function() {
                $(this).parent().css({'top': 50});
            }
        });
    }

    function clockUpdate() {
        var date = new Date();
        $('.digital-clock').css({'color': '#fff', 'text-shadow': '0 0 6px #ff0'});
        function addZero(x) {
            if (x < 10) {
                return x = '0' + x;
            } else {
                return x;
            }
        }

        function twelveHour(x) {
            if (x == 0) {
                return x = 12;
            } else {
                return x;
            }
        }
        function dayName(x){
            if(x == 0){
                x = 'Sun';
            }else if(x == 1){
                x = 'Mon';
            }else if(x == 2){
                x = 'Tue';
            }else if(x == 3){
                x = 'Wed';
            }else if(x == 4){
                x = 'Thur';
            }else if(x == 5){
                x = 'Fri';
            }else if(x == 6){
                x = 'Sat';
            }
            return x;
        }

        var siku = dayName(date.getDay());
        var day = addZero(date.getDate());
        var month = addZero(date.getMonth() + 1);
        var year = date.getFullYear();

        var h = addZero(twelveHour(date.getHours()));
        var m = addZero(date.getMinutes());
        var s = addZero(date.getSeconds());

        $('.digital-clock').html(" &nbsp;&nbsp;" + siku + " , " + day + "/" + month + "/" + year + " , " + h + ':' + m + ':' + s + "&nbsp;&nbsp;")
    }

    function showCalendar(){
        var url_link = '/calendar';

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>');
        $('#edit_dialog_content').load(encodeURI(url_link));
        $('#edit_dialog_content').dialog({
            modal: true,
            width: 700,
            title: "Calendar and Events",
            open: function() {
                $(this).parent().css({'top': 50});
            }
        });
    }

    /**Function to Send a New Email**/
    function sendEmail(id=null,module=null){
        var url_link = '/send-email/'+id+'/'+module;

        $('#edit_dialog_content').html('<div style="text-align: center; margin: 20px 0 20px 0;"><img src="<?php echo e(asset('images/loads/loader.gif')); ?>" border=0></div>')
            .load(encodeURI(url_link))
            .dialog({
                modal: true,
                width: 800,
                title: "Send a New Email",
                buttons: [
                    {
                        text: "Continue & Send",
                        icon: "ui-icon-check",
                        id: 'my-button-1',
                        click: function(e) {
                            e.preventDefault();
                            if(confirm('Are you sure to Proceed and Send Email')){
                                e.preventDefault();
                                $("#my-button-1").attr('disabled', true).text('Please Wait....');
                                var datas = new FormData($('#send-email-data')[0]);
                                $.ajax({
                                    method: "POST",
                                    url: url_link,
                                    data: datas,
                                    enctype: 'multipart/form-data',
                                    contentType: false,
                                    processData: false,
                                    success: function (res){
                                        //alert(res);
                                        //$("#my-button-1").attr('disabled', false).text('Continue to Save Files');
                                        if(res == 'no file attached'){
                                            alert('Please Attach a File to Proceed');
                                            $("#my-button-1").attr('disabled', false).text('Continue & Send');
                                        }else if(res.indexOf("The Following") >= 0){
                                            alert(res);
                                            $("#my-button-1").attr('disabled', false).text('Continue & Send');
                                        }else if(res == 'error uploading'){
                                            alert('There was an Internal Error Uploading the File. Please contact Developers');
                                            $("#edit_dialog_content").dialog('close');
                                        }else if(res == 'success'){
                                            alert('Email Sent Successfully');
                                            $('#edit_dialog_content').dialog('close');
                                        }else if(res == 'error'){
                                            alert('There was an Error uploading the Document. Please try again');
                                            $("#my-button-1").attr('disabled', false).text('Continue & Send');
                                        }else{
                                            alert('System Encountered an Error. Please Contact System Admin for Help');
                                            $('#edit_dialog_content').dialog('close');
                                        }
                                    }
                                });
                                return false;
                            }
                        }
                    }
                ],
                open: function() {
                    $(this).parent().css({'top': 50});
                }
            });
    }
</script>
<style>
    .top-navbar-buttons:hover{
        color: red;
    }

</style>

<div class="top_bar">
    <div class="toggle-btn">
        <button id="toggle-btn"><i class="fa fa-bars" data-toggle="collapse" aria-hidden="true"></i></button>
    </div>
    <?php if(auth()->user()->clock == 1): ?>
        <div class="digital-clock" >00:00:00</div>
    <?php endif; ?>
    <div class="topbar-content" style="float: left; margin-top: 5px">
        <div class="dropdown">
            <a href="javascript: void(0)" onclick="backPage()" class="inner"  title="Go Back"><i class="fa fa-arrow-left top-navbar-buttons" aria-hidden="true" style="font-size: 22px"></i></a>

        </div>
        <div class="dropdown">
            <a href="javascript: void(0)" onclick="forwardPage()" class="inner"  title="Go Forward"><i class="fa fa-arrow-right top-navbar-buttons" aria-hidden="true" style="font-size: 22px"></i></a>

        </div>
        <div class="dropdown">
            <a href="javascript: void(0)" onclick="reloadPage()" class="inner"  title="Reload"><i class="fa fa-repeat top-navbar-buttons" aria-hidden="true" style="font-size: 22px"></i></a>

        </div>
        <div class="dropdown">
            <a href="javascript: void(0)" onclick="duplicatePage()" class="inner"  title="Duplicate Page: Click to Open Same Page in a New Tab"><i class="fa fa-files-o top-navbar-buttons" aria-hidden="true" style="font-size: 22px"></i></a>
            &nbsp;
        </div>
    </div>
    <div class="topbar-content">

        
        <div class="dropdown">
            <a href="javascript: void(0)" onclick="showSettings()" class="inner" title="Settings"><i class="fa fa-cog top-navbar-buttons" aria-hidden="true" style="font-size: 24px"></i></a>
            <div class="dropdown-content" id="dropdown-content">
                
                <a href="#" id="hints-section"></a>
                <a href="#" id="clock-section"></a>
            </div>
        </div>
        <div class="dropdown navigationButtons">
            <a href="javascript: void(0)" onclick="viewMyNotifications()" class="inner" title="My Notifications">
                <i class="fa fa-bell-o top-navbar-buttons" id="my-notifications" aria-hidden="true" style="font-size: 22px"></i>
            </a>
        </div>
        <div class="dropdown">
            <a href="javascript: void(0)" onclick="premiumCalc()" class="inner" title="Premium Calculator"><i class="fa fa-calculator top-navbar-buttons" id="premium-calculator" aria-hidden="true" style="font-size: 22px"></i></a>
        </div>
        <div class="dropdown">

            <a href="javascript: void(0)" onclick="showCalendar()" class="inner" title="Calender & Events"><i class="fa fa-calendar top-navbar-buttons" id="calender" aria-hidden="true" style="font-size: 22px"></i></a>
        </div>
        <div class="dropdown">
            <a href="javascript: void(0)" onclick="managePasswords()" class="inner" title="Manage Passwords"><i class="fa fa-eye-slash top-navbar-buttons" id="manage-passwords" aria-hidden="true" style="font-size: 25px"></i></a>
        </div>
        <?php if(app('CompanyModules')->hr == 1 && auth()->user()->is_employee != 0): ?>
            <div class="dropdown">
                <a href="<?php echo e(url('employee-file?type=active')); ?>" class="inner" title="My Profile"><i class="fa fa-user top-navbar-buttons" id="user-profile" aria-hidden="true" style="font-size: 25px"></i></a>
            </div>
        <?php endif; ?>
        <div class="dropdown" >
            <?php echo Form::open(['route'=>'logout', 'method'=>'POST']); ?>

            <?php if (isset($component)) { $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4 = $component; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.responsive-nav-link','data' => ['href' => route('logout'),'onclick' => 'event.preventDefault();
                                   if(confirm(\'Are you sure to Logout?\')){
                                      this.closest(\'form\').submit();
                                   }
                                   return false;','class' => 'inner']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName('responsive-nav-link'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag && $constructor = (new ReflectionClass(Illuminate\View\AnonymousComponent::class))->getConstructor()): ?>
<?php $attributes = $attributes->except(collect($constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php $component->withAttributes(['href' => \Illuminate\View\Compilers\BladeCompiler::sanitizeComponentAttribute(route('logout')),'onclick' => 'event.preventDefault();
                                   if(confirm(\'Are you sure to Logout?\')){
                                      this.closest(\'form\').submit();
                                   }
                                   return false;','class' => 'inner']); ?>
                <i class="fa fa-power-off top-navbar-buttons" aria-hidden="true" id="log-out" style="font-size: 22px" title="Log Out"></i>
             <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4)): ?>
<?php $component = $__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4; ?>
<?php unset($__componentOriginalc254754b9d5db91d5165876f9d051922ca0066f4); ?>
<?php endif; ?>
            <?php echo Form::close(); ?>

        </div>
    </div>
</div><br><br><br><br>
<?php /**PATH C:\xampp\htdocs\edwulp_chemist\resources\views/layouts/topbar.blade.php ENDPATH**/ ?>