/**
 * mplus_mobile_operation
 */
var mplus_mobile_operation = function(){
	//상속
	mplus_common.call(this);
	//super
	var self = this;
	
	//변수
	var div = $("<div></div>");
	var tr = $("<tr></tr>");
	var th = $("<th></th>");
	var td = $("<td></td>");
	var table = $("<table></table>");
	var li = $("<li></li>");
	var a = $("<a></a>");
	var span = $("<span></span>");
	var button = $("<button></button>");
	
	var $opViewToDt = $('#opViewToDt'),
		$opViewFmDt = $('#opViewFmDt'),
		$opTotalNumSpan = $('#opTotalNumSpan'),
	 	$opSearchBtn = $('#opSearchBtn'),
	 	$ulOperationList = $('#ulOperationList'),
	 	$opSortOpenBtn  = $('#opSortOpenBtn'),
	 	
	 	$anesViewToDt = $('#anesViewToDt'),
		$anesViewFmDt = $('#anesViewFmDt'),
		$anesTotalNumSpan = $('#anesTotalNumSpan'),
	 	$anesSearchBtn = $('#anesSearchBtn'),
	 	$ulAnesthesiaList = $('#ulAnesthesiaList'),
	 	$anesSortOpenBtn  = $('#anesSortOpenBtn'),
	 	
	 	$trViewToDt = $('#trViewToDt'),
		$trViewFmDt = $('#trViewFmDt'),
		$trTotalNumSpan = $('#trTotalNumSpan'),
	 	$trSearchBtn = $('#trSearchBtn'),
	 	$ulTreatmentList = $('#ulTreatmentList'),
	 	$trSortOpenBtn  = $('#trSortOpenBtn');
	
	var today = new Date();
    var prevDay = new Date(Date.parse(new Date()) - 6 * 1000 * 60 * 60 * 24); //일주일전!!
	
	var operatingList = [];
	var anesthesiaList = [];
	var treatmentList = [];
	
	var deptList = new Array();
	self.hospital.getDeptList('D', function(result) {
		var sltList = result; 
		$('#opDepartmentCd').empty();
		$('#anesDepartmentCd').empty();
		$('#trDepartmentCd').empty();
		
		var totalOption = $('<option></option>').clone().attr('value', '%').text('전체');
		$('#opDepartmentCd, #anesDepartmentCd, #trDepartmentCd').append(totalOption);
		
		for(var i=0; i<sltList.length; i++){
			var option = $('<option></option>').clone().attr('value', sltList[i].departmentCd)
													.text(sltList[i].operatingDeptNm);
			$('#opDepartmentCd, #anesDepartmentCd, #trDepartmentCd').append(option);
		};
		$('#opDepartmentCd').val('%');
		$('#anesDepartmentCd').val('%');
		$('#trDepartmentCd').val('%');		
	});
	
	self.hospital.getOpCntrList(function(result) {
		var OpCntrList = result; 
		$('#opOperatingCntr').empty();
		$('#anesOperatingCntr').empty();
		var totalOption = $('<option></option>').clone().attr('value', '%').text('전체');
		$('#opOperatingCntr, #anesOperatingCntr').append(totalOption);
		
		for(var i=0; i<OpCntrList.length; i++){
			var option = $('<option></option>').clone().attr('value', OpCntrList[i].operatingCntrCd)
													.text(OpCntrList[i].operatingCntrNm);
			$('#opOperatingCntr, #anesOperatingCntr').append(option);
		};
		$('#opOperatingCntr').val('%');
		$('#anesOperatingCntr').val('%');
	});
	
	self.hospital.getTrCntrList(function(result) {
		var TrCntrList = result; 
		$('#trTreatmentCntr').empty();
		var totalOption = $('<option></option>').clone().attr('value', '%').text('전체');
		$('#trTreatmentCntr').append(totalOption);
		
		for(var i=0; i<TrCntrList.length; i++){
			var option = $('<option></option>').clone().attr('value', TrCntrList[i].treatmentCntrCd)
													.text(TrCntrList[i].treatmentCntrNm);
			$('#trTreatmentCntr').append(option);
		};
		$('#trTreatmentCntr').val('%');
	});
		
//	self.hospital.getOpRoomList( "MOR", function(result) {
//		var opRoomList = result; 
//		$('#opOperatingRoom').empty();
//		$('#anesOperatingRoom').empty();
//		var totalOption = $('<option></option>').clone().attr('value', '%').text('전체');
//		$('#opOperatingRoom, #anesOperatingRoom').append(totalOption);
//		
//		for(var i=0; i<opRoomList.length; i++){
//			var option = $('<option></option>').clone().attr('value', opRoomList[i].operatingRoomCd)
//													.text(opRoomList[i].operatingRoomNm);
//			$('#opOperatingRoom, #anesOperatingRoom').append(option);
//		};
//		$('#opOperatingRoom').val('%');
//		$('#anesOperatingRoom').val('%');
//	});

	/**
	 * 초기화
	 */
	this.init = function(){
		operatingInit();
		operatingAddEvent();
		searchOperatingList();
		
	    var sortList = new Array();
		sortList = [{key: 'operatingDeptNm', type: 'string', value: '집도과순'},
		            {key: 'operatingRoom', type: 'string', value: '수술방번호순'},
		            {key: 'patientNm', type: 'string', value: '이름순'}];
		sortInit(sortList);
		
		$('#operatingTab a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
			patientInfoInit();
			if($("ul#operatingTab.nav-tabs li.active a").attr('aria-controls')=='tabOperating'){
				operatingInit();
				operatingAddEvent();
				sortList = [{key: 'operatingDeptNm', type: 'string', value: '집도과순'},
				            {key: 'operatingRoom', type: 'string', value: '수술방번호순'},
				            {key: 'patientNm', type: 'string', value: '이름순'}];
				sortInit(sortList);
				searchOperatingList();
			}else if($("ul#operatingTab.nav-tabs li.active a").attr('aria-controls')=='tabAnesthesia'){
				anesthesiaInit();
				anesthesiaAddEvent();
				sortList = [{key: 'operatingDeptNm', type: 'string', value: '집도과순'},
				            {key: 'operatingRoom', type: 'string', value: '수술방번호순'},
				            {key: 'patientNm', type: 'string', value: '이름순'}];
				sortInit(sortList);
				searchAnesthesiaList();
			}else if($("ul#operatingTab.nav-tabs li.active a").attr('aria-controls')=='tabTreatment'){
				treatmentInit();
				treatmentAddEvent();
				sortList = [{key: 'operatingDeptNm', type: 'string', value: '시술과순'},
				            {key: 'treatmentCntrCd', type: 'string', value: '시술실순'},
				            {key: 'patientNm', type: 'string', value: '이름순'}];
				sortInit(sortList);
				searchTreatmentList();
			}else{
				/*slef.aler('에러메시지?');*/
			};
		});
	};
	
	var patientInfoInit = function(){
		$('#divId').text('');
		$('#divOpPatientName').text('');
		$('#divOpDoctorName').text('');
		$('#divAnesthesiaDrNm').text('');
		$('#divOperatingCntr').text('');
		$('#divOpName1').text('');
		$('#divOpTime').text('');
		$('#divAnTime').text('');
		$('#divAnesMethod').text('');
		$('#divOperatingSticksOut').text('');
	};
	/*-----------------수술 탭---------------------*/
	var operatingInit = function(){
	    var todayDateStr = moment(today).format('YYYY-MM-DD');
	    /*var prevDayStr = moment(prevDay).format('YYYY-MM-DD');*/
	    
		$opViewToDt.val(todayDateStr);
	    $opViewFmDt.val(todayDateStr);
	    
	    $('.anDisplayOnly').css('display', 'none');
		$('.trDisplayOnly').css('display', 'none');
		$('.opDisplayOnly').css('display', 'block');
		$('.trDisplayNone').css('display', 'block');
		
		$('#opDepartmentCd').val('%');
		$('#opOperatingCntr').val('%');
		$('#opOperatingRoom').val('%');
		$('[id*=opOperatingTyp]').prop('checked', false);
		$('#opOperatingTypAll').prop('checked', true);
		
		if( self.isTablet() ) {
			$('.tablet-header-ctrl').addClass('text-center');
		}
		
		operatingList = [];
		$opTotalNumSpan.text(0);
	 	$ulOperationList.empty();
	};
	/**
	 * 이벤트 등록
	 */
	var operatingAddEvent = function(){
		$opSearchBtn.unbind();
		$opSearchBtn.on("click", function(e){
			$('.header span').css('display', 'none');
			searchOperatingList();
		});
		$opSortOpenBtn.unbind();
		$opSortOpenBtn.on("click", function(e){
			$('#sortModal').modal('show');
		});
		
		$('#sortConfirmBtn').unbind();
		$('#sortConfirmBtn').on("click", function(e){
			$('#sortModal').modal('hide');
			sortOperatingList($('#sltSort').val(), $('#sltSort option:selected').attr('type'), $('input[type="radio"][name="sortRadio"]:checked').val());

			$('.header span').css('display', 'none');
			$('.header.sort_'+$('#sltSort').val()+' .sort-icon-'+$('input[type="radio"][name="sortRadio"]:checked').val()).css('display', 'inline-block');
		});
		
		$('#opOperatingTypAll').unbind();
		$('#opOperatingTypAll').change(function(e){
			if(e.currentTarget.checked){
				$('[id*=opOperatingTyp]:not(#opOperatingTypAll)').prop('checked', false);
			}
		});
		
		$('[id*=opOperatingTyp]:not(#opOperatingTypAll)').unbind();
		$('[id*=opOperatingTyp]:not(#opOperatingTypAll)').change(function(e){
			if(e.currentTarget.checked && $('#opOperatingTypAll').prop('checked')){
				$('#opOperatingTypAll').prop('checked', false);
			}
		});
		
		// 수술실 변경
		$('#opOperatingCntr').unbind();
		$('#opOperatingCntr').on("change", function(e){
			if( e.currentTarget.value == '') return;
			changeOpOperatingRoom(e.currentTarget.value);
		});

	};
	
	// 수술실 리스트 변경시, 방 목록 재로드
	var changeOpOperatingRoom = function( ParamOperatingCntr){
		self.hospital.getOpRoomList( ParamOperatingCntr, function(result) {
			var opRoomList = result; 
			$('#opOperatingRoom').empty();
			var totalOption = $('<option></option>').clone().attr('value', '%').text('전체');
			$('#opOperatingRoom').append(totalOption);
			
			for(var i=0; i<opRoomList.length; i++){
				var option = $('<option></option>').clone().attr('value', opRoomList[i].operatingRoomCd)
														.text(opRoomList[i].operatingRoomNm);
				$('#opOperatingRoom').append(option);
			};
			$('#opOperatingRoom').val('%');
		});
	};
	
	var sortOperatingList = function(key, type, method){
		operatingList = self.util.sortObj(operatingList, key, type, method);
		bindingOperatingList(operatingList);
	};
	
	var searchOperatingList = function(){
		if($opViewToDt.val()=='' || $opViewFmDt.val()==''){
			self.alert('조회 일자를 입력해주세요.');
			return;
		}
		
		if(self.dateCalc($opViewFmDt.val(), $opViewToDt.val())>6){
			self.alert('조회 기간은 7일이내로 설정해주세요.');
			return;
		}else if(self.dateCalc($opViewFmDt.val(), $opViewToDt.val())<0){
			self.alert('조회 기간을 확인해주세요.');
			return;
		}
		
		if($('[id*=opOperatingTyp]:checked').length<1){
			$('#opOperatingTypAll').prop('checked', true);
		}
		
		patientInfoInit();
		$ulOperationList.empty();
		operatingList = [];
		var param = {
				startDt: moment($opViewFmDt.val()).format('YYYYMMDD'),
				endDt: moment($opViewToDt.val()).format('YYYYMMDD'),
				operatingCntrCd: $('#opOperatingCntr').val(),
				departmentCd: $('#opDepartmentCd').val(),
				operatingRoomCd: $('#opOperatingRoom').val(),
				operatingDrNm: '%',
				operatingTyp1: ($('#opOperatingTypAll').prop('checked') || $('#opOperatingTyp1').prop('checked'))? '1': '0',
				operatingTyp2: ($('#opOperatingTypAll').prop('checked') || $('#opOperatingTyp2').prop('checked'))? '1': '0',
				operatingTyp3: ($('#opOperatingTypAll').prop('checked') || $('#opOperatingTyp3').prop('checked'))? '1': '0'
		};
		self.schedule.getOpSchedule(param);
		bindingOperatingList(operatingList, null);
	};
	bindingOperatingList = function(bindOperatingList, extraMsg){
		$ulOperationList.empty();
		$opTotalNumSpan.text(bindOperatingList.length);
		operatingList = bindOperatingList;
			 
		if(operatingList.length==0){
			$ulOperationList.append(li.clone().append(div.clone().addClass('text-center no-result').text('―')));
		}
		
		for(var i=0; i<operatingList.length; i++){
			var divWard= div.clone().addClass("num_4 col-xs-4 col-sm-4 pdr0 letter-control").text(operatingList[i].wardNm);
			var divName = div.clone().addClass("name col-xs-5 col-sm-5").text(operatingList[i].patientNm + ' ' + operatingList[i].patientId);
			/*var divNum = div.clone().addClass("num col-xs-3 col-sm-1").append(
					span.clone().addClass('badge ' + (patientSex=='F'? 'female':'male') )
					.text( (patientSex=='F'? 'F':'M') + patientAge )
			);*/
			var divNum = div.clone().addClass("num_4 col-xs-3 col-sm-3").text(operatingList[i].gender + ' / ' + operatingList[i].age);
			
			var divOperationDt = div.clone().addClass("date col-xs-4 col-sm-4 pdr0 letter-control").text(moment(operatingList[i].operatingDt).format('YYYY-MM-DD'));
			var divoperatingDeptNm = div.clone().addClass("num_b col-xs-5 col-sm-5").text(operatingList[i].departmentNm);
			var divOperatingTyp = div.clone().addClass("lowBadge col-xs-3 col-sm-3").text(operatingList[i].operatingTyp);
						
			var divRow1 = div.clone().addClass("col-xs-12 col-sm-6 pd0").append(divWard).append(divName).append(divNum);
			var divRow2 = div.clone().addClass("col-xs-12 col-sm-6 pd0").append(divOperationDt).append(divoperatingDeptNm).append(divOperatingTyp);
			var divRow = div.clone().addClass("list-row container").append(divRow1).append(divRow2);
			$ulOperationList.append(li.clone().append(a.clone().addClass('list-group-item' + (operatingList[i].emergencyYn=='Y'? ' operation-emergency': '')).attr('patientNo', i).append(divRow)));
		}
		
		$('#operationList .list-group-item').on('click',function(){
			$('.list-group-item').removeClass('active');
			$(this).addClass('active');
			$('#openToggle').stop().animate({bottom:240},500);
			$('#overlay').stop().animate({bottom:-49},500);
			$(this).addClass('active');
			$('#footer').css('overflow','visible');
			$('#openToggle').addClass('on');
			$('#openToggle').find('.fa').removeClass('fa-chevron-up');
			$('#openToggle').find('.fa').addClass('fa-chevron-down');
			$('.pop-content ul').scrollTop(0);
			
			var patientInfo = operatingList[event.currentTarget.attributes.patientNo.value];
			$('#divId').text(patientInfo.patientId);
			$('#divOpPatientName').text(patientInfo.patientNm);
			$('#divOpDoctorName').text(patientInfo.operatingDrNm);
			$('#divDiagnosisNm').text(patientInfo.diagnosisNm);
			$('#divOperatingCntr').text(patientInfo.operatingCntrCd + ' ' + patientInfo.operatingRoomCd);
			$('#divOpName1').text(patientInfo.operatingNm);
			$('#divOpTime').text(self.util.restoreTime(patientInfo.operatingFmTm) + ' ~ ' + self.util.restoreTime(patientInfo.operatingToTm));
			$('#divAnesMethod').text(patientInfo.anesthesiaMeth);
			$('#divOperatingSticksOut').text(patientInfo.operatingSticksOut);
			
			return false;
		})
	}
	
	/*---------------------수술탭 종료-----------------------*/
	
	/*---------------------마취탭-----------------------*/
	var anesthesiaInit = function(){
		var todayDateStr = moment(today).format('YYYY-MM-DD');
		/*var prevDayStr = moment(prevDay).format('YYYY-MM-DD');*/
		
		$anesViewToDt.val(todayDateStr);
	    $anesViewFmDt.val(todayDateStr);
	    
	    $('.opDisplayOnly').css('display', 'none');
		$('.anDisplayOnly').css('display', 'block');
		$('.trDisplayOnly').css('display', 'none');
		$('.trDisplayNone').css('display', 'block');
		
		$('#anesDepartmentCd').val('%');
		$('#anesOperatingCntr').val('%');
		$('#anesOperatingRoom').val('%');
		$('[id*=anesOperatingTyp]').prop('checked', false);
		$('#anesOperatingTypAll').prop('checked', true);
		
		if( self.isTablet() ) {
			$('.tablet-header-ctrl').addClass('text-center');
		}
		anesthesiaList = [];
		$anesTotalNumSpan.text(0);
		$ulAnesthesiaList.empty();
	};
	
	var anesthesiaAddEvent = function(){
		$anesSearchBtn.unbind();
		$anesSearchBtn.on("click", function(e){
			$('.header span').css('display', 'none');
			searchAnesthesiaList();
		});
		$anesSortOpenBtn.unbind();
		$anesSortOpenBtn.on("click", function(e){
			$('#sortModal').modal('show');
		});
		
		$('#sortConfirmBtn').unbind();
		$('#sortConfirmBtn').on("click", function(e){
			$('#sortModal').modal('hide');
			sortAnesthesiaList($('#sltSort').val(), $('#sltSort option:selected').attr('type'), $('input[type="radio"][name="sortRadio"]:checked').val());

			$('.header span').css('display', 'none');
			$('.header.sort_'+$('#sltSort').val()+' .sort-icon-'+$('input[type="radio"][name="sortRadio"]:checked').val()).css('display', 'inline-block');
		});
		
		$('#anesOperatingTypAll').unbind();
		$('#anesOperatingTypAll').change(function(e){
			if(e.currentTarget.checked){
				$('[id*=anesOperatingTyp]:not(#anesOperatingTypAll)').prop('checked', false);
			}
		});
		
		$('[id*=anesOperatingTyp]:not(#anesOperatingTypAll)').unbind();
		$('[id*=anesOperatingTyp]:not(#anesOperatingTypAll)').change(function(e){
			if(e.currentTarget.checked && $('#anesOperatingTypAll').prop('checked')){
				$('#anesOperatingTypAll').prop('checked', false);
			}
		});
		
		// 마취실 변경
		$('#anesOperatingCntr').unbind();
		$('#anesOperatingCntr').on("change", function(e){
			if( e.currentTarget.value == '') return;
			changeAnesOperatingRoom(e.currentTarget.value);
		});
	};
	
	// 마취실 리스트 변경시, 방 목록 재로드
	var changeAnesOperatingRoom = function( ParamOperatingCntr){
		self.hospital.getOpRoomList( ParamOperatingCntr, function(result) {
			var opRoomList = result; 
			$('#anesOperatingRoom').empty();
			var totalOption = $('<option></option>').clone().attr('value', '%').text('전체');
			$('#anesOperatingRoom').append(totalOption);
			
			for(var i=0; i<opRoomList.length; i++){
				var option = $('<option></option>').clone().attr('value', opRoomList[i].operatingRoomCd)
														.text(opRoomList[i].operatingRoomNm);
				$('#anesOperatingRoom').append(option);
			};
			$('#anesOperatingRoom').val('%');
		});
	};
	
	var sortAnesthesiaList = function(key, type, method){
		anesthesiaList = self.util.sortObj(anesthesiaList, key, type, method);
		bindingAnesthesiaList(anesthesiaList);
	};
	
	var searchAnesthesiaList = function(){
		if($anesViewToDt.val()=='' || $anesViewFmDt.val()==''){
			self.alert('조회 일자를 입력해주세요.');
			return;
		};
		
		if(self.dateCalc($anesViewFmDt.val(), $anesViewToDt.val())>6){
			self.alert('조회 기간은 7일이내로 설정해주세요.');
			return;
		}else if(self.dateCalc($anesViewFmDt.val(), $anesViewToDt.val())<0){
			self.alert('조회 기간을 확인해주세요.');
			return;
		};
		
		if($('[id*=anesOperatingTyp]:checked').length<1){
			$('#anesOperatingTypAll').prop('checked', true);
		};
		
		patientInfoInit();
		$ulAnesthesiaList.empty();
		anesthesiaList = [];
		var param = {
				startDt: moment($anesViewFmDt.val()).format('YYYYMMDD'),
				endDt: moment($anesViewToDt.val()).format('YYYYMMDD'),
				operatingCntrCd: $('#anesOperatingCntr').val(),
				departmentCd: $('#anesDepartmentCd').val(),
				operatingRoomCd: $('#anesOperatingRoom').val(),
				operatingDrNm: '%',
				operatingTyp1: ($('#anesOperatingTypAll').prop('checked') || $('#anesOperatingTyp1').prop('checked'))? '1': '0',
				operatingTyp2: ($('#anesOperatingTypAll').prop('checked') || $('#anesOperatingTyp2').prop('checked'))? '1': '0',
				operatingTyp3: ($('#anesOperatingTypAll').prop('checked') || $('#anesOperatingTyp3').prop('checked'))? '1': '0'
		};
		self.schedule.getAnSchedule(param);
		bindingAnesthesiaList(anesthesiaList, null);
	};
	bindingAnesthesiaList = function(bindAnesthesiaList, extraMsg){
		$ulAnesthesiaList.empty();
		$anesTotalNumSpan.text(bindAnesthesiaList.length);
		anesthesiaList = bindAnesthesiaList;
			 
		if(anesthesiaList.length==0){
			$ulAnesthesiaList.append(li.clone().append(div.clone().addClass('text-center no-result').text('―')));
		}
		
		for(var i=0; i<anesthesiaList.length; i++){
			var divWard = div.clone().addClass("num_3 col-xs-4 col-sm-4 pdr0 letter-control").text(anesthesiaList[i].wardNm);
			var divName = div.clone().addClass("name col-xs-5 col-sm-5").text(anesthesiaList[i].patientNm + ' ' + anesthesiaList[i].patientId);
			var divNum = div.clone().addClass("num_3 col-xs-3 col-sm-3").text(anesthesiaList[i].gender + ' / ' + anesthesiaList[i].age);
			/*var patientAge = anesthesiaList[i].age;
			var patientSex = anesthesiaList[i].sex;
			var divNum = div.clone().addClass("num col-xs-3 col-sm-1").append(
					span.clone().addClass('badge ' + (patientSex=='F'? 'female':'male') )
					.text( (patientSex=='F'? 'F':'M') + patientAge )
			);*/
			var divOperationDt = div.clone().addClass("date col-xs-4 col-sm-4 pdr0 letter-control").text(moment(anesthesiaList[i].operatingDt).format('YYYY-MM-DD'));
			var divoperatingDeptNm = div.clone().addClass("num_b col-xs-5 col-sm-5").text(anesthesiaList[i].departmentNm);
			var divOperatingTyp = div.clone().addClass("lowBadge col-xs-3 col-sm-3").text(anesthesiaList[i].operatingTyp);
									
			var divRow1 = div.clone().addClass("col-xs-12 col-sm-6 pd0").append(divWard).append(divName).append(divNum);
			var divRow2 = div.clone().addClass("col-xs-12 col-sm-6 pd0").append(divOperationDt).append(divoperatingDeptNm).append(divOperatingTyp);
			var divRow = div.clone().addClass("list-row container").append(divRow1).append(divRow2);
			
			$ulAnesthesiaList.append(li.clone().append(a.clone().addClass('list-group-item' + (anesthesiaList[i].emergencyYn=='Y'? ' operation-emergency': '')).attr('patientNo', i).append(divRow)));
		};
		
		$('#ulAnesthesiaList .list-group-item').on('click',function(){
			$('.list-group-item').removeClass('active');
			$(this).addClass('active');
			$('#openToggle').stop().animate({bottom:240},500);
			$('#overlay').stop().animate({bottom:-49},500);
			$(this).addClass('active');
			$('#footer').css('overflow','visible');
			$('#openToggle').addClass('on');
			$('#openToggle').find('.fa').removeClass('fa-chevron-up');
			$('#openToggle').find('.fa').addClass('fa-chevron-down');
			$('.pop-content ul').scrollTop(0);
			
			var patientInfo = anesthesiaList[event.currentTarget.attributes.patientNo.value];
			$('#divId').text(patientInfo.patientId);
			$('#divOpPatientName').text(patientInfo.patientNm);
			$('#divOpDoctorName').text(patientInfo.operatingDrNm);
			$('#divAnesthesiaNm').text(patientInfo.anesthesiaNm);
			$('#divAnesthesiaDrNm').text(patientInfo.anesthesiaDrNm);
			$('#divOperatingCntr').text(patientInfo.operatingCntrCd + ' ' + patientInfo.operatingRoomCd);
			$('#divAnTime').text(self.util.restoreTime(patientInfo.anesthesiaFmTm) + ' ~ ' + self.util.restoreTime(patientInfo.anesthesiaToTm));
			$('#divAnesMethod').text(patientInfo.anesthesiaMeth);
			$('#divOperatingSticksOut').text(patientInfo.operatingSticksOut);
			
			return false;
		})
	}
	
	/*-----------------마취 탭종료---------------------*/
	/*-----------------시술 탭---------------------*/
	var treatmentInit = function(){
	    var todayDateStr = moment(today).format('YYYY-MM-DD');
	    /*var prevDayStr = moment(prevDay).format('YYYY-MM-DD');*/
	    
		$trViewToDt.val(todayDateStr);
	    $trViewFmDt.val(todayDateStr);
	    
	    $('.opDisplayOnly').css('display', 'none');
		$('.anDisplayOnly').css('display', 'none');
		$('.trDisplayOnly').css('display', 'block');
		$('.trDisplayNone').css('display', 'none');
		
		$('#trDepartmentCd').val('%');
		$('#trTreatmentCntr').val('%');
		$('#trTreatTyp').val('I');
		$('[id*=trTreatmentTyp]').prop('checked', false);
		$('#trTreatmentTyp1').prop('checked', true);
		
		if( self.isTablet() ) {
			$('.tablet-header-ctrl').addClass('text-center');
		}
		
		treatmentList = [];
		$trTotalNumSpan.text(0);
	 	$ulTreatmentList.empty();
	};
	/**
	 * 이벤트 등록
	 */
	var treatmentAddEvent = function(){
		$trSearchBtn.unbind();
		$trSearchBtn.on("click", function(e){
			$('.header span').css('display', 'none');
			searchTreatmentList();
		});
		$trSortOpenBtn.unbind();
		$trSortOpenBtn.on("click", function(e){
			$('#sortModal').modal('show');
		});
		
		$('#sortConfirmBtn').unbind();
		$('#sortConfirmBtn').on("click", function(e){
			$('#sortModal').modal('hide');
			sortTreatmentList($('#sltSort').val(), $('#sltSort option:selected').attr('type'), $('input[type="radio"][name="sortRadio"]:checked').val());

			$('.header span').css('display', 'none');
			$('.header.sort_'+$('#sltSort').val()+' .sort-icon-'+$('input[type="radio"][name="sortRadio"]:checked').val()).css('display', 'inline-block');
		});
		
		$('[id*=trTreatmentTyp]').unbind();
		$('[id*=trTreatmentTyp]').change(function(e){
			$('[id*=trTreatmentTyp]:not(#' + e.currentTarget.id + ')').prop('checked', false);
		});
	};
	var sortTreatmentList = function(key, type, method){
		treatmentList = self.util.sortObj(treatmentList, key, type, method);
		bindingTreatmentList(treatmentList);
	};
	
	var searchTreatmentList = function(){
		if($trViewToDt.val()=='' || $trViewFmDt.val()==''){
			self.alert('조회 일자를 입력해주세요.');
			return;
		}
		
		if(self.dateCalc($trViewFmDt.val(), $trViewToDt.val())>6){
			self.alert('조회 기간은 7일이내로 설정해주세요.');
			return;
		}else if(self.dateCalc($trViewFmDt.val(), $trViewToDt.val())<0){
			self.alert('조회 기간을 확인해주세요.');
			return;
		}
		
		if($('[id*=trTreatmentTyp]:checked').length<1){
			$('#trTreatmentTypAll').prop('checked', true);
		}
		
		patientInfoInit();
		$ulTreatmentList.empty();
		treatmentList = [];
		var param = {
				startDt: moment($trViewFmDt.val()).format('YYYYMMDD'),
				endDt: moment($trViewToDt.val()).format('YYYYMMDD'),
				treatTyp: $('#trTreatTyp').val(),
				departmentCd: $('#trDepartmentCd').val(),
				treatmentCntrCd: $('#trTreatmentCntr').val(),
				treatmentTyp1: $('#trTreatmentTyp1').prop('checked')? '1': '0',
				treatmentTyp2: $('#trTreatmentTyp2').prop('checked')? '1': '0',
				treatmentTyp3: $('#trTreatmentTyp3').prop('checked')? '1': '0'
		};
		self.schedule.getTrSchedule(param);
		bindingTreatmentList(treatmentList, null);
	};
	bindingTreatmentList = function(bindTreatmentList, extraMsg){
		$ulTreatmentList.empty();
		$trTotalNumSpan.text(bindTreatmentList.length);
		treatmentList = bindTreatmentList;
			 
		if(treatmentList.length==0){
			$ulTreatmentList.append(li.clone().append(div.clone().addClass('text-center no-result').text('―')));
		}
		
		for(var i=0; i<treatmentList.length; i++){
			var divWard = div.clone().addClass("num_3 col-xs-4 col-sm-4 pdr0 letter-control").text(treatmentList[i].wardNm);
			var divName = div.clone().addClass("name col-xs-5 col-sm-5").text(treatmentList[i].patientNm + ' ' + treatmentList[i].patientId);
			var divNum = div.clone().addClass("num_3 col-xs-3 col-sm-3").text(treatmentList[i].gender + ' / ' + treatmentList[i].age);

			var divOperationDt = div.clone().addClass("date col-xs-4 col-sm-4 pdr0 letter-control").text(treatmentList[i].treatmentDt != ''? moment(treatmentList[i].treatmentDt).format('YYYY-MM-DD') : '-');
			var divoperatingDeptNm = div.clone().addClass("num_b col-xs-5 col-sm-5").text(treatmentList[i].departmentNm);
			var divOperatingTyp = div.clone().addClass("lowBadge col-xs-3 col-sm-3").text(treatmentList[i].treatmentTyp);
									
			var divRow1 = div.clone().addClass("col-xs-12 col-sm-6 pd0").append(divWard).append(divName).append(divNum);
			var divRow2 = div.clone().addClass("col-xs-12 col-sm-6 pd0").append(divOperationDt).append(divoperatingDeptNm).append(divOperatingTyp);
			var divRow = div.clone().addClass("list-row container").append(divRow1).append(divRow2);
			
			$ulTreatmentList.append(li.clone().append(a.clone().addClass('list-group-item' + (treatmentList[i].emergencyYn=='Y'? ' operation-emergency': '')).attr('patientNo', i).append(divRow)));
		};
		
		$('#ulTreatmentList .list-group-item').on('click',function(){
			$('.list-group-item').removeClass('active');
			$(this).addClass('active');
			$('#openToggle').stop().animate({bottom:240},500);
			$('#overlay').stop().animate({bottom:-49},500);
			$(this).addClass('active');
			$('#footer').css('overflow','visible');
			$('#openToggle').addClass('on');
			$('#openToggle').find('.fa').removeClass('fa-chevron-up');
			$('#openToggle').find('.fa').addClass('fa-chevron-down');
			$('.pop-content ul').scrollTop(0);
			
			var patientInfo = treatmentList[event.currentTarget.attributes.patientNo.value];
			$('#divId').text(patientInfo.patientId);
			$('#divOpPatientName').text(patientInfo.patientNm);
			$('#divTrDoctorName').text(patientInfo.treatmentDrNm);
			$('#divDiagnosisNm').text(patientInfo.diagnosisNm);
			$('#divTreatmentCntr').text(patientInfo.treatmentCntrCd);
			$('#divTrName1').text(patientInfo.treatmentNm);
			$('#divTrTime').text(patientInfo.treatmentFmTm + ' ~ ' + patientInfo.treatmentToTm);
			//$('#divAnesMethod').text(patientInfo.anesthesiaMeth);
			//$('#divOperatingSticksOut').text(patientInfo.operatingSticksOut);
			
			return false;
		})
	}
	
	/*---------------------시술탭 종료-----------------------*/
};
