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

<%@ include file="language.jsp" %>

<%@ page import="at.gv.egiz.pdfas.web.session.SessionAttributes" %>
<%@ page import="at.gv.egiz.pdfas.web.helper.LocalRequestHelper" %>
<%@ page import="at.gv.egiz.pdfas.web.servlets.SignServlet" %>
<%@ page import="at.gv.egiz.pdfas.api.commons.Constants" %>
<%@page import="at.gv.egiz.pdfas.web.FormFields"%>

<%
	String serverUrl=LocalRequestHelper.getLocalServerAddress(request,response);
	String baseUrl=LocalRequestHelper.getLocalContextAddress(request,response);

	String downloadURL = (String) session.getAttribute(SessionAttributes.DOWNLOAD_URL_FOR_SIGNED_PDF_DOCUMENT);

	String connector = (String)session.getAttribute(SignServlet.SUBMITFORM_SIGNATURE_DEVICE_KEY);
	
	session.setAttribute(SignServlet.SUBMITFORM_SIGNATURE_MODE_KEY, null);
	session.setAttribute(SignServlet.SUBMITFORM_SOURCE_KEY, null);
	session.setAttribute(SignServlet.SUBMITFORM_SIGNATURE_TYPE_KEY, null);
	session.setAttribute(SignServlet.SUBMITFORM_PDFA_KEY, null);
	session.setAttribute(SignServlet.SUBMITFORM_NOTE_KEY, null);
	session.setAttribute(SignServlet.SUBMITFORM_FREETEXT_KEY, null);
	session.setAttribute(SignServlet.SUBMITFORM_SIGNATURE_DEVICE_KEY, null); 
	session.setAttribute(SignServlet.SUBMITFORM_FILE_KEY, null);
	session.setAttribute(SignServlet.SUBMITFORM_FILENAME_KEY, null);
	session.setAttribute(SessionAttributes.ATTRIBUTE_SESSION_INFORMATION, null);
	session.setAttribute(SignServlet.ERROR_WITHIN_IFRAME, null);
	
	String height = (String)session.getAttribute(SignServlet.HEIGHT_SIGN_DIV);
	
	String language = (String)session.getAttribute(SessionAttributes.LANGUAGE);
	boolean german = true;
	
	//Check if application is started within an iframe from an extern application
	  boolean startedFromIFrame = false;
	  String extern = (String)session.getAttribute("extern");
	  if (extern!=null) {
		  if (extern.equals("yes")) {
			  startedFromIFrame = true;
		  }
	  }
	  //
	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<% if (language!=null) { %>
			<% if (language.equals("de")) { %>
	  			<fmt:setLocale value="de"/>
			<% } else {
				german = false; %>
				<fmt:setLocale value="en"/>
			<% } %>
		<% } else { %>
			<fmt:setLocale value="de"/>
		<% } %>
		
		<!-- Check the possibility of the page being loaded within an iframe.
			 In this case some things doesn't need to be shown (e.g. the buergerkarte-background) -->	
		<% if (!startedFromIFrame) {
			if (german) { %>
				<meta name="decorator" content="production_de" />
			<% } else { %>
				<meta name="decorator" content="production_en" />
			<% } %>
			<link rel="stylesheet" type="text/css" href="<%=baseUrl%>/css/pdfas-styles.css" />
			<!-- <link rel="stylesheet" href="<%=serverUrl%>style.css" type="text/css" /> -->
		<% } else { %>
			<link rel="stylesheet" type="text/css" href="<%=baseUrl%>/css/extern-styles.css" />
		<% } %>
		<meta http-equiv="pragma" content="no-cache,no-store,private,must-revalidate,max-stale=0,post-check=0,pre-check=0"/>
		<meta http-equiv="expires" content="0"/>
		<meta http-equiv="cache-control" content="no-cache,no-store,must-revalidate,max-age=-1"/>
		<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT"/>
		
		
		<title><fmt:message key="download.title"/></title>
		<script language="javascript" type="text/javascript">
			<!--
			//Disable download button
			function disableElement() {
				document.submitform.SendRequestButton.disabled = true;
				document.submitform.SendRequestButton.blur();
			}
			//Hit the download button to submit the form
			function hitButton() {
				disableElement();
				document.submitform.SendRequestButton.value = "<fmt:message key="download.button.alreadydone"/>";
				document.submitform.submit();
				return(true);
			}

			//Deactivate the link for changing language
			function deactivateSprachlink() {
				document.getElementById('sprachlinkneu').style.display = 'none';
				document.getElementById('sprachlinkneudeaktiviert').style.display= 'block';
			}

			//Detect browser and change sizes if IE 7.0
			function detectBrowser() {
				if ((navigator.appName.indexOf('Internet Explorer')!=-1) && (navigator.appVersion.indexOf('MSIE 7.0')!=-1)) {
					var stringHeight = "<%=height%>";
					var intHeight = stringHeight.substring(0,stringHeight.length-2);
					var iediff = 25;
					var height = parseInt(intHeight)+iediff;
					height = height + 'px';
					document.getElementById('sign').style.height=height;
					document.getElementById('downloadtext').style.height=height;
					document.getElementById('signintern').className='rechtsinhaltinternetexplorer';
					document.getElementById('downloadtextintern').className='linksinhaltinternetexplorer';
					document.getElementById('pdfasverticalspace').className='pdfasverticalspaceinternetexplorer';
				}
			}

			//Set the height of the div's equal to the previous pages
			function setHeight() {
				document.getElementById('sign').style.height = "<%=height%>";
				document.getElementById('downloadtext').style.height = "<%=height%>";
			}
				
			-->
		</script>
	</head>
		<body>
		<% if (!startedFromIFrame) { %>
			<h1 id="heading1download">
				<fmt:message key="download.title"/>
			</h1>
			<div>
				<fmt:message key="download.description"/>
			</div>
			<div class="pdfasverticalspace" id="pdfasverticalspace"></div>
		<% } %>
		<div id="inhalt">
			<div class="links" id="downloadtext">
				<div class="linksinhaltmargin" id="downloadtextintern">
					<div class="pdfasnote"><fmt:message key="download.note"/></div>
					<div class="pdfasverticalspace"></div>
					<div><form action="<%= downloadURL %>" name="submitform" accept-charset="UTF-8" method="post" enctype="application/x-www-form-urlencoded" target="_blank">
						<input type="submit" name="SendRequestButton" id="SendRequestButton" value="<fmt:message key="download.button.download"/>" onclick="return hitButton();"/>
					</form></div>
					<div class="pdfasverticalspace"></div>
					<% if (!startedFromIFrame) { %>
						<div><a href="<%=baseUrl%>/"><fmt:message key="common.finish"/></a></div>
					<% } %>
				</div>
			</div>
			<div class="rechts" id="sign">
				<div class="rechtsinhalt" id="signintern">
					<div class="rechtslinks">
						<img src="<%=baseUrl%>/images/onlineBKU.png" alt="Chip-Karte" id="Karte"/>
					</div>
					<div class="rechtsrechts">
						<img src="<%=baseUrl%>/images/mobileBKU.png" alt="Handy" id="Handy"/>
					</div>
					<div class="rechtslinks">
						<input type="submit" name="<%= FormFields.FIELD_CONNECTOR_SMARTCARD %>" value="<fmt:message key="signupload.signwithcard"/>" alt="Signatur mit Karte" disabled="disabled"/>
					</div>
					<div class="rechtsrechts">
						<input type="submit" name="<%= FormFields.FIELD_CONNECTOR_MOBILE %>" value="<fmt:message key="signupload.signwithmobile"/>" alt="Signatur mit Handy" disabled="disabled"/>
					</div>
				</div>
			</div>
		</div>
		<% if (!startedFromIFrame) { %>
			
				<script language="javascript" type="text/javascript">
					//deactivateSprachlink();
					setHeight();
					detectBrowser();
				</script>
			
		<% } %>
		</body>
	
	
	
</html>