<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DoctorList.aspx.cs" Inherits="CLIP.eForm.Consent.Web.DoctorList" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>수술/시술과(의) 선택</title>
    <script src="jquery-1.8.3.min.js" type="text/javascript"></script>
    <script src="json2.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            // 진료과 Dropdown list 만들기 
            makeDeptDropdown("");
            
	        // 진료과 Dropdown 클릭 이벤트 
	        $("#dept_dropdown_selected").bind("click", function () {
	            var list = $(".dept_dropdown_list");
	            if (list.is(":visible")) {
	                list.hide();
	            } else {
	                list.show();
	            }
            });
	    });

	   function deptDropdownInit(deptName){
	    	$("#dept_dropdown_selected").trigger("click");
	    	if(deptName != "" && deptName != undefined && deptName != null){
	    		var list = $(".dept_dropdown_list tr td");
	    		for(var i=0; i<list.length; i++){
	    			var name = list.eq(i).text();
	    			if(deptName == name){
	    				list.eq(i).trigger("click");
	    			}    			
	    		}
	    	}
	    };
	    
	    // 진료과 Dropdown list 만들기 
	    function makeDeptDropdown(data) {
	        $(".dept_dropdown_list tbody tr").remove();
	    	var colCount = 4;
	    	var depts = data;
	    	if (depts != undefined && depts != null && depts != "") {
	    		var array = $.parseJSON(depts);
	    		var tbody = $(".dept_dropdown_list tbody");
	    		var trs = "";	 
	    		trs += "<tr>";
	    		if (array[0].DeptListVo.deptcd == "") array.splice(0, 1);
	    		for(var i = 0; i<array.length; i++){
	    			var deptnm = array[i].DeptListVo.deptnm;
	    			var deptcd = array[i].DeptListVo.deptcd;
	    			if(i==0){
	   					$("#dept_name").text(deptnm);
	   		    		$("#dept_name").val(deptcd);
	   		    		trs +="<td class='dropdown_selected' attr-data="+deptcd+">";
	   				}else{
	   					trs +="<td class='' attr-data="+deptcd+">"; 
	   				}	   				
	    			trs += deptnm;
	    			trs +="</td>";
	    			if((i+1) % colCount == 0){
	    				trs += "</tr><tr>";
	    			} 				    			
	    		}	
	    		trs += "</tr>";
	    		tbody.append(trs);

    		    // 진료과 Dropdown list 클릭 이벤트 
	    		$(".dept_dropdown_list td").bind("click", function () {
	    		    $(".dept_dropdown_list").hide();
	    		    $(".dept_dropdown_list td").removeClass("dropdown_selected");
	    		    $(this).addClass("dropdown_selected");
	    		    $("#dept_name").text($(this).text());
	    		    $("#dept_name").val($(this).attr("attr-data"));

	    		    selectDept($("#dept_name").val(), $("#dept_name").text());
	    		});
	    	}else{
	    		//alert("진료과가 없습니다.");
	    	}
			if(navigator.userAgent.indexOf("Android") > 0){
	    		$(".dept_dropdown_list tr td").css("font-size", "16px");
	    	}else{
	    		$(".dept_dropdown_list tr td").css("font-size", "14px");
	    	}
            var IO_OPdept = $('#IO_OPdept').text();
            
			if (IO_OPdept != undefined && IO_OPdept != null && IO_OPdept != "") {
			    deptDropdownInit(IO_OPdept);
			} else {
			    deptDropdownInit("");
			}
	    }
    </script>
    <script type="text/javascript">
        function selectRow(obj) {
            var resultData = JSON.parse($(obj).attr('attr-ResultData'));
            if (resultData != undefined && resultData != null)
            {
                var osObject = getOsObject();

                var IO_CtrlPosition= $('#IO_CtrlPosition').text();
                if (IO_CtrlPosition == "1") {
                    // 주치의1, 마취의 1
                    if (resultData.doctorkind == "전문의") {
                        osObject.SetControlValue('PST6', resultData.deptNm);
                        osObject.SetControlValue('PST7', "");
                        osObject.SetControlValue('PSCSD1', "value1");
                        osObject.SetControlValue('PSCSD2', "");
                    }
                    else {
                        osObject.SetControlValue('PST6', "");
                        osObject.SetControlValue('PST7', resultData.deptNm);
                        osObject.SetControlValue('PSCSD1', "");
                        osObject.SetControlValue('PSCSD2', "value1");
                    }
                    osObject.SetControlValue('PST3', resultData.doctornm);
                }
                else if (IO_CtrlPosition == "2") {
                    // 주치의2, 마취의 2
                    if (resultData.doctorkind == "전문의") {
                        osObject.SetControlValue('PST8', resultData.deptNm);
                        osObject.SetControlValue('PST9', "");
                        osObject.SetControlValue('PSCSD3', "value1");
                        osObject.SetControlValue('PSCSD4', "");
                    }
                    else {
                        osObject.SetControlValue('PST8', "");
                        osObject.SetControlValue('PST9', resultData.deptNm);
                        osObject.SetControlValue('PSCSD3', "");
                        osObject.SetControlValue('PSCSD4', "value1");
                    }
                    osObject.SetControlValue('PST4', resultData.doctornm);
                }
                else if (IO_CtrlPosition == "3") {
                    // 주치의3, 마취의 3
                    if (resultData.doctorkind == "전문의") {
                        osObject.SetControlValue('PST10', resultData.deptNm);
                        osObject.SetControlValue('PST11', "");
                        osObject.SetControlValue('PSCSD5', "value1");
                        osObject.SetControlValue('PSCSD6', "");
                    }
                    else {
                        osObject.SetControlValue('PST10', "");
                        osObject.SetControlValue('PST11', resultData.deptNm);
                        osObject.SetControlValue('PSCSD5', "");
                        osObject.SetControlValue('PSCSD6', "value1");
                    }
                    osObject.SetControlValue('PST5', resultData.doctornm);
                }
                var tmp = "T";
                osObject.SetPopupResult(tmp);
                //osObject.SetPopupResult(msgReturn);
                osObject.OkClose();
            }
        }

        function getOsObject() {
            var strOs = OSCheck();

            var result;
            if (strOs == "Android") {
                result = window.android;
            }
            else if (strOs == "Windows") {
                result = window.external;
            }

            return result;
        }

        function OSCheck() {
            var playerOS = 'dont know';
            if (navigator.userAgent.match(/iPhone|iPad/gi)) {
                playerOS = 'iOS';
            }
            else if (navigator.userAgent.match(/Android/gi)) {
                playerOS = 'Android';
            }
            else if (navigator.userAgent.match(/Windows/gi)) {
                playerOS = 'Windows';
            }
            else if (navigator.userAgent.match(/Linux/gi)) {
                playerOS = 'Linux';
            }
            if (navigator.userAgent.match(/OSX/gi)) {
                playerOS = 'Mac OS';
            }

            return playerOS;
        }

        function Cancel() {
            var osObject = getOsObject();
            osObject.CancelClose();
        }
    </script>
    <script type="text/javascript">
        function selectRadio(gubun) {
            if (gubun == undefined || gubun == null)
            {
                gubun = get_radio_value(document.getElementsByName("gubun"));
            }

            var dutinstcd = $('#IO_DutinstcdText').text();

            $.ajax({
                type: "POST",
                url: "DoctorList.aspx/SetDeptDropdown",
                data: '{"gubun":"' + gubun + '", "dutinstcd":"' + dutinstcd + '"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    makeDeptDropdown(msg.d);
                }
            });
        }

        function get_radio_value(obj) {
            if (typeof (obj) == 'undefined') return;
            cnt = obj.length;
            if (cnt > 1) {
                for (i = 0; i < cnt; ++i) {
                    if (obj[i].checked) return obj[i].value;
                }
            } else {
                if (obj.checked) return obj.value;
            }
        }

        function selectDept(deptCd, deptNm) {
            var srchdd = $('#IO_ADdate').text();
            var dutinstcd = $('#IO_DutinstcdText').text();
            $.ajax({
                type: "POST",
                url: "DoctorList.aspx/SetDoctorList",
                data: '{"deptCd":"' + deptCd + '","deptNm":"' + deptNm + '","srchdd":"' + srchdd + '", "dutinstcd":"' + dutinstcd + '"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (msg) {
                    listView(msg.d);
                }
            });
        }

        function listView(data) {
            var colCount = 4;
            $("#dataTbody tr").remove();
            if (data == null || data == '') {
                var clone = $('#noDataTbodyTemplate').clone();
                $('#dataTbody').append(clone.find(".dataTrTemplate"));
                return;
            }
            var resultList = JSON.parse(data);
            if (resultList != null && resultList != undefined) {
                if (resultList.length > 0) {
                    for (var i = 0; i < resultList.length; i++) {
                        var clone = $('#dataTbodyTemplate').clone();
                        if (resultList[i].doctornm == "전체") i++;
                        if (i == resultList.length)
                        {
                            if (resultList.length == 1) {
                                var clone = $('#noDataTbodyTemplate').clone();
                                $('#dataTbody').append(clone.find(".dataTrTemplate"));
                            }
                            break;
                        }
                        clone.find('.dataTdTemplate1').text(resultList[i].doctornm);
                        clone.find(".dataTdTemplate1").attr('attr-ResultData', JSON.stringify(resultList[i]));

                        // 진료의사 클릭 이벤트 
                        clone.find(".dataTdTemplate1").bind("click", function () {
                            selectRow($(this));
                        });

                        i++;
                        for (var j = 2; j < 6; j++)
                        {
                            if (i < resultList.length) {
                                clone.find('.dataTdTemplate' + j).text(resultList[i].doctornm);
                                clone.find(".dataTdTemplate" + j).attr('attr-ResultData', JSON.stringify(resultList[i]));

                                // 진료의사 클릭 이벤트
                                clone.find(".dataTdTemplate" + j).bind("click", function () {
                                    selectRow($(this));
                                });
                                i++;
                            }
                        }
                        i--;
                        $('#dataTbody').append(clone.find(".dataTrTemplate"));
                    }
                }
            }
        }

    </script>
	<style>
        .tdCategory {width:20%;}
        .tdSelect {width:60%;}
		table {border-collapse:collapse; border-spacing:0; empty-cells:show;}
		.data_table01 {width:100%;}
		table.data_table01{border-top:1px solid #c3c3c3; border-left: 1px solid #c3c3c3; font-family: dotum; font-size: 12px;}
		.data_table01 tr th{padding:5px 10px 5px; color:#666;  line-height:20px; text-align:left; font-weight:bold;  background: #e9e9e9; text-align:center;}
		.data_table01 tr td{padding:5px 7px 5px; background: #fff; color:#6d6d6d; line-height:20px; font-weight:bold; cursor:pointer; }






		.data_table01 th {border-bottom: 1px solid #c3c3c3; border-right: 1px solid #c3c3c3;}
		.data_table01 td {border-bottom: 1px solid #c3c3c3; border-right: 1px solid #c3c3c3;}
		.data_table01 td.center{padding-left:0; padding-right:0; text-align:center;}
		
		/* 진료과 Dropdown CSS */
		.dept_dropdown_selected{
			text-align: left;
		    white-space: nowrap;
		    width: 14em;
			padding: .4em 1em;
			display: inline-block;
			position: relative;
			line-height: normal;
			margin-right: .1em;
			cursor: pointer;
			vertical-align: middle;
			-webkit-user-select: none;
			-moz-user-select: none;
			-ms-user-select: none;
			user-select: none;
		
			/* Support: IE <= 11 */
			overflow: visible;
			border: 1px solid #c5c5c5;
 			background: #f6f6f6;
		}
		.dept_dropdown_selected .dropdown_icon{ 
			background-position: -65px -16px; 
			background-image: url(https://code.jquery.com/ui/1.12.1/themes/base/images/ui-icons_777777_256x240.png);
		    float: right;
		    margin-top: 0;
		    width: 16px;
 					height: 16px;
		}
		.dept_dropdown_selected .dept_name{
		    display: block;
		    margin-right: 20px;
		    overflow: hidden;
		    text-overflow: ellipsis;
		}
		/* 진료과 Dropdown list CSS */
		.dept_dropdown_list {border-collapse:separate; border-spacing:5px;}
		.dept_dropdown_list tr td {height: 30px;background:#FCDBF2; font-size: 14px;}
		.dept_dropdown_list .dropdown_selected {background:#A2D4F1}	
		.defaultTextFont {font-size: 16px;}
		</style>	
</head>
<body style="padding:0; margin:10px;">
    <form id="form1" runat="server">
        <div id="dataDiv">
            <table id="dataTable2" class="data_table01">
                <tr style="display:none;">

                    <td class="tdCategory defaultTextFont">
		                구분 : 
		                <input type="radio" class="defaultTextFont" name="gubun" value="OP" checked onclick="selectRadio('OP')"/> 수술
		                <input type="radio" class="defaultTextFont" name="gubun" value="OI" onclick="selectRadio('OI')"/> 시술
                    </td>
                </tr>
                <tr>
                    <td class="tdSelect">
	                    <div id="dept_dropdown">
       	                    <span tabindex="0" id="dept_dropdown_selected" class="dept_dropdown_selected defaultTextFont" role="combobox">
			                    <span class="dropdown_icon"></span>
			                    <span id="dept_name" class="dept_name"></span>
		                    </span>
		                    <table class="dept_dropdown_list" summary="진료과를 선택 하세요." style="display: none;">
			                    <caption></caption>
			                    <colgroup>
				                    <col width="25%">
									<col width="25%">
									<col width="25%">
									<col width="25%">
			                    </colgroup>
			                    <tbody>
			                    </tbody>
		                    </table>
	                    </div>
                    </td>
                </tr>
            </table>
            <br />
            
            <table id="dataTable" class="data_table01">
		        <colgroup>
			        <col width="20%" /> 
			        <col width="20%" /> 
			        <col width="20%" /> 
			        <col width="20%" /> 
			        <col width="20%" /> 
		        </colgroup>
		        <tr>
			        <th align="center" colspan="5" class="defaultTextFont">수술/시술의</th>
		        </tr>
                <tbody id="dataTbody">
                </tbody>
            </table>
            <table id="dataTableTemplate" class="data_table01" style="display:none;">
		        <colgroup>
			        <col width="20%" /> 
			        <col width="20%" /> 
			        <col width="20%" /> 
			        <col width="20%" /> 
			        <col width="20%" /> 
		        </colgroup>
		        <tr>
			        <th align="center" colspan="5">수술/시술의</th>
		        </tr>
                <tbody id="dataTbodyTemplate">
		            <tr class="dataTrTemplate">
			            <td class="dataTdTemplate1 defaultTextFont" align="center"></td>
			            <td class="dataTdTemplate2 defaultTextFont" align="center"></td>
			            <td class="dataTdTemplate3 defaultTextFont" align="center"></td>
			            <td class="dataTdTemplate4 defaultTextFont" align="center"></td>
			            <td class="dataTdTemplate5 defaultTextFont" align="center"></td>
		            </tr>
                </tbody>
                <tbody id="noDataTbodyTemplate">
		            <tr class="dataTrTemplate">
			            <td align="center" colspan="5">조회된 데이터가 없습니다.</td>
		            </tr>
                </tbody>
            </table>
        </div>
    </form>
    <div id="dis" style="display:none;">
        <asp:Label ID="IO_ADdate" runat="server" />
        <asp:Label ID="IO_OPdept" runat="server" />
        <asp:Label ID="IO_CtrlPosition" runat="server" />
        <asp:Label ID="IO_DutinstcdText" runat="server" />
    </div>
    <script language="C#" runat="server">
        protected void Page_Load(Object s, EventArgs e)
        {
            string IO_ADdate = (string.IsNullOrEmpty(this.Request.Params["IO_ADdate"])) ? DateTime.Now.ToShortDateString() : this.Request.Params["IO_ADdate"];
            this.IO_ADdate.Text = (IO_ADdate);
            string IO_OPdept = (string.IsNullOrEmpty(this.Request.Params["IO_OPdept"])) ? string.Empty : this.Request.Params["IO_OPdept"];
            this.IO_OPdept.Text = (IO_OPdept);
            
            string IO_CtrlPosition = (string.IsNullOrEmpty(this.Request.Params["IO_CtrlPosition"])) ? string.Empty : this.Request.Params["IO_CtrlPosition"];
            this.IO_CtrlPosition.Text = (IO_CtrlPosition);

            string IO_dutinstcd = (string.IsNullOrEmpty(this.Request.Params["IO_DUTINSTCD"])) ? string.Empty : this.Request.Params["IO_DUTINSTCD"];
            this.IO_DutinstcdText.Text = (IO_dutinstcd);
        }
    </script>
    <script>
        function loadEnd() {
            if (document.getElementById("dataTable") == null || document.getElementById("dataTable") == undefined) {
                document.getElementById("dataDiv").innerHTML = "<table class='data_table01'><tr><td  height='100' align='center'>조회된 데이터가 없습니다.</td></tr></table>";
            }
        }
        loadEnd();
    </script>
    <script>
        selectRadio(null);
    </script>
</body>
</html>
