<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="addcal.aspx.cs" Inherits="Book.m.addcal" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="../javascript/jquery-1.9.1.min.js"></script>
    <link href="../bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <script src="../bootstrap/js/bootstrap.min.js"></script>
    <script src="../javascript/datepick/moment.min.js"></script>
       <script>
        ROOMID = '<%=Request.QueryString["roomid"]%>';
       </script>

      <style>
        a.v{ color:#ffffff; font-size:13px;  }
        th{ text-align:center }
        ._time{ height:50px;  text-align:center }
        .tip{ background-color:#ff0000; padding:2px; font-size:12px;  color:#ffffff; border-radius:4px; overflow:hidden; line-height:23px;  word-break:break-all; }
    </style>

    <script>


        function GetOffSetX(leftspan) { 

            if (leftspan < 0) {
                return -5000;
            }

            if (leftspan <= 6) {
                var idx = leftspan + 1;
                return $('#tbl th').eq(idx).offset().left + 5;
            }
            return -5000;

        }






        function GetOffSetY(begintime) {
            var Y = -1000;
            switch (begintime) {
                case "00:00":
                case "00:30":
                case "01:00":
                case "01:30":
                case "02:00":
                case "02:30":
                case "03:00":
                case "03:30":
                case "04:00":
                case "04:30":
                case "05:00":
                case "05:30":
                case "06:00":
                case "06:30":
                case "07:00":
                case "07:30":
                case "08:00":
                    Y = $('#tbl tr').eq(1).offset().top + 5;
                    break;

                case "08:30":
                    Y = $('#tbl tr').eq(1).offset().top + 25;
                    break;

                case "09:00":
                    Y = $('#tbl tr').eq(2).offset().top + 5;
                    break;

                case "09:30":
                    Y = $('#tbl tr').eq(2).offset().top + 25;
                    break;


                case "10:00":
                    Y = $('#tbl tr').eq(3).offset().top + 5;
                    break;


                case "10:30":
                    Y = $('#tbl tr').eq(3).offset().top + 25;
                    break;


                case "11:00":
                    Y = $('#tbl tr').eq(4).offset().top + 5;
                    break;


                case "11:30":
                    Y = $('#tbl tr').eq(4).offset().top + 25;
                    break;


                case "12:00":
                    Y = $('#tbl tr').eq(5).offset().top + 5;
                    break;


                case "12:30":
                    Y = $('#tbl tr').eq(5).offset().top + 25;
                    break;

                case "13:00":
                    Y = $('#tbl tr').eq(6).offset().top + 5;
                    break;


                case "13:30":
                    Y = $('#tbl tr').eq(6).offset().top + 25;
                    break;

                case "14:00":
                    Y = $('#tbl tr').eq(7).offset().top + 5;
                    break;

                case "14:30":
                    Y = $('#tbl tr').eq(7).offset().top + 25;
                    break;

                case "15:00":
                    Y = $('#tbl tr').eq(8).offset().top + 5;
                    break;

                case "15:30":
                    Y = $('#tbl tr').eq(8).offset().top + 25;
                    break;

                case "16:00":
                    Y = $('#tbl tr').eq(9).offset().top + 5;
                    break;

                case "16:30":
                    Y = $('#tbl tr').eq(9).offset().top + 25;
                    break;

                case "17:00":
                    Y = $('#tbl tr').eq(10).offset().top + 5;
                    break;


                case "17:30":
                    Y = $('#tbl tr').eq(10).offset().top + 25;
                    break;

                case "18:00":
                    Y = $('#tbl tr').eq(11).offset().top + 5;
                    break;

                case "18:30":
                    Y = $('#tbl tr').eq(11).offset().top + 25;
                    break;


                case "19:00":
                    Y = $('#tbl tr').eq(12).offset().top + 5;
                    break;

                case "19:30":
                    Y = $('#tbl tr').eq(12).offset().top + 25;
                    break;


                case "20:00":
                    Y = $('#tbl tr').eq(13).offset().top + 5;
                    break;

                case "20:30":
                case "21:00":
                case "21:30":
                case "22:00":
                case "22:30":
                case "23:00":
                case "23:30":
                    Y = $('#tbl tr').eq(13).offset().top + 25;
                    break;

            }
            return Y;
        }



        function FixTime(dt) {
            var hour = dt.split(':')[0];
            var minter = dt.split(':')[1];


            if (minter >= 0 && minter <= 15) {
                return hour + ":" + "00";
            }
            if (minter > 15 && minter <= 45) {
                return hour + ":" + "30";
            }

            if (minter > 45) {
                var t = parseInt(hour);
                t = t + 1;

                if (t <= 9) {
                    return "0" + t + ":00";
                }
                else {
                    return t + ":00";
                }

            }

            return "";

        }




        function timeHeight(startTime, endTime) {
            var start1 = startTime.split(":");
            var startAll = parseInt(start1[0] * 60) + parseInt(start1[1]);

            var end1 = endTime.split(":");
            var endAll = parseInt(end1[0] * 60) + parseInt(end1[1]);

            var total = (endAll - startAll) / 30;

            return total;


        }



    </script>

</head>
<body>
    <form id="form1" runat="server">
        <div>

            <asp:Label runat="server" ID="lbl_table"></asp:Label>
        </div>









        
        <script>
            ToDay = '<%=DateTime.Parse(Request.QueryString["date"]).ToString("yyyy-MM-dd")%>';





            function checkTime(ar) {
                var d = new Date();
                var current = d.getHours() * 60 + d.getMinutes();

                var ar_begin = ar[0].split(':');
                var ar_end = ar[1].split(':');

                var b = parseInt(ar_begin[0]) * 60 + parseInt(ar_begin[1]);
                var e = parseInt(ar_end[0]) * 60 + parseInt(ar_end[1]);
                 
            }


  

            $(document).ready(function () {
              
                GetData();
            });



            function GetData() {

                $.getJSON("js_cal/data.aspx",
                    {
                        "roomid": ROOMID,
                        dayspan: "2",
                        dt:"<%=Request.QueryString["date"]%>",
                        random: Math.random()
                    },

                    function (data) {
                        console.log(data);
                        var c = data.length;

                        for (var i = 0; i < c; i++) {

                            var d = data[i];
                            var dt = d.date;
                            var dt2 = d.date;
                            var day =1;
                            var begintime = d.ssstart;
                            var endtime = d.ssend;
                            var intro = d.name;
                            if (intro == "") {
                                intro = "使用中";
                            }

                            var html = "";

                            

                            var OffSetX = 0;
                            var OffSetY = 0; 
                            var CellWidth = 190;
                            var leftspan = 0;



                            if (dt == ToDay) {
                               
                                var leftspan = 0; 

                                //if (leftspan == 0) {
                                //    checkTime([begintime, endtime]);
                                //}

                                OffSetX = GetOffSetX(leftspan); 
                                begintime = FixTime(begintime);
                                endtime = FixTime(endtime); 
                                StartY1 = GetOffSetY(begintime)
                                StartY2 = GetOffSetY(endtime) 

                                var height = StartY2 - StartY1;
                                var top = StartY1;
                                var left = OffSetX;

                                html = "<div class=tip style='overflow:hidden;position:absolute; height:" + height + "px; left:" + left + "px; top:" + top + "px; width:" + CellWidth + "px; '><a class=v href=###>" + intro + "</a></div>"
                                $("body").append(html);

                            }
                        }

                    }
                )

            }
        </script>








    </form>
</body>
</html>