{if $tableName == "ivf_records" }
<tr>
    <td>
        <input type="text" class="form-control  datepicker updateElement"   
               data-colName="record_date" value="{$data->record_date}"   id="recordDate{$data->id}"  
               data-tableName="ivf_records"    data-id="{$data->id}"/>
    </td>
    <td>
        <input type="text" class="form-control updateElement " 
               value="{$data->cycle_day}" data-colName="cycle_day"  
               data-tableName="ivf_records" data-id="{$data->id}">
    </td>
    <td>
        <input type="text" class="form-control updateElement " 
               value="{$data->e2}" data-colName="e2"  
               data-tableName="ivf_records" data-id="{$data->id}">
    </td>
    <td>
        <input type="hidden"  id="ivfRecordsId" value="{$data->id}" >
        <table >
            <thead>
                <tr>
                    <th style="width: 200px;">Type
                        <a  class="btn green-haze btn-sm fright addIvfRecordDrug" id="addIvfRecordDrug{$data->id}" 
                            data-id="{$data->id}"  data-tableName="ivf_records_drugs"    
                            data-container="ivfRecordsDrugsContent{$data->id}"  >  
                            <i class="fa fa-plus"></i>  </a>
                    </th>
                    <th style="width: 260px;">Dose</th>
                    <th style="width: 40px;"></th>
                </tr>
            </thead>
            <tbody id="ivfRecordsDrugsContent{$data->id}"> </tbody>
        </table>
    </td>
    <td>
        <input type="text" class="form-control updateElement " 
               value="{$data->r_no}" data-colName="r_no"  
               data-tableName="ivf_records" data-id="{$data->id}">
    </td>
    <td>
        <input type="text" class="form-control updateElement " 
               value="{$data->r_size}" data-colName="r_size"  
               data-tableName="ivf_records" data-id="{$data->id}">
    </td>
    <td>
        <input type="text" class="form-control updateElement " 
               value="{$data->l_no}" data-colName="l_no"  
               data-tableName="ivf_records" data-id="{$data->id}">
    </td>
    <td>
        <input type="text" class="form-control updateElement " 
               value="{$data->l_size}" data-colName="l_size"  
               data-tableName="ivf_records" data-id="{$data->id}">
    </td>
    <td>
        <input type="text" class="form-control updateElement " 
               value="{$data->endo}" data-colName="endo"  
               data-tableName="ivf_records" data-id="{$data->id}">
    </td>

    <td>
        <a class="btn grey-cascade btn-xs deletemsgEX" data-id="{$data->id}"  data-tableName="ivf_records" 
           style=" float: left;" href="#" data-link="ivf_reports" data-fn="del">
            <i class="fa fa-close"></i>
        </a>
    </td>
</tr>



{else if $tableName == "ivf_drugs" || $tableName == "ivf_records_drugs" }
<tr>
    <td>
        <input type="hidden"  id="newDrudRowId" value="{$data->id}" >
        <input type="hidden"  id="drgName" value="{$drgName}" >
        <input type="hidden"  id="dosName" value="{$dosName}" >

        <select class="form-control xx dnameIvf  updateElement " id="{$drgName}{$data->id}" 
                data-id="{$data->id}" data-colName="drugid" data-tableName="{$tableName}" 
                data-itr="{$data->id}" data-placeholder="Select..." data-createNew="0" data-origin="{$origin}"   >
            <option value=""  >Choose Drug</option>
            {foreach $ivfDrugs as $drug}
            <option value="{$drug['id']}" >{$drug['drugname']} </option>
            {/foreach}
            <option class="deleteoptincompo" value=""   >Choose Drug</option>
        </select>
    </td>
    <td>
        <select class="form-control xx  updateElement ddosIvf" id="{$dosName}{$data->id}" 
                data-id="{$data->id}" data-colName="drugdos" data-tableName="{$tableName}" 
                data-itr="{$data->id}" data-placeholder="Select..."  >
            <option value=""  >choose dose </option>
            {foreach $allDrugDoses as $dos}
            <option value="{$dos['drugdos']}"  >{$dos['drugdos']}</option>
            {/foreach}
            <option class="deleteoptincompo" value=""   >choose dose </option>
        </select>
    </td>
    <td>
        <a class="btn grey-cascade btn-xs deletemsgEX" data-id="{$data->id}"  data-tableName="{$tableName}" 
           style=" float: left;" href="#" data-link="ivf_reports" data-fn="del">
            <i class="fa fa-close"></i>
        </a>
    </td>
</tr>
{/if}

{literal}
<script type="text/javascript" >
    var itr = $('#newDrudRowId').val();
    var drgName = $('#drgName').val();
    var dosName = $('#dosName').val();
    if ($().select2 && itr > 0)
    {
        $('#' + dosName + itr).select2({
            // width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                var thisId = $(this).attr("id");
                return "<input class='form-control' id='newddosIvfTerm' value='" + term + "'>\n\
                               <a href='#' id='addNewTableRow' data-id='" + thisId + "'  \n\
                                  class='btn blue custombtnstyle'>ADD</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNewTableRow', function () {
            /* add the new term */
            var newTerm = $('#newddosIvfTerm').val();
            var thisId = $(this).attr("data-id");
            $.post(hosturl + "/controllers/ivf_reports.php?ac=addnewrecord", {selectId: 'drugs'
                , new_name: newTerm, colname: "drugdos"
            }, function (data) {

                $('.ddosIvf > .deleteoptincompo').before('<option value="' + data + '" >' + newTerm + '</option>');
                $('#' + thisId + '').select2('val', data); // select the new term
                $('.ddosIvf').select2('close'); // close the dropdown
                $('.updateElement[id=' + thisId + ']').trigger("change");
            });
        });

        $('#' + drgName + itr).select2({
            // width: '240px',
            allowClear: true,
            formatNoMatches: function (term) {
                /* customize the no matches output */
                var thisId = $(this).attr("id");
                return "<input class='form-control' id='newdnameIvfTerm' value='" + term + "'>\n\
                               <a href='#' id='addNewTableRow' data-id='" + thisId + "'  \n\
                                  class='btn blue custombtnstyle'>ADD</a>"
            }
        }).parent().find('.select2-with-searchbox').on('click', '#addNewTableRow', function () {
            /* add the new term */
            var newTerm = $('#newdnameIvfTerm').val();
            var thisId = $(this).attr("data-id");
            $.post(hosturl + "/controllers/ivf_reports.php?ac=addnewrecord", {selectId: 'drugs'
                , new_name: newTerm, colname: "drugname"
            }, function (data) {

                $('.dnameIvf > .deleteoptincompo').before('<option value="' + Number(data) + '" >' + newTerm + '</option>');
                $('#' + thisId + '').select2('val', Number(data)); // select the new term
                $('.dnameIvf').select2('close'); // close the dropdown
                $('.updateElement[id=' + thisId + ']').trigger("change");
            });
        });



        $('#newDrudRowId').remove();
        $('#drgName').remove();
        $('#dosName').remove();
    }

    var ivfRecordsId = $('#ivfRecordsId').val();
    if (ivfRecordsId > 0)
    {
        $("#recordDate" + ivfRecordsId).datepicker();
        $("#addIvfRecordDrug" + ivfRecordsId).trigger('click');
        $('#ivfRecordsId').remove();
    }
</script>
{/literal}