
/****************************************************************************
* 병원 정보 상세 조회
****************************************************************************/
function fn_selectHospitalJson(){
	let formData = new FormData();
	formData.append("menuClass", menuClass);

	$.ajax({
		url: encodeURI('/webhospital/selectHospital.do'),
		data: formData,
		dataType: "json",
		processData: false,
		contentType: false,
		type: 'POST',
		async: true,
		success: function(data){
			if('0'==data.msgCode){
				// 병원 정보
				let hospitalRows = data.rows[0];
				
				$("#muHospitalId").val(hospitalRows.muHospitalId);
				if('Y'==hospitalRows.monOpenYn){
					$('#checkMonOpenYn').prop('checked',true).trigger("change");
					
					let CheckMonOpenParent = $('#checkMonOpenYn').closest('li.on');
					CheckMonOpenParent.find("#monOpenStartTime").siblings("button").text(hospitalRows.monOpenStartTime);
					CheckMonOpenParent.find("#monOpenStartTime").val(hospitalRows.monOpenStartTime);
					CheckMonOpenParent.find("#monOpenEndTime").siblings("button").text(hospitalRows.monOpenEndTime);
					CheckMonOpenParent.find("#monOpenEndTime").val(hospitalRows.monOpenEndTime);
					CheckMonOpenParent.find("#monBreakStartTime").siblings("button").text(hospitalRows.monBreakStartTime);
					CheckMonOpenParent.find("#monBreakStartTime").val(hospitalRows.monBreakStartTime);
					CheckMonOpenParent.find("#monBreakEndTime").siblings("button").text(hospitalRows.monBreakEndTime);
					CheckMonOpenParent.find("#monBreakEndTime").val(hospitalRows.monBreakEndTime);
				}
				
				if('Y'==hospitalRows.tueOpenYn){
					$('#checkTueOpenYn').prop('checked',true).trigger("change");
					
					let CheckTueOpenParent = $('#checkTueOpenYn').closest('li.on');
					CheckTueOpenParent.find("#tueOpenStartTime").siblings("button").text(hospitalRows.tueOpenStartTime);
					CheckTueOpenParent.find("#tueOpenStartTime").val(hospitalRows.tueOpenStartTime);
					CheckTueOpenParent.find("#tueOpenEndTime").siblings("button").text(hospitalRows.tueOpenEndTime);
					CheckTueOpenParent.find("#tueOpenEndTime").val(hospitalRows.tueOpenEndTime);
					CheckTueOpenParent.find("#tueBreakStartTime").siblings("button").text(hospitalRows.tueBreakStartTime);
					CheckTueOpenParent.find("#tueBreakStartTime").val(hospitalRows.tueBreakStartTime);
					CheckTueOpenParent.find("#tueBreakEndTime").siblings("button").text(hospitalRows.tueBreakEndTime);
					CheckTueOpenParent.find("#tueBreakEndTime").val(hospitalRows.tueBreakEndTime);
				}
				
				if('Y'==hospitalRows.wedOpenYn){
					$('#checkWedOpenYn').prop('checked',true).trigger("change");
					
					let CheckWedOpenParent = $('#checkWedOpenYn').closest('li.on');
					CheckWedOpenParent.find("#wedOpenStartTime").siblings("button").text(hospitalRows.wedOpenStartTime);
					CheckWedOpenParent.find("#wedOpenStartTime").val(hospitalRows.wedOpenStartTime);
					CheckWedOpenParent.find("#wedOpenEndTime").siblings("button").text(hospitalRows.wedOpenEndTime);
					CheckWedOpenParent.find("#wedOpenEndTime").val(hospitalRows.wedOpenEndTime);
					CheckWedOpenParent.find("#wedBreakStartTime").siblings("button").text(hospitalRows.wedBreakStartTime);
					CheckWedOpenParent.find("#wedBreakStartTime").val(hospitalRows.wedBreakStartTime);
					CheckWedOpenParent.find("#wedBreakEndTime").siblings("button").text(hospitalRows.wedBreakEndTime);
					CheckWedOpenParent.find("#wedBreakEndTime").val(hospitalRows.wedBreakEndTime);
				}

				if('Y'==hospitalRows.thuOpenYn){
					$('#checkThuOpenYn').prop('checked',true).trigger("change");
					
					let CheckThuOpenParent = $('#checkThuOpenYn').closest('li.on');
					CheckThuOpenParent.find("#thuOpenStartTime").siblings("button").text(hospitalRows.thuOpenStartTime);
					CheckThuOpenParent.find("#thuOpenStartTime").val(hospitalRows.thuOpenStartTime);
					CheckThuOpenParent.find("#thuOpenEndTime").siblings("button").text(hospitalRows.thuOpenEndTime);
					CheckThuOpenParent.find("#thuOpenEndTime").val(hospitalRows.thuOpenEndTime);
					CheckThuOpenParent.find("#thuBreakStartTime").siblings("button").text(hospitalRows.thuBreakStartTime);
					CheckThuOpenParent.find("#thuBreakStartTime").val(hospitalRows.thuBreakStartTime);
					CheckThuOpenParent.find("#thuBreakEndTime").siblings("button").text(hospitalRows.thuBreakEndTime);
					CheckThuOpenParent.find("#thuBreakEndTime").val(hospitalRows.thuBreakEndTime);
				}
				
				if('Y'==hospitalRows.friOpenYn){
					$('#checkFriOpenYn').prop('checked',true).trigger("change");
					
					let CheckFriOpenParent = $('#checkFriOpenYn').closest('li.on');
					CheckFriOpenParent.find("#friOpenStartTime").siblings("button").text(hospitalRows.friOpenStartTime);
					CheckFriOpenParent.find("#friOpenStartTime").val(hospitalRows.friOpenStartTime);
					CheckFriOpenParent.find("#friOpenEndTime").siblings("button").text(hospitalRows.friOpenEndTime);
					CheckFriOpenParent.find("#friOpenEndTime").val(hospitalRows.friOpenEndTime);
					CheckFriOpenParent.find("#friBreakStartTime").siblings("button").text(hospitalRows.friBreakStartTime);
					CheckFriOpenParent.find("#friBreakStartTime").val(hospitalRows.friBreakStartTime);
					CheckFriOpenParent.find("#friBreakEndTime").siblings("button").text(hospitalRows.friBreakEndTime);
					CheckFriOpenParent.find("#friBreakEndTime").val(hospitalRows.friBreakEndTime);
				}
				
				if('Y'==hospitalRows.satOpenYn){
					$('#checkSatOpenYn').prop('checked',true).trigger("change");
					
					let CheckSatOpenParent = $('#checkSatOpenYn').closest('li.on');
					CheckSatOpenParent.find("#satOpenStartTime").siblings("button").text(hospitalRows.satOpenStartTime);
					CheckSatOpenParent.find("#satOpenStartTime").val(hospitalRows.satOpenStartTime);
					CheckSatOpenParent.find("#satOpenEndTime").siblings("button").text(hospitalRows.satOpenEndTime);
					CheckSatOpenParent.find("#satOpenEndTime").val(hospitalRows.satOpenEndTime);
					CheckSatOpenParent.find("#satBreakStartTime").siblings("button").text(hospitalRows.satBreakStartTime);
					CheckSatOpenParent.find("#satBreakStartTime").val(hospitalRows.satBreakStartTime);
					CheckSatOpenParent.find("#satBreakEndTime").siblings("button").text(hospitalRows.satBreakEndTime);
					CheckSatOpenParent.find("#satBreakEndTime").val(hospitalRows.satBreakEndTime);
				}

				if('Y'==hospitalRows.sunOpenYn){
					$('#checkSunOpenYn').prop('checked',true).trigger("change");
					
					let CheckSunOpenParent = $('#checkSunOpenYn').closest('li.on');
					CheckSunOpenParent.find("#sunOpenStartTime").siblings("button").text(hospitalRows.sunOpenStartTime);
					CheckSunOpenParent.find("#sunOpenStartTime").val(hospitalRows.sunOpenStartTime);
					CheckSunOpenParent.find("#sunOpenEndTime").siblings("button").text(hospitalRows.sunOpenEndTime);
					CheckSunOpenParent.find("#sunOpenEndTime").val(hospitalRows.sunOpenEndTime);
					CheckSunOpenParent.find("#sunBreakStartTime").siblings("button").text(hospitalRows.sunBreakStartTime);
					CheckSunOpenParent.find("#sunBreakStartTime").val(hospitalRows.sunBreakStartTime);
					CheckSunOpenParent.find("#sunBreakEndTime").siblings("button").text(hospitalRows.sunBreakEndTime);
					CheckSunOpenParent.find("#sunBreakEndTime").val(hospitalRows.sunBreakEndTime);
				}
				
				if('Y'==hospitalRows.publicHolidayUseYn){
					$('#checkPublicHolidayUseYn').prop('checked',true);
				}
				
				$("#txt_muMemberId").val(hospitalRows.muMemberId);
				$("#txt_memberName").val(hospitalRows.memberName);
				
				// 휴일 상세 정보
				fn_addRow2(hospitalRows.holidayRows);
			}
			else{
				modalEvent.danger("조회 오류", data.msgDesc);
			}
		},
		error : function(xhr, status, error) {
			modalEvent.danger("조회 오류", "조회 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
		},
		beforeSend:function(){
			
		},
		complete:function(){
			
		}
	});
}

/****************************************************************************
* 조회 row 추가 이벤트
****************************************************************************/
function fn_addRow2(detailList){
	let addRowHtml = '';
	
	if(0<detailList.length){
		addRowHtml += '<li class="list_title_li">';
		addRowHtml += '	<span class="list_title">휴일명</span>';
		addRowHtml += '	<span class="list_title">날짜</span>';
		addRowHtml += '	<span class="list_title">일정반복</span>';
		addRowHtml += '	<span class="list_title"></span>';
		addRowHtml += '</li>';
		
		for(let i = 0; i < detailList.length; i++){
			let hospitalHolidayName = detailList[i].hospitalHolidayName;
			let locDate             = detailList[i].locDate;
			let repeatYn            = detailList[i].repeatYn;
			
			addRowHtml += '<li>';
			addRowHtml += '	<div class="input_box">';
			addRowHtml += '		<input type="text" name="hospitalHolidayName" value="'+hospitalHolidayName+'" placeholder="휴일명" maxlength="50">';
			addRowHtml += '	</div>';
			
			addRowHtml += '	<div class="calendar_box">';
			addRowHtml += '		<div class="date_box">';
			addRowHtml += '			<img src="/image/web/calendar.svg" alt="calendar"/>';
			addRowHtml += '			<input type="date" class="date_picker" name="dateLocDate" value="'+locDate+'">';
			addRowHtml += '		</div>';
			addRowHtml += '	</div>';
			
			addRowHtml += '	<div class="select_list">';
			addRowHtml += '		<div class="select_box dropdown">';
			if('Y'==repeatYn){
				addRowHtml += '		<button type="button" class="label" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">반복</button>';
				addRowHtml += '		<input type="hidden" name="repeatYn" value="Y"/>';
			}
			else{
				addRowHtml += '		<button type="button" class="label" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">반복 안함</button>';
				addRowHtml += '		<input type="hidden" name="repeatYn" value="N"/>';
			}
			addRowHtml += '			<ul class="select_option_list dropdown-menu">';
			addRowHtml += '				<li class="option_list_item first" onclick="fn_clickSelectValue(this, \'Y\', \'반복\');">반복</li>';
			addRowHtml += '				<li class="option_list_item" onclick="fn_clickSelectValue(this, \'N\', \'반복 안함\');">반복 안함</li>';
			addRowHtml += '			</ul>';
			addRowHtml += '		</div>';
			addRowHtml += '	</div>';
			
			if(i==0){
				addRowHtml += '<div class="add_box">';
				addRowHtml += '	<button onclick="javascript:fn_removeRow2(this);"><img src="/image/web/subtract.svg" alt="삭제"></button>';
				addRowHtml += '</div>';

				addRowHtml += '<div class="add_box">';
				addRowHtml += '	<button onclick="javascript:fn_addRow(this);"><img src="/image/web/add.svg" alt="추가"/></button>';
				addRowHtml += '</div>';
			}
			else{
				addRowHtml += '<div class="add_box" style="display:none;">';
				addRowHtml += '	<button onclick="javascript:fn_addRow(this);"><img src="/image/web/add.svg" alt="추가"/></button>';
				addRowHtml += '</div>';
				
				addRowHtml += '<div class="subtract_box">';
				addRowHtml += '	<button onclick="javascript:fn_removeRow(this);"><img src="/image/web/subtract.svg" alt="삭제"></button>';
				addRowHtml += '</div>';
			}
			
			addRowHtml += '</li>';
		}
		$('#hospitalHolidayList').empty().html(addRowHtml).trigger("create");
	}
	else{
		fn_addRow();
	}
	
	// 날짜  datepicker
	fn_datePicker("#hospitalHolidayList input[type='date']");
	
	let parentTable = $("#hospitalHolidayList");
	fn_hospitalRefreshOrderNumber(parentTable);
	
}

/****************************************************************************
* row 추가 이벤트
****************************************************************************/
function fn_addRow(param){
	let addRowHtml = '';
	addRowHtml += '<li>';
	addRowHtml += '	<div class="input_box">';
	addRowHtml += '		<input type="text" name="hospitalHolidayName" value="" placeholder="휴일명" maxlength="50">';
	addRowHtml += '	</div>';
	
	addRowHtml += '	<div class="calendar_box">';
	addRowHtml += '		<div class="date_box">';
	addRowHtml += '			<img src="/image/web/calendar.svg" alt="calendar"/>';
	addRowHtml += '			<input type="date" class="date_picker" name="dateLocDate">';
	addRowHtml += '		</div>';
	addRowHtml += '	</div>';
	
	addRowHtml += '	<div class="select_list">';
	addRowHtml += '		<div class="select_box dropdown">';
	addRowHtml += '			<button type="button" class="label" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">반복 여부</button>';
	addRowHtml += '			<input type="hidden" name="repeatYn" value=""/>';
	addRowHtml += '			<ul class="select_option_list dropdown-menu">';
	addRowHtml += '				<li class="option_list_item first" onclick="fn_clickSelectValue(this, \'Y\', \'반복\');">반복</li>';
	addRowHtml += '				<li class="option_list_item" onclick="fn_clickSelectValue(this, \'N\', \'반복 안함\');">반복 안함</li>';
	addRowHtml += '			</ul>';
	addRowHtml += '		</div>';
	addRowHtml += '	</div>';

	addRowHtml += '	<div class="subtract_box" style="display:none;">';
	addRowHtml += '		<button onclick="javascript:fn_removeRow(this);"><img src="/image/web/subtract.svg" alt="삭제"></button>';
	addRowHtml += '	</div>';

	addRowHtml += '	<div class="add_box">';
	addRowHtml += '		<button onclick="javascript:fn_addRow(this);"><img src="/image/web/add.svg" alt="추가"/></button>';
	addRowHtml += '	</div>';

	addRowHtml += '</li>';
	$('#hospitalHolidayList').append(addRowHtml).trigger("create");
	
	// 날짜  datepicker
	fn_datePicker("#hospitalHolidayList input[type='date']");

	let parentTable = $("#hospitalHolidayList");
	fn_hospitalRefreshOrderNumber(parentTable);
}

/****************************************************************************
* row 삭제 이벤트
****************************************************************************/
function fn_removeRow(param){
	let liLength = $('#hospitalHolidayList').children('li').length;
	
	if(2<liLength){
		let liNum = $(param).closest('li').prevAll().length;
		$('#hospitalHolidayList').children('li').eq(liNum).remove();
	}
	else{
		modalEvent.warning("입력 오류", "더 이상 삭제할 수 없습니다.");
	}
}

/****************************************************************************
* row 삭제 이벤트
****************************************************************************/
function fn_removeRow2(param){
	let liNum = $(param).closest('li').prevAll().length;
	$('#hospitalHolidayList').children('li').eq(liNum).remove();

	fn_addRow();
}

/****************************************************************************
* 전체 row 버튼 변경
****************************************************************************/
function fn_hospitalRefreshOrderNumber(param){
	// row 추가/삭제 버튼 처리
	$(param).find(".add_box").hide();
	$(param).find('.subtract_box').show();
	$(param).children("li:eq(1)").find(".subtract_box").hide();
	$(param).children("li:eq(1)").find(".add_box").show();
}

/****************************************************************************
* 병원 정보 수정
****************************************************************************/
function fn_updateHospital(){
	let muHospitalId       = $("#muHospitalId").val();
	
	let monOpenYn          = $("#checkMonOpenYn").is(':checked')==true?'Y':'N';
	let monOpenStartTime   = $("#monOpenStartTime").val();
	let monOpenEndTime     = $("#monOpenEndTime").val();
	let monBreakStartTime  = $("#monBreakStartTime").val();
	let monBreakEndTime    = $("#monBreakEndTime").val();
	
	let tueOpenYn          = $("#checkTueOpenYn").is(':checked')==true?'Y':'N';
	let tueOpenStartTime   = $("#tueOpenStartTime").val();
	let tueOpenEndTime     = $("#tueOpenEndTime").val();
	let tueBreakStartTime  = $("#tueBreakStartTime").val();
	let tueBreakEndTime    = $("#tueBreakEndTime").val();
	
	let wedOpenYn          = $("#checkWedOpenYn").is(':checked')==true?'Y':'N';
	let wedOpenStartTime   = $("#wedOpenStartTime").val();
	let wedOpenEndTime     = $("#wedOpenEndTime").val();
	let wedBreakStartTime  = $("#wedBreakStartTime").val();
	let wedBreakEndTime    = $("#wedBreakEndTime").val();
	
	let thuOpenYn          = $("#checkThuOpenYn").is(':checked')==true?'Y':'N';
	let thuOpenStartTime   = $("#thuOpenStartTime").val();
	let thuOpenEndTime     = $("#thuOpenEndTime").val();
	let thuBreakStartTime  = $("#thuBreakStartTime").val();
	let thuBreakEndTime    = $("#thuBreakEndTime").val();

	let friOpenYn          = $("#checkFriOpenYn").is(':checked')==true?'Y':'N';
	let friOpenStartTime   = $("#friOpenStartTime").val();
	let friOpenEndTime     = $("#friOpenEndTime").val();
	let friBreakStartTime  = $("#friBreakStartTime").val();
	let friBreakEndTime    = $("#friBreakEndTime").val();

	let satOpenYn          = $("#checkSatOpenYn").is(':checked')==true?'Y':'N';
	let satOpenStartTime   = $("#satOpenStartTime").val();
	let satOpenEndTime     = $("#satOpenEndTime").val();
	let satBreakStartTime  = $("#satBreakStartTime").val();
	let satBreakEndTime    = $("#satBreakEndTime").val();

	let sunOpenYn          = $("#checkSunOpenYn").is(':checked')==true?'Y':'N';
	let sunOpenStartTime   = $("#sunOpenStartTime").val();
	let sunOpenEndTime     = $("#sunOpenEndTime").val();
	let sunBreakStartTime  = $("#sunBreakStartTime").val();
	let sunBreakEndTime    = $("#sunBreakEndTime").val();
	
	let publicHolidayUseYn = $("#checkPublicHolidayUseYn").is(':checked')==true?'Y':'N';
	
	
	// 휴일 정보
	let detailArray = new Object();
	
	if("Y"!=updateUseYn){
		modalEvent.warning("", "수정 권한이 없습니다.");
		return false;
	}
	
	if(!muHospitalId){
		modalEvent.warning("", "병원 정보가 없습니다.");
		return false;
	}
	
	if('Y'==monOpenYn){
		if(!monOpenStartTime){
			modalEvent.warning("", "월요일 운영 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!monOpenEndTime){
			modalEvent.warning("", "월요일 운영 종료시간 정보가 없습니다.");
			return false;
		}
		
		if(!monBreakStartTime){
			modalEvent.warning("", "월요일 휴게 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!monBreakEndTime){
			modalEvent.warning("", "월요일 휴게 종료시간 정보가 없습니다.");
			return false;
		}
	}
	else{
		monOpenYn = 'N'
		monOpenStartTime = '00:00';
		monOpenEndTime = '00:00';
		monBreakStartTime = '00:00';
		monBreakEndTime = '00:00';
	}
	

	if('Y'==tueOpenYn){
		if(!tueOpenStartTime){
			modalEvent.warning("", "화요일 운영 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!tueOpenEndTime){
			modalEvent.warning("", "화요일 운영 종료시간 정보가 없습니다.");
			return false;
		}
		
		if(!tueBreakStartTime){
			modalEvent.warning("", "화요일 휴게 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!tueBreakEndTime){
			modalEvent.warning("", "화요일 휴게 종료시간 정보가 없습니다.");
			return false;
		}
	}
	else{
		tueOpenYn = 'N'
		tueOpenStartTime = '00:00';
		tueOpenEndTime = '00:00';
		tueBreakStartTime = '00:00';
		tueBreakEndTime = '00:00';
	}
	
	if('Y'==wedOpenYn){
		if(!wedOpenStartTime){
			modalEvent.warning("", "수요일 운영 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!wedOpenEndTime){
			modalEvent.warning("", "수요일 운영 종료시간 정보가 없습니다.");
			return false;
		}
		
		if(!wedBreakStartTime){
			modalEvent.warning("", "수요일 휴게 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!wedBreakEndTime){
			modalEvent.warning("", "수요일 휴게 종료시간 정보가 없습니다.");
			return false;
		}
	}
	else{
		wedOpenYn = 'N'
		wedOpenStartTime = '00:00';
		wedOpenEndTime = '00:00';
		wedBreakStartTime = '00:00';
		wedBreakEndTime = '00:00';
	}

	if('Y'==thuOpenYn){
		if(!thuOpenStartTime){
			modalEvent.warning("", "목요일 운영 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!thuOpenEndTime){
			modalEvent.warning("", "목요일 운영 종료시간 정보가 없습니다.");
			return false;
		}
		
		if(!thuBreakStartTime){
			modalEvent.warning("", "목요일 휴게 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!thuBreakEndTime){
			modalEvent.warning("", "목요일 휴게 종료시간 정보가 없습니다.");
			return false;
		}
	}
	else{
		thuOpenYn = 'N'
		thuOpenStartTime = '00:00';
		thuOpenEndTime = '00:00';
		thuBreakStartTime = '00:00';
		thuBreakEndTime = '00:00';
	}
	
	if('Y'==friOpenYn){
		if(!friOpenStartTime){
			modalEvent.warning("", "금요일 운영 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!friOpenEndTime){
			modalEvent.warning("", "금요일 운영 종료시간 정보가 없습니다.");
			return false;
		}
		
		if(!friBreakStartTime){
			modalEvent.warning("", "금요일 휴게 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!friBreakEndTime){
			modalEvent.warning("", "금요일 휴게 종료시간 정보가 없습니다.");
			return false;
		}
	}
	else{
		friOpenYn = 'N'
		friOpenStartTime = '00:00';
		friOpenEndTime = '00:00';
		friBreakStartTime = '00:00';
		friBreakEndTime = '00:00';
	}

	if('Y'==satOpenYn){
		if(!satOpenStartTime){
			modalEvent.warning("", "토요일 운영 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!satOpenEndTime){
			modalEvent.warning("", "토요일 운영 종료시간 정보가 없습니다.");
			return false;
		}
		
		if(!satBreakStartTime){
			modalEvent.warning("", "토요일 휴게 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!satBreakEndTime){
			modalEvent.warning("", "토요일 휴게 종료시간 정보가 없습니다.");
			return false;
		}
	}
	else{
		satOpenYn = 'N'
		satOpenStartTime = '00:00';
		satOpenEndTime = '00:00';
		satBreakStartTime = '00:00';
		satBreakEndTime = '00:00';
	}

	if('Y'==sunOpenYn){
		if(!sunOpenStartTime){
			modalEvent.warning("", "일요일 운영 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!sunOpenEndTime){
			modalEvent.warning("", "일요일 운영 종료시간 정보가 없습니다.");
			return false;
		}
		
		if(!sunBreakStartTime){
			modalEvent.warning("", "일요일 휴게 시작시간 정보가 없습니다.");
			return false;
		}
		
		if(!sunBreakEndTime){
			modalEvent.warning("", "일요일 휴게 종료시간 정보가 없습니다.");
			return false;
		}
	}
	else{
		sunOpenYn = 'N'
		sunOpenStartTime = '00:00';
		sunOpenEndTime = '00:00';
		sunBreakStartTime = '00:00';
		sunBreakEndTime = '00:00';
	}
	
	if(!publicHolidayUseYn){
		modalEvent.warning("", "법정 공휴일 정보가 없습니다.");
		return false;
	}
	
	// 휴일정보
	let holidayLi = $('#hospitalHolidayList').children('li');
	let liLength  = holidayLi.length;
	
	let tempArray = new Array();
	for(let i=1 ; i < liLength ; i++){
		let hospitalHolidayName = holidayLi.eq(i).find('input[name="hospitalHolidayName"]').val();
		let locDate             = holidayLi.eq(i).find('input[name="dateLocDate"]').val();
		let repeatYn            = holidayLi.eq(i).find('input[name="repeatYn"]').val();
		
		let arr_sub = new Object();
		arr_sub.hospitalHolidayName = hospitalHolidayName;
		arr_sub.locDate             = locDate;
		arr_sub.repeatYn            = repeatYn;
		tempArray.push(arr_sub);
		
		detailArray.data = tempArray;
	}
	
	modalEvent.info("수정", "선택한 병원 정보를 수정하시겠습니까?", function(){
		let formData = new FormData();
		formData.append("menuClass", menuClass);
		formData.append("muHospitalId", muHospitalId);
		formData.append("monOpenYn", monOpenYn);
		formData.append("monOpenStartTime", monOpenStartTime);
		formData.append("monOpenEndTime", monOpenEndTime);
		formData.append("monBreakStartTime", monBreakStartTime);
		formData.append("monBreakEndTime", monBreakEndTime);
		formData.append("tueOpenYn", tueOpenYn);
		formData.append("tueOpenStartTime", tueOpenStartTime);
		formData.append("tueOpenEndTime", tueOpenEndTime);
		formData.append("tueBreakStartTime", tueBreakStartTime);
		formData.append("tueBreakEndTime", tueBreakEndTime);
		formData.append("wedOpenYn", wedOpenYn);
		formData.append("wedOpenStartTime", wedOpenStartTime);
		formData.append("wedOpenEndTime", wedOpenEndTime);
		formData.append("wedBreakStartTime", wedBreakStartTime);
		formData.append("wedBreakEndTime", wedBreakEndTime);
		formData.append("thuOpenYn", thuOpenYn);
		formData.append("thuOpenStartTime", thuOpenStartTime);
		formData.append("thuOpenEndTime", thuOpenEndTime);
		formData.append("thuBreakStartTime", thuBreakStartTime);
		formData.append("thuBreakEndTime", thuBreakEndTime);
		formData.append("friOpenYn", friOpenYn);
		formData.append("friOpenStartTime", friOpenStartTime);
		formData.append("friOpenEndTime", friOpenEndTime);
		formData.append("friBreakStartTime", friBreakStartTime);
		formData.append("friBreakEndTime", friBreakEndTime);
		formData.append("satOpenYn", satOpenYn);
		formData.append("satOpenStartTime", satOpenStartTime);
		formData.append("satOpenEndTime", satOpenEndTime);
		formData.append("satBreakStartTime", satBreakStartTime);
		formData.append("satBreakEndTime", satBreakEndTime);
		formData.append("sunOpenYn", sunOpenYn);
		formData.append("sunOpenStartTime", sunOpenStartTime);
		formData.append("sunOpenEndTime", sunOpenEndTime);
		formData.append("sunBreakStartTime", sunBreakStartTime);
		formData.append("sunBreakEndTime", sunBreakEndTime);
		formData.append("publicHolidayUseYn", publicHolidayUseYn);
		formData.append("holidayRows",JSON.stringify(detailArray));

		$.ajax({
			url: encodeURI('/webhospital/updateHospital.do'),
			data: formData,
			dataType: "json",
			processData: false,
			contentType: false,
			type: 'POST',
			async: true,
			success: function(data){
				if('0'==data.msgCode){
					modalEvent.success("수정 성공", data.msgDesc, function(){
						fn_reload();
					});
				}
				else{
					modalEvent.danger("수정 오류", data.msgDesc);
				}
			},
			error : function(xhr, status, error) {
				modalEvent.danger("수정 오류", "수정 중 오류가 발생하였습니다. 잠시후 다시시도하십시오.");
			},
			beforeSend:function(){
				
			},
			complete:function(){
				
			}
		});
	});
}

/****************************************************************************
* 운영여부 변경 이벤트
* type : 요일(mon:월요일....)
****************************************************************************/
function fn_changeOpenYn(target, type){
	let checked = $(target).is(':checked');
	
	if(checked){
		// 기본 셋팅
		fn_setTimeValue("sel"+type+"OpenStartTime", "09:00");
		fn_setTimeValue("sel"+type+"OpenEndTime", "19:00");
		fn_setTimeValue("sel"+type+"BreakStartTime", "14:00");
		fn_setTimeValue("sel"+type+"BreakEndTime", "15:00");
		$(target).parents("li").find("button").prop("disabled",false);
		$(target).closest('li').addClass('on');
	}
	else{
		// 초기화
		$(target).parents("li").find("button").text("00:00");
		$(target).parents("li").find("input").text("00:00");
		$(target).parents("li").find("button").prop("disabled",true);
		$(target).closest('li').removeClass('on');
	}
}

/****************************************************************************
* select box 선택 값 셋팅
****************************************************************************/
function fn_clickSelectValue(target, param, paramText){
	$(target).parent().siblings("button").text(paramText);
	$(target).parent().siblings("input").val(param);
}

/****************************************************************************
* 페이지 init
****************************************************************************/
function fn_pageInit(){
	// 병원 상세 조회
	fn_selectHospitalJson();
}

/****************************************************************************
* 페이지 event
****************************************************************************/
function fn_pageEvent(){
	// 월요일 운영여부 체크
	$("#checkMonOpenYn").change(function () {
		fn_changeOpenYn(this, 'Mon');
	});
	
	// 화요일 운영여부 체크
	$("#checkTueOpenYn").change(function () {
		fn_changeOpenYn(this, 'Tue');
	});
	
	// 수요일 운영여부 체크
	$("#checkWedOpenYn").change(function () {
		fn_changeOpenYn(this, 'Wed');
	});
	
	// 목요일 운영여부 체크
	$("#checkThuOpenYn").change(function () {
		fn_changeOpenYn(this, 'Thu');
	});
	
	// 금요일 운영여부 체크
	$("#checkFriOpenYn").change(function () {
		fn_changeOpenYn(this, 'Fri');
	});
	
	// 토요일 운영여부 체크
	$("#checkSatOpenYn").change(function () {
		fn_changeOpenYn(this, 'Sat');
	});
	
	// 일요일 운영여부 체크
	$("#checkSunOpenYn").change(function () {
		fn_changeOpenYn(this, 'Sun');
	});
	
	// 저장 버튼
	$("#btnUpdateHospital").click(function () {
		fn_updateHospital();
	});
}

$(function(){
	// 페이지 init
	fn_pageInit();
	
	// 페이지 event
	fn_pageEvent();
});