<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0">
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>다운로드 페이지</title>
		<link rel="shortcut icon" href="./resource/image/favicon.ico" />


		<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
		<link type="text/css" rel="stylesheet" href="./resource/css/mcare.admin.css" />
		
		
		<script type="text/javascript" src="./resource/plugins/jquery/jquery-2.0.3.min.js"></script>
		<script type="text/javascript" src="./resource/plugins/kendo/kendo.web.min.js"></script>
		<script type="text/javascript" src="./resource/plugins/kendo/cultures/kendo.culture.ko.min.js"></script>
		<script type="text/javascript" src="./resource/plugins/chartjs/Chart.min.js"></script>
		
		<!-- 부트스트랩 css및 스크립트 -->
		<link rel="stylesheet" href="./resource/plugins/bootstrap/css/bootstrap.css ">
		<script src="./resource/plugins/bootstrap/js/bootstrap.min.js "></script>
		
		<!-- FancyTree -->
		<script src="./resource/plugins/jquery-ui-1.11.1/jquery-ui.js"></script>
		<link rel="stylesheet" href="./resource/plugins/fancytree-2.2.0/dist/skin-win8/ui.fancytree.min.css">
		<script src="./resource/plugins/fancytree-2.2.0/dist/jquery.fancytree-all.js"></script>
		
		<script src="./resource/plugins/bootstrap-datepicker/js/moment.js "></script>

	</head>
	<body>
		<div class="mainContainer" id="loginForm">
			<div class="form-container">
				<div class="line-container">
				<img src="./resource/image/download_logo.png" width="150">
				</div>
				<div class="line-container">
				          <i class="material-icons">perm_identity</i>
					<input type="text" id="_username" placeholder="아이디를 입력하세요" />
				</div>
				<div class="line-container">
					<i class="material-icons">lock_outline</i>
					<input type="password" id="_password" placeholder="비밀번호를 입력하세요" />
				</div>
				<div class="line-container">
					<!-- <input type="button" id="login_btn" class="k-button"  value="로그인" /> -->
					<input type="button" id="login_btn" class="btn btn-default"  value="로그인" />
				</div>
			</div>
			
			<div class="form-container2">
				<div class="line-container">
					본  서비스를 이용하여 정보를 취급함에 있어 소중한 개인정보를 보호하고 건국대학교병원이 국민으로부터 신뢰받을 수 있는 공공기관이 될 수 있도록 <span style="color:red;">개인정보 보호 규정준수</span>에 동의합니다.
				</div>	
		</div>
	</body>
	<script type="text/javascript">
		// 1: 사내개발, 2: 개발서버, 3: 운영서버
		var gServerKind = 3; 	
		localStorage.setItem('userId', "");
		
		$("#login_btn").unbind();
		$("#login_btn").on("click", function(e){
			if( $("#_username").val() === "" ) {
				alert("아이디를 입력하세요.");
				$("#_username").focus();
		        return;
			};
			if( $("#_password").val() === "" ) {
				self.alert("패스워드를 입력하세요.");
				$("#_password").focus();
		        return;
			};
			var param = {
					userId: $("#_username").val(),
					userPw: $("#_password").val(),
					rememberMe: true,
					hospitalCd: "01",
					deviceId: "downloadpage"
			};
			var result;
			
			var tmpLoginSubmitURL = "";
			if( gServerKind == 1)
				tmpLoginSubmitURL =  "http://192.168.1.18:48080/mcare-plus/loginSubmit.json";
			else if( gServerKind == 2)
				tmpLoginSubmitURL =  "https://nps.kuh.ac.kr/mcare-plus-dev/mobile/login/loginSubmitApp.json";
			else if( gServerKind == 3)
				tmpLoginSubmitURL =  "https://nps.kuh.ac.kr/mcare-plus/mobile/login/loginSubmitApp.json";
			else
				tmpLoginSubmitURL =  "http://192.168.1.18:48080/mcare-plus/loginSubmit.json";
			
			var tmpDownloadURL = "";
			if( gServerKind == 1)
				tmpDownloadURL =  "http://192.168.1.18:48080/mplus-deploy/downview.page?d1=" + $("#_username").val();
			else if( gServerKind == 2)
				tmpDownloadURL =  "https://nps.kuh.ac.kr/mplus-deploy-dev/downview.page?d1=" + $("#_username").val();
			else if( gServerKind == 3)
				tmpDownloadURL =  "https://nps.kuh.ac.kr/mplus-deploy/downview.page?d1=" + $("#_username").val();
			else
				tmpDownloadURL =  "http://192.168.1.18:48080/mplus-deploy/downview.page?d1=" + $("#_username").val();
			
			$.ajax ({
				  url : tmpLoginSubmitURL,
				  type : "POST",
				  contentType: "application/json", 
				  data: JSON.stringify(param),
				  async: false,
				  success: function(response){
					  console.log(response);
					  if(response.msg) {
						  // 현재 로그인 error는 모두 LoginException으로 처리되기 때문에
						  // type 체크는 하지 않았습니다.
						  alert(response.msg);
						  return;
					  } else {
						  localStorage.setItem('userId', $("#_username").val());
						  window.location.href = tmpDownloadURL;
					  }
				  },
				  error : function(XHR, textStatus, errorThrown) { 
						//self.loading("hide");
						if (XHR.status == 0) {
							alert("You are offline!! Please Check Your Network.");
						} else if (XHR.status == 404) {
							alert("Requested URL not found.");
						} else if (XHR.status == 500) {
							alert("Internel Server Error.");
						} else if (textStatus == "parsererror") {
							alert("Error. Parsing JSON Request failed.");
						} else if (textStatus == "timeout") {
							alert("Request Time out.");
						} else {
							alert("Unknow Error. " + XHR.responseText);
						}
						console.log("code:" + XHR.status + "\n" + "message:" + XHR.responseText + "\n" + "error:" + errorThrown);
				  }
			});
		});
	</script>
</html>