<%@ page language="C#" autoeventwireup="true" inherits="Pages_MobileView_TopperStudentAnalysis, App_Web_pifj025g" masterpagefile="~/Pages/Common/MasterPages/MobileViewMasterPage.master" enableEventValidation="false" viewStateEncryptionMode="Never" %>

<asp:Content ID="Content1" ContentPlaceHolderID="CP" runat="Server">
    <script>
        var GroupId;
        var BatchId;
        var DepartmentId;
        var classId;
        var DivisionId;
        var statusId;
        var ExamSubGroupId;
        var Header = [];
        var ReHeader;
        var NoOfTopStudent;
        var GroupLevelName;
        //var ClassId;

        $(document).ready(function () {
            var myurl = window.location.href;
            var keyval = myurl.split('?')[1].split('&');
            OrgId = parseInt(keyval[0].split('=')[1].toString());
            Id = OrgId = parseInt(keyval[0].split('=')[1].toString());
            BatchId = parseInt(keyval[1].split('=')[1].toString());
            ExamSubGroupId = parseInt(keyval[2].split('=')[1].toString());

            $.ajax({
                type: "POST",
                url: "BrightStudentList.aspx/GetOrgId",
                data: JSON.stringify({ "Id": Id }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    Header[0] = "<h5 class='page-title'><a href='#' onclick='dashboardpage()'>" + obj[0].Title + "</a></h5>" +
                    " <h5 class='page-title' ><a href='#' onclick='PageName()'>Bright Student List</a></h5>";
                    $("#HeaderLabel").text("Assessment Dashboard");
                    document.getElementById("HeaderTitle").innerHTML = Header;
                    ReHeader = document.getElementById("HeaderTitle").innerHTML;
                }
            });

            GroupLevelName = $("#drpGroup").children("option").filter(":selected").text()
            GroupFunction();
        });
        function PageName() {
            window.location.href = "../MobileView/AssessmentDetailDashboard.aspx?OrgId=" + Id;
        }

        function BrightStudentDataBind(BatchId, ExamSubGroupId, GroupId, NoOfTopStudent) {
            $.ajax({
                type: "POST",
                url: "BrightStudentList.aspx/BrightStudentListGet",
                data: JSON.stringify({ "BatchId": parseInt(BatchId), "ExamSubGroupId": parseInt(ExamSubGroupId), "GroupId": parseInt(GroupId), "NoOfTopStudent": parseInt(NoOfTopStudent) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblBright = "";
                    var alreadyAdded = [];
                    if (obj != "") {
                        tblBright += "<tr><th>Class</th><th>Rank</th><th>ID No</th><th>Roll No</th><th>Name</th><th>Marks</th><th>Obtained</th><th>Grade</th><th>Per %</th></tr>";

                        $.each(obj, function (j, item1) {

                            if (alreadyAdded.indexOf(item1.GroupName) >= 0)
                            { }
                            else
                            {
                                //if (GroupLevelName === "Class Level")
                                //{
                                //    tblBright += "<tr><th colspan='9'>" + item1.GroupTitle + " : " + item1.GroupName + "</th></tr>";
                                //    $.each(obj, function (i, item) {
                                //        if (item.Class == item1.Class) {
                                //            tblBright += "<tr><td>" + item.Class + "</td><td>" + item.rn + "</td><td>" + item.Code + "</td><td>" + item.RollNo + "</td><td>" + item.Name +
                                //                "</td><td>" + item.TotalMarks + "</td><td>" + item.TotalObtain + "</td><td>" + item.ResultGrade + "</td><td>" + item.Percentage + "</td></tr>";
                                //        }
                                //        else {
                                //        }
                                //    });
                                //    alreadyAdded.push(item1.Class);
                                //}
                                tblBright += "<tr><th colspan='9'>" + item1.GroupTitle + " : " + item1.GroupName + "</th></tr>";
                                $.each(obj, function (i, item) {
                                    if (item.GroupId === item1.GroupId) {
                                        tblBright += "<tr><td>" + item.Class + "</td><td>" + item.rn + "</td><td>" + item.Code + "</td><td>" + item.RollNo + "</td><td>" + item.Name +
                                            "</td><td>" + item.TotalMarks + "</td><td>" + item.TotalObtain + "</td><td>" + item.ResultGrade + "</td><td>" + item.Percentage + "</td></tr>";
                                    }
                                    else {
                                    }
                                });
                                alreadyAdded.push(item1.GroupName);
                            }

                        });

                        document.getElementById("HeaderTitle").innerHTML = Header;
                        ReHeader = document.getElementById("HeaderTitle").innerHTML;
                    }
                    else { tblBright += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblBright").innerHTML = tblBright;
                    document.getElementById("BrightHead").style.display = "block";
                    statusId = 1;
                }
            });
        }

        function dashboardpage() {
            window.location.href = "../MobileView/AssessmentDetailDashboard.aspx?OrgId=" + Id;
        }

        function BackOrgFunction() {
            window.location.href = "../MobileView/AssessmentDetailDashBoard.aspx?OrgId=" + Id;
        }

        function GroupFunction() {
            GroupId = $("#drpGroup").val();
            sessionStorage.setItem('GroupId', GroupId);
            $("#drpGroup").val(GroupId);
            NoOfTopStudentFunction();
        }

        function NoOfTopStudentFunction() {
            NoOfTopStudent = $("#drpNoOfTopStudent").val();
            sessionStorage.setItem('NoOfTopStudent', NoOfTopStudent);
            $("#drpNoOfTopStudent").val(NoOfTopStudent);
            BrightStudentDataBind(BatchId, ExamSubGroupId, GroupId, NoOfTopStudent);
        }

        function DashBoard() { window.location.href = "../MobileView/DashBoard.aspx"; }
    </script>
    <asp:UpdatePanel ID="DoctorScheduleUpdatePanel" runat="server">
        <ContentTemplate>
               <div class="col-md-12 ptb12 d-inline-flex">
                        <span class='btn btn-home btn-icon' onclick='DashBoard()' title='home'><span><i class='material-icons'>home</i></span></span>
                        <label class="header-topic justify-content-center" id="HeaderLabel"></label>
                        <input type="button" value="&#xf3e5;" id="bntBackOrg" onclick="BackOrgFunction()" skinid="0" class="float-right btn btn-back btn-icon fas" />
                    </div>
            <div class="top-btn col-md-12">
                <div class="custom-select">
                    <div class='fLeft pRight5'>
                        <select id='drpNoOfTopStudent' onchange="NoOfTopStudentFunction()">
                            <option value='1'>Top 1</option>
                            <option selected="selected" value='3'>Top 3</option>
                            <option value='5'>Top 5</option>
                            <option value='10'>Top 10</option>
                        </select>
                    </div>
                </div>
                <div class="custom-select">
                    <div class='fLeft pRight5'>
                        <select id='drpGroup' onchange="GroupFunction()">
                            <option value='1'>Division Level</option>
                            <option selected="selected" value='2'>Class Level</option>
                            <option value='3'>Department Level</option>
                            <option value='4'>Organization Level</option>
                        </select>
                    </div>
                </div>
            </div>
             <div class="page-header mb37">
                <div class="col-xl-12 col-sm-12 col-xs-12 border-bottom-inline xs-padd0">
                    <div class="main-topic inner" id="HeaderTitle">
                    </div>
                </div>
            </div>

            <div class="bg-white row center-block">
                <div class="container-fluid">
                    <div class="gutters-tiny push js-appear-enabled animated fadeIn overflow-hidden" data-toggle="appear">
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="BrightHead" style="display: none">
                            <h3 class="table-topic">Bright Student List</h3>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblBright' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
