<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>

<%@page import="ru.curs.showcase.security.SecurityParamsFactory"%>   
<%@page import="ru.curs.showcase.runtime.UserDataUtils"%> 

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
<%
	String title = "Авторизация в КУРС: Showcase";
	if (UserDataUtils.getGeneralOptionalProp("login.title") != null) {
		title = UserDataUtils.getGeneralOptionalProp("login.title");
	}
%>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!--
	<meta http-equiv="X-UA-Compatible" content="IE=8"/>
-->	
	<title><%=title%></title>
	<style type="text/css">
		@font-face {
			font-family: "r-Condensed-Regular";
			src: url(resources/login_content/roboto-2014/RobotoCondensed-Regular.ttf) format("truetype");
		}	
		@font-face {
			font-family: "r-Medium";
			src: url(resources/login_content/roboto-2014/Roboto-Medium.ttf) format("truetype");
		}		
		@font-face {
			font-family: "r-Regular";
			src: url(resources/login_content/roboto-2014/Roboto-Regular.ttf) format("truetype");
		}	
		.centerbox { 
			background-image: url("resources/login_content/bc_lines.jpg");
			background-position: center top;
			background-repeat: repeat;
			height: calc(50% + 206px);
			left: 0;
			margin-top: -270px;
			position: absolute;
			top: 50%;
			width: 100%;
			text-align: center;
			z-index: 20;
		}
		.centertable { 
			margin: 11px;
			position: absolute;
			left: calc(50% - 197px);
		}	
		.formtd {
			background-image: url("resources/login_content/form.png");
			background-position: center center;
			background-repeat: no-repeat;
			padding: 12px;
			
		}
		.lp {
			height: 26px;
			border: 1px solid #BBB;
			width: 169px;
		}
		.controltable {
			height: 130px;
		}
		.footer {
			background-color: #252828;
			height: 64px;
			left: 0;
			position: absolute;
			text-align: center;
			top: calc(100% - 64px);
			width: 100%;

		}
		.footertable {
			background-color: #252828;
			height: 64px;
			margin: 0 auto;
			z-index: 10;
		}		
		.inputButton {
			cursor: pointer;
		}
	</style>
	<link rel="shortcut icon" href="solutions/default/resources/favicon.ico" type="image/x-icon" />
	<link rel="icon" href="solutions/default/resources/favicon.ico" type="image/x-icon" />
	
    <script type="text/javascript">
        var djConfig = {
            parseOnLoad: false,
            isDebug: false
        };
    </script>
	<script src="js/dojo/dojo.js"></script>
	<script language="javascript">
		function doPopup(popupPath) {
		window.open(popupPath,'name',
		'width=450,height=200,scrollbars=YES');
		}
	</script>
	
<script type="text/javascript">

	function checkAuthenticationImageSize() {
		var w;
		<%if (UserDataUtils.getGeneralOptionalProp("security.crossdomain.authentication") != null && "true".equalsIgnoreCase(UserDataUtils.getGeneralOptionalProp("security.crossdomain.authentication").trim())) {%>
		var pic = document.getElementById("authenticationImage");
		w = pic.offsetWidth;<%}%>  
		<%if (UserDataUtils.getGeneralOptionalProp("security.crossdomain.authentication") == null || !("true".equalsIgnoreCase(UserDataUtils.getGeneralOptionalProp("security.crossdomain.authentication").trim()))) {%>
		w = 1000;
		<%}%>
		
		if (w == 178) {	
			if (document.getElementById('helloMessage')) 
		 		dojo.attr("helloMessage", "innerHTML", "");
			if (document.getElementById('informationMessage')) 
				dojo.attr("informationMessage", "innerHTML", "Идет проверка подлинности пользователя...<br>Пожалуйста подождите...");
			id = setTimeout("checkIsAuthenticatedSession()",1000);
		}
		else {			
		    document.formlogin.style.display = "";
		    document.getElementById("j_username").focus();
		}
	}
	
	function checkIsAuthenticatedSession() {
		dojo.xhrGet({
			sync: true,
			url: "<%=request.getContextPath()%>/auth/isAuthenticatedServlet?sesid=<%=request.getSession().getId()%>",
			handleAs: "json",
			preventCache: true,
			timeout: 10000,
			load: function(data) {
				document.getElementsByName("j_username")[0].value = data.login;
				document.getElementsByName("j_password")[0].value = data.pwd;
				document.formlogin.submit();
			},
			error: function(error) {
				alert("Ошибка соединения с сервером аутентификации.");
			}
		});
	}
   

   
</script>	
	
	
	
</head>
<body onLoad="checkAuthenticationImageSize()" >

     <!--[if lte IE 7]>
     <p style="margin: 0.2em 0; background: #ccc; color: #000; padding: 0.2em 0;">Ваша текущая версия Internet explorer устарела. Приложение будет работать некорректно. <a href="http://browsehappy.com/">Обновите свой браузер!</a></p>
     <![endif]-->

<%
	String authGifSrc = String.format("%s/authentication.gif?sesid=%s",
			SecurityParamsFactory.getAuthServerUrl(), request.getSession()
					.getId());

    authGifSrc = SecurityParamsFactory.correctAuthGifSrcRequestInCaseOfInaccessibility(authGifSrc);
%>

<div style = "position: absolute; left: 5px; top: 5px; width: 131px; height: 186px; background: url(resources/login_content/pirogov.png); z-index: 80">
</div>

<div class = "centerbox" >

<image src = "resources/login_content/header.png"/>
<table style="margin: 12px auto 4px auto;">
	<tr><td style="font-family: r-Condensed-Regular, sans-serif; font-size: 1.2em;  text-align: center; color: #555">Прототип ФГИС АМР</td></tr>

</table>

<span id="informationMessage" style="font-family: sans-serif;"></span>
<form name="formlogin" method="POST" action="<c:url value="/j_spring_security_check" />" style="display:none">

	<table class = "centertable" >
		<tr>

			<td width="340px" height="199" class="formtd">
				<table class="controltable">
					<!--<tr>			    <td align='right'>Домен</td>-->

					<!--%=SecurityParamsFactory.getHTMLTextForPrividerGroupsComboBoxSecector(authGifSrc)%-->

					<!--</tr>-->
					<!--   <tr> -->
					<!--     <td align="rigfht">Домен</td> -->
					<!--     <td> -->
					<!--      <select id="j_domain" type="text" name="j_domain"> -->
					<!--       <option value="Группа1">Группа1</option> -->
					<!--       <option selected  value="Группа2">Группа2</option> -->
					<!--      </select> -->
					<!--     </td> -->
					<!--   </tr> -->

					  <!--   test -->

					  
					  
					  
					<tr height="38px">
						<td align="right" width="130px" style="font-family: r-Condensed-Regular, sans-serif; font-size: 0.9em; padding-right: 5px; color: #444;">Имя пользователя:</td>
						<td><input class="lp"  id="j_username" type="text" name="j_username" /></td>
						<td></td>
					</tr>
					<tr height="38px">
						<td align="right" style="font-family: r-Condensed-Regular, sans-serif; font-size: 0.9em; padding-right: 5px; color: #444;">Пароль:</td>
						<td><input class="lp"  id="j_password" type="password" name="j_password" autocomplete = "off"/></td>
						<td></td>
					</tr>
					<!--<tr style="display: none;">
						<td align="right">Запомнить меня</td>
						<td><input type="checkbox" name="_spring_security_remember_me" /></td>
						<td></td>
					</tr>-->
					<tr >
						<td></td>
						<td align="right" style="padding-top: 8px">
						  	<input class="inputButton" style="background: url(resources/login_content/enter.png);border: 0 none; height: 41px; width: 169px; 
							font-family: r-Medium, sans-serif; font-size: 0.9em; color: #0dffd4" type="submit" value="Войти в систему"/>
						  <!--<input type="reset" value="Сбросить" />-->
						</td>
						<td><%if (UserDataUtils.getGeneralOauth2Properties() != null) {%><a href="oauth?auth=websphere">WebSphere авторизация</a><%}%> <%if (UserDataUtils.getGeneralSpnegoProperties() != null) {%><a href="spnego">Spnego авторизация</a><%}%></td>
					</tr>
					<!--<tr>
						<td colspan="3">
						<a href="forall/state" target="_blank">О программе</a>
						</td>
					</tr>-->
			
				</table>
			</td>
			<td style="padding-left: 10px" width="120px" ><a href="javascript:doPopup('../fdpo/resources/login_content/registr.html');" style="font-family: r-Medium, sans-serif; font-size: small; padding-right: 5px; color: #0c74c9; white-space: nowrap">Регистрация</a>
				</br><a href="javascript:doPopup('../fdpo/resources/login_content/remind.html');" style="font-family: r-Medium, sans-serif; font-size: small; padding-right: 5px; color: #0c74c9; white-space: nowrap">Забыли пароль?</a>
			</td>
		</tr>
	    <tr>
			<td style="text-align: center; padding-top: 15px; padding-left: 35px">
				<a href="http://rsmu.ru/12179.html" target="_blank" >
					<table>
						<tr>
							<td width="25px">
								<img src="resources/login_content/triangle.png"></img>
							</td>
							<td>
								<span style="font-size: 1.2em; font-family: r-Medium, sans-serif; color: #0c74c9">Инструкция для слушателей</span>
							</td>
						</tr>
					</table>
				</a>
			</td>
			<td></td>
		</tr>


	</table>
</div>
</form>
<div class="footer">
	<table class="footertable" cellspacing="0" cellpadding="0">
		<tr>
			<td width="180px" style="background: rgba(0, 0, 0, 0) url('resources/login_content/wifi_plus.png') no-repeat scroll left center; font-family: r-Regular, sans-serif; font-size: x-small; color: white; padding-left: 68px">
				Cлужба сопровождения системы:
				</br><a style="color: #0090ff" href="mailto:fuv_online@rsmu.ru">fuv_online@rsmu.ru</a>
			</td>
			<td width="435px" style="background: rgba(0, 0, 0, 0) url('resources/login_content/footer_embl.png') no-repeat scroll left center; font-family:  r-Regular, sans-serif; font-size: x-small; color: white; padding-left: 12px">
				<div style="width: 5px;  float: left; text-align: center"><img src="resources/login_content/vertical_line.png"/></div>
				<div style="width: 330px; float: left; padding-left: 97px">ГБОУ ВПО Российский национальный исследовательский</br>медицинский университет им. Н.И. Пирогова Минздрава России</br>117997, г. Москва, ул. Островитянова, д. 1</div>
			</td>
		</tr>
	</table>
</div>
<c:if test="${not empty param.error}">
<div id="accessDenied" style="display: table; height: 156px; left: calc(50% - 330px); position: absolute; text-align: center; top: calc(50% - 47px); width: 120px; z-index: 40;  background: #fd7373; border-radius: 10px; padding: 10px">
	<div style="display: table-cell; vertical-align: middle;">
	  <span style="font-family: r-Regular, sans-serif; font-size: 0.9em; color: white; margin: auto">
	  <b>Ошибка:</b></br>
	  имя пользователя и/или пароль неверны<br/>
	  ${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message} 
	  <br/>
	  </span>
	</div>

	</div>
</c:if>
<br/>
<%if (UserDataUtils.getGeneralOptionalProp("security.crossdomain.authentication") != null && "true".equalsIgnoreCase(UserDataUtils.getGeneralOptionalProp("security.crossdomain.authentication").trim())) {%><img src="<%=authGifSrc%>" alt=" " id="authenticationImage" style="visibility:hidden" /><%}%>

</body>
</html>
