//check for investigation page
if ($('#investigationPage').val() == 1)
{
    var hosturl = $('#hosturl').val();
    var tdate = $("#tdate").val();
    var patientId = $("#patientId").val();
    var controllName = $("#controllName").val();
    var docname = $("#DocName").val();
    var showDoc = $("#showDoc").val();
    //Add Row for semen
    $("#addSemen").live('click', function () {
        //get semen iteration
        var semenitr = $("#semenitr").val();
        semenitr++;
        var tableName = $(this).attr('data-table');
        //insert new row in semen table
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=addRow', {patientId: patientId, tableName: tableName}, function (res)
        {
            var semenid = Number(res);
            //add new row in html
            $("#semenDiv").prepend('' + (showDoc == 1 ? '<div class="row ">\
                                        <div class="col-md-1">\
                                            <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                                <label for="form_control_1">' + docname + '</label>\
                                            </div>\
                                        </div>\
                                        </div>' : '')
                    + '<div class="row clinick">\
                                    <div class="col-md-1">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <input type="text" class="form-control datepicker updateElement txtc edited" id="semendate' + semenitr + '" data-tableName="semen" data-colName="sdate" data-id="' + semenid + '" value="' + tdate + '"/>\
                                            <label for="form_control_1">Date</label>\
                                        </div>\
                                    </div>\
                                    <div class="col-md-1">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <input type="text" class="form-control updateElement" id="semencount' + semenitr + '" data-tableName="semen" data-colName="count" data-id="' + semenid + '"/>\
                                            <label for="form_control_1">count</label>\
                                        </div>\
                                    </div>\
                                    <div class="col-md-1">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <input type="text" class="form-control updateElement" id="semenA' + semenitr + '" data-tableName="semen" data-colName="motilitya" data-id="' + semenid + '"/>\
                                            <label for="form_control_1">motilityA</label>\
                                        </div>\
                                    </div>\
                                    <div class="col-md-2">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <input type="text" class="form-control updateElement" id="semenAB' + semenitr + '" data-tableName="semen" data-colName="motilityab" data-id="' + semenid + '"/>\
                                            <label for="form_control_1">motilityA+B</label>\
                                        </div>\
                                    </div>\
                                    <div class="col-md-1">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <input type="text" class="form-control updateElement" id="semennormal' + semenitr + '" data-tableName="semen" data-colName="normal" data-id="' + semenid + '"/>\
                                            <label for="form_control_1">Normal</label>\
                                        </div>\
                                    </div>\
                                    <div class="col-md-1">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <input type="text" class="form-control updateElement" id="semenpus' + semenitr + '" data-tableName="semen" data-colName="puscell" data-id="' + semenid + '"/>\
                                            <label for="form_control_1">pus cells</label>\
                                        </div>\
                                    </div>\
                                    <div class="col-md-5">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <input type="text" class="form-control updateElement" id="semennote' + semenitr + '" data-tableName="semen" data-colName="notes" data-id="' + semenid + '"/>\
                                            <label for="form_control_1">Notes</label>\
                                        </div>\
                                    </div>\
                                    <div class="form-group form-md-line-input">\
                                        <div class="col-md-1"></div>\
                                        <div class="col-md-11">\
                                            <div class="md-checkbox-inline">\
                                                <div class="md-checkbox">\
                                                    <input type="checkbox" class="md-check updateCheckbox" id="normaltype' + semenitr + '" name="sementype" data-tableName="semen" data-colName="normaltype" data-id="' + semenid + '">\
                                                    <label for="normaltype' + semenitr + '">\
                                                        <span></span>\
                                                        <span class="check"></span>\
                                                        <span class="box"></span>\
                                                        Normal </label>\
                                                </div>\
                                                <div class="md-checkbox">\
                                                    <input type="checkbox" class="md-check updateCheckbox" id="Oligotype' + semenitr + '" name="sementype" data-tableName="semen" data-colName="oligo" data-id="' + semenid + '"/>\
                                                    <label for="Oligotype' + semenitr + '">\
                                                        <span></span>\
                                                        <span class="check"></span>\
                                                        <span class="box"></span>\
                                                        Oligo sprerm</label>\
                                                </div>\
                                                <div class="md-checkbox">\
                                                    <input type="checkbox" class="md-check updateCheckbox" id="asthenotype' + semenitr + '" name="sementype" data-tableName="semen" data-colName="astheno" data-id="' + semenid + '"/>\
                                                    <label for="asthenotype' + semenitr + '">\
                                                        <span></span>\
                                                        <span class="check"></span>\
                                                        <span class="box"></span>\
                                                        astheno sperm </label>\
                                                </div>\
                                                <div class="md-checkbox">\
                                                    <input type="checkbox" class="md-check updateCheckbox" id="Tetratotype' + semenitr + '" name="sementype" data-tableName="semen" data-colName="tetrato" data-id="' + semenid + '"/>\
                                                    <label for="Tetratotype' + semenitr + '">\
                                                        <span></span>\
                                                        <span class="check"></span>\
                                                        <span class="box"></span>\
                                                        Tetrato sperm </label>\
                                                </div>\
                                            </div>\
                                            <button type="button" class="btn btn-xs red fright removeMsg axedelete2" id="delsemen' + semenitr + '" data-tableName="semen" data-id="' + semenid + '"><i class="fa fa-close"></i></button>\
                                        </div>\
                                    </div>\
                                </div>\
                                <div class="clearfix"></div>');

            $("#semenitr").val(semenitr);

            $('.datepickertoday').datepicker('setDate', '+0');
            $(".datepicker").datepicker({
                todayBtn: "linked",
                autoclose: true,
                todayHighlight: true,
                format: 'yy/mm/dd',
                isRTL: true
            });
        });

    });

    $(".updateCheckbox").live('click', function () {

        var id = $(this).attr("data-id");
        var colName = $(this).attr("data-colName");
        var tableName = $(this).attr("data-tableName");
        var value;

        if ($(this).is(":checked"))
        {
            var value = 1;
        }
        else
        {
            var value = 0;
        }
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=update', {id: id, value: value, tableName: tableName, colName: colName, patientId: patientId}, function (res)
        {
        });
    });

//Add Row for HSG
    $("#addHsg").live('click', function () {
        //get semen iteration
        var hsgitr = $("#hsgitr").val();
        hsgitr++;
        var tableName = $(this).attr('data-table');
        //insert new row in semen table
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=addRow', {patientId: patientId, tableName: tableName}, function (res)
        {
            var semenid = Number(res);

            //add new row in html
            $("#hsgDiv").prepend('' + (showDoc == 1 ? '<div class="row">\
                                    <div class="col-md-1">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <label for="form_control_1">' + docname + '</label>\
                                        </div>\
                                    </div>\
                                    </div>' : '') +
                    '<div class="row clinick">\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control datepicker txtc updateElement edited" id="hsgdate' + hsgitr + '" data-tableName="hsg" data-colName="sdate" data-id="' + semenid + '" value="' + tdate + '">\
                                        <label for="form_control_1">Date</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="uterus' + hsgitr + '" data-tableName="hsg" data-colName="uterus" data-id="' + semenid + '">\
                                        <label for="form_control_1">Uterus</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="rtube' + hsgitr + '" data-tableName="hsg" data-colName="rtube" data-id="' + semenid + '">\
                                        <label for="form_control_1">R.tube</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="ltube' + hsgitr + '" data-tableName="hsg" data-colName="ltube" data-id="' + semenid + '">\
                                        <label for="form_control_1">L.tube</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="smear' + hsgitr + '" data-tableName="hsg" data-colName="smear" data-id="' + semenid + '">\
                                        <label for="form_control_1">Smear</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-3">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="hnotes' + hsgitr + '" data-tableName="hsg" data-colName="notes" data-id="' + semenid + '">\
                                        <label for="form_control_1">Notes</label>\
                                    </div>\
                                    <button type="button" class="axedelete2 btn btn-xs red fright removeMsg" style="margin-top: 25px;" id="delsemen' + hsgitr + '" data-tableName="hsg" data-id="' + semenid + '"><i class="fa fa-close"></i></button>\
                                </div>\
                            </div>\
                                <div class="clearfix"></div>');

            $("#hsgitr").val(hsgitr);

            $('.datepickertoday').datepicker('setDate', '+0');
            $(".datepicker").datepicker({
                todayBtn: "linked",
                // autoclose: true,
                todayHighlight: true,
                format: 'yy/mm/dd',
                isRTL: true
            });
        });

    });

    //Add Row for ustv
    $("#addUs").live('click', function () {
        //get semen iteration
        var ustvitr = $("#ustvitr").val();
        ustvitr++;
        var tableName = $(this).attr('data-table');
        //insert new row in semen table
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=addRow', {patientId: patientId, tableName: tableName}, function (res)
        {
            var semenid = Number(res);

            //add new row in html
            $("#usDiv").prepend('' + (showDoc == 1 ? '<div class="row">\
                                    <div class="col-md-1">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <label for="form_control_1">' + docname + '</label>\
                                        </div>\
                                    </div>\
                                    </div>' : '') +
                    '<div class="row clinick">\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control datepicker txtc updateElement edited" id="ustvdate' + ustvitr + '" data-tableName="ustv" data-colName="sdate" data-id="' + semenid + '" value="' + tdate + '">\
                                        <label for="form_control_1">Date</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="uuterus' + ustvitr + '" data-tableName="ustv" data-colName="uterus" data-id="' + semenid + '">\
                                        <label for="form_control_1">Uterus</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="uradnexa' + ustvitr + '" data-tableName="ustv" data-colName="radnexa" data-id="' + semenid + '">\
                                        <label for="form_control_1">R.adnexa</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="uladnexa' + ustvitr + '" data-tableName="ustv" data-colName="ladnexa" data-id="' + semenid + '">\
                                        <label for="form_control_1">L.adnexa</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="upelvis' + ustvitr + '" data-tableName="ustv" data-colName="pelvis" data-id="' + semenid + '">\
                                        <label for="form_control_1">Pelvis</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-3">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="unotes' + ustvitr + '" data-tableName="ustv" data-colName="notes" data-id="' + semenid + '">\
                                        <label for="form_control_1">Notes</label>\
                                    </div>\
                                    <button type="button" class="axedelete2 btn btn-xs red fright removeMsg" style="margin-top: 25px;" id="delustv' + ustvitr + '" data-tableName="ustv" data-id="' + semenid + '"><i class="fa fa-close"></i></button>\
                                </div>\
                            </div>\
                                <div class="clearfix"></div>');

            $("#ustvitr").val(ustvitr);

            $('.datepickertoday').datepicker('setDate', '+0');
            $(".datepicker").datepicker({
                todayBtn: "linked",
                // autoclose: true,
                todayHighlight: true,
                format: 'yy/mm/dd',
                isRTL: true
            });
        });

    });

    //Add Row for laparoscopy
    $("#addLap").live('click', function () {
        //get semen iteration
        var lapitr = $("#lapitr").val();
        lapitr++;
        var tableName = $(this).attr('data-table');
        //insert new row in semen table
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=addRow', {patientId: patientId, tableName: tableName}, function (res)
        {
            var semenid = Number(res);

            //add new row in html
            $("#lapDiv").prepend('' + (showDoc == 1 ? '<div class="row">\
                                    <div class="col-md-1">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <label for="form_control_1">' + docname + '</label>\
                                        </div>\
                                    </div>\
                                    </div>' : '') +
                    ' <div class="row clinick">\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control datepicker txtc updateElement edited" id="lsdate' + lapitr + '" data-tableName="laparoscopy" data-colName="sdate" data-id="' + semenid + '" value="' + tdate + '">\
                                        <label for="form_control_1">Date</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="luterus' + lapitr + '" data-tableName="laparoscopy" data-colName="uterus" data-id="' + semenid + '">\
                                        <label for="form_control_1">Uterus</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="lradnexa' + lapitr + '" data-tableName="laparoscopy" data-colName="radnexa" data-id="' + semenid + '">\
                                        <label for="form_control_1">R.adnexa</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="lladnexa' + lapitr + '" data-tableName="laparoscopy" data-colName="ladnexa" data-id="' + semenid + '">\
                                        <label for="form_control_1">L.adnexa</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="lpelvis' + lapitr + '" data-tableName="laparoscopy" data-colName="pelvis" data-id="' + semenid + '">\
                                        <label for="form_control_1">Pelvis</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-3">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="lnotes' + lapitr + '" data-tableName="laparoscopy" data-colName="notes" data-id="' + semenid + '">\
                                        <label for="form_control_1">Notes</label>\
                                    </div>\
                                    <button type="button" class="axedelete2 btn btn-xs red fright removeMsg" style="margin-top: 25px;" id="dellap' + lapitr + '" data-tableName="laparoscopy" data-id="' + semenid + '"><i class="fa fa-close"></i></button>\
                                </div>\
                            </div>\
                                <div class="clearfix"></div>');

            $("#lapitr").val(lapitr);

            $('.datepickertoday').datepicker('setDate', '+0');
            $(".datepicker").datepicker({
                todayBtn: "linked",
                // autoclose: true,
                todayHighlight: true,
                format: 'yy/mm/dd',
                isRTL: true
            });
        });

    });

    //Add Row for hysteroscopy
    $("#addHyst").live('click', function () {
        //get semen iteration
        var hystitr = $("#hystitr").val();
        hystitr++;
        var tableName = $(this).attr('data-table');
        //insert new row in semen table
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=addRow', {patientId: patientId, tableName: tableName}, function (res)
        {
            var semenid = Number(res);

            //add new row in html
            $("#hystDiv").prepend('' + (showDoc == 1 ? '<div class="row">\
                                    <div class="col-md-1">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <label for="form_control_1">' + docname + '</label>\
                                        </div>\
                                    </div>\
                                    </div>' : '') +
                    ' <div class="row clinick">\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control datepicker txtc updateElement edited" id="hystdate' + hystitr + '" data-tableName="hysteroscopy" data-colName="sdate" data-id="' + semenid + '" value="' + tdate + '">\
                                        <label for="form_control_1">Date</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="hcervix' + hystitr + '" data-tableName="hysteroscopy" data-colName="cervix" data-id="' + semenid + '">\
                                        <label for="form_control_1">Cervix</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="huterine' + hystitr + '" data-tableName="hysteroscopy" data-colName="uterine" data-id="' + semenid + '">\
                                        <label for="form_control_1">Ut Cavity</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="hrostium' + hystitr + '" data-tableName="hysteroscopy" data-colName="rostium" data-id="' + semenid + '">\
                                        <label for="form_control_1">R.Ostium</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="hlostium' + hystitr + '" data-tableName="hysteroscopy" data-colName="lostium" data-id="' + semenid + '">\
                                        <label for="form_control_1">L.Ostium</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-3">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="hystnotes' + hystitr + '" data-tableName="hysteroscopy" data-colName="notes" data-id="' + semenid + '">\
                                        <label for="form_control_1">Notes</label>\
                                    </div>\
                                    <button type="button" class="axedelete2 btn btn-xs red fright removeMsg" style="margin-top: 25px;" id="delhyst' + hystitr + '" data-tableName="hysteroscopy" data-id="' + semenid + '"><i class="fa fa-close"></i></button>\
                                </div>\
                            </div>\
                                <div class="clearfix"></div>');

            $("#hystitr").val(hystitr);

            $('.datepickertoday').datepicker('setDate', '+0');
            $(".datepicker").datepicker({
                todayBtn: "linked",
                // autoclose: true,
                todayHighlight: true,
                format: 'yy/mm/dd',
                isRTL: true
            });
        });

    });

    //Add Row for mrict
    $("#addMri").live('click', function () {
        //get semen iteration
        var mriitr = $("#mriitr").val();
        mriitr++;
        var tableName = $(this).attr('data-table');
        //insert new row in semen table
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=addRow', {patientId: patientId, tableName: tableName}, function (res)
        {
            var semenid = Number(res);

            //add new row in html
            $("#mriDiv").prepend('' + (showDoc == 1 ? '<div class="row">\
                                    <div class="col-md-1">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <label for="form_control_1">' + docname + '</label>\
                                        </div>\
                                    </div>\
                                    </div>' : '') +
                    '<div class="row clinick">\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control datepicker txtc updateElement edited" id="mridate' + mriitr + '" data-tableName="mrict" data-colName="sdate" data-id="' + semenid + '" value="' + tdate + '">\
                                        <label for="form_control_1">Date</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="muterus' + mriitr + '" data-tableName="mrict" data-colName="uterus"  data-id="' + semenid + '">\
                                        <label for="form_control_1">Uterus</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="mradnexa' + mriitr + '" data-tableName="mrict" data-colName="radnexa" data-id="' + semenid + '">\
                                        <label for="form_control_1">R.adnexa</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="mladnexa' + mriitr + '" data-tableName="mrict" data-colName="ladnexa" data-id="' + semenid + '">\
                                        <label for="form_control_1">L.adnexa</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-2">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="mpelvis' + mriitr + '" data-tableName="mrict" data-colName="pelvis" data-id="' + semenid + '">\
                                        <label for="form_control_1">Pelvis</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-3">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="mnotes' + mriitr + '" data-tableName="mrict" data-colName="notes" data-id="' + semenid + '">\
                                        <label for="form_control_1">Notes</label>\
                                    </div>\
                                    <button type="button" class="axedelete2 btn btn-xs red fright removeMsg" style="margin-top: 25px;" id="delmri' + mriitr + '" data-tableName="mrict" data-id="' + semenid + '"><i class="fa fa-close"></i></button>\
                                </div>\
                            </div>\
                            <div class="clearfix"></div>');

            $("#mriitr").val(mriitr);

            $('.datepickertoday').datepicker('setDate', '+0');
            $(".datepicker").datepicker({
                todayBtn: "linked",
                // autoclose: true,
                todayHighlight: true,
                format: 'yy/mm/dd',
                isRTL: true
            });
        });

    });


    //Add Row for Hormones
    $("#addHormon").live('click', function () {
        //get iteration
        var hormonitr = $("#hormonitr").val();
        hormonitr++;
        var tableName = $(this).attr('data-table');
        var form = $("#hosHormon").val();
        //insert new row in semen table
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=addRow', {patientId: patientId, tableName: tableName}, function (res)
        {
            var semenid = Number(res);
            //add new row in html
            $("#hormonDiv").prepend('' + (showDoc == 1 ? '<div class="row">\
                                    <div class="col-md-1">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <label for="form_control_1">' + docname + '</label>\
                                        </div>\
                                    </div>\
                                    </div>' : '') +
                    '<div class="row clinick">\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control datepicker txtc updateElement edited" id="hodate' + hormonitr + '" data-tableName="hormon" data-colName="sdate" data-id="' + semenid + '" value="' + tdate + '">\
                                        <label for="form_control_1">Date</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                     <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="fsh' + hormonitr + '" data-tableName="hormon" data-colName="fsh" data-id="' + semenid + '">\
                                        <label for="form_control_1">FSH</label>\
                                        <span class="input-group-addon">mIU/ml</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="lh' + hormonitr + '" data-tableName="hormon" data-colName="lh" data-id="' + semenid + '">\
                                        <label for="form_control_1">LH</label>\
                                        <span class="input-group-addon">mIU/ml</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="prl' + hormonitr + '" data-tableName="hormon" data-colName="prl" data-id="' + semenid + '">\
                                        <label for="form_control_1">PRL</label>\
                                        <span class="input-group-addon">ng/ml</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="etwo' + hormonitr + '" data-tableName="hormon" data-colName="etwo" data-id="' + semenid + '">\
                                        <label for="form_control_1">E2</label>\
                                        <span class="input-group-addon">pg/ml</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="amh' + hormonitr + '" data-tableName="hormon" data-colName="amh" data-id="' + semenid + '">\
                                        <label for="form_control_1">AMH</label>\
                                        <span class="input-group-addon">ng/ml</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="freet' + hormonitr + '" data-tableName="hormon" data-colName="freet" data-id="' + semenid + '">\
                                        <label for="form_control_1">FreeT</label>\
                                        <span class="input-group-addon">pg/ml</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="totalt' + hormonitr + '" data-tableName="hormon" data-colName="totalt" data-id="' + semenid + '">\
                                        <label for="form_control_1">TotalT</label>\
                                        <span class="input-group-addon">ng/dl</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="pfour' + hormonitr + '" data-tableName="hormon" data-colName="pfour" data-id="' + semenid + '">\
                                        <label for="form_control_1">P4</label>\
                                        <span class="input-group-addon">ng/ml</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="tsh' + hormonitr + '" data-tableName="hormon" data-colName="tsh" data-id="' + semenid + '">\
                                        <label for="form_control_1">TSH</label>\
                                        <span class="input-group-addon">uIU/ml</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="tthree' + hormonitr + '" data-tableName="hormon" data-colName="tthree" data-id="' + semenid + '">\
                                        <label for="form_control_1">T3</label>\
                                        <span class="input-group-addon">ng/ml</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="tfour' + hormonitr + '" data-tableName="hormon" data-colName="tfour" data-id="' + semenid + '">\
                                        <label for="form_control_1">T4</label>\
                                        <span class="input-group-addon">ug/dl</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="dheas' + hormonitr + '" data-tableName="hormon" data-colName="dheas" data-id="' + semenid + '">\
                                        <label for="form_control_1">DHEAS</label>\
                                        <span class="input-group-addon">ug/dl</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="dht' + hormonitr + '" data-tableName="hormon" data-colName="dht" data-id="' + semenid + '">\
                                        <label for="form_control_1">DHT</label>\
                                        <span class="input-group-addon">ng/ml</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="bhcg' + hormonitr + '" data-tableName="hormon" data-colName="bhcg" data-id="' + semenid + '">\
                                        <label for="form_control_1">B-HCG</label>\
                                        <span class="input-group-addon">mIU/ml</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="inhibinb' + hormonitr + '" data-tableName="hormon" data-colName="inhibinb" data-id="' + semenid + '">\
                                        <label for="form_control_1">InhibinB</label>\
                                        <span class="input-group-addon">pg/ml</span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="asd' + hormonitr + '" data-tableName="hormon" data-colName="asd" data-id="' + semenid + '">\
                                        <label for="form_control_1">ASD</label>\
                                        <span class="input-group-addon">ng/ml</span>\
                                    </div>\
                                </div>' + (form == 1 ? '<div class="col-md-1" style="width: 12%;">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <label class="form-control" style="background-color: #999;font-weight: bold;">Tum.markers</label>\
                                        <label for="form_control_1"></label>\
                                        <span class="input-group-addon"></span>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="ca125' + hormonitr + '" data-tableName="hormon" data-colName="ca125" data-id="' + semenid + '">\
                                        <label for="form_control_1">CA125</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="cea' + hormonitr + '" data-tableName="hormon" data-colName="cea" data-id="' + semenid + '">\
                                        <label for="form_control_1">CEA</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="calgg' + hormonitr + '" data-tableName="hormon" data-colName="calgg" data-id="' + semenid + '">\
                                        <label for="form_control_1">CAlg-9</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="ldh' + hormonitr + '" data-tableName="hormon" data-colName="ldh" data-id="' + semenid + '">\
                                        <label for="form_control_1">LDH</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="tfehprotein' + hormonitr + '" data-tableName="hormon" data-colName="tfehprotein" data-id="' + semenid + '">\
                                        <label for="form_control_1">tfehprotein</label>\
                                    </div>\
                                </div>' : '') + '\
                                <div class="col-md-7">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="honotes' + hormonitr + '" data-tableName="hormon" data-colName="notes" data-id="' + semenid + '">\
                                        <label for="form_control_1">Notes</label>\
                                    </div>\
                                    <button type="button" class="axedelete2 btn btn-xs red fright removeMsg" style="margin-top: 25px;" id="delhormon' + hormonitr + '" data-tableName="hormon" data-id="' + semenid + '"><i class="fa fa-close"></i></button>\
                                </div>\
                            </div>\
                            <div class="clearfix"></div>');

            $("#hormonitr").val(hormonitr);

            $('.datepickertoday').datepicker('setDate', '+0');
            $(".datepicker").datepicker({
                todayBtn: "linked",
                // autoclose: true,
                todayHighlight: true,
                format: 'yy/mm/dd',
                isRTL: true
            });
        });

    });


    //Add Row for Pathology
    $("#addPathology").live('click', function () {
        //get iteration
        var pathitr = $("#pathitr").val();
        pathitr++;
        var tableName = $(this).attr('data-table');
        //insert new row in semen table
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=addRow', {patientId: patientId, tableName: tableName}, function (res)
        {
            var semenid = Number(res);

            //add new row in html
            $("#pathDiv").prepend('' + (showDoc == 1 ? '<div class="row">\
                                    <div class="col-md-1">\
                                        <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                            <label for="form_control_1">' + docname + '</label>\
                                        </div>\
                                    </div>\
                                    </div>' : '') +
                    '<div class="row clinick">\
                                <div class="col-md-1">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control datepicker txtc updateElement edited" id="psdate' + pathitr + '" data-tableName="pathology" data-colName="sdate" data-id="' + semenid + '" value="' + tdate + '">\
                                        <label for="form_control_1">Date</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-5">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="cytology' + pathitr + '" data-tableName="pathology" data-colName="cytology" data-id="' + semenid + '">\
                                        <label for="form_control_1">Cytology</label>\
                                    </div>\
                                </div>\
                                <div class="col-md-6">\
                                    <div class="form-group form-md-line-input form-md-floating-label has-info">\
                                        <input type="text" class="form-control updateElement" id="histopathology' + pathitr + '" data-tableName="pathology" data-colName="histopathology" data-id="' + semenid + '">\
                                        <label for="form_control_1">Histopathology</label>\
                                    <button type="button" class="axedelete4 btn btn-xs red fright removeMsg"  id="delpath' + pathitr + '" data-tableName="pathology" data-id="' + semenid + '"><i class="fa fa-close"></i></button>\
</div>\
                                </div>\
                            </div>\
                            <div class="clearfix"></div>');

            $("#pathitr").val(pathitr);

            $('.datepickertoday').datepicker('setDate', '+0');
            $(".datepicker").datepicker({
                todayBtn: "linked",
                // autoclose: true,
                todayHighlight: true,
                format: 'yy/mm/dd',
                isRTL: true
            });
        });

    });

    //remove row
    //to open model for accept del
    $('.removeMsg').live('click', function () {
        var itemid = $(this).attr('data-id');
        var tableName = $(this).attr('data-tableName');
        bootbox.dialog({
            message: "Do you want to delete this item?",
            title: "Delete confirmation",
            buttons: {
                danger: {
                    label: "Cancel",
                    className: "btn-primary"
                },
                main: {
                    label: "Delete",
                    className: "btn-danger",
                    callback: function () {
                        //do something else
                        window.location.href = hosturl + "/controllers/" + controllName + ".php?ac=delData&id=" + itemid + "&tableName=" + tableName + "&patientid=" + patientId;
                    }
                }
            }
        }).find('.modal-content').addClass('modal-sm');
    });

    $('.removeMsgOther').live('click', function () {
        var itemid = $(this).attr('data-id');
        var tableName = $(this).attr('data-tableName');

        bootbox.dialog({
            message: "Do you want to delete this item?",
            title: "Delete confirmation",
            buttons: {
                danger: {
                    label: "Cancel",
                    className: "btn-primary"
                },
                main: {
                    label: "Delete",
                    className: "btn-danger",
                    callback: function () {
                        //do something else
                        window.location.href = hosturl + "/controllers/" + controllName + ".php?ac=delotherinvestsRow&id=" + itemid + "&tableName=" + tableName + "&patientid=" + patientId;
                    }
                }
            }
        }).find('.modal-content').addClass('modal-sm');
    });


    $('body').on('click', '#addNewInv', function ()
    {
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=otherinvests', function (res)
        {
            $('#othersi').html('');
            $('#othersi').html(res);
            $("#otherinvests").modal('show');
        });

    });

    $('body').on('click', '#addOtherRow', function ()
    {
        var otheritr = $("#otheritr").val();
        otheritr++;
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=otherinvestsRow', {patientId: patientId, otheritr: otheritr}, function (res)
        {
            $('#otherDiv').prepend(res);
            $("#otheritr").val(otheritr);
        });

    });

    $('body').on('click', '#addNewM', function ()
    {
        $.post(hosturl + '/controllers/' + controllName + '.php?ac=otherinvestsAdd', function (res)
        {
            $('#otherBody').prepend('<tr>'
                    + '<td>'
                    + '<input type="text" class="form-control updateElement"    data-id="' + res + '" data-colName="name" data-tableName="otherinvestigations" value=""/>'
                    + '</td>'
                    + '<td>'
                    + '<a class="fa fa-times btn red fleft deletemsgEX" data-id="' + res + '" href="#" data-link="investigation" data-fn="delotherinvest" ></a>'
                    + '</td>'
                    + '</tr>');
        });

    });

}
