var invests = function () {

    var hosturl = $('#hosturl').val();
    var cbcDirection = 1;     ///// 1    down    ,   2   up  

//    var doc = new jsPDF();
//    var elementHTML = $('#contnetXXX').html();
//    var specialElementHandlers = {
//        '#elementH': function (element, renderer) {
//            return true;
//        }
//    };
//    doc.fromHTML(elementHTML, 15, 15, {
//        'width': 170,
//        'elementHandlers': specialElementHandlers
//    });
//
//// Save the PDF
//    doc.save('sample-document.pdf');

    function updateOne(id, colName, tableName, value) {
        var controllName = $('#controllName').val();
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=update', {
            id: id,
            value: value,
            tableName: tableName,
            colName: colName
        }, function (res) {
            console.log(res);
        });
    }

    function updateArray(id, tableName, updatedArray) {
        var controllName = $('#controllName').val();
        var jsonString = JSON.stringify(updatedArray);
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=updatearray', {
            id: id,
            tableName: tableName,
            data: jsonString
        }, function (res) {
            console.log(res);
        });
    }

    function checkRange(id, colName, tableName, value, element, text) {
        var controllName = $('#controllName').val();
        if (element.is('select')) {
            value = text;
        }


        $.post(hosturl + '/controllers/' + controllName + '.php?ac=checkRange', {
            id: id,
            value: value,
            tableName: tableName,
            colName: colName
        }, function (res) {
            if (Number(res) == 1) {
                if (element.is('input')) {
                    element.css(
                            {"background-color": "#FFFF99"
                                , "border": "1px solid red"
                                , "animation": " fadein 6s"
                                , "transition": "opacity 0.5s"});
                }

                if (element.is('select')) {
                    element.parent().css(
                            {"background-color": "#FFFF99"
                                , "border": "1px solid red"
                                , "animation": " fadein 6s"
                                , "transition": "opacity 0.5s"});
                }
            } else {

                if (element.is('input')) {
                    element.css({'background-color': '#fff', "border": "1px solid #000000"});
                }

                if (element.is('select')) {
                    element.parent().css({'background-color': '#fff', "border": "none"});
                }

            }
        });
    }

    var forAll = function () {
        $('body').on('change', '.updateInvest', function () {

            var id = $(this).attr("data-id");
            var colName = $(this).attr("data-colName");
            var tableName = $(this).attr("data-tableName");
            var value = $(this).val();
            var element = $(this);
            var text = '';
            if (element.is('select') && value > 0) {
                text = $(this).select2('data').text;
            }

            checkRange(id, colName, tableName, value, element, text);
            updateOne(id, colName, tableName, value);

            //   var myArr = tableName.split("_");
            if (tableName == 'investigationresults') {
                var filled = $('#invFilled' + id).attr('data-val');
                if (filled == 1) {
                    $('#invFilled' + id).trigger('click');
                }
            }


        });
        // pdf
        $('body').on('change', '.addInvPdf', function ()
        {
            var id = $(this).attr("data-id");
            $('#talks-loading' + id).show();
            var files = $("#invPdf_" + id)[0].files;
            var isValid = 2;
            for (var i = 0; i < files.length; i++)
            {
//alert(files[i].name);
                var valid = checkFile(files[i].name, id);
                if (valid == 2)
                {

                } else if (valid == 1)
                {
                    isValid = 1;
                }
            }

            if (isValid == 2)
            {
                var myformdata = new FormData();
                myformdata.append("type", "All");
                myformdata.append("name", 'invPdf');
                myformdata.append("id", id);
                myformdata.append("imgCount", files.length);
                jQuery.each(jQuery("#invPdf_" + id)[0].files, function (i, file)
                {
                    myformdata.append('file-' + i, file);
                });
                $.ajax({
                    url: hosturl + '/controllers/invsdept.php?ac=uploadone', // Url to which the request is send
                    type: "POST", // Type of request to be send, called as method
                    data: myformdata, // Data sent to server, a set of key/value pairs representing form fields and values
                    contentType: false, // The content type used when sending data to the server. Default is: "application/x-www-form-urlencoded"
                    cache: false, // To unable request pages to be cached
                    processData: false, // To send DOMDocument or non processed data file it is set to false (i.e. data should not be in the form of string)
                    success: function (data)  		// A function to be called if request succeeds
                    {
                        if (data != -1 && data != 'no image')
                        {
                            var patientNo = $('#patientNo').val();
                            $('#pdfDownload' + id).attr('href', hosturl + '/../upload/inv_pdf/' + patientNo + '/' + data);
                            $('#pdfDownload' + id).show('');
                        } else {
                            alert('error while uploading ');
                        }

                        $('#talks-loading' + id).hide();
                    }
                });
            }

        });
        function checkFile(filename, id) {
            filename = filename.replace(/C:\\fakepath\\/i, '');
            if (filename != "")
            {
                var ext = filename;
                var extindex = ext.lastIndexOf(".") + 1;
                ext = ext.slice(extindex, ext.length);
                ext = ext.toLowerCase();
                if ($.inArray(ext, ['doc', 'docx', 'pdf']) == -1)
                {
                    alert("pictures only allowed ( doc , docx , pdf )");
                    $('#talks-loading' + id).hide();
                    return 1;
                } else
                {
                    return 2;
                }
            } else
            {
                return 1;
            }
        }

        $('select').on('change', function () {
            var select = $(this);
            var colName = select.attr("select-colName");
//            var delColName = select.attr("select-delColName");
            var delColName = 'deleted';
            var tableName = select.attr("select-tableName");
            var defaultValue = select.attr("select-default");
            var value = select.val();
            if (value == '-2') {
                $.post(hosturl + '/controllers/invsdept.php?ac=editModal', {
                    tableName: tableName, delColName: delColName, selectClass: tableName
                    , colName: colName, defaultValue: defaultValue}, function (data) {
                    select.select2("val", "");
                    $("#editModalDiv").html(data);
                    $("#edit_model").modal('show');
                });
            }

        });

    };

    var urineInvest = function () {

        $("#urine_volume").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_volume' value='" + term + "'><a href='#' id='addNew_urine_volume' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_volume', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_volume').val();
            var id = $("#urine_volume").attr('data-id');
            var tableName = $("#urine_volume").attr('data-tableName');
            var colName = $("#urine_volume").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_volume',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_volume > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_volume').select2('val', Number(data)); // select the new term
                $("#urine_volume").select2('close'); // close the dropdown

            });
        });
        $("#urine_color").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_color' value='" + term + "'><a href='#' id='addNew_urine_color' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_color', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_color').val();
            var id = $("#urine_color").attr('data-id');
            var tableName = $("#urine_color").attr('data-tableName');
            var colName = $("#urine_color").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_color',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_color > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_color').select2('val', Number(data)); // select the new term
                $("#urine_color").select2('close'); // close the dropdown

            });
        });
        $("#urine_odor").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_odor' value='" + term + "'><a href='#' id='addNew_urine_odor' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_odor', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_odor').val();
            var id = $("#urine_odor").attr('data-id');
            var tableName = $("#urine_odor").attr('data-tableName');
            var colName = $("#urine_odor").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_odor',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_odor > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_odor').select2('val', Number(data)); // select the new term
                $("#urine_odor").select2('close'); // close the dropdown

            });
        });
        $("#urine_ova").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_ova' value='" + term + "'><a href='#' id='addNew_urine_ova' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_ova', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_ova').val();
            var id = $("#urine_ova").attr('data-id');
            var tableName = $("#urine_ova").attr('data-tableName');
            var colName = $("#urine_ova").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_ova',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_ova > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_ova').select2('val', Number(data)); // select the new term
                $("#urine_ova").select2('close'); // close the dropdown

            });
        });
        $("#urine_bacteria").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_bacteria' value='" + term + "'><a href='#' id='addNew_urine_bacteria' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_bacteria', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_bacteria').val();
            var id = $("#urine_bacteria").attr('data-id');
            var tableName = $("#urine_bacteria").attr('data-tableName');
            var colName = $("#urine_bacteria").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_bacteria',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_bacteria > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_bacteria').select2('val', Number(data)); // select the new term
                $("#urine_bacteria").select2('close'); // close the dropdown

            });
        });
        $("#urine_mucus").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_mucus' value='" + term + "'><a href='#' id='addNew_urine_mucus' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_mucus', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_mucus').val();
            var id = $("#urine_mucus").attr('data-id');
            var tableName = $("#urine_mucus").attr('data-tableName');
            var colName = $("#urine_mucus").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_mucus',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_mucus > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_mucus').select2('val', Number(data)); // select the new term
                $("#urine_mucus").select2('close'); // close the dropdown

            });
        });
        $("#urine_trophazite").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_trophazite' value='" + term + "'><a href='#' id='addNew_urine_trophazite' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_trophazite', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_trophazite').val();
            var id = $("#urine_trophazite").attr('data-id');
            var tableName = $("#urine_trophazite").attr('data-tableName');
            var colName = $("#urine_trophazite").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_trophazite',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_trophazite > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_trophazite').select2('val', Number(data)); // select the new term
                $("#urine_trophazite").select2('close'); // close the dropdown

            });
        });
//        $("#urine_pbcs").select2({
//            placeholder: "Select",
//            width: '240px',
//            allowClear: true,
//            formatNoMatches: function (term) {
//                /* customize the no matches output */
//                return "<input class='form-control' id='newTerm_urine_pbcs' value='" + term + "'><a href='#' id='addNew_urine_pbcs' class='btn blue custombtnstyle'>إضافة جديد</a>"
//            }
//        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_pbcs', function () {
//            /* add the new term */
//            var new_name = $('#newTerm_urine_pbcs').val();
//            var id = $("#urine_pbcs").attr('data-id');
//            var tableName = $("#urine_pbcs").attr('data-tableName');
//            var colName = $("#urine_pbcs").attr('data-colName');
//            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
//                selectId: 'urine_pbcs',
//                new_name: new_name,
//                id: id,
//                tableName: tableName,
//                colName: colName
//            }, function (data) {
//
//
//                $('#urine_pbcs > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
//                $('#urine_pbcs').select2('val', Number(data)); // select the new term
//                $("#urine_pbcs").select2('close'); // close the dropdown
//
//            });
//        });
        $("#urine_reaction").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_reaction' value='" + term + "'><a href='#' id='addNew_urine_reaction' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_reaction', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_reaction').val();
            var id = $("#urine_reaction").attr('data-id');
            var tableName = $("#urine_reaction").attr('data-tableName');
            var colName = $("#urine_reaction").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_reaction',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_reaction > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_reaction').select2('val', Number(data)); // select the new term
                $("#urine_reaction").select2('close'); // close the dropdown

            });
        });
        $("#urine_casts").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_casts' value='" + term + "'><a href='#' id='addNew_urine_casts' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_casts', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_casts').val();
            var id = $("#urine_casts").attr('data-id');
            var tableName = $("#urine_casts").attr('data-tableName');
            var colName = $("#urine_casts").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_casts',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_casts > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_casts').select2('val', Number(data)); // select the new term
                $("#urine_casts").select2('close'); // close the dropdown

            });
        });
        $("#urine_sugar").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_sugar' value='" + term + "'><a href='#' id='addNew_urine_sugar' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_sugar', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_sugar').val();
            var id = $("#urine_sugar").attr('data-id');
            var tableName = $("#urine_sugar").attr('data-tableName');
            var colName = $("#urine_sugar").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_sugar',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_sugar > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_sugar').select2('val', Number(data)); // select the new term
                $("#urine_sugar").select2('close'); // close the dropdown

            });
        });
//        $("#urine_pus2").select2({
//            placeholder: "Select",
//            width: '240px',
//            allowClear: true,
//            formatNoMatches: function (term) {
//                /* customize the no matches output */
//                return "<input class='form-control' id='newTerm_urine_pus2' value='" + term + "'><a href='#' id='addNew_urine_pus2' class='btn blue custombtnstyle'>إضافة جديد</a>"
//            }
//        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_pus2', function () {
//            /* add the new term */
//            var new_name = $('#newTerm_urine_pus2').val();
//            var id = $("#urine_pus2").attr('data-id');
//            var tableName = $("#urine_pus2").attr('data-tableName');
//            var colName = $("#urine_pus2").attr('data-colName');
//            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
//                selectId: 'urine_pus2',
//                new_name: new_name,
//                id: id,
//                tableName: tableName,
//                colName: colName
//            }, function (data) {
//
//
//                $('#urine_pus2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
//                $('#urine_pus2').select2('val', Number(data)); // select the new term
//                $("#urine_pus2").select2('close'); // close the dropdown
//
//            });
//        });
//        $("#urine_pus").select2({
//            placeholder: "Select",
//            width: '240px',
//            allowClear: true,
//            formatNoMatches: function (term) {
//                /* customize the no matches output */
//                return "<input class='form-control' id='newTerm_urine_pus' value='" + term + "'><a href='#' id='addNew_urine_pus' class='btn blue custombtnstyle'>إضافة جديد</a>"
//            }
//        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_pus', function () {
//            /* add the new term */
//            var new_name = $('#newTerm_urine_pus').val();
//            var id = $("#urine_pus").attr('data-id');
//            var tableName = $("#urine_pus").attr('data-tableName');
//            var colName = $("#urine_pus").attr('data-colName');
//            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
//                selectId: 'urine_pus',
//                new_name: new_name,
//                id: id,
//                tableName: tableName,
//                colName: colName
//            }, function (data) {
//
//
//                $('#urine_pus > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
//                $('#urine_pus').select2('val', Number(data)); // select the new term
//                $("#urine_pus").select2('close'); // close the dropdown
//
//            });
//        });
        $("#urine_blood").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_blood' value='" + term + "'><a href='#' id='addNew_urine_blood' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_blood', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_blood').val();
            var id = $("#urine_blood").attr('data-id');
            var tableName = $("#urine_blood").attr('data-tableName');
            var colName = $("#urine_blood").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_blood',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_blood > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_blood').select2('val', Number(data)); // select the new term
                $("#urine_blood").select2('close'); // close the dropdown

            });
        });
        $("#urine_leucocytes").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_leucocytes' value='" + term + "'><a href='#' id='addNew_urine_leucocytes' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_leucocytes', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_leucocytes').val();
            var id = $("#urine_leucocytes").attr('data-id');
            var tableName = $("#urine_leucocytes").attr('data-tableName');
            var colName = $("#urine_leucocytes").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_leucocytes',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_leucocytes > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_leucocytes').select2('val', Number(data)); // select the new term
                $("#urine_leucocytes").select2('close'); // close the dropdown

            });
        });
        $("#urine_aspect").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_aspect' value='" + term + "'><a href='#' id='addNew_urine_aspect' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_aspect', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_aspect').val();
            var id = $("#urine_aspect").attr('data-id');
            var tableName = $("#urine_aspect").attr('data-tableName');
            var colName = $("#urine_aspect").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_aspect',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_aspect > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_aspect').select2('val', Number(data)); // select the new term
                $("#urine_aspect").select2('close'); // close the dropdown

            });
        });
        $("#urine_protein").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_protein' value='" + term + "'><a href='#' id='addNew_urine_protein' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_protein', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_protein').val();
            var id = $("#urine_protein").attr('data-id');
            var tableName = $("#urine_protein").attr('data-tableName');
            var colName = $("#urine_protein").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_protein',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_protein > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_protein').select2('val', Number(data)); // select the new term
                $("#urine_protein").select2('close'); // close the dropdown

            });
        });
        $("#urine_epithelial").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_epithelial' value='" + term + "'><a href='#' id='addNew_urine_epithelial' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_epithelial', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_epithelial').val();
            var id = $("#urine_epithelial").attr('data-id');
            var tableName = $("#urine_epithelial").attr('data-tableName');
            var colName = $("#urine_epithelial").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_epithelial',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_epithelial > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_epithelial').select2('val', Number(data)); // select the new term
                $("#urine_epithelial").select2('close'); // close the dropdown

            });
        });
        $("#urine_bacteria2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_bacteria2' value='" + term + "'><a href='#' id='addNew_urine_bacteria2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_bacteria2', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_bacteria2').val();
            var id = $("#urine_bacteria2").attr('data-id');
            var tableName = $("#urine_bacteria2").attr('data-tableName');
            var colName = $("#urine_bacteria2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_bacteria2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_bacteria2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_bacteria2').select2('val', Number(data)); // select the new term
                $("#urine_bacteria2").select2('close'); // close the dropdown

            });
        });
        $("#urine_fungi").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_fungi' value='" + term + "'><a href='#' id='addNew_urine_fungi' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_fungi', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_fungi').val();
            var id = $("#urine_fungi").attr('data-id');
            var tableName = $("#urine_fungi").attr('data-tableName');
            var colName = $("#urine_fungi").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_fungi',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_fungi > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_fungi').select2('val', Number(data)); // select the new term
                $("#urine_fungi").select2('close'); // close the dropdown

            });
        });
        $("#urine_urobilinigen").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_urobilinigen' value='" + term + "'><a href='#' id='addNew_urine_urobilinigen' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_urobilinigen', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_urobilinigen').val();
            var id = $("#urine_urobilinigen").attr('data-id');
            var tableName = $("#urine_urobilinigen").attr('data-tableName');
            var colName = $("#urine_urobilinigen").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_urobilinigen',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_urobilinigen > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_urobilinigen').select2('val', Number(data)); // select the new term
                $("#urine_urobilinigen").select2('close'); // close the dropdown

            });
        });
        $("#urine_amorphous2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_amorphous2' value='" + term + "'><a href='#' id='addNew_urine_amorphous2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_amorphous2', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_amorphous2').val();
            var id = $("#urine_amorphous2").attr('data-id');
            var tableName = $("#urine_amorphous2").attr('data-tableName');
            var colName = $("#urine_amorphous2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_amorphous2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_amorphous2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_amorphous2').select2('val', Number(data)); // select the new term
                $("#urine_amorphous2").select2('close'); // close the dropdown

            });
        });
        $("#urine_deposit").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_deposit' value='" + term + "'><a href='#' id='addNew_urine_deposit' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_deposit', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_deposit').val();
            var id = $("#urine_deposit").attr('data-id');
            var tableName = $("#urine_deposit").attr('data-tableName');
            var colName = $("#urine_deposit").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_deposit',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_deposit > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_deposit').select2('val', Number(data)); // select the new term
                $("#urine_deposit").select2('close'); // close the dropdown

            });
        });
        $("#urine_artifacts").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_artifacts' value='" + term + "'><a href='#' id='addNew_urine_artifacts' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_artifacts', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_artifacts').val();
            var id = $("#urine_artifacts").attr('data-id');
            var tableName = $("#urine_artifacts").attr('data-tableName');
            var colName = $("#urine_artifacts").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_artifacts',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_artifacts > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_artifacts').select2('val', Number(data)); // select the new term
                $("#urine_artifacts").select2('close'); // close the dropdown

            });
        });
        $("#urine_acetone").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_acetone' value='" + term + "'><a href='#' id='addNew_urine_acetone' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_acetone', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_acetone').val();
            var id = $("#urine_acetone").attr('data-id');
            var tableName = $("#urine_acetone").attr('data-tableName');
            var colName = $("#urine_acetone").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_acetone',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_acetone > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_acetone').select2('val', Number(data)); // select the new term
                $("#urine_acetone").select2('close'); // close the dropdown

            });
        });
        $("#urine_casts2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_casts2' value='" + term + "'><a href='#' id='addNew_urine_casts2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_casts2', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_casts2').val();
            var id = $("#urine_casts2").attr('data-id');
            var tableName = $("#urine_casts2").attr('data-tableName');
            var colName = $("#urine_casts2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_casts2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_casts2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_casts2').select2('val', Number(data)); // select the new term
                $("#urine_casts2").select2('close'); // close the dropdown

            });
        });
        $("#urine_nitrite").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_nitrite' value='" + term + "'><a href='#' id='addNew_urine_nitrite' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_nitrite', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_nitrite').val();
            var id = $("#urine_nitrite").attr('data-id');
            var tableName = $("#urine_nitrite").attr('data-tableName');
            var colName = $("#urine_nitrite").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_nitrite',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_nitrite > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_nitrite').select2('val', Number(data)); // select the new term
                $("#urine_nitrite").select2('close'); // close the dropdown

            });
        });
//        $("#urine_pbcs2").select2({
//            placeholder: "Select",
//            width: '240px',
//            allowClear: true,
//            formatNoMatches: function (term) {
//                /* customize the no matches output */
//                return "<input class='form-control' id='newTerm_urine_pbcs2' value='" + term + "'><a href='#' id='addNew_urine_pbcs2' class='btn blue custombtnstyle'>إضافة جديد</a>"
//            }
//        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_pbcs2', function () {
//            /* add the new term */
//            var new_name = $('#newTerm_urine_pbcs2').val();
//            var id = $("#urine_pbcs2").attr('data-id');
//            var tableName = $("#urine_pbcs2").attr('data-tableName');
//            var colName = $("#urine_pbcs2").attr('data-colName');
//            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
//                selectId: 'urine_pbcs2',
//                new_name: new_name,
//                id: id,
//                tableName: tableName,
//                colName: colName
//            }, function (data) {
//
//
//                $('#urine_pbcs2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
//                $('#urine_pbcs2').select2('val', Number(data)); // select the new term
//                $("#urine_pbcs2").select2('close'); // close the dropdown
//
//            });
//        });
        $("#urine_gravity").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_gravity' value='" + term + "'><a href='#' id='addNew_urine_gravity' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_gravity', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_gravity').val();
            var id = $("#urine_gravity").attr('data-id');
            var tableName = $("#urine_gravity").attr('data-tableName');
            var colName = $("#urine_gravity").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_gravity',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_gravity > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_gravity').select2('val', Number(data)); // select the new term
                $("#urine_gravity").select2('close'); // close the dropdown

            });
        });
        $("#urine_crystal2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_crystal2' value='" + term + "'><a href='#' id='addNew_urine_crystal2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_crystal2', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_crystal2').val();
            var id = $("#urine_crystal2").attr('data-id');
            var tableName = $("#urine_crystal2").attr('data-tableName');
            var colName = $("#urine_crystal2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_crystal2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_crystal2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_crystal2').select2('val', Number(data)); // select the new term
                $("#urine_crystal2").select2('close'); // close the dropdown

            });
        });
        $("#urine_crystal").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_crystal' value='" + term + "'><a href='#' id='addNew_urine_crystal' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_crystal', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_crystal').val();
            var id = $("#urine_crystal").attr('data-id');
            var tableName = $("#urine_crystal").attr('data-tableName');
            var colName = $("#urine_crystal").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_crystal',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_crystal > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_crystal').select2('val', Number(data)); // select the new term
                $("#urine_crystal").select2('close'); // close the dropdown

            });
        });
        $("#urine_bilirubin").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_bilirubin' value='" + term + "'><a href='#' id='addNew_urine_bilirubin' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_bilirubin', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_bilirubin').val();
            var id = $("#urine_bilirubin").attr('data-id');
            var tableName = $("#urine_bilirubin").attr('data-tableName');
            var colName = $("#urine_bilirubin").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_bilirubin',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_bilirubin > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_bilirubin').select2('val', Number(data)); // select the new term
                $("#urine_bilirubin").select2('close'); // close the dropdown

            });
        });
        $("#urine_amorphous").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_urine_amorphous' value='" + term + "'><a href='#' id='addNew_urine_amorphous' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_urine_amorphous', function () {
            /* add the new term */
            var new_name = $('#newTerm_urine_amorphous').val();
            var id = $("#urine_amorphous").attr('data-id');
            var tableName = $("#urine_amorphous").attr('data-tableName');
            var colName = $("#urine_amorphous").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_amorphous',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#urine_amorphous > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#urine_amorphous').select2('val', Number(data)); // select the new term
                $("#urine_amorphous").select2('close'); // close the dropdown

            });
        });
    };

    var stoolInvest = function () {

        $("#stool_color").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_color' value='" + term + "'><a href='#' id='addNew_stool_color' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_color', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_color').val();
            var id = $("#stool_color").attr('data-id');
            var tableName = $("#stool_color").attr('data-tableName');
            var colName = $("#stool_color").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_color',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_color > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_color').select2('val', Number(data)); // select the new term
                $("#stool_color").select2('close'); // close the dropdown

            });
        });
        $("#stool_blood").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_blood' value='" + term + "'><a href='#' id='addNew_stool_blood' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_blood', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_blood').val();
            var id = $("#stool_blood").attr('data-id');
            var tableName = $("#stool_blood").attr('data-tableName');
            var colName = $("#stool_blood").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_blood',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_blood > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_blood').select2('val', Number(data)); // select the new term
                $("#stool_blood").select2('close'); // close the dropdown

            });
        });
        $("#stool_ciliate").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_ciliate' value='" + term + "'><a href='#' id='addNew_stool_ciliate' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_ciliate', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_ciliate').val();
            var id = $("#stool_ciliate").attr('data-id');
            var tableName = $("#stool_ciliate").attr('data-tableName');
            var colName = $("#stool_ciliate").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_ciliate',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_ciliate > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_ciliate').select2('val', Number(data)); // select the new term
                $("#stool_ciliate").select2('close'); // close the dropdown

            });
        });
        $("#stool_consistency").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_consistency' value='" + term + "'><a href='#' id='addNew_stool_consistency' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_consistency', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_consistency').val();
            var id = $("#stool_consistency").attr('data-id');
            var tableName = $("#stool_consistency").attr('data-tableName');
            var colName = $("#stool_consistency").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_consistency',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_consistency > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_consistency').select2('val', Number(data)); // select the new term
                $("#stool_consistency").select2('close'); // close the dropdown

            });
        });
        $("#stool_cysts").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_cysts' value='" + term + "'><a href='#' id='addNew_stool_cysts' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_cysts', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_cysts').val();
            var id = $("#stool_cysts").attr('data-id');
            var tableName = $("#stool_cysts").attr('data-tableName');
            var colName = $("#stool_cysts").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_cysts',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_cysts > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_cysts').select2('val', Number(data)); // select the new term
                $("#stool_cysts").select2('close'); // close the dropdown

            });
        });
        $("#stool_flagellates").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_flagellates' value='" + term + "'><a href='#' id='addNew_stool_flagellates' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_flagellates', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_flagellates').val();
            var id = $("#stool_flagellates").attr('data-id');
            var tableName = $("#stool_flagellates").attr('data-tableName');
            var colName = $("#stool_flagellates").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_flagellates',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_flagellates > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_flagellates').select2('val', Number(data)); // select the new term
                $("#stool_flagellates").select2('close'); // close the dropdown

            });
        });
        $("#stool_parasitology").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_parasitology' value='" + term + "'><a href='#' id='addNew_stool_parasitology' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_parasitology', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_parasitology').val();
            var id = $("#stool_parasitology").attr('data-id');
            var tableName = $("#stool_parasitology").attr('data-tableName');
            var colName = $("#stool_parasitology").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_parasitology',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_parasitology > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_parasitology').select2('val', Number(data)); // select the new term
                $("#stool_parasitology").select2('close'); // close the dropdown

            });
        });
        $("#stool_larva").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_larva' value='" + term + "'><a href='#' id='addNew_stool_larva' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_larva', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_larva').val();
            var id = $("#stool_larva").attr('data-id');
            var tableName = $("#stool_larva").attr('data-tableName');
            var colName = $("#stool_larva").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_larva',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_larva > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_larva').select2('val', Number(data)); // select the new term
                $("#stool_larva").select2('close'); // close the dropdown

            });
        });
        $("#stool_odor").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_odor' value='" + term + "'><a href='#' id='addNew_stool_odor' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_odor', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_odor').val();
            var id = $("#stool_odor").attr('data-id');
            var tableName = $("#stool_odor").attr('data-tableName');
            var colName = $("#stool_odor").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_odor',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_odor > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_odor').select2('val', Number(data)); // select the new term
                $("#stool_odor").select2('close'); // close the dropdown

            });
        });
        $("#stool_mucus").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_mucus' value='" + term + "'><a href='#' id='addNew_stool_mucus' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_mucus', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_mucus').val();
            var id = $("#stool_mucus").attr('data-id');
            var tableName = $("#stool_mucus").attr('data-tableName');
            var colName = $("#stool_mucus").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_mucus',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_mucus > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_mucus').select2('val', Number(data)); // select the new term
                $("#stool_mucus").select2('close'); // close the dropdown

            });
        });
        $("#stool_reaction").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_reaction' value='" + term + "'><a href='#' id='addNew_stool_reaction' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_reaction', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_reaction').val();
            var id = $("#stool_reaction").attr('data-id');
            var tableName = $("#stool_reaction").attr('data-tableName');
            var colName = $("#stool_reaction").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_reaction',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_reaction > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_reaction').select2('val', Number(data)); // select the new term
                $("#stool_reaction").select2('close'); // close the dropdown

            });
        });
        $("#stool_trophozoite").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_trophozoite' value='" + term + "'><a href='#' id='addNew_stool_trophozoite' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_trophozoite', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_trophozoite').val();
            var id = $("#stool_trophozoite").attr('data-id');
            var tableName = $("#stool_trophozoite").attr('data-tableName');
            var colName = $("#stool_trophozoite").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_trophozoite',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_trophozoite > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_trophozoite').select2('val', Number(data)); // select the new term
                $("#stool_trophozoite").select2('close'); // close the dropdown

            });
        });
        $("#stool_undigested").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_undigested' value='" + term + "'><a href='#' id='addNew_stool_undigested' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_undigested', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_undigested').val();
            var id = $("#stool_undigested").attr('data-id');
            var tableName = $("#stool_undigested").attr('data-tableName');
            var colName = $("#stool_undigested").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_undigested',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_undigested > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_undigested').select2('val', Number(data)); // select the new term
                $("#stool_undigested").select2('close'); // close the dropdown

            });
        });
        $("#stool_ova").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_ova' value='" + term + "'><a href='#' id='addNew_stool_ova' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_ova', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_ova').val();
            var id = $("#stool_ova").attr('data-id');
            var tableName = $("#stool_ova").attr('data-tableName');
            var colName = $("#stool_ova").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_ova',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_ova > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_ova').select2('val', Number(data)); // select the new term
                $("#stool_ova").select2('close'); // close the dropdown

            });
        });
//        $("#stool_rbc").select2({
//            placeholder: "Select",
//            width: '240px',
//            allowClear: true,
//            formatNoMatches: function (term) {
//                /* customize the no matches output */
//                return "<input class='form-control' id='newTerm_stool_rbc' value='" + term + "'><a href='#' id='addNew_stool_rbc' class='btn blue custombtnstyle'>إضافة جديد</a>"
//            }
//        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_rbc', function () {
//            /* add the new term */
//            var new_name = $('#newTerm_stool_rbc').val();
//            var id = $("#stool_rbc").attr('data-id');
//            var tableName = $("#stool_rbc").attr('data-tableName');
//            var colName = $("#stool_rbc").attr('data-colName');
//            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
//                selectId: 'stool_rbc',
//                new_name: new_name,
//                id: id,
//                tableName: tableName,
//                colName: colName
//            }, function (data) {
//
//
//                $('#stool_rbc > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
//                $('#stool_rbc').select2('val', Number(data)); // select the new term
//                $("#stool_rbc").select2('close'); // close the dropdown
//
//            });
//        });
//        $("#stool_wbc").select2({
//            placeholder: "Select",
//            width: '240px',
//            allowClear: true,
//            formatNoMatches: function (term) {
//                /* customize the no matches output */
//                return "<input class='form-control' id='newTerm_stool_wbc' value='" + term + "'><a href='#' id='addNew_stool_wbc' class='btn blue custombtnstyle'>إضافة جديد</a>"
//            }
//        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_wbc', function () {
//            /* add the new term */
//            var new_name = $('#newTerm_stool_wbc').val();
//            var id = $("#stool_wbc").attr('data-id');
//            var tableName = $("#stool_wbc").attr('data-tableName');
//            var colName = $("#stool_wbc").attr('data-colName');
//            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
//                selectId: 'stool_wbc',
//                new_name: new_name,
//                id: id,
//                tableName: tableName,
//                colName: colName
//            }, function (data) {
//
//
//                $('#stool_wbc > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
//                $('#stool_wbc').select2('val', Number(data)); // select the new term
//                $("#stool_wbc").select2('close'); // close the dropdown
//
//            });
//        });
        $("#stool_food").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_food' value='" + term + "'><a href='#' id='addNew_stool_food' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_food', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_food').val();
            var id = $("#stool_food").attr('data-id');
            var tableName = $("#stool_food").attr('data-tableName');
            var colName = $("#stool_food").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_food',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_food > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_food').select2('val', Number(data)); // select the new term
                $("#stool_food").select2('close'); // close the dropdown

            });
        });
//        $("#stool_wbc2").select2({
//            placeholder: "Select",
//            width: '240px',
//            allowClear: true,
//            formatNoMatches: function (term) {
//                /* customize the no matches output */
//                return "<input class='form-control' id='newTerm_stool_wbc2' value='" + term + "'><a href='#' id='addNew_stool_wbc2' class='btn blue custombtnstyle'>إضافة جديد</a>"
//            }
//        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_wbc2', function () {
//            /* add the new term */
//            var new_name = $('#newTerm_stool_wbc2').val();
//            var id = $("#stool_wbc2").attr('data-id');
//            var tableName = $("#stool_wbc2").attr('data-tableName');
//            var colName = $("#stool_wbc2").attr('data-colName');
//            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
//                selectId: 'stool_wbc2',
//                new_name: new_name,
//                id: id,
//                tableName: tableName,
//                colName: colName
//            }, function (data) {
//
//
//                $('#stool_wbc2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
//                $('#stool_wbc2').select2('val', Number(data)); // select the new term
//                $("#stool_wbc2").select2('close'); // close the dropdown
//
//            });
//        });
//        $("#stool_rbc2").select2({
//            placeholder: "Select",
//            width: '240px',
//            allowClear: true,
//            formatNoMatches: function (term) {
//                /* customize the no matches output */
//                return "<input class='form-control' id='newTerm_stool_rbc2' value='" + term + "'><a href='#' id='addNew_stool_rbc2' class='btn blue custombtnstyle'>إضافة جديد</a>"
//            }
//        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_rbc2', function () {
//            /* add the new term */
//            var new_name = $('#newTerm_stool_rbc2').val();
//            var id = $("#stool_rbc2").attr('data-id');
//            var tableName = $("#stool_rbc2").attr('data-tableName');
//            var colName = $("#stool_rbc2").attr('data-colName');
//            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
//                selectId: 'stool_rbc2',
//                new_name: new_name,
//                id: id,
//                tableName: tableName,
//                colName: colName
//            }, function (data) {
//
//
//                $('#stool_rbc2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
//                $('#stool_rbc2').select2('val', Number(data)); // select the new term
//                $("#stool_rbc2").select2('close'); // close the dropdown
//
//            });
//        });
        $("#stool_prog2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_prog2' value='" + term + "'><a href='#' id='addNew_stool_prog2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_prog2', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_prog2').val();
            var id = $("#stool_prog2").attr('data-id');
            var tableName = $("#stool_prog2").attr('data-tableName');
            var colName = $("#stool_prog2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_prog2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_prog2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_prog2').select2('val', Number(data)); // select the new term
                $("#stool_prog2").select2('close'); // close the dropdown

            });
        });
        $("#stool_prog").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_prog' value='" + term + "'><a href='#' id='addNew_stool_prog' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_prog', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_prog').val();
            var id = $("#stool_prog").attr('data-id');
            var tableName = $("#stool_prog").attr('data-tableName');
            var colName = $("#stool_prog").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_prog',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_prog > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_prog').select2('val', Number(data)); // select the new term
                $("#stool_prog").select2('close'); // close the dropdown

            });
        });
        $("#stool_trophozoite2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_trophozoite2' value='" + term + "'><a href='#' id='addNew_stool_trophozoite2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_trophozoite2', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_trophozoite2').val();
            var id = $("#stool_trophozoite2").attr('data-id');
            var tableName = $("#stool_trophozoite2").attr('data-tableName');
            var colName = $("#stool_trophozoite2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_trophozoite2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_trophozoite2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_trophozoite2').select2('val', Number(data)); // select the new term
                $("#stool_trophozoite2").select2('close'); // close the dropdown

            });
        });
        $("#stool_trophozoite3").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_trophozoite3' value='" + term + "'><a href='#' id='addNew_stool_trophozoite3' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_trophozoite3', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_trophozoite3').val();
            var id = $("#stool_trophozoite3").attr('data-id');
            var tableName = $("#stool_trophozoite3").attr('data-tableName');
            var colName = $("#stool_trophozoite3").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_trophozoite3',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_trophozoite3 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_trophozoite3').select2('val', Number(data)); // select the new term
                $("#stool_trophozoite3").select2('close'); // close the dropdown

            });
        });
        $("#stool_flagellates2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_flagellates2' value='" + term + "'><a href='#' id='addNew_stool_flagellates2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_flagellates2', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_flagellates2').val();
            var id = $("#stool_flagellates2").attr('data-id');
            var tableName = $("#stool_flagellates2").attr('data-tableName');
            var colName = $("#stool_flagellates2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_flagellates2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_flagellates2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_flagellates2').select2('val', Number(data)); // select the new term
                $("#stool_flagellates2").select2('close'); // close the dropdown

            });
        });
        $("#stool_undigested2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_undigested2' value='" + term + "'><a href='#' id='addNew_stool_undigested2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_undigested2', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_undigested2').val();
            var id = $("#stool_undigested2").attr('data-id');
            var tableName = $("#stool_undigested2").attr('data-tableName');
            var colName = $("#stool_undigested2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_undigested2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_undigested2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_undigested2').select2('val', Number(data)); // select the new term
                $("#stool_undigested2").select2('close'); // close the dropdown

            });
        });
        $("#stool_cysts2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_cysts2' value='" + term + "'><a href='#' id='addNew_stool_cysts2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_cysts2', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_cysts2').val();
            var id = $("#stool_cysts2").attr('data-id');
            var tableName = $("#stool_cysts2").attr('data-tableName');
            var colName = $("#stool_cysts2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_cysts2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_cysts2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_cysts2').select2('val', Number(data)); // select the new term
                $("#stool_cysts2").select2('close'); // close the dropdown

            });
        });
        $("#stool_undigested3").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_undigested3' value='" + term + "'><a href='#' id='addNew_stool_undigested3' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_undigested3', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_undigested3').val();
            var id = $("#stool_undigested3").attr('data-id');
            var tableName = $("#stool_undigested3").attr('data-tableName');
            var colName = $("#stool_undigested3").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_undigested3',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_undigested3 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_undigested3').select2('val', Number(data)); // select the new term
                $("#stool_undigested3").select2('close'); // close the dropdown

            });
        });
        $("#stool_ova2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_ova2' value='" + term + "'><a href='#' id='addNew_stool_ova2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_ova2', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_ova2').val();
            var id = $("#stool_ova2").attr('data-id');
            var tableName = $("#stool_ova2").attr('data-tableName');
            var colName = $("#stool_ova2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_ova2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_ova2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_ova2').select2('val', Number(data)); // select the new term
                $("#stool_ova2").select2('close'); // close the dropdown

            });
        });
        $("#stool_parasitology2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_parasitology2' value='" + term + "'><a href='#' id='addNew_stool_parasitology2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_parasitology2', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_parasitology2').val();
            var id = $("#stool_parasitology2").attr('data-id');
            var tableName = $("#stool_parasitology2").attr('data-tableName');
            var colName = $("#stool_parasitology2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_parasitology2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_parasitology2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_parasitology2').select2('val', Number(data)); // select the new term
                $("#stool_parasitology2").select2('close'); // close the dropdown

            });
        });
        $("#stool_larva2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_larva2' value='" + term + "'><a href='#' id='addNew_stool_larva2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_larva2', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_larva2').val();
            var id = $("#stool_larva2").attr('data-id');
            var tableName = $("#stool_larva2").attr('data-tableName');
            var colName = $("#stool_larva2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_larva2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_larva2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_larva2').select2('val', Number(data)); // select the new term
                $("#stool_larva2").select2('close'); // close the dropdown

            });
        });
        $("#stool_undigested4").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_stool_undigested4' value='" + term + "'><a href='#' id='addNew_stool_undigested4' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_stool_undigested4', function () {
            /* add the new term */
            var new_name = $('#newTerm_stool_undigested4').val();
            var id = $("#stool_undigested4").attr('data-id');
            var tableName = $("#stool_undigested4").attr('data-tableName');
            var colName = $("#stool_undigested4").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'stool_undigested4',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#stool_undigested4 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#stool_undigested4').select2('val', Number(data)); // select the new term
                $("#stool_undigested4").select2('close'); // close the dropdown

            });
        });
    };

    var bPictureInvest = function () {

        var all_levels = ['hgb_blood', 'rbc_blood', 'hct_blood', 'rdw_blood', 'wbc_blood'
                    , 'neutrophil_r_blood', 'segmented_blood', 'band_blood', 'lymphocytes_r_blood', 'monocytes_r_blood'
                    , 'eosinophils_r_blood', 'basophils_r_blood', 'plt_blood'];


        $('body').on('change', '.blood', function () {

            var element = $(this).attr('data-target');
            var value = $('#' + element + '_blood').val();
            var rangeid = $('#' + element + '_rangeid').val();
            var bloodId = $(this).attr('data-id');
            $.post(hosturl + '/controllers/invsdept.php?ac=invlevel', {
                value: value,
                rangeid: rangeid,
                element: element,
                bloodId: bloodId
            }, function (res) {

                var obj = res.split("-");
                $('#' + element + '_level').val(obj[0]);
                $('#' + element + '_unit').val(obj[1]);
            });
        });
        $('body').on('change', '.bloodCalc', function () {

            var hgb = $('#hgb_blood').val();
            var rbc = $('#rbc_blood').val();
            var hct = $('#hct_blood').val();
            var bloodId = $(this).attr('data-id');
            var mcvCalc = mcv_calc(hct, rbc);
            var mchCalc = mch_calc(hgb, rbc);
            var mchcCalc = mchc_calc(hct, hgb);
            $('#mcv_calc').val(mcvCalc);
            $('#mch_calc').val(mchCalc);
            $('#mchc_calc').val(mchcCalc);
            if (bloodId > 0) {
                var data = [['mcv_calc', mcvCalc], ['mch_calc', mchCalc], ['mchc_calc', mchcCalc]];
                updateArray(bloodId, 'investigationresults_blood', data);
            }
        });
        function mchc_calc(hct, hgb) {
            var res = '';
            if (hct > 0 && hgb >= 0) {
                res = (100 * hgb) / hct;
                res = Math.round(res * 10) / 10;
            }
            return res;
        }

        function mch_calc(hgb, rbc) {
            var res = '';
            if (rbc > 0 && hgb >= 0) {
                res = (10 * hgb) / rbc;
                res = Math.round(res * 10) / 10;
            }
            return res;
        }

        function mcv_calc(hct, rbc) {
            var res = '';
            if (rbc > 0 && hct >= 0) {
                res = (10 * hct) / rbc;
                res = Math.round(res * 10) / 10;
            }

            return res;
        }

        $('body').on('change', '.absCalc', function () {

            var colName = $(this).attr("data-colName");
            var element = $(this).attr('data-target');
            var value = $(this).val();
            var bloodId = $(this).attr('data-id');
            var wbc = $('#wbc_blood').val();
            var elem = $(this);
            var absCalc = abs_calc(wbc, value);
            $('#' + element + '_blood').val(absCalc);
            if (bloodId > 0) {
                checkRange(bloodId, colName, 'investigationresults_blood', value, elem, '');
                var data = [[colName, value], [element, absCalc]];
                updateArray(bloodId, 'investigationresults_blood', data);
            }


        });
        function abs_calc(wbc, value) {
            var res = '';
            if (wbc >= 0 && value >= 0) {
                res = (value * wbc) / 100;
                res = Math.round(res * 100) / 100;
            }

            return res;
        }

        $('body').on('change', '.absCalcAllPreview ,  .absCalcAll', function () {
            var bloodId = $(this).attr('data-id');
            var wbc = $('#wbc_blood').val();
            absCalcAll(wbc, bloodId);
        });
        $('body').on('change', '.cells_calc', function () {
            var elementId = $(this).attr('id');
            var colName = $(this).attr("data-colName");
            var tableName = $(this).attr("data-tableName");
            var id = $(this).attr("data-id");
            var sum = checkSum();
            var diff;
            if (sum > 100) {
                $('#' + elementId).val(0);
                updateOne(id, colName, tableName, 0);
                sum = checkSum();
            }

            diff = 100 - sum;
            $('#othercells_blood').val(diff);
            var bloodId = $('#wbc_blood').attr('data-id');
            var wbc = $('#wbc_blood').val();
            //     absCalcAll(wbc, bloodId);

            updateOne($('#othercells_blood').attr('data-id'), $('#othercells_blood').attr('data-colName')
                    , $('#othercells_blood').attr('data-tableName'), diff);
        });
        $('body').on('change', '#neutrophil_r_blood , #segmented_blood , #band_blood', function () {
            var elementId = $(this).attr('id');
            var neutrophil_r = Number($('#neutrophil_r_blood').val());
            var id = $(this).attr("data-id");
            switch (elementId) {
                case  'neutrophil_r_blood':
                    var segmented = neutrophil_r - 2;
                    var band = 2;
                    $('#segmented_blood').val(segmented);
                    $('#band_blood').val(band);
                    break;
                case  'segmented_blood':
                    var segmented = Number($('#segmented_blood').val());
                    var band = neutrophil_r - segmented;
                    $('#band_blood').val(band);
                    break;
                case  'band_blood':
                    var band = Number($('#band_blood').val());
                    var segmented = neutrophil_r - band;
                    $('#segmented_blood').val(segmented);
                    break;
            }

            if (id > 0) {
                var data = [[$('#band_blood').attr('data-colName'), band], [$('#segmented_blood').attr('data-colName'), segmented]];
                updateArray(id, $('#band_blood').attr('data-tableName'), data);
            }
        });
        $('body').on('keydown', 'input', function (e) {
            if (e.keyCode == 13) {

                if (cbcDirection == 1) {
                    var level = Number($(this).attr("data-level"));
                } else {
                    var level = Number($(this).attr("data-level_d"));
                }


                if (level == 13) {
                    cbcDirection = 2;
                    level = 11;
                }

                if (level == 0 && cbcDirection == 2) {
                    cbcDirection = 1;
                    level = 0;
                }




                if (level >= 0 && level < 13) {
                    var new_id = all_levels[level];
                    $('#' + new_id).focus();
                    $('#' + new_id).select();
                }
            }
        });
        function checkSum() {
            var neutrophil_r_blood = Number($('#neutrophil_r_blood').val());
            var lymphocytes_r_blood = Number($('#lymphocytes_r_blood').val());
            var monocytes_r_blood = Number($('#monocytes_r_blood').val());
            var eosinophils_r_blood = Number($('#eosinophils_r_blood').val());
            var basophils_r_blood = Number($('#basophils_r_blood').val());
            var sum = neutrophil_r_blood + lymphocytes_r_blood + monocytes_r_blood
                    + eosinophils_r_blood + basophils_r_blood;
            return  sum;
        }

        function absCalcAll(wbc, bloodId) {
            var inputs = ["neutrophil", "lymphocytes", "monocytes", "eosinophils", "basophils"];
            var nameR = '';
            var nameAbs = '';
            var value = '';
            var absCalc = '';
            var one;
            var data = [];
            for (var i = 0; i < inputs.length; i++)
            {
                nameR = inputs[i] + '_r_blood';
                nameAbs = inputs[i] + '_abs_blood';
                value = $('#' + nameR).val();
                absCalc = abs_calc(wbc, value);
                $('#' + nameAbs).val(absCalc);
                one = [inputs[i] + '_abs', absCalc];
                data[i] = one;
            }

            if (bloodId > 0) {
                updateArray(bloodId, 'investigationresults_blood', data);
            }
        }

    };

    var esrInvest = function () {

        $("#esr_hour1").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_esr_hour1' value='" + term + "'><a href='#' id='addNew_esr_hour1' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_esr_hour1', function () {
            /* add the new term */
            var new_name = $('#newTerm_esr_hour1').val();
            var id = $("#esr_hour1").attr('data-id');
            var tableName = $("#esr_hour1").attr('data-tableName');
            var colName = $("#esr_hour1").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'esr_hour1',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#esr_hour1 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#esr_hour1').select2('val', Number(data)); // select the new term
                $("#esr_hour1").select2('close'); // close the dropdown

            });
        });
        $("#esr_hour2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_esr_hour2' value='" + term + "'><a href='#' id='addNew_esr_hour2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_esr_hour2', function () {
            /* add the new term */
            var new_name = $('#newTerm_esr_hour2').val();
            var id = $("#esr_hour2").attr('data-id');
            var tableName = $("#esr_hour2").attr('data-tableName');
            var colName = $("#esr_hour2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'esr_hour2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#esr_hour2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#esr_hour2').select2('val', Number(data)); // select the new term
                $("#esr_hour2").select2('close'); // close the dropdown

            });
        });
        $('body').on('change', '.esr', function () {
            var element = $(this).attr('data-target');
            var hour = $('#esr_' + element).val();
            var rangeid = $('#' + element + '_rangeid').val();
            $.post(hosturl + '/controllers/invsdept.php?ac=esrchange', {
                hour: hour,
                rangeid: rangeid,
                element: element
            }, function (res) {

                var obj = res.split("-");
                $('#' + element + '_unit').val(obj[0]);
                $('#' + element + '_level').val(obj[1]);
            });
        });
    };

    var cultureInvest = function () {

        $("#culture_sample").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_sample' value='" + term + "'><a href='#' id='addNew_culture_sample' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_sample', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_sample').val();
            var id = $("#culture_sample").attr('data-id');
            var tableName = $("#culture_sample").attr('data-tableName');
            var colName = $("#culture_sample").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'culture_sample',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_sample > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_sample').select2('val', Number(data)); // select the new term
                $("#culture_sample").select2('close'); // close the dropdown

            });
        });
        $("#culture_organism_a").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_organism_a' value='" + term + "'><a href='#' id='addNew_culture_organism_a' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_organism_a', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_organism_a').val();
            var id = $("#culture_organism_a").attr('data-id');
            var tableName = $("#culture_organism_a").attr('data-tableName');
            var colName = $("#culture_organism_a").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'culture_organism_a',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_organism_a > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_organism_a').select2('val', Number(data)); // select the new term
                $("#culture_organism_a").select2('close'); // close the dropdown

            });
        });
        $("#culture_organism_b").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_organism_b' value='" + term + "'><a href='#' id='addNew_culture_organism_b' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_organism_b', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_organism_b').val();
            var id = $("#culture_organism_b").attr('data-id');
            var tableName = $("#culture_organism_b").attr('data-tableName');
            var colName = $("#culture_organism_b").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'culture_organism_b',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_organism_b > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_organism_b').select2('val', Number(data)); // select the new term
                $("#culture_organism_b").select2('close'); // close the dropdown

            });
        });
        $("#culture_organism_c").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_organism_c' value='" + term + "'><a href='#' id='addNew_culture_organism_c' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_organism_c', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_organism_c').val();
            var id = $("#culture_organism_c").attr('data-id');
            var tableName = $("#culture_organism_c").attr('data-tableName');
            var colName = $("#culture_organism_c").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'culture_organism_c',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_organism_c > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_organism_c').select2('val', Number(data)); // select the new term
                $("#culture_organism_c").select2('close'); // close the dropdown

            });
        });
        $("#culture_condition").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_condition' value='" + term + "'><a href='#' id='addNew_culture_condition' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_condition', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_condition').val();
            var id = $("#culture_condition").attr('data-id');
            var tableName = $("#culture_condition").attr('data-tableName');
            var colName = $("#culture_condition").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'culture_condition',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_condition > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_condition').select2('val', Number(data)); // select the new term
                $("#culture_condition").select2('close'); // close the dropdown

            });
        });
        $("#culture_condition1").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_condition1' value='" + term + "'><a href='#' id='addNew_culture_condition1' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_condition1', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_condition1').val();
            var id = $("#culture_condition1").attr('data-id');
            var tableName = $("#culture_condition1").attr('data-tableName');
            var colName = $("#culture_condition1").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'culture_condition1',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_condition1 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_condition1').select2('val', Number(data)); // select the new term
                $("#culture_condition1").select2('close'); // close the dropdown

            });
        });
        $("#culture_colony_count").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_colony_count' value='" + term + "'><a href='#' id='addNew_culture_colony_count' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_colony_count', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_colony_count').val();
            var id = $("#culture_colony_count").attr('data-id');
            var tableName = $("#culture_colony_count").attr('data-tableName');
            var colName = $("#culture_colony_count").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'culture_colony_count',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_colony_count > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_colony_count').select2('val', Number(data)); // select the new term
                $("#culture_colony_count").select2('close'); // close the dropdown

            });
        });
        $("#culture_sensitivity_cat").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_sensitivity_cat' value='" + term + "'><a href='#' id='addNew_culture_sensitivity_cat' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_sensitivity_cat', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_sensitivity_cat').val();
            var id = $("#culture_sensitivity_cat").attr('data-id');
            var tableName = $("#culture_sensitivity_cat").attr('data-tableName');
            var colName = $("#culture_sensitivity_cat").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'culture_sensitivity_cat',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_sensitivity_cat > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_sensitivity_cat').select2('val', Number(data)); // select the new term
                $("#culture_sensitivity_cat").select2('close'); // close the dropdown

            });
        });
        $("#culture_reaction").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_reaction' value='" + term + "'><a href='#' id='addNew_culture_reaction' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_reaction', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_reaction').val();
            var id = $("#culture_reaction").attr('data-id');
            var tableName = $("#culture_reaction").attr('data-tableName');
            var colName = $("#culture_reaction").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_reaction',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_reaction > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_reaction').select2('val', Number(data)); // select the new term
                $("#culture_reaction").select2('close'); // close the dropdown

            });
        });
        $("#culture_pus").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_pus' value='" + term + "'><a href='#' id='addNew_culture_pus' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_pus', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_pus').val();
            var id = $("#culture_pus").attr('data-id');
            var tableName = $("#culture_pus").attr('data-tableName');
            var colName = $("#culture_pus").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_pus',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_pus > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_pus').select2('val', Number(data)); // select the new term
                $("#culture_pus").select2('close'); // close the dropdown

            });
        });
        $("#culture_pus2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_pus2' value='" + term + "'><a href='#' id='addNew_culture_pus2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_pus2', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_pus2').val();
            var id = $("#culture_pus2").attr('data-id');
            var tableName = $("#culture_pus2").attr('data-tableName');
            var colName = $("#culture_pus2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_pus2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_pus2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_pus2').select2('val', Number(data)); // select the new term
                $("#culture_pus2").select2('close'); // close the dropdown

            });
        });
        $("#culture_pbcs").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_pbcs' value='" + term + "'><a href='#' id='addNew_culture_pbcs' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_pbcs', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_pbcs').val();
            var id = $("#culture_pbcs").attr('data-id');
            var tableName = $("#culture_pbcs").attr('data-tableName');
            var colName = $("#culture_pbcs").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_pbcs',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_pbcs > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_pbcs').select2('val', Number(data)); // select the new term
                $("#culture_pbcs").select2('close'); // close the dropdown

            });
        });
        $("#culture_pbcs2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_pbcs2' value='" + term + "'><a href='#' id='addNew_culture_pbcs2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_pbcs2', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_pbcs2').val();
            var id = $("#culture_pbcs2").attr('data-id');
            var tableName = $("#culture_pbcs2").attr('data-tableName');
            var colName = $("#culture_pbcs2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_pbcs2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_pbcs2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_pbcs2').select2('val', Number(data)); // select the new term
                $("#culture_pbcs2").select2('close'); // close the dropdown

            });
        });
        $("#culture_epithelial").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_epithelial' value='" + term + "'><a href='#' id='addNew_culture_epithelial' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_epithelial', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_epithelial').val();
            var id = $("#culture_epithelial").attr('data-id');
            var tableName = $("#culture_epithelial").attr('data-tableName');
            var colName = $("#culture_epithelial").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_epithelial',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_epithelial > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_epithelial').select2('val', Number(data)); // select the new term
                $("#culture_epithelial").select2('close'); // close the dropdown

            });
        });
        $("#culture_crystal").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_crystal' value='" + term + "'><a href='#' id='addNew_culture_crystal' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_crystal', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_crystal').val();
            var id = $("#culture_crystal").attr('data-id');
            var tableName = $("#culture_crystal").attr('data-tableName');
            var colName = $("#culture_crystal").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_crystal',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_crystal > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_crystal').select2('val', Number(data)); // select the new term
                $("#culture_crystal").select2('close'); // close the dropdown

            });
        });
        $("#culture_fungi").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_fungi' value='" + term + "'><a href='#' id='addNew_culture_fungi' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_fungi', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_fungi').val();
            var id = $("#culture_fungi").attr('data-id');
            var tableName = $("#culture_fungi").attr('data-tableName');
            var colName = $("#culture_fungi").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_fungi',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_fungi > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_fungi').select2('val', Number(data)); // select the new term
                $("#culture_fungi").select2('close'); // close the dropdown

            });
        });
        $("#culture_bacteria").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_bacteria' value='" + term + "'><a href='#' id='addNew_culture_bacteria' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_bacteria', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_bacteria').val();
            var id = $("#culture_bacteria").attr('data-id');
            var tableName = $("#culture_bacteria").attr('data-tableName');
            var colName = $("#culture_bacteria").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_bacteria',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_bacteria > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_bacteria').select2('val', Number(data)); // select the new term
                $("#culture_bacteria").select2('close'); // close the dropdown

            });
        });
        $("#culture_other").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_other' value='" + term + "'><a href='#' id='addNew_culture_other' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_other', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_other').val();
            var id = $("#culture_other").attr('data-id');
            var tableName = $("#culture_other").attr('data-tableName');
            var colName = $("#culture_other").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_other',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_other > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_other').select2('val', Number(data)); // select the new term
                $("#culture_other").select2('close'); // close the dropdown

            });
        });
        $("#culture_other1").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_other1' value='" + term + "'><a href='#' id='addNew_culture_other1' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_other1', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_other1').val();
            var id = $("#culture_other1").attr('data-id');
            var tableName = $("#culture_other1").attr('data-tableName');
            var colName = $("#culture_other1").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_other1',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_other1 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_other1').select2('val', Number(data)); // select the new term
                $("#culture_other1").select2('close'); // close the dropdown

            });
        });
        $("#culture_other2").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_other2' value='" + term + "'><a href='#' id='addNew_culture_other2' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_other2', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_other2').val();
            var id = $("#culture_other2").attr('data-id');
            var tableName = $("#culture_other2").attr('data-tableName');
            var colName = $("#culture_other2").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_other2',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_other2 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_other2').select2('val', Number(data)); // select the new term
                $("#culture_other2").select2('close'); // close the dropdown

            });
        });
        $("#culture_other3").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_other3' value='" + term + "'><a href='#' id='addNew_culture_other3' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_other3', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_other3').val();
            var id = $("#culture_other3").attr('data-id');
            var tableName = $("#culture_other3").attr('data-tableName');
            var colName = $("#culture_other3").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_other3',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_other3 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_other3').select2('val', Number(data)); // select the new term
                $("#culture_other3").select2('close'); // close the dropdown

            });
        });
        $("#culture_other4").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_other4' value='" + term + "'><a href='#' id='addNew_culture_other4' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_other4', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_other4').val();
            var id = $("#culture_other4").attr('data-id');
            var tableName = $("#culture_other4").attr('data-tableName');
            var colName = $("#culture_other4").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_other4',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_other4 > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_other4').select2('val', Number(data)); // select the new term
                $("#culture_other4").select2('close'); // close the dropdown

            });
        });
        $("#culture_gram").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_gram' value='" + term + "'><a href='#' id='addNew_culture_gram' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_gram', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_gram').val();
            var id = $("#culture_gram").attr('data-id');
            var tableName = $("#culture_gram").attr('data-tableName');
            var colName = $("#culture_gram").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_gram',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_gram > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_gram').select2('val', Number(data)); // select the new term
                $("#culture_gram").select2('close'); // close the dropdown

            });
        });
        $("#culture_zn_film").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_culture_zn_film' value='" + term + "'><a href='#' id='addNew_culture_zn_film' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_culture_zn_film', function () {
            /* add the new term */
            var new_name = $('#newTerm_culture_zn_film').val();
            var id = $("#culture_zn_film").attr('data-id');
            var tableName = $("#culture_zn_film").attr('data-tableName');
            var colName = $("#culture_zn_film").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'urine_zn_film',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {


                $('#culture_zn_film > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#culture_zn_film').select2('val', Number(data)); // select the new term
                $("#culture_zn_film").select2('close'); // close the dropdown

            });
        });
        $('body').on('click', '#AddAbbr', function () {

            var abbr = $('#abbr').val();
            var scientific_name = $('#scientific_name').val();
            var sensitivity = $('#sensitivity').val();
            var culture_id = $(this).attr('data-culture');
            $.post(hosturl + '/controllers/invsdept.php?ac=addabbr', {
                abbr: abbr,
                culture_id: culture_id,
                scientific_name: scientific_name,
                sensitivity: sensitivity
            }, function (res) {

                if (res != -1) {
                    $('#abbrContainer').html('');
                    $('#abbrContainer').html(res);
                }
            });
        });
        $('body').on('click', '.activeTab', function () {
            var tab = $(this).attr('data-tab');
            $('#activeTab').val(tab);
        });
        $('body').on('click', '.moveAbbr', function () {
            var abbr_id = $(this).attr('data-id');
            var culture_id = $(this).attr('data-culture');
            var activeTab = $('#activeTab').val();
            var tr = $(this).parent().parent();
            $.post(hosturl + '/controllers/invsdept.php?ac=moveabbr', {
                abbr_id: abbr_id,
                culture_id: culture_id,
                activeTab: activeTab
            }, function (res) {

                if (Number(res) == 1) {
                    tr.remove();
                    $.post(hosturl + '/controllers/invsdept.php?ac=loadtabcontent', {
                        culture_id: culture_id,
                        activeTab: activeTab
                    }, function (dat) {

                        $('#' + activeTab + 'Container').html('');
                        $('#' + activeTab + 'Container').html(dat);
                    });
                }
            });
        });
        $('body').on('click', '.deleteMAbbr', function () {
            var id = $(this).attr('data-id');
            var tableName = $(this).attr('data-tableName');
            var culture_id = $(this).attr('data-culture');
            var activeTab = $('#activeTab').val();
            var tr = $(this).parent().parent();
            $.post(hosturl + '/controllers/invsdept.php?ac=tabdeleteabbr', {
                id: id,
                tableName: tableName
            }, function (res) {

                if (Number(res) == 1) {
                    tr.remove();
                    $.post(hosturl + '/controllers/invsdept.php?ac=loadtabcontent', {
                        culture_id: culture_id,
                        activeTab: activeTab
                    }, function (dat) {

                        $('#' + activeTab + 'Container').html('');
                        $('#' + activeTab + 'Container').html(dat);
                    });
                    $.post(hosturl + '/controllers/invsdept.php?ac=getallabbr', {
                        culture_id: culture_id
                    }, function (dat) {

                        $('#abbrContainer').html('');
                        $('#abbrContainer').html(dat);
                    });
                }
            });
        });
    };

    var crossInvest = function () {
        $("#cross_abo").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_cross_abo' value='" + term + "'><a href='#' id='addNew_cross_abo' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_cross_abo', function () {
            /* add the new term */
            var new_name = $('#newTerm_cross_abo').val();
            var id = $("#cross_abo").attr('data-id');
            var tableName = $("#cross_abo").attr('data-tableName');
            var colName = $("#cross_abo").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'cross_abo',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {

                $('.cross_abo').each(function () {
                    var sId = $(this).attr("id");
                    $('#' + sId + ' > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                });
                $('#cross_abo').select2('val', Number(data)); // select the new term
                $("#cross_abo").select2('close'); // close the dropdown

            });
        });
        $("#cross_rh").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_cross_rh' value='" + term + "'><a href='#' id='addNew_cross_rh' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_cross_rh', function () {
            /* add the new term */
            var new_name = $('#newTerm_cross_rh').val();
            var id = $("#cross_rh").attr('data-id');
            var tableName = $("#cross_rh").attr('data-tableName');
            var colName = $("#cross_rh").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'cross_rh',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {

                $('.cross_rh').each(function () {
                    var sId = $(this).attr("id");
                    $('#' + sId + ' > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                });
                $('#cross_rh').select2('val', Number(data)); // select the new term
                $("#cross_rh").select2('close'); // close the dropdown

            });
        });
        var crossDonnersItr = $('#crossDonnersItr').val();
        for (var x = 1; x <= crossDonnersItr; x++) {

            loadSelect(x);
        }


        $('body').on('click', '#AddDonor', function () {

            var cross_id = $(this).attr('data-cross');
            var crossDonnersItr = $('#crossDonnersItr').val();
            var new_itr = crossDonnersItr + 1;
            $('#crossDonnersItr').val(new_itr);
            $.post(hosturl + '/controllers/invsdept.php?ac=addnewdonner', {
                cross_id: cross_id,
                new_itr: new_itr
            }, function (res) {

                if (res != -1) {
                    $('#donorsDiv').append(res);
                    loadSelect(new_itr)
                }
            });
        });
    };

    function loadSelect(i) {

        $('#donner_abo' + i).select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                var itr = $(this).attr('data-itr');
                var id = $(this).attr('data-id');
                var tableName = $(this).attr('data-tableName');
                var colName = $(this).attr('data-colName');
                return "<input class='form-control' id='newTerm_donner_abo" + itr + "' value='" + term + "' data-itr='" + itr + "' data-id='" + id + "' ><a href='#' id='addNew_donner_abo" + itr + "' data-itr='" + itr + "' data-id='" + id + "'  data-tableName='" + tableName + "' data-colName='" + colName + "' class='btn blue addNew_donner_abo'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '.addNew_donner_abo', function () {
            /* add the new term */
            var itr = $(this).attr('data-itr');
            var new_name = $('#newTerm_donner_abo' + itr).val();
            var id = $(this).attr('data-id');
            var tableName = $(this).attr('data-tableName');
            var colName = $(this).attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'cross_abo',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {

                $('.cross_abo > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#donner_abo' + itr).select2('val', Number(data)); // select the new term
                $('#donner_abo' + itr).select2('close'); // close the dropdown

            });
        });
        $('#donner_rh' + i).select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                var itr = $(this).attr('data-itr');
                var id = $(this).attr('data-id');
                var tableName = $(this).attr('data-tableName');
                var colName = $(this).attr('data-colName');
                return "<input class='form-control' id='newTerm_donner_rh" + itr + "' value='" + term + "' data-itr='" + itr + "' data-id='" + id + "' ><a href='#' id='addNew_donner_rh" + itr + "' data-itr='" + itr + "' data-id='" + id + "'  data-tableName='" + tableName + "' data-colName='" + colName + "' class='btn blue addNew_donner_rh'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '.addNew_donner_rh', function () {
            /* add the new term */
            var itr = $(this).attr('data-itr');
            var new_name = $('#newTerm_donner_rh' + itr).val();
            var id = $(this).attr('data-id');
            var tableName = $(this).attr('data-tableName');
            var colName = $(this).attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'cross_rh',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {

                $('.cross_rh > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#donner_rh' + itr).select2('val', Number(data)); // select the new term
                $('#donner_rh' + itr).select2('close'); // close the dropdown

            });
        });
        $('#cross_compatibility' + i).select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                var itr = $(this).attr('data-itr');
                var id = $(this).attr('data-id');
                var tableName = $(this).attr('data-tableName');
                var colName = $(this).attr('data-colName');
                return "<input class='form-control' id='newTerm_cross_compatibility" + itr + "' value='" + term + "' data-itr='" + itr + "' data-id='" + id + "' ><a href='#' id='addNew_cross_compatibility" + itr + "' data-itr='" + itr + "' data-id='" + id + "'  data-tableName='" + tableName + "' data-colName='" + colName + "' class='btn blue addNew_cross_compatibility'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '.addNew_cross_compatibility', function () {
            /* add the new term */
            var itr = $(this).attr('data-itr');
            var new_name = $('#newTerm_cross_compatibility' + itr).val();
            var id = $(this).attr('data-id');
            var tableName = $(this).attr('data-tableName');
            var colName = $(this).attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'cross_compatibility',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {

                $('.cross_compatibility > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#cross_compatibility' + itr).select2('val', Number(data)); // select the new term
                $('#cross_compatibility' + itr).select2('close'); // close the dropdown

            });
        });
        $('#cross_hcv' + i).select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                var itr = $(this).attr('data-itr');
                var id = $(this).attr('data-id');
                var tableName = $(this).attr('data-tableName');
                var colName = $(this).attr('data-colName');
                return "<input class='form-control' id='newTerm_cross_hcv" + itr + "' value='" + term + "' data-itr='" + itr + "' data-id='" + id + "' ><a href='#' id='addNew_cross_hcv" + itr + "' data-itr='" + itr + "' data-id='" + id + "'  data-tableName='" + tableName + "' data-colName='" + colName + "' class='btn blue addNew_cross_hcv'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '.addNew_cross_hcv', function () {
            /* add the new term */
            var itr = $(this).attr('data-itr');
            var new_name = $('#newTerm_cross_hcv' + itr).val();
            var id = $(this).attr('data-id');
            var tableName = $(this).attr('data-tableName');
            var colName = $(this).attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'cross_hcv',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {

                $('.cross_hcv > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#cross_hcv' + itr).select2('val', Number(data)); // select the new term
                $('#cross_hcv' + itr).select2('close'); // close the dropdown

            });
        });
        $('#cross_hbsag' + i).select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                var itr = $(this).attr('data-itr');
                var id = $(this).attr('data-id');
                var tableName = $(this).attr('data-tableName');
                var colName = $(this).attr('data-colName');
                return "<input class='form-control' id='newTerm_cross_hbsag" + itr + "' value='" + term + "' data-itr='" + itr + "' data-id='" + id + "' ><a href='#' id='addNew_cross_hbsag" + itr + "' data-itr='" + itr + "' data-id='" + id + "'  data-tableName='" + tableName + "' data-colName='" + colName + "' class='btn blue addNew_cross_hbsag'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '.addNew_cross_hbsag', function () {
            /* add the new term */
            var itr = $(this).attr('data-itr');
            var new_name = $('#newTerm_cross_hbsag' + itr).val();
            var id = $(this).attr('data-id');
            var tableName = $(this).attr('data-tableName');
            var colName = $(this).attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'cross_hbsag',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {

                $('.cross_hbsag > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#cross_hbsag' + itr).select2('val', Number(data)); // select the new term
                $('#cross_hbsag' + itr).select2('close'); // close the dropdown

            });
        });
        $('#cross_hv' + i).select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                var itr = $(this).attr('data-itr');
                var id = $(this).attr('data-id');
                var tableName = $(this).attr('data-tableName');
                var colName = $(this).attr('data-colName');
                return "<input class='form-control' id='newTerm_cross_hv" + itr + "' value='" + term + "' data-itr='" + itr + "' data-id='" + id + "' ><a href='#' id='addNew_cross_hv" + itr + "' data-itr='" + itr + "' data-id='" + id + "'  data-tableName='" + tableName + "' data-colName='" + colName + "' class='btn blue addNew_cross_hv'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '.addNew_cross_hv', function () {
            /* add the new term */
            var itr = $(this).attr('data-itr');
            var new_name = $('#newTerm_cross_hv' + itr).val();
            var id = $(this).attr('data-id');
            var tableName = $(this).attr('data-tableName');
            var colName = $(this).attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'cross_hv',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {

                $('.cross_hv > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                $('#cross_hv' + itr).select2('val', Number(data)); // select the new term
                $('#cross_hv' + itr).select2('close'); // close the dropdown

            });
        });
    }

    var hbsagInvest = function () {

    };

    var clothingInvest = function () {

        $('body').on('change', '.clothing', function () {

            var element = $(this).attr('data-target');
            var value = $('#' + element + '_clothing').val();
            var rangeid = $('#' + element + '_rangeid').val();
            $.post(hosturl + '/controllers/invsdept.php?ac=invlevel', {
                value: value,
                rangeid: rangeid
            }, function (res) {

                var obj = res.split("-");
                $('#' + element + '_level').val(obj[0]);
                $('#' + element + '_unit').val(obj[1]);
            });
        });
    };

    var ptInvest = function () {
        $('body').on('change', '.pt', function () {

            var element = $(this).attr('data-target');
            ptChange(element);
        });
        function ptChange(element) {

            var value = $('#' + element + '_pt').val();
            var rangeid = $('#' + element + '_rangeid').val();
            $.post(hosturl + '/controllers/invsdept.php?ac=invlevel', {
                value: value,
                rangeid: rangeid
            }, function (res) {

                var obj = res.split("-");
                $('#' + element + '_level').val(obj[0]);
                $('#' + element + '_unit').val(obj[1]);
            });
        }

        $('body').on('keyup', '#patient_time_pt', function () {

            var pt_patient = Number($('#patient_time_pt').val());
            var id = $(this).attr('data-id');
            $.post(hosturl + '/controllers/invsdept.php?ac=inrcalc', {pt_patient: pt_patient, id: id}, function (res) {
                var obj = res.split("-");
                $('#inr_pt').val(obj[0]);
                var element = $('#inr_pt').attr('data-target');
                ptChange(element);
                $('#concentration_pt').val(obj[1]);
                var element = $('#concentration_pt').attr('data-target');
                ptChange(element);
            });
        });
        $('body').on('click', '#calculator', function () {
            $.post(hosturl + '/controllers/invsdept.php?ac=calculator', function (res) {
                $('#calculatorDiv').html('');
                $('#calculatorDiv').html(res);
                $("#calculatorModal").modal('show');
            });
        });
        $('body').on('click', '#newCalculation', function () {
            $.post(hosturl + '/controllers/invsdept.php?ac=newcalculation', function (res) {
                $('#calculationContainer').prepend(res);
            });
        });
    };

    var aborhInvest = function () {
        $("#aborh_abo").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_aborh_abo' value='" + term + "'><a href='#' id='addNew_aborh_abo' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_aborh_abo', function () {
            /* add the new term */
            var new_name = $('#newTerm_aborh_abo').val();
            var id = $("#aborh_abo").attr('data-id');
            var tableName = $("#aborh_abo").attr('data-tableName');
            var colName = $("#aborh_abo").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'cross_abo',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {

                $('.cross_abo').each(function () {
                    var sId = $(this).attr("id");
                    $('#' + sId + ' > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                });
                $('#aborh_abo').select2('val', Number(data)); // select the new term
                $("#aborh_abo").select2('close'); // close the dropdown

            });
        });
        $("#aborh_rh").select2({
            placeholder: "Select",
            width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                return "<input class='form-control' id='newTerm_aborh_rh' value='" + term + "'><a href='#' id='addNew_aborh_rh' class='btn blue custombtnstyle'>إضافة جديد</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNew_aborh_rh', function () {
            /* add the new term */
            var new_name = $('#newTerm_aborh_rh').val();
            var id = $("#aborh_rh").attr('data-id');
            var tableName = $("#aborh_rh").attr('data-tableName');
            var colName = $("#aborh_rh").attr('data-colName');
            $.post(hosturl + "/controllers/invsdept.php?ac=addnewrecord", {
                selectId: 'cross_rh',
                new_name: new_name,
                id: id,
                tableName: tableName,
                colName: colName
            }, function (data) {

                $('.cross_rh').each(function () {
                    var sId = $(this).attr("id");
                    $('#' + sId + ' > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + new_name + '</option>');
                });
                $('#aborh_rh').select2('val', Number(data)); // select the new term
                $("#aborh_rh").select2('close'); // close the dropdown

            });
        });
    };

    return {
        //main function to initiate the module
        init: function () {


            if ($('#controllName').val() == 'invsdept')
            {
                forAll();
            }

            if ($('#urineInvest').val() == 1)
            {
                urineInvest();
            }
            if ($('#stoolInvest').val() == 1)
            {
                stoolInvest();
            }
            if ($('#bPictureInvest').val() == 1)
            {
                bPictureInvest();
            }
            if ($('#esrInvest').val() == 1)
            {
                esrInvest();
            }
            if ($('#cultureInvest').val() == 1)
            {
                cultureInvest();
            }
            if ($('#crossInvest').val() == 1)
            {
                crossInvest();
            }
            if ($('#hbsagInvest').val() == 1)
            {
                hbsagInvest();
            }
            if ($('#clothingInvest').val() == 1)
            {
                clothingInvest();
            }
            if ($('#ptInvest').val() == 1)
            {
                ptInvest();
            }

            if ($('#aborhInvest').val() == 1)
            {
                aborhInvest();
            }
        }

    };
}();
