/// <reference path="../../../Pages/BaseFramework/TeacherDashBoard.aspx" />
/// <reference path="../../../Pages/BaseFramework/MyDashBoard.aspx" />
/// <reference path="../../../Pages/BaseFramework/MyDashBoard.aspx" />
var my_skins = ["skin-blue", "skin-black", "skin-red", "skin-yellow", "skin-purple", "skin-green"];

$(function () {

    //$("#ButtonSearch").click(function () {
    //    var row = "";
    //    $.ajax({
    //        type: "POST",
    //        url: "../../../Pages/BaseFramework/MyDashBoard.aspx/GetData",
    //        data: "{}",
    //        contentType: "application/json;charset=utf-8",
    //        dataType: "json",
    //        success: function (msg) {
    //            $.each(msg.d, function (index, obj) {
    //                row += "<tr><td>" + obj.FirstName + "</td><td>" + obj.Name + "</td></tr>";
    //            });
    //            $("#table1").append(row);
    //        }
    //    });

    //});
    //var Theme = $("<style type=text/css>.table-striped > tbody > tr:nth-of-type(odd) {background-color: #f9f9f9;} .table-bordered { border: 1px solid #ddd;}</style>")



    //var demo_Student = $("<div />").css({
    //    position: "fixed",
    //    top: "590px",
    //    right: "0",
    //    background: "#fff",

    //    "border-radius": "5px 0px 0px 5px",
    //    padding: "10px 15px",
    //    "font-size": "16px",
    //    "z-index": "99999",
    //    cursor: "pointer",
    //    color: "#3c8dbc",
    //    "box-shadow": "0 1px 3px rgba(0,0,0,0.1)"

    //}).html("<i class='fa fa-search ' ></i>");
    //var demo_settingsStudent = $("<div />").css({
    //    "padding": "10px",
    //    position: "fixed",
    //    top: "155px",
    //    right: "-600px",
    //    background: "#fff",
    //    border: "0px solid #ddd",
    //    "width": "600px",
    //    "z-index": "99999",
    //    "box-shadow": "0 1px 3px rgba(0,0,0,0.1)",
    //    height: "75%"
    //});
    //demo_settingsStudent.append("<h4 class='text-light-blue' style='margin: 0 0 5px 0; border-bottom: 1px solid #ddd; padding-bottom: 15px;'>Student Search</h4>"
    //    //    + "<div style=background-image:../../../Images/images.png;></div>"
    //    + "<div border: 1px solid #e9e9e9;background-color: #FFF;margin: 0 30px;> "
    //     + "  First Name &nbsp;&nbsp; <input type='text' style='width:25%;' Id='Nametext' placeholder='Name' required='required'> &nbsp;&nbsp;&nbsp;&nbsp;"
    //     + "Last Name &nbsp;&nbsp; <input type='text' style=width:25% Id='Name_text' placeholder='Surname'><br><br>"
    //     + " SUID &nbsp;&nbsp; <input type='text' style=width:25%;margin-left:35px; Id='SUIDtext' placeholder='SUID'> &nbsp;&nbsp;&nbsp;&nbsp;"
    //     + "  ID  <input type='text' style=width:25%;margin-left:55px Id='ID_text' placeholder='Id'><br><br>"
    //     + "<input type='checkbox' Id='CurrentBatch'>Current Batch Student"
    //     + " <input type='button' value='Search' style='margin-left:140px' Id='ButtonSearch'><input type='button' value='Reset' style='margin-left:10px' Id='ClearButton'></div>"
    //    + "<br> "
    //      //font-weight:800;font-family:
    //	+ "<div id='divStudent' style='border-radius: 4px;border: 1px solid;background-color:#fff;height:290px;font-size:14px;font-family: arial;overflow:scroll;' class='text-light-blue';>"

    //	+ "</div>"

    //);



    //var skins_list = $("<ul />", { "class": 'list-unstyled' });
    //demo_settingsStudent.append(skins_list);
    //demo_Student.click(function () {
    //    if (!$(this).hasClass("open")) {
    //        $(this).animate({ "right": "600px" });
    //        demo_settingsStudent.animate({ "right": "0" });
    //        $(this).addClass("open");

    //    } else {
    //        $(this).animate({ "right": "0" });
    //        demo_settingsStudent.animate({ "right": "-600px" });
    //        $(this).removeClass("open");
    //        //("#table").remove();
    //    }
    //});

    //$("body").append(demo_Student);
    //$("body").append(demo_settingsStudent);
    //$("body").append(Theme);
    var count = 0;
    $("#ButtonSearch").click(function () {
        count = 0;
        //LoadDataStudent();
        var check = 0;
        if ($("#CurrentBatch").is(':checked')) {
            check = 1;
        }
        else {
            check = 0;
        }


        if ($('#Nametext').val() != '') {
            count++;
        }
        if ($("#MiddleNameText").val() != '') {
            count++;
        }
        if ($('#Name_text').val() != '') {
            count++;
        }
        if ($("#SUIDtext").val() != '') {
            count++;
        }
        if ($("#ID_text").val() != '') {
            count++;
        }
        if ($("#ContactNoText").val() != '') {
            count++;
        }
        // changes for Mantis Id :35145
        if ($("#MasterStudentAutoSearchTextBox").val() != '') {
            count++;
        }
        //    if ($(this).val() != '') {
        //        count++;

        //    }
        //})

        if (count == 0) {
            $('#Nametext').css('border-color', 'red');
            $('#Name_text').css('border-color', 'red');
            $('#MiddleNameText').css('border-color', 'red');
            $('#SUIDtext').css('border-color', 'red');
            $('#ID_text').css('border-color', 'red');
            $('#ContactNoText').css('border-color', 'red');
            $('#MasterStudentAutoSearchTextBox').css('border-color', 'red');
            alert('Enter any one criteria');
            return;
        }


        $.ajax({
            url: '/Pages/BaseFramework/MyDashBoard.aspx/GetData',
            type: 'POST',
            data: "{ FirstName:'" + $("#Nametext").val() + "',LastName: '" + $("#Name_text").val() + "',SUID:'" + $("#SUIDtext").val() + "',ID: '" + $("#ID_text").val() + "',Batch:" + check + ",MiddleName:'" + $("#MiddleNameText").val() + "',ContactNo: '" + $("#ContactNoText").val() + "',StudentAutoSearch:'" + $("#MasterStudentAutoSearchTextBox").val() + "'}",
            contentType: 'application/json;charset=utf-8',
            dataType: 'json',
            success: function (data) {
                $("#divStudent").html('');
                var tableData = '<table border="1"  width="100%"   Id="Table_"><tr> <td width="20%" style="background:grey;color:#fff;">Name</td>' + '<td style="background:grey;color:#fff;">Class</td>';

                var datas = $.parseJSON(data.d);

                if (datas[0].SUIDConfig == "False") {
                    if (document.getElementById('ContactNos').checked)
                        tableData += '<td style="background:grey;color:#fff;">' + datas[0].IDConfigValue + '</td><td style="background:grey;color:#fff;">Roll No</td><td style="background:grey;color:#fff;">Batch</td><td style="background:grey;color:#fff;">Organization</td><td style="background:grey;color:#fff;">Status</td><td style="background:grey;color:#fff;">Contact No.</td></tr>';
                    else
                        tableData += '<td style="background:grey;color:#fff;">' + datas[0].IDConfigValue + '</td><td style="background:grey;color:#fff;">Roll No</td><td style="background:grey;color:#fff;">Batch</td><td style="background:grey;color:#fff;">Organization</td><td style="background:grey;color:#fff;">Status</td></tr>';
                }
                else {
                    if (document.getElementById('ContactNos').checked)
                        tableData += '<td style="background:grey;color:#fff;">' + datas[0].IDConfigValue + '</td><td style="background:grey;color:#fff;">Roll No</td><td style="background:grey;color:#fff;">Batch</td><td style="background:grey;color:#fff;">Organization</td><td style="background:grey;color:#fff;">Status</td><td style="background:grey;color:#fff;">Contact No.</td></tr>';
                    else
                        tableData += '<td style="background:grey;color:#fff;">' + datas[0].IDConfigValue + '</td><td style="background:grey;color:#fff;">Roll No</td><td style="background:grey;color:#fff;">Batch</td><td style="background:grey;color:#fff;">Organization</td><td style="background:grey;color:#fff;">Status</td></tr>';
                }

                if (datas[0].Is360Permission == "True")
                    tableData = tableData.replace("</tr>", "<td style='background:grey;color:#fff;'></td></tr>");

                for (var i = 0; i < datas.length; i++) {
                    tableData += '<tr><td style="color:Black;">' + datas[i].Name + '</td><td style="color:Black;">' + datas[i].Standard;
                    if (datas[0].IsStudentDetailFormPermission == "False") {
                        if (datas[0].Is360Permission == "False") {
                            if (datas[0].SUIDConfig == "False") {
                                if (document.getElementById('ContactNos').checked)
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;">' + datas[i].Code + '</td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td><td style="color:black;" >' + datas[i].ContactNo + '</td></tr>';
                                else
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;">' + datas[i].Code + '</td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td></tr>';
                            }
                            else {
                                if (document.getElementById('ContactNos').checked)
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;">' + datas[i].Code + '</td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td><td style="color:black;" >' + datas[i].ContactNo + '</td></tr>';
                                else
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;">' + datas[i].Code + '</td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td></tr>';
                            }
                        }
                        else {
                            if (datas[0].SUIDConfig == "False") {
                                if (document.getElementById('ContactNos').checked)
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;">' + datas[i].Code + '</td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td><td style="color:black;" >' + datas[i].ContactNo + '</td><td style="color:black;" ><a style="color: #03afc5 !important;" onclick=\'window.open("../../Pages/StudentManagement/Student360View.aspx?AcademicId=' + datas[i].AcademicId + '", "Student View", "height=600,width=900,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes");\'>360 View</a></td></tr>';
                                else
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;">' + datas[i].Code + '</td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td><td style="color:black;" ><a style="color: #03afc5 !important;" onclick=\'window.open("../../Pages/StudentManagement/Student360View.aspx?AcademicId=' + datas[i].AcademicId + '", "Student View", "height=600,width=900,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes");\'>360 View</a></td></tr>'
                            }
                            else {
                                if (document.getElementById('ContactNos').checked)
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;">' + datas[i].Code + '</td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td><td style="color:black;" >' + datas[i].ContactNo + '</td><td style="color:black;" ><a style="color: #03afc5 !important;" onclick=\'window.open("../../Pages/StudentManagement/Student360View.aspx?AcademicId=' + datas[i].AcademicId + '", "Student View", "height=600,width=900,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes");\'>360 View</a></td></tr>'
                                else
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;">' + datas[i].Code + '</td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td><td style="color:black;" ><a style="color: #03afc5 !important;" onclick=\'window.open("../../Pages/StudentManagement/Student360View.aspx?AcademicId=' + datas[i].AcademicId + '", "Student View", "height=600,width=900,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes");\'>360 View</a></td></tr>'
                            }
                        }
                    }
                    else {
                        if (datas[0].Is360Permission == "False") {
                            if (datas[0].SUIDConfig == "False") {
                                if (document.getElementById('ContactNos').checked)
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;"><a style="color: #03afc5 !important;" onclick=\'StudentDetailFormRedirect(' + datas[i].StudentId + ',' + datas[i].OrgId + ',' + datas[i].BatchId + ')\'>' + datas[i].Code + '</a></td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td><td style="color:black;" >' + datas[i].ContactNo + '</td></tr>';
                                else
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;"><a style="color: #03afc5 !important;" onclick=\'StudentDetailFormRedirect(' + datas[i].StudentId + ',' + datas[i].OrgId + ',' + datas[i].BatchId + ')\'>' + datas[i].Code + '</a></td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td></tr>';
                            }
                            else {
                                if (document.getElementById('ContactNos').checked)
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;"><a style="color: #03afc5 !important;" onclick=\'StudentDetailFormRedirect(' + datas[i].StudentId + ',' + datas[i].OrgId + ',' + datas[i].BatchId + ')\'>' + datas[i].Code + '</a></td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td><td style="color:black;" >' + datas[i].ContactNo + '</td></tr>';
                                else
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;"><a style="color: #03afc5 !important;" onclick=\'StudentDetailFormRedirect(' + datas[i].StudentId + ',' + datas[i].OrgId + ',' + datas[i].BatchId + ')\'>' + datas[i].Code + '</a></td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td></tr>';
                            }
                        }
                        else {
                            if (datas[0].SUIDConfig == "False") {
                                if (document.getElementById('ContactNos').checked)
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;"><a style="color: #03afc5 !important;" onclick=\'StudentDetailFormRedirect(' + datas[i].StudentId + ',' + datas[i].OrgId + ',' + datas[i].BatchId + ')\'>' + datas[i].Code + '</a></td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td><td style="color:black;" >' + datas[i].ContactNo + '</td><td style="color:black;" ><a style="color: #03afc5 !important;" onclick=\'window.open("../../Pages/StudentManagement/Student360View.aspx?AcademicId=' + datas[i].AcademicId + '", "Student View", "height=600,width=900,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes");\'>360 View</a></td></tr>';
                                else
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;"><a style="color: #03afc5 !important;" onclick=\'StudentDetailFormRedirect(' + datas[i].StudentId + ',' + datas[i].OrgId + ',' + datas[i].BatchId + ')\'>' + datas[i].Code + '</a></td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td><td style="color:black;" ><a style="color: #03afc5 !important;" onclick=\'window.open("../../Pages/StudentManagement/Student360View.aspx?AcademicId=' + datas[i].AcademicId + '", "Student View", "height=600,width=900,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes");\'>360 View</a></td></tr>'
                            }
                            else {
                                if (document.getElementById('ContactNos').checked)
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;"><a style="color: #03afc5 !important;" onclick=\'StudentDetailFormRedirect(' + datas[i].StudentId + ',' + datas[i].OrgId + ',' + datas[i].BatchId + ')\'>' + datas[i].Code + '</a></td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td><td style="color:black;" >' + datas[i].ContactNo + '</td><td style="color:black;" ><a style="color: #03afc5 !important;" onclick=\'window.open("../../Pages/StudentManagement/Student360View.aspx?AcademicId=' + datas[i].AcademicId + '", "Student View", "height=600,width=900,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes");\'>360 View</a></td></tr>'
                                else
                                    tableData += '</td><td style="color:Black;overflow-wrap:anywhere;"><a style="color: #03afc5 !important;" onclick=\'StudentDetailFormRedirect(' + datas[i].StudentId + ',' + datas[i].OrgId + ',' + datas[i].BatchId + ')\'>' + datas[i].Code + '</a></td><td style="color:Black;">' + datas[i].RollNo + '</td><td style="color:black;">' + datas[i].BatchName + '</td><td style="color:black;">' + datas[i].Organization + '</td><td style="color:black;" >' + datas[i].StatusName + '</td><td style="color:black;" ><a style="color: #03afc5 !important;" onclick=\'window.open("../../Pages/StudentManagement/Student360View.aspx?AcademicId=' + datas[i].AcademicId + '", "Student View", "height=600,width=900,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,modal=yes");\'>360 View</a></td></tr>'
                            }
                        }
                    }
                }
                tableData += '</table>';
                $('#divStudent').append(tableData);
                $("#Table_").addClass("table table-striped table-bordered gridviewfont");
                $("#Table_").css("margin-left", "-15px")
            }
        });
    });




    $("#ClearButton1").click(function () {
        $("#Nametext").val("");
        $("#MiddleNameText").val("");
        $("#Name_text").val("");
        $("#SUIDtext").val("");
        $("#ID_text").val("");
        $("#ContactNoText").val("");
        $("#MasterStudentAutoSearchTextBox").val("");
        $("#divStudent").html('');
    });

    //setup();
});

function ClickFor() {
    //LoadingMsg('Loading Details', '<b>Please Wait ...</b>');
    //window.setTimeout(function () {
    //CloseLoading();
    //$('.hls-bg').show();
    $('#searchnewpopup').slideDown("slow", function () {
    });
    //    $('#targetId').hide();
    //}, 500);
}

function CloseLoading() {
    $('.hls-bg').hide();
    $('#dvMainLoadingmsg').hide();
}
function Closepopup1() {
    $('.hls-bg').hide();
    $('#searchnewpopup').hide();
    $("#dvHDpopup").hide();
    $('#targetId').show();
}
function LoadingMsg(msg1, msg2) {
    $('.hls-bg').show();
    $('#spnmain1msg').html(msg1);
    $('#spnmain2msg').html(msg2);
    $('#dvMainLoadingmsg').show();
}

function ClickHD() {

    //LoadingMsg('Loading Details', '<b>Please Wait ...</b>');
    //window.setTimeout(function () {
    //    CloseLoading();
    //$('.hls-bg').show();
    $('#dvHDpopup').show();
    //$('#targetId').hide();
    LoadData();
    //}, 500);
}

function LoadData() {
    var Screenid = $('#ctl00_HiddenField_Id').val();
    var getdataUrl = "http://support.vidyalayaschoolsoftware.com/api/ModuleData?Screenid=";
    //$.ajax({
    //    type: "POST",
    //    url: getdataUrl,
    //    data: {},
    //    contentType: "application/json; charset=utf-8",
    //    dataType: "json",
    //    success: function(response) {
    //        //alert(response.d);
    //        var Employees = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
    //        //alert(Employees);
    //        $("#div1").empty();
    //        alert(Employees.length);
    //        for (var i = 0; i < Employees.length; i++) {
    //            $('#div1').append('<p><strong>' + Employees[i].Id + ' ' +
    //                          Employees[i].Name + '</strong><br />'+
    //                           '</p>');
    //        }
    //    },
    //    failure: function(msg) {
    //        $('#div1').text(msg);
    //    }
    //}); 
    var apiUrl = $("#ctl00_DeskHiddenField").val();
    $.getJSON(getdataUrl + Screenid,
        function (Data) {
            $("#div1").empty();
            uri = $.parseJSON(Data);
            var htmlText = '';
            for (var key in uri) {
                htmlText += "<i class='fa fa-hand-o-right' style='padding-left:10px;'></i> <a target='_blank' id='Key_' style='padding-left:10px;'  href='" + apiUrl + "Home/ArticleModuleData?i=" + uri[key].Url + "'>" + uri[key].Value + "</a> </a></br>";
            }
            $("#div1").append(htmlText);
        });
}

function LoadData1() {


    var uri = [{ "Url": "999900044", "Value": "repeat article tes" }, { "Url": "https://www.google.co.in", "Value": "Test" }, { "Url": "https://www.google.co.in", "Value": "Test" }, { "Url": "https://www.google.co.in", "Value": "Test" }];

    //$.getJSON(uri, function(data){ 

    //$.each(uri, function (key, item) { 
    var htmlText = '';

    for (var key in uri) {
        htmlText += "<i class='fa fa-hand-o-right' style='padding-left:10px;'></i><a target='_blank' style='padding-left:10px;'  href='" + uri[key].Url + "'>" + uri[key].Value + "</a> </br>";
    }

    $("#div1").append(htmlText);
    //}); 





}

function LoadDataStudent() {

    var tableData = '';
    $("#divStudent").html('');
    var data = [
        {
            Organization: "Organization",
            Batch: "Batch",
            SUID: "SUID",
            RollNo: "RollNo", Class: "Class", Name: "Name", Status: "Status"
        }];

    tableData = '<table border="1"><tr><td>Organization</td><td>Batch</td><td>SUID</td><td>RollNo</td><td>Class</td><td>Name</td></tr>';
    for (var i = 0; i < data.d.length; i++) {
        tableData += '<tr><td>' + data.d[i].Name + '</td><td>' + data.d[i].Batch + '</td><td>' + data.d[i].SUID + '</td><td>' + data.d[i].RollNo + '</td><td>' + data.d[i].Class + '</td><td>' + data[i].Name + '</td></tr>';
    }

    tableData += '</table>';
    $('#divStudent').append(tableData);
}

function opensearchScreendetail() {
    $.ajax(
        {
            type: "POST",
            url: '/Pages/BaseFramework/MyDashBoard.aspx/SearchscreenDetail',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                $('#Scrrensearchdetail').html('');
                $('#Scrrensearchdetail').append($.parseHTML(data.d));
            },
            error: function (data) {
                // alert(data.status + " " + data.statusText + "</br>" + data.responseText);
            }
        });
}

function opensearchScreenDependency() {
    $.ajax(
        {
            type: "POST",
            url: '/Pages/BaseFramework/MyDashBoard.aspx/SearchDependency',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                $('#ScrrensearchdetailExtra').html('');
                $('#ScrrensearchdetailExtra').append($.parseHTML(data.d));
            },
            error: function (data) {
                //alert("Not working");
            }
        });
}

document.addEventListener('keydown', function (e) {
    var path = window.location.pathname;
    var page = path.split("/").pop();
    if (page != 'StudentDetailForm.aspx' && page != 'FeeReceipt.aspx' && page != 'EmployeeDetailForm.aspx' && page != 'StockIssueStudent.aspx') {
        var tag = $(e.target).attr("id");
        var tag1 = $(e.target).attr('class');
        if (tag1 == "studentautosearchitem" && (e.keyCode == 37 || e.keyCode == 38 || e.keyCode == 39 || e.keyCode == 40)) {
            switch (e.keyCode) {
                case 37: case 39: case 38: case 40: e.preventDefault();
            }
        }
        if ((tag == "MasterStudentAutoSearchTextBox" || e.keyCode == 13) || (e.keyCode == 13 || tag1 == "studentautosearchitem")) {
            Focus();
        }
    }
});

$(document).mouseup(function (e) {
    var container = $("#MasterAutoSearchSuggestion");

    // if the target of the click isn't the container nor a descendant of the container
    if (!container.is(e.target) && container.has(e.target).length === 0) {
        document.getElementById("MasterAutoSearchSuggestion").hidden = true;
    }
});

function StudentAutoSearchNavigate(e) {
    var tag = $(event.target).attr("id");
    var tag1 = $(event.target).attr('class');
    switch (event.keyCode) {
        case 37: case 39: case 38: case 40: event.preventDefault();
    }
}

function MasterSearch(obj) {
    if ($(obj).val().length > 1) {
        $.ajax({
            type: "POST",
            url: "/Pages/BaseFramework/MyDashBoard.aspx/SearchStudent",
            data: '{"SearchValue":"' + $(obj).val() + '"}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                document.getElementById("MasterAutoSearchSuggestion").hidden = false;
                document.getElementById("MasterAutoSearchSuggestion").innerHTML = data.d;
            },
            error: function (jqXHR, Status, errorMsg) {

            }
        });
    }
    else {
        document.getElementById("MasterAutoSearchSuggestion").hidden = true;
    }
}

function Focus() {
    var keyCode = window.event.keyCode;
    if (keyCode !== 38 && keyCode !== 40 && keyCode !== 13) return;

    var current = document.activeElement;
    let items = [];
    for (i = 0; i < document.getElementsByClassName('studentautosearchitem').length; i++) {
        items[i] = document.getElementsByClassName('studentautosearchitem')[i];
    }
    var currentIndex = items.indexOf(current);
    var newIndex;

    if (currentIndex !== -1 && keyCode == 13) {
        MasterselectStudent(items[currentIndex].innerHTML, true);
    }
    else {
        if (currentIndex === -1) {
            newIndex = 0
        } else {
            if (keyCode === 38) newIndex = (currentIndex + items.length - 1) % items.length
            else newIndex = (currentIndex + 1) % items.length
        }
        items[newIndex].focus();
    }
}

function MasterselectStudent(val, IsEnter) {
    $("#MasterStudentAutoSearchTextBox").val(val);
    var str = $("#MasterStudentAutoSearchTextBox").val();
    if (!IsEnter)
        str = str.substring(0, str.length - 1);

    $("#MasterStudentAutoSearchTextBox").val(str);
    document.getElementById("MasterAutoSearchSuggestion").hidden = true;
    $("#ButtonSearch").click();
}

function StudentDetailFormRedirect(StudentId, OrgId, BatchId) {
    var MasterOrgDropdown = document.getElementById('ctl00_MasterPageOrganizationDropDownList');
    var MasterBatchDropdown = document.getElementById('ctl00_MasterPageBatchDropDownList');
    if (MasterOrgDropdown.value == OrgId && MasterBatchDropdown.value == BatchId) {
        sessionStorage.removeItem('StudentId_Name');
        sessionStorage.setItem('StudentId_Name', StudentId);
        window.location = "/Pages/StudentManagement/StudentDetailForm.aspx?StudentId=" + StudentId;
    }
    else {
        MasterOrgDropdown.value = OrgId; // Set new value
        MasterBatchDropdown.value = BatchId; // Set new value
        //mantis: 42212
        sessionStorage.removeItem('StudentId_Name');
        sessionStorage.setItem('StudentId_Name', StudentId);
        __doPostBack('ctl00_MasterPageOrganizationDropDownList', "{'StudentId': " + StudentId + ",'OrgId':" + OrgId + ",'BatchId': " + BatchId + "}");

        //if (StudentId > 0 && OrgId > 0 && BatchId > 0) {
        //    $.ajax({
        //        type: "POST",
        //        url: "/Pages/BaseFramework/MyDashBoard.aspx/ChangeOrg",
        //        data: '{"OrgId":"' + OrgId + '","BatchId":"' + BatchId + '","StudentId":"' + StudentId + '"}',
        //        contentType: "application/json; charset=utf-8",
        //        dataType: "json",
        //        success: function (data) { if (data.d == "success") { window.location = "/Pages/StudentManagement/StudentDetailForm.aspx?StudentId=" + StudentId; } },
        //        error: function (jqXHR, Status, errorMsg) { }
        //    });
        //}
    }
}