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

<asp:Content ID="Content1" ContentPlaceHolderID="CP" runat="Server">

    <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 d-inline-flex">
                        <span class='btn btn-home btn-icon' onclick='DashBoard()' title='home'><span><i class='material-icons'>home</i></span></span>
                        <div class="d-inline-flex w-100">
                            <label class="header-topic justify-content-center" id="HeaderLabel"></label>
                        </div>
                        <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">
                        <%--<input type="button" value="Back" id="bntBack1" onclick="BackFunction1()" style="display:none" />
                        <input type="button" value="Back" id="bntBack2" onclick="BackFunction2()" style="display:none" />--%>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="OrgHead" style="display: block">
                            <h3 class="table-topic">Organization</h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblOrg' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="DepartHead" style="display: none">
                            <h3 class="table-topic">Department Wise Student</h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <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 Student</h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblClss' 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 Student</h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblDivision' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="himssuHeader1WireBox col-md-12 pTop5" id="StudentHead" style="display: none">
                            <h3 class="table-topic">Student List </h3>
                            <%-- <asp:PlaceHolder ID="DepartMentPlaceHolder" runat="server" /> --%>
                            <div class='himsBoxContent'>
                                <div class='table-responsive'>
                                    <table id='tblstudent' class='table table-striped table-bordered'>
                                    </table>
                                </div>
                            </div>
                        </div>
                        <%--   <input type="hidden" id="Departmentid" runat="server" />
                         <input type="hidden" id="ClassHiddenId" runat="server" />
                         <input type="hidden" id="DivisionHiddenId" runat="server" />--%>
                    </div>
                </div>
            </div>



            <%--<script>

       function openDiv(obj) {
           //debugger;
           var id = $(obj);
          // document.getElementById("txtDistance").value = id;
           if ($('.Detail1_' + id[0]).css('display') == 'none') {
               $('.Detail1_' + id[0]).css('display', 'table-row');
               $('.DetailNew1_' + id[0]).css('display', 'table-row');
               //  $('.Detail_' + id).css('display', 'none');
               //$('.DetailNew_' + id).css('display', 'none');
           }
           else {
               $('.Detail1_' + id[0]).css('display', 'none');
               $('.DetailNew1_' + id[0]).css('display', 'none');
           }
       }

       function openDivNew(obj) {
           // debugger;
           
            var id = $(obj);
           // alert(id[0]);
           // alert(obj);
           $("#Departmentid").val(obj);
           // document.getElementById("Departmentid") = id[0].tostring();
           if ($('.Detail1_' + id[0]).css('display') == 'none') {
               $('.Detail1_' + id[0]).css('display', 'table-row');
               $('.DetailNew_' + id[0]).css('display', 'table-row');
             //  $('.Detail_' + id).css('display', 'none');
               //$('.DetailNew_' + id).css('display', 'none');
           }
           else {
               $('.Detail1_' + id[0]).css('display', 'none');
               $('.DetailNew_' + id[0]).css('display', 'none');
           }
       }

       function ClassDisplay(obj) {
           //debugger;
           var id = $(obj);
           $("#ClassHiddenId").val(obj);
           if ($('.ClassDisplay' + id[0]).css('display') == 'none') {
               $('.ClassDisplay' + id[0]).css('display', 'table-row');
               $('.ClassDisplay1' + id[0]).css('display', 'table-row');
               //  $('.Detail_' + id).css('display', 'none');
               //$('.DetailNew_' + id).css('display', 'none');
           }
           else {
               $('.ClassDisplay' + id[0]).css('display', 'none');
               $('.ClassDisplay1' + id[0]).css('display', 'none');
           }
       }

       function Studentdisplay(obj) {
           //debugger;
           var id = $(obj);
           $("#DivisionHiddenId").val(obj);
           if ($('.Studentdisplay' + id[0]).css('display') == 'none') {
               $('.Studentdisplay' + id[0]).css('display', 'table-row');
               $('.Studentdisplay1' + id[0]).css('display', 'table-row');
               //  $('.Detail_' + id).css('display', 'none');
               //$('.DetailNew_' + id).css('display', 'none');
           }
           else {
               $('.Studentdisplay' + id[0]).css('display', 'none');
               $('.Studentdisplay1' + id[0]).css('display', 'none');
           }
       }
    </script>--%>
        </ContentTemplate>
    </asp:UpdatePanel>
    <script>
        var Id;
        var Group;
        var BatchId;
        var DepartmentId;
        var classId;
        var DivisionId;
        var statusId;
        var Header = [];
        var ReHeader;
        var SessionGroup;
        $(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());
            Group = keyval[1].split('=')[1].toString();
            BatchId = parseInt(keyval[2].split('=')[1].toString());

            
            if (keyval[1].split('=')[0].toString() == 'OrgId' || keyval[1].split('=')[0].toString() == 'OrgGroupId') {
                Id = parseInt(keyval[0].split('=')[1].toString()); SessionGroup = sessionStorage.getItem("NewGroup"); Group = SessionGroup;
            }
            else { Group = keyval[1].split('=')[1].toString(); sessionStorage.setItem('NewGroup', Group); sessionStorage.clear(); }
            $.ajax({
                type: "POST",
                url: "NoOfStudent.aspx/GetOrgId",
                data: JSON.stringify({ "Id": Id, "Group": Group }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    if (Group == "OrgId") {
                        Header[0] = "<h5 class='page-title'><a href='#' onclick='dashboardpage()'>" + obj[0].Title + "</a></h5>" +
                        " <h5 class='page-title' ><a href='#' onclick='PageName()'>No of Student</a></h5>";
                        $("#HeaderLabel").text("MIS DashBoard");

                    }
                    else {
                        Header[0] = "<h5 class='page-title'><a href='#' onclick='dashboardpage()'>" + obj[0].Title + "</a></h5>" +
                         " <h5 class='page-title' ><a href='#' onclick='PageName()'>No of Student</a></h5>";
                        $("#HeaderLabel").text("EIS DashBoard");
                    }

                    document.getElementById("HeaderTitle").innerHTML = Header;
                    ReHeader = document.getElementById("HeaderTitle").innerHTML;
                    // console.log(Header);
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
            if (Group == "OrgId")
            { DepartmentDataBind(); }
            else { OrganizationGet(); }

        });
        function PageName() {
            if (Group == "OrgId") {
                window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgId=" + Id;
            }
            else {
                window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgGroupId=" + 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 OrganizationGet() {
            $.ajax({
                type: "POST",
                url: "NoOfStudent.aspx/OrganizationGet",
                data: JSON.stringify({ "OrgId": OrgId, "BatchId": parseInt(BatchId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblOrg = "";
                    var total = 0;
                    // console.log(obj);
                    if (obj != "") {
                        tblOrg += "<tr><th>Organization Name</th><th>Count</th></tr>";
                        $.each(obj, function (i, item) {

                            tblOrg += "<tr><td><a onclick='DepartmentDataBind(" + item.OrgId + ")'>" + item.OrganizationName + "</a></td><td>" + item.StudentCount + "</td></tr>";
                            total += parseInt(item.StudentCount);
                        });
                        tblOrg += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                        // Header += " <h5 class='page-title' style='display:Block' id='ClassName'><a href='#' onclick='HeaderDisplay(1)'>" + ClassName + "</a></h5>";
                    }
                    else { tblOrg += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    // alert(obj);
                    document.getElementById("tblOrg").innerHTML = tblOrg;
                    document.getElementById("DepartHead").style.display = "none";
                    document.getElementById("OrgHead").style.display = "block";
                    // document.getElementById("HeaderTitle").innerHTML = Header;
                    statusId = 0;
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }
        function DepartmentDataBind(Id) {
            if (Group == "OrgId")
            { OrgGroupId = 0; }
            else { OrgGroupId = OrgId;; OrgId = Id; }
            $.ajax({
                type: "POST",
                url: "NoOfStudent.aspx/StudentDataBind",
                data: JSON.stringify({ "OrgId": OrgId, "Group": Group, "BatchId": parseInt(BatchId), "OrgGroupId": OrgGroupId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tlbDepartment = "";
                    var total = 0;
                    if (obj != "") {
                        tlbDepartment += "<tr><th>Department Name</th><th>Active Student Count</th></tr>";
                        $.each(obj, function (i, item) {
                            tlbDepartment += "<tr><td><a onclick='ClassDataBind(" + item.DepartmentId + ",\"" + item.DepartmentName + " \")'>" + item.DepartmentName + "</a></td><td>" + item.StudentCount + "</td></tr>";
                            total += parseInt(item.StudentCount);

                        });

                        tlbDepartment += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></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";
                    document.getElementById("OrgHead").style.display = "none";

                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }
        function dashboardpage() {
            if (Group == "OrgId") {
                window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgId=" + Id;
            }
            else {
                window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgGroupId=" + Id;
            }
        }
        function ClassDataBind(DepartmentId, DepartmentName) {
            $.ajax({
                type: "POST",
                url: "NoOfStudent.aspx/StudentClassBind",
                data: JSON.stringify({ "OrgId": OrgId, "Group": Group, "BatchId": parseInt(BatchId), "DepartId": parseInt(DepartmentId), "OrgGroupId": OrgGroupId }),
                // data: JSON.stringify({ "OrgId": OrgId, "Group": Group, "BatchId": parseInt(BatchId), "OrgGroupId": OrgGroupId }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblClss = "";
                    var total = 0;
                    Header[0] = ReHeader;
                    if (obj != "") {
                        tblClss += "<tr><th>Class Name</th><th>Active Student Count</th></tr>";
                        $.each(obj, function (i, item) {
                            tblClss += "<tr><td><a onclick='DivisionDataBind(" + item.ClassId + ",\"" + item.ClassName + " \")'>" + item.ClassName + "</a></td><td>" + item.ClassStudentCount + "</td></tr>";
                            total += parseInt(item.ClassStudentCount);

                        });
                        Header[1] = " <h5 class='page-title' style='display:Block' id='Depart'><a href='#' onclick='HeaderDisplay(1)'>" + DepartmentName + "</a></h5>";
                        tblClss += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                    }
                    else { tblClss += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblClss").innerHTML = tblClss;
                    document.getElementById("HeaderTitle").innerHTML = '';
                    $.each(Header, function (i, item) {
                        // alert('' + Header[i]    );
                        document.getElementById("HeaderTitle").innerHTML += Header[i];

                    });

                    //document.getElementById("HeaderTitle").innerHTML = Header;
                    document.getElementById("DepartHead").style.display = "none";
                    document.getElementById("ClassHead").style.display = "block";
                    statusId = 1;
                    console.log(Header);
                    //$("#class").show();
                    //$("#Depart").show();
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        }
        function DivisionDataBind(ClassId, ClassName) {

            $.ajax({
                type: "POST",
                url: "NoOfStudent.aspx/StudentDivisionBind",
                data: JSON.stringify({ "OrgId": OrgId, "Group": Group, "BatchId": parseInt(BatchId), "ClassId": parseInt(ClassId), "OrgGroupId": OrgGroupId }),
                //data: JSON.stringify({ "Id": Id, "Group": Group, "BatchId": parseInt(BatchId), "ClassId": parseInt(ClassId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblDivision = "";
                    var total = 0;
                    if (obj != "") {
                        tblDivision += "<tr><th>Division Name</th><th>Active Student Count</th></tr>";
                        $.each(obj, function (i, item) {
                            tblDivision += "<tr><td><a onclick='StudentDataBind( " + item.DivisionId + ",\"" + item.DivisionName + " \")'>" + item.DivisionName + "</a></td><td>" + item.StudentCount + "</td></tr>";
                            total += parseInt(item.StudentCount);
                        });
                        tblDivision += "<tr><td style='font-weight:bold'>Total</td><td style='font-weight:bold'>" + total + "</td></tr>";
                        Header[2] = " <h5 class='page-title' style='display:block'  id='class'><a href='#' onclick='HeaderDisplay(2)'>" + ClassName + "</a></h5>";
                    }
                    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) {
                        //alert('' + Header[i]);
                        document.getElementById("HeaderTitle").innerHTML += Header[i];

                    });
                    document.getElementById("DepartHead").style.display = "none";
                    document.getElementById("ClassHead").style.display = "none";
                    document.getElementById("DivisionHead").style.display = "block";
                    // $("#division").show(); 
                    statusId = 2;
                }
            });
        }
        function StudentDataBind(DivisionId, DivisionName) {

            $.ajax({
                type: "POST",
                url: "NoOfStudent.aspx/StudentListDataBind",
                data: JSON.stringify({ "OrgId": OrgId, "Group": Group, "BatchId": parseInt(BatchId), "DivisionId": parseInt(DivisionId), "OrgGroupId": OrgGroupId }),
                // data: JSON.stringify({ "Id": Id, "Group": Group, "BatchId": parseInt(BatchId), "DivisionId": parseInt(DivisionId) }),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var obj = (result.d);
                    var tblstudent = "";
                    if (obj != "") {
                        tblstudent += "<tr><th>Student Code</th><th>Active Student Name</th></tr>";
                        $.each(obj, function (i, item) {
                            tblstudent += "<tr><td>" + item.Code + "</td><td>" + item.Name + "</td></tr>";
                        });
                        Header[3] = " <h5 class='page-title' style='display:block' id='division'><a href='#' onclick='HeaderDisplay(3)'>" + DivisionName + "</a></h5>";
                    }
                    else { tblstudent += "<tr><td colspan='8' class='record'>No records found..!!</td></tr>"; }
                    document.getElementById("tblstudent").innerHTML = tblstudent;
                    document.getElementById("HeaderTitle").innerHTML = '';
                    $.each(Header, function (i, item) {
                        // alert('' + Header[i]);
                        document.getElementById("HeaderTitle").innerHTML += Header[i];

                    });
                    document.getElementById("DepartHead").style.display = "none";
                    document.getElementById("ClassHead").style.display = "none";
                    document.getElementById("DivisionHead").style.display = "none";
                    document.getElementById("StudentHead").style.display = "block";
                    //$("#Student").show();
                    statusId = 3;

                }
            });
        }
        function BackOrgFunction() {
            if (statusId == 0) {
                if (Group == "OrgId")
                { window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgId=" + OrgId; }
                else {
                    document.getElementById("DepartHead").style.display = "none";
                    document.getElementById("ClassHead").style.display = "none";
                    document.getElementById("DivisionHead").style.display = "none";
                    document.getElementById("StudentHead").style.display = "none";
                    document.getElementById("OrgHead").style.display = "block";
                    statusId--;
                }
            }
            else if (statusId == 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";
                //$("#Student").show();
                //$("#Depart").show();
                //$("#class").show();
                $("#division").hide();
                statusId--;
            }
            else if (statusId == 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";
                $("#class").hide();
                $("#division").hide();
                var h1 = [Header[0], Header[1]];
                Header = h1;
                statusId--;
            }
            else if (statusId == 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();
                $("#class").hide();
                $("#division").hide();
                document.getElementById("HeaderTitle").innerHTML = ReHeader;
                Header = [];
                statusId--;
            }
            else {
                if (Group == "OrgId")
                { window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgId=" + OrgId; sessionStorage.setItem('NewId', OrgId); sessionStorage.setItem('NewBatchId', BatchId); }
                else {
                    window.location.href = "../MobileView/MobileDashBoard2.aspx?OrgGroupId=" + Id; sessionStorage.setItem('NewId', OrgId); sessionStorage.setItem('NewBatchId', BatchId);
                }
            }

        }
        function DashBoard() { window.location.href = "../MobileView/DashBoard.aspx"; }
    </script>
</asp:Content>
