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

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

        $(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());
            DepartmentDataBind(Id, BatchId, ExamSubGroupId);

        });
        function PageName() {
            window.location.href = "../MobileView/AssessmentDetailDashboard.aspx?OrgId=" + Id;
        }
        function HeaderDisplay(id) {
            if (id == 1) {
                document.getElementById("DepartHead").style.display = "block";
                document.getElementById("ClassHead").style.display = "none";
                document.getElementById("DivisionHead").style.display = "none";
                document.getElementById("StudentHead").style.display = "none";
                $("#Depart").hide();
                $("#division").hide();
                $("#class").hide();
                document.getElementById("HeaderTitle").innerHTML = ReHeader;
                Header = [];
            }
            else if (id == 2) {
                document.getElementById("DepartHead").style.display = "none";
                document.getElementById("ClassHead").style.display = "block";
                document.getElementById("DivisionHead").style.display = "none";
                document.getElementById("StudentHead").style.display = "none";
                $("#Student").hide();
                $("#Depart").show();
                $("#division").hide();
                $("#class").hide();
                var h1 = [Header[0], Header[1]];
                Header = h1;
            }
            else if (id == 3) {
                document.getElementById("DepartHead").style.display = "none";
                document.getElementById("ClassHead").style.display = "none";
                document.getElementById("DivisionHead").style.display = "block";
                document.getElementById("StudentHead").style.display = "none";
                $("#Depart").show();
                $("#division").hide();
                $("#class").show();
            }
        }

        function DepartmentDataBind(Id, BatchId, ExamSubGroupId) {
            $.ajax({
                type: "POST",
                url: "TopperStudentAnalysis.aspx/DeptWiseTopStdGet",
                data: JSON.stringify({ "OrgId": Id, "BatchId": parseInt(BatchId), "ExamSubGroupId": parseInt(ExamSubGroupId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tlbDepartment = "";
                    var total = 0;
                    var finaltotal = 0;
                    if (obj != "") {
                        Header[0] = "<h3 class='page-title text-muted'><a href ='#' onclick='dashboardpage()'>Assessment Dashboard</a></h3>" +
                                    "<div class='cBoth'></div>" + " <h5 class='page-title' ><a href='#' onclick='PageName()'>Topper Student Analysis</a></h5>";
                        document.getElementById("HeaderTitle").innerHTML = Header;
                        ReHeader = document.getElementById("HeaderTitle").innerHTML;

                        var newObj = {};
                        var keyCount=0;
                        tlbDepartment += "<tr>";
                        for (var item in obj[0]) {
                            var columnsIn = obj[0][item];
                            if (columnsIn.key === "GroupId") { continue; }
                            else if (columnsIn.key == "GroupTitle") { continue; }
                            else if (columnsIn.key == "GroupName" || columnsIn.key == "Department Name") {
                                newObj[keyCount++] = { "Department Name": "Total" };
                                tlbDepartment += "<th>Department Name</th>";
                            }
                            else {
                                tlbDepartment += "<th>" + columnsIn.key + "</th>";
                                newObj[keyCount] = {};
                                newObj[keyCount++][columnsIn.key] = 0;
                            }
                        }
                       
                        tlbDepartment += "<th>Total</th></tr>";
                        keyCount = 1;
                        $.each(obj, function (i, item) {
                            tlbDepartment += "<tr>";
                            var groupId = "";
                            var groupname = "";
                            for (var key in item) {
                                if(item[key].key === "GroupId")
                                {
                                    groupId = item[key].value;
                                }
                                if (item[key].key === "GroupName") {
                                    groupname = item[key].value;
                                }
                            }
                            for (var key in item) {
                                if (item[key].key !== "GroupId") {
                                    if (item[key].key === "GroupName") {
                                        if (item[key].value !== "null" && item[key].value !== undefined && item[key].value !== null) {
                                            tlbDepartment += "<td><a onclick='ClassDataBind(" + groupId + ",\"" + groupname + " \")'>" + item[key].value + "</a></td>";
                                        }
                                    }
                                    if (item[key].key !== "GroupTitle") {
                                        if (item[key].key !== "GroupName") {
                                            if (item[key].value === null || item[key].value === undefined) { item[key].value = 0; }
                                            tlbDepartment += "<td>" + item[key].value + "</td>";
                                            
                                            if (item[key].key !== "Department Name" && item[key].key !== "GroupName")
                                            {
                                                if (item[key].value !== "null" && item[key].value !== undefined && item[key].value !== null) {
                                                    for (var key1 in newObj[keyCount]) {
                                                        if (item[key].key == key1)
                                                        {
                                                            newObj[keyCount][key1] += parseInt(item[key].value)
                                                        }
                                                        keyCount++;
                                                    }
                                                    total += parseInt(item[key].value);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            tlbDepartment += "<td>" + total + "</td></tr>";
                            keyCount = 1;
                            finaltotal += total;
                            total = 0;
                        });
                        tlbDepartment += "<tr>";
                        for (var item in newObj) {
                            var columnsIn = newObj[item];
                            for (var key in columnsIn) {
                                if (key === "GroupId") { continue; }
                                else if (key == "GroupTitle") { continue; }
                                else if (key == "Department Name") {
                                    tlbDepartment += "<th>" + columnsIn[key] + "</th>";
                                }
                                else {
                                    tlbDepartment += "<th>" + columnsIn[key] + "</th>";
                                }
                            }
                        }
                        tlbDepartment += "<th>" + finaltotal + "</th></tr>";
                    }
                    else { tlbDepartment += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblDepartment").innerHTML = tlbDepartment;
                    document.getElementById("DepartHead").style.display = "block";
                    statusId = 1;
                }
            });
        }

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

        function ClassDataBind(GroupId, GroupName) {
            $.ajax({
                type: "POST",
                url: "TopperStudentAnalysis.aspx/ClassWiseTopStdGet",
                data: JSON.stringify({ "OrgId": OrgId, "BatchId": parseInt(BatchId), "DepartId": parseInt(GroupId), "ExamSubGroupId": parseInt(ExamSubGroupId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblClass = "";
                    var total = 0;
                    var finaltotal = 0;
                    if (obj != "") {
                        Header[1] = " <h5 class='page-title' style='display:Block' id='Depart'><a href='#' onclick='HeaderDisplay(1)'>" + GroupName + "</a></h5>";

                        document.getElementById("HeaderTitle").innerHTML = Header;
                        ReHeader = document.getElementById("HeaderTitle").innerHTML;

                        var newObj = {};
                        var keyCount = 0;
                        tblClass += "<tr>";
                        for (var item in obj[0]) {
                            var columnsIn = obj[0][item];
                            if (columnsIn.key === "GroupId") { continue; }
                            else if (columnsIn.key == "GroupTitle") { continue; }
                            else if (columnsIn.key == "GroupName" || columnsIn.key == "Class Name") {
                                newObj[keyCount++] = { "Class Name": "Total" };
                                tblClass += "<th>Class Name</th>";
                            }
                            else {
                                tblClass += "<th>" + columnsIn.key + "</th>";
                                newObj[keyCount] = {};
                                newObj[keyCount++][columnsIn.key] = 0;
                            }
                        }

                        tblClass += "<th>Total</th></tr>";
                        keyCount = 1;
                        $.each(obj, function (i, item) {
                            tblClass += "<tr>";
                            var groupId = "";
                            var groupname = "";
                            for (var key in item) {
                                if (item[key].key === "GroupId") {
                                    groupId = item[key].value;
                                }
                                if (item[key].key === "GroupName") {
                                    groupname = item[key].value;
                                }
                            }
                            for (var key in item) {

                                if (item[key].key !== "GroupId") {
                                    if (item[key].key === "GroupName") {
                                        if (item[key].value !== "null" && item[key].value !== undefined && item[key].value !== null) {
                                            tblClass += "<td><a onclick='DivisionDataBind(" + groupId + ",\"" + groupname + " \")'>" + item[key].value + "</a></td>";
                                        }
                                    }
                                    if (item[key].key !== "GroupTitle") {
                                        if (item[key].key !== "GroupName") {
                                            if (item[key].value === null || item[key].value === undefined) { item[key].value = 0; }
                                            tblClass += "<td>" + item[key].value + "</td>";

                                            if (item[key].key !== "Class Name" && item[key].key !== "GroupName") {
                                                if (item[key].value !== "null" && item[key].value !== undefined && item[key].value !== null) {
                                                    for (var key1 in newObj[keyCount]) {
                                                        if (item[key].key == key1) {
                                                            newObj[keyCount][key1] += parseInt(item[key].value)
                                                        }
                                                        keyCount++;
                                                    }
                                                    total += parseInt(item[key].value);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            tblClass += "<td>" + total + "</td></tr>";
                            keyCount = 1;
                            finaltotal += total;
                            total = 0;
                        });
                        tblClass += "<tr>";
                        for (var item in newObj) {
                            var columnsIn = newObj[item];
                            for (var key in columnsIn) {
                                if (key === "GroupId") { continue; }
                                else if (key == "GroupTitle") { continue; }
                                else if (key == "Class Name") {
                                    tblClass += "<th>" + columnsIn[key] + "</th>";
                                }
                                else {
                                    tblClass += "<th>" + columnsIn[key] + "</th>";

                                }
                            }
                        }
                        tblClass += "<th>" + finaltotal + "</th></tr>";
                    }

                    else { tblClass += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblClass").innerHTML = tblClass;
                    document.getElementById("HeaderTitle").innerHTML = '';
                    $.each(Header, function (i, item) {
                        document.getElementById("HeaderTitle").innerHTML += Header[i];
                    });

                    document.getElementById("DepartHead").style.display = "none";
                    document.getElementById("ClassHead").style.display = "block";
                    statusId = 2;
                    console.log(Header);
                }
            });
        }
        function DivisionDataBind(GroupId, GroupName) {
            $.ajax({
                type: "POST",
                url: "TopperStudentAnalysis.aspx/DivWiseTopStdGet",
                data: JSON.stringify({ "OrgId": OrgId, "BatchId": parseInt(BatchId), "ClassId": parseInt(GroupId), "ExamSubGroupId": parseInt(ExamSubGroupId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblDivision = "";
                    var total = 0;
                    var finaltotal = 0;
                    if (obj != "") {
                        Header[2] = " <h5 class='page-title' style='display:block'  id='class'><a href='#' onclick='HeaderDisplay(2)'>" + GroupName + "</a></h5>";
                        document.getElementById("HeaderTitle").innerHTML = Header;
                        ReHeader = document.getElementById("HeaderTitle").innerHTML;

                        var newObj = {};
                        var keyCount = 0;
                        tblDivision += "<tr>";
                        for (var item in obj[0]) {
                            var columnsIn = obj[0][item];
                            if (columnsIn.key === "GroupId") { continue; }
                            else if (columnsIn.key == "GroupTitle") { continue; }
                            else if (columnsIn.key == "GroupName" || columnsIn.key == "Division Name") {
                                newObj[keyCount++] = { "Division Name": "Total" };
                                tblDivision += "<th>Division Name</th>";
                            }
                            else {
                                tblDivision += "<th>" + columnsIn.key + "</th>";
                                newObj[keyCount] = {};
                                newObj[keyCount++][columnsIn.key] = 0;
                            }
                        }

                        tblDivision += "<th>Total</th></tr>";
                        keyCount = 1;
                        $.each(obj, function (i, item) {
                            tblDivision += "<tr>";
                            var groupId = "";
                            var groupname = "";
                            for (var key in item) {
                                if (item[key].key === "GroupId") {
                                    groupId = item[key].value;
                                }
                                if (item[key].key === "GroupName") {
                                    groupname = item[key].value;
                                }
                            }
                            for (var key in item) {

                                if (item[key].key !== "GroupId") {
                                    if (item[key].key === "GroupName") {
                                        if (item[key].value !== "null" && item[key].value !== undefined && item[key].value !== null) {
                                            tblDivision += "<td>" + item[key].value + "</td>";
                                        }
                                    }
                                    if (item[key].key !== "GroupTitle") {
                                        if (item[key].key !== "GroupName") {
                                            if (item[key].value === null || item[key].value === undefined) { item[key].value = 0; }
                                            tblDivision += "<td>" + item[key].value + "</td>";

                                            if (item[key].key !== "Division Name" && item[key].key !== "GroupName") {
                                                if (item[key].value !== "null" && item[key].value !== undefined && item[key].value !== null) {
                                                    for (var key1 in newObj[keyCount]) {
                                                        if (item[key].key == key1) {
                                                            newObj[keyCount][key1] += parseInt(item[key].value)
                                                        }
                                                        keyCount++;
                                                    }
                                                    total += parseInt(item[key].value);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            tblDivision += "<td>" + total + "</td></tr>";
                            keyCount = 1;
                            finaltotal += total;
                            total = 0;
                        });
                        tblDivision += "<tr>";
                        for (var item in newObj) {
                            var columnsIn = newObj[item];

                            for (var key in columnsIn) {
                                if (key === "GroupId") { continue; }
                                else if (key == "GroupTitle") { continue; }
                                else if (key == "Division Name") {
                                    tblDivision += "<th>" + columnsIn[key] + "</th>";
                                }
                                else {
                                    tblDivision += "<th>" + columnsIn[key] + "</th>";

                                }
                            }
                        }
                        tblDivision += "<th>" + finaltotal + "</th></tr>";
                    }

                    else { tblDivision += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblDivision").innerHTML = tblDivision;
                    document.getElementById("HeaderTitle").innerHTML = '';
                    $.each(Header, function (i, item) {
                        document.getElementById("HeaderTitle").innerHTML += Header[i];
                    });
                    document.getElementById("DepartHead").style.display = "none";
                    document.getElementById("ClassHead").style.display = "none";
                    document.getElementById("DivisionHead").style.display = "block";
                    statusId = 3;
                }
            });
        }

        function BackOrgFunction() {
            if (statusId == 2) {
                document.getElementById("DepartHead").style.display = "block";
                document.getElementById("ClassHead").style.display = "none";
                document.getElementById("DivisionHead").style.display = "none";
                $("#division").hide();
                statusId--;
            }
            else if (statusId == 3) {
                document.getElementById("DepartHead").style.display = "none";
                document.getElementById("ClassHead").style.display = "block";
                document.getElementById("DivisionHead").style.display = "none";
                $("#class").hide();
                $("#division").hide();
                var h1 = [Header[0], Header[1]];
                Header = h1;
                statusId--;
            }
            else {
                window.location.href = "../MobileView/AssessmentDetailDashboard.aspx?OrgId=" + OrgId;
            }

        }
        function DashBoard() { window.location.href = "../MobileView/DashBoard.aspx"; }
    </script>
    <asp:UpdatePanel ID="DoctorScheduleUpdatePanel" runat="server">
        <ContentTemplate>
          <div class="page-header row mb20">
                <div class="col-xl-12 col-sm-12 col-xs-12 border-bottom-inline padd-0">
                    <div class="col-md-12 ptb12">
                        <span class='btn btn-home btn-icon' onclick='DashBoard()' title='home'><span><i class='material-icons'>home</i></span></span>
                        <input type="button" value="&#xf3e5;" id="bntBackOrg" onclick="BackOrgFunction()" skinid="0" class="float-right btn btn-back btn-icon fas" />
                    </div>
                    <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="DepartHead" style="display: none">
                            <h3 class="table-topic">Department Wise Count</h3>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblDepartment' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="ClassHead" style="display: none">
                            <h3 class="table-topic">Class Wise Count</h3>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblClass' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="DivisionHead" style="display: none">
                            <h3 class="table-topic">Division Wise Count</h3>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblDivision' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>