/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 * Amr in 16-11-2015
 */

var hosturl = $('#hosturl').val();

$(document).ready(function () {

    $("#awval").validate();
    $(".awval").validate();
    $(".today").datepicker("setDate", "0");
    $(".tomoro").datepicker("setDate", "+1");
    $(".datepicker").datepicker();
    $.datepicker.setDefaults({
        dateFormat: "yy/mm/dd",
        changeMonth: true,
        changeYear: true
    });
    $(".datepicker").datepicker({
        appendText: "(yy/mm/dd)"
    });

    $('[data-toggle="popover"]').popover();

    var minxhit = $(window).height();
    var mihitx = minxhit + "px";
    $("#pageminheight").css("min-height", mihitx);
/////////////////////////

//$(window).scroll(function () {
//    if ($(this).scrollTop() > 370) {
//        $('.opsrisk').addClass('fixed');
//        var fulwdz = $('.col-md-12').width();
//        var fullwidth = fulwdz + "px";
//        $(".fixed").css("width", fullwidth);
//    } else {
//        $('.opsrisk').removeClass('fixed');
//    }
//});


    $(".btn-group").hover(function () {
        $(".btn-group").removeClass("open");
        $(this).addClass("open");
    });
    $("*").click(function () {
        $(".btn-group").removeClass("open");
    });
    $(".clinick.invz .form-group.form-md-line-input.has-info").focusin(function () {
        $(this).children(".input-group-addon").css("z-index", "-500");
    });
    $(".clinick.invz .form-group.form-md-line-input.has-info").focusout(function () {
        $(this).children(".input-group-addon").css("z-index", "500");
    });
    $(".amrpop,input[type='text']:not(.datepicker):not(.notPop),textarea:not(.notPop)").hover(function () {
        var pop_value = $(this).val();
        $(this).attr({
            "data-toggle": "popover",
            "data-trigger": "hover",
            "data-placement": "bottom",
            "data-content": pop_value
        });
        $(this).popover("show");
    });
    $(window).load(function () {
        $('input[type="search"]').attr("placeholder", "Search ..");
    });
    $(".focus-search-index").click(function () {
        $(this).hide();
        $(".xhide").hide();
        $(".indexsearchbox").css("z-index", "1");
    });
    $(document).keyup(function (e) {
        $(".focus-search-index").hide();
        //$(".xhide").hide();
        $(".indexsearchbox").css("z-index", "1");
    });


    var check_heigt_and_make_new_class = $(".check_heigt_and_make_new_class").height();
    if (check_heigt_and_make_new_class > 400) {
        $(".check_heigt_and_make_new_class").addClass("overflow_scroll");
    } else {
        $(".check_heigt_and_make_new_class").removeClass("overflow_scroll");
    }


    /***********/


//
//    $("input").hover(function () {
//        var xlabel = $(this).parent('#awval div').first().children('label').html();
//        $(this).parent('#awval div').first().children('label').hide()
//        $(this).attr("placeholder", xlabel);
//    });
//
//    $("input").hover(function () {
//        var xlabel = $(this).parent('#div_exmination div').first().children('label').html();
//        $(this).parent('#div_exmination div').first().children('label').hide()
//        $(this).attr("placeholder", xlabel);
//    });
//
//
//    $("input").hover(function () {
//        var xlabel = $(this).parent('.invz div').first().children('label').html();
//        $(this).parent('.invz div').first().children('label').hide()
//        $(this).attr("placeholder", xlabel);
//    });
//
//
//    $("input").hover(function () {
//        var xlabel = $(this).parent('.ng-pristine div').first().children('label').html();
//        $(this).parent('.ng-pristine div').first().children('label').hide()
//        $(this).attr("placeholder", xlabel);
//    });
//
//


    /***************************************************************/

    var showNum = 10;
    var showScrollLines = (showNum * 31) + 23;
    $(".showNum").height(showScrollLines);

    var showNumGyna = 10;
    var showScrollLines = (showNumGyna * 31) + 43;
    $(".showNumGyna").height(showScrollLines);


    /***********/


});
$(document).ready(function () {
    $('.menu_role_item').change(function () {

        let check_val = $(this).val();
        let role_id = $('input[name=roleid]').val();
        let menu_id = $(this).attr('data-menuid');
        $.post(hosturl + '/controllers/_role.php?ac=updateMenuSetting', {roleid: role_id, menuid: menu_id, menurolecheck: check_val}, function (result) {
            //alert(result);
        });
    });

    $('.menu_user_item').change(function () {

        let check_val = $(this).val();
        let user_id = $('input[name=userid]').val();
        let menu_id = $(this).attr('data-menuid');
        $.post(hosturl + '/controllers/_member.php?ac=updateMenuUserSetting', {userid: user_id, menuid: menu_id, menurolecheck: check_val}, function (result) {
            //alert(result);
        });
    });

    $('.control_prop_role_item').change(function () {

        let check_val = $(this).val();
        let role_id = $('input[name=roleid]').val();
        let control_prop_id = $(this).attr('data-controlpropid');
        $.post(hosturl + '/controllers/_role.php?ac=updateControlSetting', {roleid: role_id, controllpropid: control_prop_id, proprolecheck: check_val}, function (result) {
            //alert(result);
        });
    });

    $('.btn_role_item').change(function () {

        let check_val = $(this).val();
        let role_id = $('input[name=roleid]').val();
        let btn_id = $(this).attr('data-btnid');
        $.post(hosturl + '/controllers/_role.php?ac=updateBtnSetting', {roleid: role_id, btn_id: btn_id, btncheck: check_val}, function (result) {
            //alert(result);
        });
    });
});

$(document).ready(function () {
    $('.remove_patient_tank_cell').click(function () {
        let cell_id = $(this).attr('data-id');
        let tank_id = $(this).attr('data-tank-id');
        $.post(hosturl + '/controllers/tanks.php?ac=removePatientCell', {cell_id: cell_id}, function (result) {
            if (Boolean(result) === true) {
                window.location.href = hosturl + "/controllers/tanks.php?ac=cells&id=" + tank_id;
            }
        });
    });


    $('#lab_tank_id').change(function () {
        let tank_id = $(this).val();
        $.post(hosturl + '/controllers/tanks.php?ac=tankLabCells', {tank_id: tank_id}, function (result) {
            $('#tankCellsContainer').html(result);
        });
    });

    let selected_name_group_lab = '';
    $('body').on('change', '.last_cell_tank', function (e) {
        let select_group = $(this).attr('data-name');
        if (selected_name_group_lab == '' || select_group == selected_name_group_lab) {
            selected_name_group_lab = select_group;
            $('#up_level_name').val($(this).attr('data-up-level'));
            $('#cell_name').val($(this).attr('data-cell-name'));
        } else {
            $(this).prop("checked", false);
            alert('You can not choose another cell');
        }

        // check if empty
        if ($('input[data-name="' + selected_name_group_lab + '"]:checked').length <= 0) {
            selected_name_group_lab = '';
            $('#up_level_name').val(0);
            $('#cell_name').val(0);
        }

    });

    $('#save_tank_lab_cell_patient').click(function () {
        $.post(hosturl + '/controllers/tanks.php?ac=saveTankLabCell', $('#tank_lab_locations').serialize(), function (result) {
            if (Boolean(result)) {
                $('#addTankLocation').modal('toggle');
                location.reload();
            } else {
                alert('Some thing bad happened , check again after refresh');
            }
        });
    })
});