

$(function () {

    /* disable click events outsite from modal */
    $('.modal').modal({
        backdrop: 'static',
        keyboard: false
    });


    // onload call select2 locality county list
    $(".js-example-basic-single").select2({
        width: '100%'
    });

    //selectRefresh();

    /*Units Pattern*/
    $('.units').on('input', function (e) {
        $(this).val($(this).val().replace(/[^0-9]/g, ''));

        if($(this).val() < 1){
            $(this).addClass('invalid-unit');

        }else{
            $(this).removeClass('invalid-unit');

        }
    });
    $('.cptcode').mask('#####-####-##');

    /*Date Picker Pattern*/
    $('#dos').datepicker({
        format: 'mm/dd/yyyy',
        language: "es",
        autoclose: true,
        startDate: "01/01/2000"
    });
    $('#dos').mask('00/00/0000');

    $('#e-dos').datepicker({
        format: 'mm/dd/yyyy',
        language: "es",
        autoclose: true,
        startDate: "01/01/2000"
    });
    $('#e-dos').mask('00/00/0000');

    $('#rfa-dos').datepicker({
        format: 'mm/dd/yyyy',
        language: "es",
        autoclose: true,
        startDate: "01/01/2000"
    });
    $('#rfa-dos').mask('00/00/0000');

    $('#pr2-dos').datepicker({
        format: 'mm/dd/yyyy',
        language: "es",
        autoclose: true,
        startDate: "01/01/2000"
    });
    $('#pr2-dos').mask('00/00/0000');

    $('#admin-dos').datepicker({
        format: 'mm/dd/yyyy',
        language: "es",
        autoclose: true,
        startDate: "01/01/2000"
    });
    $('#admin-dos').mask('00/00/0000');


    var formSubmitted = false;
    /*Check Physician Form Validation before Submit*/
    $("#submitButton").click(function (event) {
        //Fetch form to apply custom Bootstrap validation
        var form = $("#calc_form")
        if (form[0].checkValidity() !== false) {
            //Check cptcodes in multiple rows
            $(".cptcode").each(function () {
                if (!$(this).val()) {
                    $(this).parent().parent().parent().remove();
                }
            });

            formSubmitted = true;
            $('.modal').modal('show');
        }
        else if (form[0].checkValidity() === false) {
            event.preventDefault()
            event.stopPropagation()
        }
        form.addClass('was-validated')

    });

    $("#e-submitButton").click(function (event) {
        //Fetch form to apply custom Bootstrap validation
        var form = $("#e-calc_form")
        if (form[0].checkValidity() !== false) {
            //Check cptcodes in multiple rows
            $(".cptcode").each(function () {
                if (!$(this).val()) {
                    $(this).parent().parent().parent().remove();
                }
            });

            formSubmitted = true;
            $('.modal').modal('show');
        }
        else if (form[0].checkValidity() === false) {
            event.preventDefault()
            event.stopPropagation()
        }
        form.addClass('was-validated')

    });

    $("#rfa-submitButton").click(function (event) {
        //Fetch form to apply custom Bootstrap validation
        var form = $("#rfa-calc_form")
        if (form[0].checkValidity() !== false) {
            //Check cptcodes in multiple rows
            $(".cptcode").each(function () {
                if (!$(this).val()) {
                    $(this).parent().parent().parent().remove();
                }
            });

            formSubmitted = true;
            $('.modal').modal('show');
        }
        else if (form[0].checkValidity() === false) {
            event.preventDefault()
            event.stopPropagation()
        }
        form.addClass('was-validated')

    });

    $("#pr2-submitButton").click(function (event) {
        //Fetch form to apply custom Bootstrap validation
        var form = $("#pr2-calc_form")
        if (form[0].checkValidity() !== false) {
            //Check cptcodes in multiple rows
            $(".cptcode").each(function () {
                if (!$(this).val()) {
                    $(this).parent().parent().parent().remove();
                }
            });

            formSubmitted = true;
            $('.modal').modal('show');
        }
        else if (form[0].checkValidity() === false) {
            event.preventDefault()
            event.stopPropagation()
        }
        form.addClass('was-validated')

    });

    $("#admin-submitButton").click(function (event) {
        //Fetch form to apply custom Bootstrap validation
        var form = $("#admin-calc_form")
        if (form[0].checkValidity() !== false) {
            //Check cptcodes in multiple rows
            $(".cptcode").each(function () {
                if (!$(this).val()) {
                    $(this).parent().parent().parent().remove();
                }
            });

            formSubmitted = true;
            $('.modal').modal('show');
        }
        else if (form[0].checkValidity() === false) {
            event.preventDefault()
            event.stopPropagation()
        }
        form.addClass('was-validated')

    });

    if (!formSubmitted) {
        $('.modal').modal('hide');
    }



    /*BS4 Table Data*/
    var $table = $('#table');
    $(function () {
        $('#toolbar').find('select').change(function () {
            $table.bootstrapTable('refreshOptions', {
                exportDataType: $(this).val(),
                'data-pagination': 'true',

            });
        });
    })

    var trBoldBlue = $("table");

    $(trBoldBlue).on("click", "tr", function () {
        $(this).toggleClass("bold-blue");
    });


    $('#csvTable').bootstrapTable({
        'data-pagination': true
    });


});

$(document).ready(function () {
    /*Alert Messages for 3 seconds*/
    setTimeout(function () {
        $('.alert').hide("slow");
    }, 4000);

    var email, serviceName, cptcode, omfs;
    $('#table tbody').on('click', 'tr', function () {
        // var rowData = $(this).children('td').map(function(){
        //     return $(this).text();
        // }).get();
        email = $(this).find('td:first-child').text();
        serviceName = $(this).find('td:nth-of-type(2)').text();
        cptcode = $(this).find('td:nth-of-type(9)').text();
        omfs = $(this).find('td:last-child').text();

        $('.email').html(email);
        $('.serviceName').html(serviceName);
        $('.cptcode').html(cptcode);
        $('.omfs').html(omfs);

        // for (var i = 0; i < rowData.length; i++) {
        // $('.row-details').append('<div class="col-md-4">'+rowData[i]+'</div>');
        // }
    });

});
