// Radio buttons - sets value to hidden radio
$('#radioBtn a').on('click', function () {
    var sel = $(this).data('title');
    var tog = $(this).data('toggle');
    $('#' + tog).prop('value', sel).trigger('change');

    $('a[data-toggle="' + tog + '"]').not('[data-title="' + sel + '"]').removeClass('active').addClass('not-active');
    $('a[data-toggle="' + tog + '"][data-title="' + sel + '"]').removeClass('not-active').addClass('active');
    
})

$(document).ready(function () {
    //var $dialog = $('#videocall');

    //$dialog.dialog({
    //    autoOpen: false
    //});

    //$('#openVideo').on('click', function () {
    //    $dialog.dialog('open');
    //});
    $('.modal-content').resizable({
        alsoResize: "#videoCall",
        //minHeight: 150
    });
    $('#videoCall').draggable();

    $('#videoCall').on('show.bs.modal', function () {
        $(document).off('focusin.modal');
    });


});


$('#datepickern').on('changeDate', function (e) {
    $('#datepickerscan').datepicker('setDate', e.date);
});

$('#mWatchlist').on('click', function () {
    if ($('#mWatchlist').prop('checked')) {
        $('#mWatchSection').show();
    } else {
        $('#mWatchSection').hide();
    }
});
$('.moreinfocloseicon').on('click', function () {
    $('.detail_graph_backdrop_new').addClass('hide').removeClass('bd_in_new');
    $('.org_detail_box_close_btn').trigger('click');
});
$('#modalVIP').on('click', function () {
    if ($('#modalVIP').prop('checked')) {
        $('#mVIPSection').show();
    } else {
        $('#mVIPSection').hide();
    }
});


function DiagnosticsTemplate(Facility, FacilityId, Date) {
    
    var sess_key;
    var rowcount = $.trim($('#labTableRowCount').val());
    var tot_row = (Number(rowcount) + 1);
    var j = 1;
    var sess_data = FacilityId + "," + Facility + "," + Date;
    var ikey = 'row' + tot_row;
    
    sessionStorage.setItem(ikey, sess_data);

    var a = 'Lab';
    
    var value = "<tr id='t_" + ikey + "'><td>" + FacilityId + "</td><td>" + a + "</td><td>" + Date + "</td><td><button class='edit btn btn-default  btn-sm btn-add' onclick='scanedit(\"" + ikey + "\")'><i class='fa fa-pencil' aria-hidden='true'></i></button><button class='edit btn btn-default  btn-sm btn-add' onclick='deleteRow(\"" + tot_row + "\")'><i class='fa fa-trash' aria-hidden='true'></i></button></td></tr>";
    
    $('#tbl-scan > tbody:last').append(value);
    $('#labTableRowCount').val(tot_row);
}
//Prescription UI js

$('#setDurationUnit').on('click', function () {
    $('#DurationUnitToggle').show();
    $(this).hide();
});
$('#setDurationUnit_1').on('click', function () {
    $('#DurationUnitToggle_1').show();
    $(this).hide();
});
$("#duration_days_1, #duration_week_1, #duration_month_1,#duration_year_1,#duration_life_1").on('click', function () {
    $('#hndduration_1').val($(this).val()).trigger('change');
});

//$('#setTypeText').on('click', function () {
//    $('#tabTypeToggle').show();
//    $('#SelMedicineType').trigger('click');
//    $(this).hide();
//});
//$('#setStrengthText').on('click', function () {
//    $('#strengthToggle').show();
//    $(this).hide();
//});
//$('#setUnitsText').on('click', function () {
//    $('#unitsToggle').show();
//    $(this).hide();
//});

$('#presNotesSet').on('click', function () {
    $('#prescriptionNotesToggle').toggle();
});
$("#duration_days, #duration_week, #duration_month").on('click', function () {
    $('#hndduration').val($(this).val()).trigger('change');
});

//$("#fpago2").attr('checked', true).trigger('click');

$("#hndduration").change(function () {
    var dur = $(this).val();
    var durTxt;
    if (dur == 1) {
        durTxt = "Days";
    } else if (dur == 2) {
        durTxt = "Week";
    } else if (dur == 3) {
        durTxt = "Month";
    }
    $('#setDurationUnit').text(durTxt);
    $('#setDurationUnit').show();
    $('#DurationUnitToggle').hide();
});
$("#hndduration_1").change(function () {
    debugger;
    var dur = $(this).val();
    var durTxt;
    if (dur == 1) {
        durTxt = "Days";
    } else if (dur == 2) {
        durTxt = "Week";
    } else if (dur == 3) {
        durTxt = "Month";
    }
    else if (dur == 4) {
        durTxt = "Year";
    }
    else if (dur == 5) {
        durTxt = "Life Long";
    }
    $('#setDurationUnit_1').text(durTxt);
    $('#setDurationUnit_1').show();
    $('#DurationUnitToggle_1').hide();
});



$('#AlcText').on('click', function () {
    $('.ChkAlcoholOptions').show();
    $(this).hide();
});

$("#ChkAlcohol").change(function () {
    var ls = $(this).val();
    var lsTxt;
    if (ls == 1) {
        lsTxt = "Non Drinker";
    } else if (ls == 2) {
        lsTxt = "Rare";
    } else if (ls == 3) {
        lsTxt = "Social";
    } else if (ls == 4) {
        lsTxt = "Regular";
    } else if (ls == 5) {
        lsTxt = "Heavy";
    }
    $('#AlcText>span').text(lsTxt);
    $('#AlcText').show();
    $('.ChkAlcoholOptions').hide();
});

$('#smkText').on('click', function () {
    $('.smkChkOptions').show();
    $(this).hide();
});

$("#ChkSmoking").change(function () {
    var ls = $(this).val();
    var lsTxt;
    if (ls == 8517006) {
        lsTxt = "Iv'e quit";
    } else if (ls == 266919005) {
        lsTxt = "Don't Smoke";
    } else if (ls == 4.28061E+14) {
        lsTxt = "1-2/day";
    } else if (ls == 4.28041E+14) {
        lsTxt = "3-5/day";
    } else if (ls == 4.28071E+14) {
        lsTxt = "5-10/day";
    } else if (ls == 449868002) {
        lsTxt = "10/day";
    }
    $('#smkText>span').text(lsTxt);
    $('#smkText').show();
    $('.smkChkOptions').hide();
});

$('#ChkActText').on('click', function () {
    $('.ChkActOptions').show();
    $(this).hide();
});

$("#ChkActivity").change(function () {
    var ls = $(this).val();
    var lsTxt;
    if (ls == 1) {
        lsTxt = "Sedentary(low)";
    } else if (ls == 2) {
        lsTxt = "Moderately(normal)";
    } else if (ls == 3) {
        lsTxt = "Active(high)";
    } else if (ls == 4) {
        lsTxt = "Athletic(Very high)";
    }
    $('#ChkActText>span').text(lsTxt);
    $('#ChkActText').show();
    $('.ChkActOptions').hide();
});

$('#ChkFoodText').on('click', function () {
    $('.ChkFoodOptions').show();
    $(this).hide();
});

$("#ChkFood").change(function () {
    var ls = $(this).val();
    var lsTxt;
    if (ls == 1) {
        lsTxt = "Vegetarian";
    } else if (ls == 2) {
        lsTxt = "Non-Vegetarian";
    } else if (ls == 3) {
        lsTxt = "Eggetarian";
    } else if (ls == 4) {
        lsTxt = "Vegan";
    }
    $('#ChkFoodText>span').text(lsTxt);
    $('#ChkFoodText').show();
    $('.ChkFoodOptions').hide();
});

//Prescription UI js ends


$('#TestTemplate').change(function () { //.bind("change", function() {
    var t_date = $('#datepickern').val();
    if (!t_date) {
        $('#Pdatepickern').show();
        $('#Pdatepickern').fadeOut(8000);
        $('#Pdatepickern').html('Select Date');
        return false;
    }
    var tempid = $(this).val();
    var rowLen = $('#DiagnosticsTestTable').children().length;
    $('#TableRowCount').val(0);
    
    
    var t_arr = [];
    var rowcount = $.trim($('#TableRowCount').val());
    var tot_row = (Number(rowcount) + 1);
    var j = 1;
    for (j = 1; j <= rowLen; j++) {
            sessionStorage.removeItem('row' + j);
             $('#t_row'+j).remove();
    }
    
    //$('#DiagnosticsTestTable').remove();
    var i = 1;
    switch (tempid) {
        case '1':
            t_arr = ['Fasting Blood Sugar', 'Post Prandial Blood Sugar'];
            for (i = 1; i <= t_arr.length; i++) {
                DiagnosticsTemplate(1, t_arr[i-1], t_date);
            }
            break;
        case '2':
            t_arr = ['Fasting Blood Sugar', 'Post Prandial Blood Sugar', 'HbA1C'];
            for (i = 1; i <= t_arr.length; i++) {
                DiagnosticsTemplate(1, t_arr[i-1], t_date);
            }
            break;
        case '3':
            t_arr = ['Fasting Blood Sugar', 'Post Prandial Blood Sugar', 'HbA1C', 'Urea', 'Creatinine', 'Urine Albumin Creatinine Ratio'];
            for (i = 1; i <= t_arr.length; i++) {
                DiagnosticsTemplate(1, t_arr[i-1], t_date);
            }
            break;
        case '4':
            t_arr = ['Fasting Blood Sugar', 'Post Prandial Blood Sugar', 'HbA1C', 'Urea', 'Creatinine', 'Urine Albumin Creatinine Ratio', 'Lipid  Profile', 'LPT', 'Urine ACR'];
            for (i = 1; i <= t_arr.length; i++) {
                DiagnosticsTemplate(1, t_arr[i-1], t_date);
            }
            break;
        default:
            console.log('default');
    }

});

//scroll down arrow issue fix
//$(document).keydown(function(e){
//    switch (e.which){
//        case 37:    //left arrow key
//            $("#myMoreInfoModal .modal-content").finish().animate({
//                left: "-=50"
//            });
//            break;
//        case 38:    //up arrow key
//            $("#myMoreInfoModal .modal-content").finish().animate({
//                top: "-=50"
//            });
//            break;
//        case 39:    //right arrow key
//            $("#myMoreInfoModal .modal-content").finish().animate({
//                left: "+=50"
//            });
//            break;
//        case 40:    //bottom arrow key
//            alert('key down');
//            //document.getElementById('container').scrollTop = topPos - 10;
//            $(".modal-content").finish().animate({
//                top: "+=50"
//            });
//            break;
//    }
//});
