<%@page import="at.gv.egiz.pdfas.web.FormFields"%>
<%@page import="at.gv.egiz.pdfas.web.session.SessionAttributes"%>
<%@ page import="org.apache.commons.lang.StringEscapeUtils" %>
<%@ page import="at.gv.egiz.pdfas.api.commons.Constants" %>
<%@ page import="at.gv.egiz.pdfas.web.i18n.LanguageDecoratorMapper"%>
<%@ page import="org.apache.commons.lang.BooleanUtils"%>
<%@ page import="at.gv.egiz.pdfas.web.i18n.LocaleParamFilter" %>
<%@ page import="java.util.Locale" %>
<%@ page import="at.gv.egiz.pdfas.web.servlets.SignServlet" %>
<%@ page import="at.gv.egiz.pdfas.web.helper.LocalRequestHelper" %>

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>

	
	<%
	
	session = request.getSession();
	
	session.removeAttribute(SessionAttributes.DOWNLOAD_URL_FOR_SIGNED_PDF_DOCUMENT);
	session.removeAttribute(SessionAttributes.SIGNED_PDF_DOCUMENT);
	
	//Check if application is started within an iframe from an extern application
	String extern = (String)request.getParameter("extern");
	boolean startedFromIFrame = false;
	
	if (extern !=null) {
		if (extern.equals("yes")) {
			startedFromIFrame = true;
		}
	}
	
	//When Change Language link is hit, three parameters are passed with a hidden form
	//so that the settings keep the same. Check if this parameters are passed...
	String source_mode_request = (String)request.getParameter("source_mode");
    String text_request = (String)request.getParameter("text");
    String lang_request = (String)request.getParameter("newlanguage");
    
    if (lang_request!=null) {
    	if (source_mode_request.equals("file")) {
    		session.setAttribute(SignServlet.SUBMITFORM_SOURCE_KEY, FormFields.VALUE_SOURCE_FILE);
    	}
    	else {
    		session.setAttribute(SignServlet.SUBMITFORM_SOURCE_KEY, FormFields.VALUE_SOURCE_FREETEXT);
    		session.setAttribute(SignServlet.SUBMITFORM_FREETEXT_KEY, text_request);
    	}
    	if (lang_request.equals("de")) {
    		session.setAttribute(SessionAttributes.LANGUAGE, "en");
    	}
    	else {
    		session.setAttribute(SessionAttributes.LANGUAGE, "de");
    	}
    	
    }
    
	
	boolean testMode = request.getContextPath().startsWith("/test-");
	//boolean forceTextualForMocca = false;
	
	String requestLang = (String)request.getParameter("lang");
	String sessionLang = (String)session.getAttribute(SessionAttributes.LANGUAGE);
    String language = "";
	
    //If language within session...
    if (sessionLang!=null) {
    	//But if language also changed by clicking the change language link
    	//or passed as parameter with the URL...
    	if (requestLang!=null) {
    		//If language has changed, change it also within session
    		if (!sessionLang.equals(requestLang)) {
    			session.setAttribute(SessionAttributes.LANGUAGE, requestLang);
    		}
    		//else do nothing
    	}
    	//else no change
    }
    //Else still no language within session 
    else {
    	//But if language changed by clicking the change language link
    	//or passed as parameter with the URL...
    	if (requestLang!=null) {
    		if (requestLang.equals("de")) {
    			session.setAttribute(SessionAttributes.LANGUAGE,"de");
    		}
    		else {
    			session.setAttribute(SessionAttributes.LANGUAGE,"en");
    		}
    	}
    	//No language here. Set to german
    	else {
    		session.setAttribute(SessionAttributes.LANGUAGE,"de");
    	}
    }
	
	language = (String)session.getAttribute(SessionAttributes.LANGUAGE);
	
	
	boolean german=true;
    
    if (language!=null) {
    	if (language.equals("en")) {
    		german = false;
    	}
    }
    
    String sign_freetext = "";
    
    //Get the previous settings if user hitted back or back link
    //Many of this settings do not apply anymore
    String sign_mode = (String)session.getAttribute(SignServlet.SUBMITFORM_SIGNATURE_MODE_KEY);
    String source_mode = (String)session.getAttribute(SignServlet.SUBMITFORM_SOURCE_KEY);
    String sign_type = (String)session.getAttribute(SignServlet.SUBMITFORM_SIGNATURE_TYPE_KEY);
    String sign_pdfa = (String)session.getAttribute(SignServlet.SUBMITFORM_PDFA_KEY);
    String sign_note = (String)session.getAttribute(SignServlet.SUBMITFORM_NOTE_KEY);
    sign_freetext = (String)session.getAttribute(SignServlet.SUBMITFORM_FREETEXT_KEY);
    
    if (german) {
    %>
   		<fmt:setLocale value="de"/>
    <% } else { %>
    	<fmt:setLocale value="en"/>
    <% } %>
    <title>
	<%
	if (testMode) {
	%>
		<fmt:message key="test.common.title"/>
	<% } else { %>
		<fmt:message key="common.title"/>
	<% } // end if %>		   
	</title>
	
	<% 
	//If application called within an IFrame from an external application
	//choose template and set session attribute
	if (!startedFromIFrame) { 
		session.setAttribute("extern", "no");
		if (german) {
		%>
			<meta name="decorator" content="production_de" />
			<link rel="stylesheet" type="text/css" href="https://www.buergerkarte.at/test-pdf-as/css/pdfas-styles.css" />
		<% } else { %>
			<meta name="decorator" content="production_en" />
			<link rel="stylesheet" type="text/css" href="https://www.buergerkarte.at/test-pdf-as/css/pdfas-styles.css" />
		<% }
	 } else { 
		session.setAttribute("extern", "yes");
		%>
		<link rel="stylesheet" type="text/css" href="https://www.buergerkarte.at/test-pdf-as/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="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"/>
	
	<script language="javascript" type="text/javascript">

			//Check the user inputs when sign preview is choosed
			function previewForm() {
				var submitform = document.getElementById('submitform');
				if (submitform.source_filefreetext.selectedIndex=='0') {
					if (!submitform.file.value) {
						alert('<fmt:message key="signupload.documentnotselected.preview"/>');
						return (false);
					}
				}
				else {
					if (!submitform.freetext.value) {
						alert('<fmt:message key="signupload.nofreetext.preview"/>');
						return (false);
					}
				}
				submitform.action = "<%=request.getContextPath()%>/SignPreview";
				submitform.target = "_self";
				return(true);
			}

			//Check the user inputs when sign is choosed
			function submitForm(button) {
				var submitform = document.getElementById('submitform');
				//If file is choosed...
				if (submitform.source_filefreetext.selectedIndex=='0') {
					if (!submitform.file.value) {
						document.getElementById('error').style.display='block';
						document.getElementById('errordocument').style.display='block';
						document.getElementById('errorfreetext').style.display='none';
						document.getElementById('fakefile').style.borderColor='#ff0000';
						document.getElementById('fakefile').style.borderStyle='solid';
						document.getElementById('fakefile').style.borderWidth='2px';
						document.getElementById('errorspace').style.display='block';
						return (false);
					}
				}
				//If freetext is choosed...
				else {
					if (!submitform.freetext.value) {
						document.getElementById('error').style.display='block';
						document.getElementById('errorfreetext').style.display='block';
						document.getElementById('errordocument').style.display='none';
						document.getElementById('freetext').style.borderColor='#ff0000';
						document.getElementById('freetext').style.borderStyle='solid';
						document.getElementById('freetext').style.borderWidth='2px';
						document.getElementById('errorspace').style.display='block';
						return (false);
					}
				}

				submitform.action = "<%=request.getContextPath()%>/Sign";

				//If local bku is choosed target of the form is not the IFrame
				if (button.name == "localbku") {
					submitform.target = "_self";
				}
				else {
					//Also if application is started within an IFrame the target is not another IFrame
					if (<%=startedFromIFrame%>==true) {
						submitform.target = "_self";
					}
					else {
						document.getElementById('sign').style.display = 'none';
						document.getElementById('signiframe').style.display = 'block';
						document.getElementById('signiframe').style.height = document.getElementById('signaturesettings').offsetHeight+'px';
						if (document.getElementById('descriptionbeforedocument').style.display=='block') {
							document.getElementById('descriptionbeforedocument').style.display='none';
						}
						else {
							document.getElementById('descriptionbeforefreetext').style.display='none';
						}
						document.getElementById('descriptionduring').style.display='block';
						document.getElementById('sprachlink').style.display = 'none';
						document.getElementById('sprachlinkdeaktiviert').style.display= 'block';
						if (document.getElementById('error').style.display=='block') {
							document.getElementById('error').style.display='none';
							if (document.getElementById('errordocument').style.display=='block') {
								document.getElementById('errordocument').style.display='none';
								document.getElementById('errorspace').style.display='none';
								document.getElementById('fileupload').style.borderColor='#e6f2fa';
								document.getElementById('fileupload').style.borderStyle='solid';
								document.getElementById('fileupload').style.borderWidth='2px';
							}
							else {
								document.getElementById('error').style.display='none';
								document.getElementById('errorfreetext').style.display='none';
								document.getElementById('errorspace').style.display='none';
								document.getElementById('freetext').style.borderColor='#e6f2fa';
								document.getElementById('freetext').style.borderStyle='solid';
								document.getElementById('freetext').style.borderWidth='2px';
							}
						}
					}
				}
				return (true);
			}

			//Function for changing the IFrame position and size when the error has to be
			//shown within the IFrame to no force a reload of the page
			function moveErrorIFrame(object) {
				var signSettings = document.getElementById('signaturesettings');
				var signButtons = document.getElementById('sign');
				var signIframe = document.getElementById('signiframe');
				var signIframeIntern = document.getElementById('signiframeintern');
				var inhalt = document.getElementById('submitform');

				if (document.getElementById('descriptionbeforedocument').style.display=='block') {
					document.getElementById('descriptionbeforedocument').style.display='none'
				}
				if (document.getElementById('descriptionbeforefreetext').style.display=='block') {
					document.getElementById('descriptionbeforefreetext').style.display='none'
				}
				if (document.getElementById('descriptionduring').style.display=='block') {
					document.getElementById('descriptionduring').style.display='none'
				}
				document.getElementById('descriptionerror').style.display='block';
				
				inhalt.removeChild(signSettings);
				inhalt.removeChild(signButtons);

				signIframe.className='links';
				signIframeIntern.className='linksinhaltmargin';

				document.getElementById('iframe').width = '460px';
				
				document.getElementById('downloadsignbuttons').style.display='block';
				document.getElementById('downloadsignbuttons').style.height = document.submitform.height_sign_div.value;
				
				document.getElementById('localbku').style.display='none';
				document.getElementById('backlink').style.display='none';
			}

			//Function to show the textarea if freetext mode is choosen or the file upload
			//field if file is choosen
			function showTextarea() {
				var file = document.submitform.source.options[0].selected;
				if (!file) {
					document.getElementById('freetext').style.display='block';
					document.getElementById('fileupload').style.display='none';
					document.getElementById('fakefile').style.display='none';
					document.getElementById('labeldocument').style.display='none';
					document.getElementById('labeltext').style.display='block';
					document.getElementById('descriptionbeforedocument').style.display='none';
					document.getElementById('descriptionbeforefreetext').style.display='block';
					if (document.getElementById('error').style.display=='block') {
						document.getElementById('error').style.display='none';
						document.getElementById('errordocument').style.display='none';
						document.getElementById('errorspace').style.display='none';
						document.getElementById('fakefile').style.borderColor='#e6f2fa';
					}
				}
				else {
					document.getElementById('freetext').style.display='none';
					document.getElementById('fileupload').style.display='block';
					document.getElementById('fakefile').style.display='block';
					document.getElementById('labeldocument').style.display='block';
					document.getElementById('labeltext').style.display='none';
					document.getElementById('descriptionbeforedocument').style.display='block';
					document.getElementById('descriptionbeforefreetext').style.display='none';
					if (document.getElementById('error').style.display=='block') {
						document.getElementById('error').style.display='none';
						document.getElementById('errorfreetext').style.display='none';
						document.getElementById('errorspace').style.display='none';
						document.getElementById('freetext').style.borderColor='#e6f2fa';
					}
				}
				//showAdvice();
			}

			//Shows the advice when for example choosing textual signature. Not used anymore
			/*function showAdvice() {
				var file = document.submitform.source.options[0].selected;
				//var textual = document.submitform.textual.checked;
				//var binary = document.submitform.binary.checked;
				var pdfa = document.submitform.pdfa.checked;

				var textual = false;
				var binary = true;
				
				var hinweise = new Array("hinweispdfa", "hinweistextfile", "hinweistext", "hinweistextfilepdfa", "hinweistextpdfa");
				
				//Check which hinweis now showed
				for (var i=0; i<hinweise.length; i++) {
					if (document.getElementById(hinweise[i]).style.display=='block') {
						document.getElementById(hinweise[i]).style.display='none';
						document.getElementById('space').style.display='block';
						break;
					}
				}
				
				//Check which hinweis to show
				if ((pdfa) || ((textual) && (!binary))) {
					if ((pdfa) && (!textual) && (binary)) {
						document.getElementById('hinweispdfa').style.display='block';
					}
					if ((textual) && (!binary) && (file) && (!pdfa)) {
						document.getElementById('hinweistextfile').style.display='block';
					}
					if ((textual) && (!binary) && (!file) && (!pdfa)) {
						document.getElementById('hinweistext').style.display='block';
					}
					if ((pdfa) && (textual) && (!binary) && (file)) {
						document.getElementById('hinweistextfilepdfa').style.display='block';
					}
					if ((pdfa) && (textual) && (!binary) && (!file)) {
						document.getElementById('hinweistextpdfa').style.display='block';
					}
					document.getElementById('space').style.display='block';
				}
			}*/

			//Function to display the file upload field equally for each browser 
			function initFileUploads() {
				var W3CDOM = (document.createElement && document.getElementsByTagName);
				if (!W3CDOM) return;

				var fakeFileUpload = document.createElement('div');
				fakeFileUpload.className = 'fakefile';
				fakeFileUpload.id = 'fakefile';

				if (document.submitform.source.options[0].selected) {
					fakeFileUpload.style.display='block';
				}
				else {
					fakeFileUpload.style.display='none';
				}
				var input = document.createElement('input');
				input.style.verticalAlign = 'top';
				fakeFileUpload.appendChild(input);
				
				var img = document.createElement('img');
				img.src = 'https://www.buergerkarte.at/test-pdf-as/images/durchsuchen.png';
				img.id = 'buttonimage';
					
				var fakeButton = document.createElement('input');
				fakeButton.type = 'submit';

				if (<%=german%>==true) {
					fakeButton.value = 'Durchsuchen';
				}
				else {
					fakeButton.value = 'Browse';
				}
				fakeButton.id = 'fakebutton';
				fakeButton.name = 'fakebutton';
				fakeButton.alt = 'Choose file';
				fakeButton.style.verticalAlign = 'top';
							
				//fakeFileUpload.appendChild(img);
				fakeFileUpload.appendChild(fakeButton);
				
				var normalFileUpload = document.getElementById('fileupload');
				normalFileUpload.className = 'fileuploadinvisible';
				var clone = fakeFileUpload.cloneNode(true);
				normalFileUpload.parentNode.appendChild(clone);
				normalFileUpload.relatedElement = clone.getElementsByTagName('input')[0];
				normalFileUpload.onchange = normalFileUpload.onmouseout = function () {
					this.relatedElement.value = this.value;
				}
			}

			//Check the height of the IFrame to be shown for adjusting the high
			//of the currently showed div's as well as of those of other pages
			function checkHeight() {
				var sign = document.getElementById('sign');
				var signiframe = document.getElementById('signiframe');
				var localbku = document.getElementById('localbku');
				var signaturesettings = document.getElementById('signaturesettings');
				sign.style.display='none';
				signiframe.style.display='block';
				localbku.style.display='block';
				var height = signiframe.offsetHeight;
				sign.style.height=height+'px';
				signaturesettings.style.height=height+'px';
				signiframe.style.display='none';
				localbku.style.display='none';
				sign.style.display='block';
				document.submitform.<%=FormFields.FIELD_HEIGHT_SIGNDIV%>.value=height+'px';	
			}

			//Show the fake image/button as it would be focused (mouse over)
			function focusButton() {
				document.getElementById('buttonimage').src = 'https://www.buergerkarte.at/test-pdf-as/images/durchsuchen_aktiv.png';
			}

			//Show the fake image/button as it would be unfocused (mouse out)
			function unfocusButton() {
				document.getElementById('buttonimage').src = 'https://www.buergerkarte.at/test-pdf-as/images/durchsuchen.png';
			}

			//Change some size settings when IE7 is found
			function detectBrowser() {
				if ((navigator.appName.indexOf('Internet Explorer')!=-1) && (navigator.appVersion.indexOf('MSIE 7.0')!=-1)) {
					document.getElementById('signintern').className='rechtsinhaltinternetexplorer';
					document.getElementById('signiframeintern').className='rechtsinhaltinternetexplorer';
					document.getElementById('downloadsignbuttonsintern').className='rechtsinhaltinternetexplorer';
					document.getElementById('signaturesettingsintern').className='linksinhaltinternetexplorer';
					
					var stringHeight = document.submitform.<%=FormFields.FIELD_HEIGHT_SIGNDIV%>.value;
					var iediff = 25;
					var height = parseInt(stringHeight)+iediff;
					height = height + 'px';
					document.getElementById('sign').style.height = height;
					document.getElementById('signaturesettings').style.height = height;
					document.getElementById('signiframe').style.height = height;
					document.getElementById('downloadsignbuttons').style.height = height;
				}
			}
			
	</script>
    
</head>
<body>

	
	<% if (!startedFromIFrame) { %>
		<h1 id="heading1" style="display:block">
			<%
				if (testMode) {
			%>
				<fmt:message key="test.common.title"/>
			<% } else { %>
				<fmt:message key="common.title"/>
			<% } // end if %>		   
		</h1>
		
		<h1 id="heading1download" style="display:none">
			<fmt:message key="download.title"/>
		</h1>
	<% } %>
	
	<!-- Error text possibly shown when no text or file provided -->
	<div id="error" class="error" style="display:none">
		<div><fmt:message key="signupload.leftblank"/>:</div>
		<li id="errordocument" style="display:none"><fmt:message key="signupload.documentnotselected"/></li>
		<li id="errorfreetext" style="display:none"><fmt:message key="signupload.nofreetext"/></li>
	</div>
	<div id="errorspace" class="pdfasverticalspace" style="display:none"></div>
	
	
	<!-- <div id="descriptionbefore" style="display:block">
					<fmt:message key="signupload.sign"/>
	</div>
	<div id="descriptionduring" style="display:none">
					<fmt:message key="signupload.signing"/>
	</div> -->
	
	
	<% if (source_mode!=null) { 
		if (source_mode.contains(FormFields.VALUE_SOURCE_FILE)) { %>
			<div id="descriptionbeforedocument" style="display:block">
				<fmt:message key="signupload.sign.document"/>
			</div>
			<div id="descriptionbeforefreetext" style="display:none">
				<fmt:message key="signupload.sign.freetext"/>
			</div>
		<% } else { %>	
			<div id="descriptionbeforedocument" style="display:none">
				<fmt:message key="signupload.sign.document"/>
			</div>
			<div id="descriptionbeforefreetext" style="display:block">
				<fmt:message key="signupload.sign.freetext"/>
			</div>
		<% }
	} else { %>
			<div id="descriptionbeforedocument" style="display:block">
				<fmt:message key="signupload.sign.document"/>
			</div>
			<div id="descriptionbeforefreetext" style="display:none">
				<fmt:message key="signupload.sign.freetext"/>
			</div>
	<% } %>
	
	<div id="descriptionduring" style="display:none">
		<fmt:message key="signupload.signing"/>
	</div>
	<div id="descriptionerror" style="display:none">
		<fmt:message key="error.description"/>
	</div>	
	
	
	<div class="pdfasverticalspace"></div>
		
	<div id="inhalt">
	
	<!-- Form with the signature settings. Most of them are just disabled because may be they are not more needed -->
	<form name="submitform" id="submitform" method="post" enctype="multipart/form-data" accept-charset="UTF-8" action="<%= request.getContextPath() %>/Sign" target="iframe">
	<div class="links" id="signaturesettings" style="display:block">
	<div class="linksinhalt" id="signaturesettingsintern">
		<!-- <div class="linkslabelkurz">
			<label for="signaturetype"><fmt:message key="signupload.signaturetype"/>:</label>
		</div>
		<div class="linksauswahllang">
			<select id="signaturetype" name="<%= FormFields.FIELD_SIGNATURE_TYPE %>" autocomplete="off">
				<% if (sign_type!=null) { 
					if (sign_type.equals(FormFields.VALUE_SIGNATURE_TYPE_DE) || sign_type.equals(FormFields.VALUE_SIGNATURE_TYPE_DE+"_NOTE")) { %>
						<option name="<%= FormFields.FIELD_SIGNATURE_TYPE_DE %>" value="<%= FormFields.VALUE_SIGNATURE_TYPE_DE %>" selected="selected"><fmt:message key="signupload.signaturetype.signaturblock.de"/></option>
						<option name="<%= FormFields.FIELD_SIGNATURE_TYPE_EN %>" value="<%= FormFields.VALUE_SIGNATURE_TYPE_EN %>"><fmt:message key="signupload.signaturetype.signaturblock.en"/></option>
					<% } else { %>
						<option name="<%= FormFields.FIELD_SIGNATURE_TYPE_DE %>" value="<%= FormFields.VALUE_SIGNATURE_TYPE_DE %>"><fmt:message key="signupload.signaturetype.signaturblock.de"/></option>
						<option name="<%= FormFields.FIELD_SIGNATURE_TYPE_EN %>" value="<%= FormFields.VALUE_SIGNATURE_TYPE_EN %>" selected="selected"><fmt:message key="signupload.signaturetype.signaturblock.en"/></option>
					<% }
				} else {
					if (german) { %>
						<option name="<%= FormFields.FIELD_SIGNATURE_TYPE_DE %>" value="<%= FormFields.VALUE_SIGNATURE_TYPE_DE %>" selected="selected"><fmt:message key="signupload.signaturetype.signaturblock.de"/></option>
						<option name="<%= FormFields.FIELD_SIGNATURE_TYPE_EN %>" value="<%= FormFields.VALUE_SIGNATURE_TYPE_EN %>"><fmt:message key="signupload.signaturetype.signaturblock.en"/></option>
					<% } else { %>
						<option name="<%= FormFields.FIELD_SIGNATURE_TYPE_DE %>" value="<%= FormFields.VALUE_SIGNATURE_TYPE_DE %>"><fmt:message key="signupload.signaturetype.signaturblock.de"/></option>
						<option name="<%= FormFields.FIELD_SIGNATURE_TYPE_EN %>" value="<%= FormFields.VALUE_SIGNATURE_TYPE_EN %>" selected="selected"><fmt:message key="signupload.signaturetype.signaturblock.en"/></option>
					<% }
				} %>
			</select>
		</div> -->
		<!-- <div class="linkslabellang">
			<% if (german) { %>
				<label for="pdfa">
					<div id="pdfalink" style="display:block"><a href="#" class="glossarbegriff" onclick='this.href="javascript:lightboxShow(\"pdfade\")"'>PDF/A-1b</a> verwenden<sup>(?)</sup>:</div>
					<div id="pdfalinkdeaktiviert" style="display:none">PDF/A-1b verwenden<sup>(?)</sup>:</div>
				</label>
			<% } else { %>
				<label for="pdfa">
					<div id="pdfalink" style="display:block">Use <a href="#" class="glossarbegriff" onclick='this.href="javascript:lightboxShow(\"pdfaen\")"'>PDF/A-1b</a><sup>(?)</sup>:</div>
					<div id="pdfalinkdeaktiviert" style="display:none">Use PDF/A-1b<sup>(?)</sup>:</div>
				</label>
			<% } %>
		</div> -->
		<!-- <div class="linksauswahlkurz">
			<% if ((sign_pdfa!=null) && (sign_pdfa.equals("on"))) { %>
				<% if (german) { %>
					<input id="pdfa" type="checkbox" name="<%= FormFields.FIELD_PDFA_ENABLED %>" onclick="showAdvice()" checked="checked" autocomplete="off"/>
				<%} else {%>
					<input id="pdfa" type="checkbox" name="<%= FormFields.FIELD_PDFA_ENABLED %>" onclick="showAdvice()" checked="checked" autocomplete="off"/>
				<% } %>
			<% } if ((sign_pdfa==null) || (sign_pdfa.equals("off"))) { %>
				<% if (german) { %>
					<input id="pdfa" type="checkbox" name="<%= FormFields.FIELD_PDFA_ENABLED %>" onclick="showAdvice()" autocomplete="off"/>
				<%} else {%>
					<input id="pdfa" type="checkbox" name="<%= FormFields.FIELD_PDFA_ENABLED %>" onclick="showAdvice()" autocomplete="off"/>
				<% } %>
			<% } %>
		</div> -->
		<!-- <div class="linkslabellang">
			<% if (german) { %>
				<label for="note">
					<div id="notelink" style="display:block"><a href="#" class="glossarbegriff" onclick='this.href="javascript:lightboxShow(\"notede\")"'>Rechtlicher Hinweis im Signaturblock </a><sup>(?)</sup>:</div>
					<div id="notelinkdeaktiviert" style="display:none">Rechtlicher Hinweis im Signaturblock </a><sup>(?)</sup>:</div>
				</label>
			<% } else { %>
				<label for="note">
					<div id="notelink" style="display:block"><a href="#" class="glossarbegriff" onclick='this.href="javascript:lightboxShow(\"noteen\")"'>Legal note within the signature block </a><sup>(?)</sup>:</div>
					<div id="notelinkdeaktiviert" style="display:none">Legal note within the signature block </a><sup>(?)</sup>:</div>
				</label>
			<% } %>
		</div> -->
		<!-- <div class="linksauswahlkurz">
			<% if (((sign_note!=null) && (sign_note.equals("on"))) || (sign_note==null)) { %>
				<% if (german) { %>
					<input id="note" type="checkbox" name="<%= FormFields.FIELD_NOTE_ENABLED %>" checked="checked" autocomplete="off"/>
				<% } else { %>
					<input id="note" type="checkbox" name="<%= FormFields.FIELD_NOTE_ENABLED %>" checked="checked" autocomplete="off"/>
				<% } %>
			<% } else { %>
				<%if (german) { %>
					<input id="note" type="checkbox" name="<%= FormFields.FIELD_NOTE_ENABLED %>" autocomplete="off"/>
				<% } else { %>
					<input id="note" type="checkbox" name="<%= FormFields.FIELD_NOTE_ENABLED %>" autocomplete="off"/>
				<% } %>
			<% } %>
		</div> -->
		
		
		
		<% if (source_mode!=null) { %>
			<% if (source_mode.contains(FormFields.VALUE_SOURCE_FILE)) { %>
				<div class="linkslabelkurz">
					<label for="Choose source"><fmt:message key="signupload.source"/>:</label>
				</div>
				<div class="linksauswahllang">
					<select id="source" name="<%= FormFields.FIELD_SOURCE %>" onchange="showTextarea();" autocomplete="off">
						<option name="sourcefile" value="<%= FormFields.VALUE_SOURCE_FILE %>" selected="selected"> <fmt:message key="signupload.file"/></option>
						<option name="sourcefreetext" value="<%= FormFields.VALUE_SOURCE_FREETEXT %>"> <fmt:message key="signupload.freetext"/></option>
					</select>
				</div>
				<div class="pdfasverticalspace"></div>
				<div class="linkslabelkurz">
					<label id="labeldocument" for="Choose document" style="display:block"><fmt:message key="signupload.choose.document"/> <b>*</b>:</label>
					<label id="labeltext" for="Enter text" style="display:none"><fmt:message key="signupload.choose.text"/> <b>*</b>:</label>
				</div>
				<div class="linkssourcefield">
					<textarea class="freetext" id="freetext" name="<%= FormFields.FIELD_SOURCE_FREETEXT %>" autocomplete="off" align="right" style="display:none"></textarea>
					<input size="20" type="file" id="fileupload" name="<%= FormFields.FIELD_SOURCE_FILE %>" accept="application/pdf" autocomplete="off" align="right" style="display:block"/>
				</div>
			<% } else {%>
				<div class="linkslabelkurz">
					<label for="Choose source"><fmt:message key="signupload.source"/>:</label>
				</div>
				<div class="linksauswahllang">	
					<select id="source" name="<%= FormFields.FIELD_SOURCE %>" onchange="showTextarea();" autocomplete="off">
						<option name="sourcefile" value="<%= FormFields.VALUE_SOURCE_FILE %>"> <fmt:message key="signupload.file"/></option>
						<option name="sourcefreetext" name="<%= FormFields.VALUE_SOURCE_FREETEXT %>" selected="selected"> <fmt:message key="signupload.freetext"/></option>
					</select>
				</div>
				<div class="pdfasverticalspace"></div>
				<div class="linkslabelkurz">
					<label id="labeldocument" for="Choose document" style="display:none"><fmt:message key="signupload.choose.document"/> <b>*</b>:</label>
					<label id="labeltext" for="Enter text" style="display:block"><fmt:message key="signupload.choose.text"/> <b>*</b>:</label>
				</div>
				<div class="linkssourcefield">
					<textarea class="freetext" id="freetext" name="<%= FormFields.FIELD_SOURCE_FREETEXT %>" autocomplete="off" align="right" style="display:block"><%= sign_freetext %></textarea>
					<input size="20" type="file" id="fileupload" name="<%= FormFields.FIELD_SOURCE_FILE %>" accept="application/pdf" autocomplete="off" align="right" style="display:none"/>
				</div>
			<% } %>
		<% } else { %>
			<div class="linkslabelkurz">
				<label for="Choose source"><fmt:message key="signupload.source"/>:</label>
			</div>
			<div class="linksauswahllang">
				<select id="source" name="<%= FormFields.FIELD_SOURCE %>" onchange="showTextarea();" autocomplete="off">
					<option name="sourcefile" value="<%= FormFields.VALUE_SOURCE_FILE %>" selected="selected"> <fmt:message key="signupload.file"/></option>
					<option name="sourcefreetext" value="<%= FormFields.VALUE_SOURCE_FREETEXT %>"> <fmt:message key="signupload.freetext"/></option>
				</select>
			</div>
			<div class="pdfasverticalspace"></div>
			<div class="linkslabelkurz">
					<label id="labeldocument" for="Choose document" style="display:block"><fmt:message key="signupload.choose.document"/> <b>*</b>:</label>
					<label id="labeltext" for="Enter text" style="display:none"><fmt:message key="signupload.choose.text"/> <b>*</b>:</label>
			</div>
			<div class="linkssourcefield">
				<textarea class="freetext" id="freetext" name="<%= FormFields.FIELD_SOURCE_FREETEXT %>" autocomplete="off" align="right" style="display:none"></textarea>
				<input size="20" type="file" id="fileupload" name="<%= FormFields.FIELD_SOURCE_FILE %>" accept="application/pdf" autocomplete="off" align="right" style="display:block"/>
			</div>
		<% } %>
		<!-- <div class="pdfasverticalspace"></div>
		<div class="linksnote">
			<% if (((sign_pdfa!=null) && (sign_pdfa.equals("on"))) || ((sign_mode!=null) && (sign_mode.contains("textual")))) { %>
				<% if ((sign_pdfa!=null) && (sign_pdfa.equals("on")) && ((sign_mode==null) || (!sign_mode.contains("textual")))) { %>
					<div id="hinweispdfa" style="display:block"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.pdfa"/></div>
					<div id="hinweistextfile" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.file"/></div>
					<div id="hinweistext" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note"/></div>
					<div id="hinweistextpdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note"/> <fmt:message key="signupload.note.pdfa"/></div>
					<div id="hinweistextfilepdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.file"/> <fmt:message key="signupload.note"/> <fmt:message key="signupload.note.pdfa"/></div>
					<div id="space" class="pdfasverticalspace" style="display:block"></div>
				<% } if ((sign_mode!=null) && (sign_mode.contains("textual")) && (source_mode.equals(FormFields.VALUE_SOURCE_FILE)) && ((sign_pdfa==null) || (!sign_pdfa.equals("on")))) { %>
					<div id="hinweistextfile" style="display:block"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.file"/></div>
					<div id="hinweistext" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note"/></div>
					<div id="hinweispdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.pdfa"/></div>
					<div id="hinweistextpdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note"/> <fmt:message key="signupload.note.pdfa"/></div>
					<div id="hinweistextfilepdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.file"/> <fmt:message key="signupload.note"/> <fmt:message key="signupload.note.pdfa"/></div>
					<div id="space" class="pdfasverticalspace" style="display:block"></div>
				<% } if ((sign_mode!=null) && (sign_mode.contains("textual")) && (!source_mode.equals(FormFields.VALUE_SOURCE_FILE)) && ((sign_pdfa==null) || (!sign_pdfa.equals("on")))) { %>
					<div id="hinweistext" style="display:block"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note"/></div>
					<div id="hinweistextfile" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.file"/></div>
					<div id="hinweispdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.pdfa"/></div>
					<div id="hinweistextpdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note"/> <fmt:message key="signupload.note.pdfa"/></div>
					<div id="hinweistextfilepdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.file"/> <fmt:message key="signupload.note"/> <fmt:message key="signupload.note.pdfa"/></div>
					<div id="space" class="pdfasverticalspace" style="display:block"></div>
				<% } if ((sign_mode!=null) && (sign_mode.contains("textual")) && (source_mode.equals(FormFields.VALUE_SOURCE_FILE)) && (sign_pdfa!=null) && (sign_pdfa.equals("on"))) { %>
					<div id="hinweistextfilepdfa" style="display:block"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.file"/> <fmt:message key="signupload.note"/> <fmt:message key="signupload.note.pdfa"/></div>
					<div id="hinweistextfile" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.file"/></div>
					<div id="hinweistext" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note"/></div>
					<div id="hinweispdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.pdfa"/></div>
					<div id="hinweistextpdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note"/> <fmt:message key="signupload.note.pdfa"/></div>
					<div id="space" class="pdfasverticalspace" style="display:block"></div>
				<% } if ((sign_mode!=null) && (sign_mode.contains("textual")) && (!source_mode.equals(FormFields.VALUE_SOURCE_FILE)) && (sign_pdfa!=null) && (sign_pdfa.equals("on"))) { %>
					<div id="hinweistextpdfa" style="display:block"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note"/> <fmt:message key="signupload.note.pdfa"/></div>
					<div id="hinweistextfile" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.file"/></div>
					<div id="hinweistext" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note"/></div>
					<div id="hinweispdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.pdfa"/></div>
					<div id="hinweistextfilepdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.file"/> <fmt:message key="signupload.note"/> <fmt:message key="signupload.note.pdfa"/></div>
					<div id="space" class="pdfasverticalspace" style="display:block"></div>
				<% } 
			} else { %>
				<div id="hinweistextfile" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.file"/></div>
				<div id="hinweistext" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note"/></div>
				<div id="hinweispdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.pdfa"/></div>
				<div id="hinweistextpdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note"/> <fmt:message key="signupload.note.pdfa"/></div>
				<div id="hinweistextfilepdfa" style="display:none"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>: </span><fmt:message key="signupload.note.file"/> <fmt:message key="signupload.note"/> <fmt:message key="signupload.note.pdfa"/></div>
				<div id="space" class="pdfasverticalspace" style="display:none"></div>
			<% } %>
		</div> -->
		<!-- <div class="linkssigblock">
			<% if (german) { %>
				<img src="images/SIGNATURBLOCK_DE.jpg" id="Signaturblock" width="410" height="190"
					alt="Der Signaturblock stellt den Signaturwert, den Namen und gegebenenfalls Titel des Unterzeichners,
					das Aussteller-Zertifikat, die Seriennummer, die Signaturmethode die entweder bin�r oder textuell ist,
					die Signaturparameter, welche zum Beispiel den verwendeten Hashalgorithmus beinhalten,
					Informationen zur Signaturpr�fung, einen Hinweis und schlie�lich das Datum und die Uhrzeit der Signatur"/>
			<% } else { %>
				<img src="images/SIGNATURBLOCK_EN.jpg" id="Signaturblock" width="410" height="190"
					alt="The signature block shows the signature value, the name of the signator, the certificate of the issuer,
					the serial number, one of the possible signature methods binary or textual, the signature parameters that
					for example do provide informations about the hash algorithm, informations on the signature verification,
					an advice and finally the date and time when the document is signed."/>
			<% } %>
		</div> -->
		<!-- <div class="linksnotesigblock">
			<fmt:message key="signupload.noteonsigmark"/>
		</div>
		<div class="pdfasverticalspace"></div>
		<div class="linkspreview">
			<input type="submit" name="<%= FormFields.FIELD_PREVIEW %>" value="<fmt:message key="signupload.button.preview"/>" onclick="return previewForm()"/>
		</div> -->
	</div>
	</div>
	
	<div class="rechts" id="sign" style="display:block">
		<div class="rechtsinhalt" id="signintern">
			<div class="rechtslinks">
				<img src="https://www.buergerkarte.at/test-pdf-as/images/onlineBKU.png" alt="Chip-Karte" id="Karte" />
			</div>
			<div class="rechtsrechts">
				<img src="https://www.buergerkarte.at/test-pdf-as/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" onclick="return submitForm(this)"></input>
			</div>
			<div class="rechtsrechts">
				<input type="submit" name="<%= FormFields.FIELD_CONNECTOR_MOBILE %>" value="<fmt:message key="signupload.signwithmobile"/>" alt="Signatur mit Handy" onclick="return submitForm(this)"></input>
			</div>
			<!-- Here the hidden signature parameters are inserted because in the meanwhile they can
			not more choosed by the user -->
			<div id="hiddenfields" style="display:none">
				<input type="hidden" name="<%=FormFields.FIELD_MODE %>" value="<%=FormFields.VALUE_MODE_BINARY %>"/>
				<input type="hidden" name="<%=FormFields.FIELD_PDFA_ENABLED %>" value="off"/>
				<input type="hidden" name="<%=FormFields.FIELD_NOTE_ENABLED %>" value="on"/>
				<% if (german) { %>
					<input type="hidden" name="<%=FormFields.FIELD_SIGNATURE_TYPE %>" value="<%=FormFields.VALUE_SIGNATURE_TYPE_DE %>"/>
				<% } else { %>
					<input type="hidden" name="<%=FormFields.FIELD_SIGNATURE_TYPE %>" value="<%=FormFields.VALUE_SIGNATURE_TYPE_EN %>"/>
				<% } %>
				<input type="hidden" name="<%=FormFields.FIELD_HEIGHT_SIGNDIV %>" value=""/>
			</div>
		</div>
	</div>
	<!-- The IFrame and Local BKU button -->
	<div class="rechts" id="signiframe" style="display:none">
		<div class="rechtsinhalt" id="signiframeintern">
			<div style="background:#e6f2fa"><iframe id="iframe" src="https://www.buergerkarte.at/test-pdf-as/jsp/please_wait.jsp" name="iframe" width="190px" height="190px" scrolling="no" title="iframe" frameborder="0">
			</iframe></div>
			<div class="pdfassmallverticalspace"></div>
			<div id="localbku" style="display:none; border-top:1px solid black; text-align:left; padding:3px">
				<input type="submit" name="<%= FormFields.FIELD_CONNECTOR_LOCALBKU %>" value="<fmt:message key="common.bku"/>" alt="Signatur mit lokaler BKU" onclick="return submitForm(this)"/>
				<div style="font-size:75%"><fmt:message key="nullrequestpage.localbku.advice"/></div>
				<div class="pdfassmallverticalspace"></div>
			</div>
			<div id="backlink" align="left"><a href="<%= request.getContextPath() %>/" target="_parent"><fmt:message key="common.cancel"/></a></div>
		</div>
	</div>
	<!-- Fake signature buttons for the case an error occured and this error has to be displayed
	within the above IFrame. In this case the real signature buttons are deleted with javascript
	and this buttons are showed -->
	<div class="rechts" id="downloadsignbuttons" style="display:none">
		<div class="rechtsinhalt" id="downloadsignbuttonsintern">
			<div class="rechtslinks">
				<img src="https://www.buergerkarte.at/test-pdf-as/images/onlineBKU.png" alt="Chip-Karte" id="Karte"/>
			</div>
			<div class="rechtsrechts">
				<img src="https://www.buergerkarte.at/test-pdf-as/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" onclick="return submitForm(this)" disabled="disabled"></input>
			</div>
			<div class="rechtsrechts">
				<input type="submit" name="<%= FormFields.FIELD_CONNECTOR_MOBILE %>" value="<fmt:message key="signupload.signwithmobile"/>" alt="Signatur mit Handy" onclick="return submitForm(this)" disabled="disabled"></input>
			</div>
		</div>
	</div>
	</form>
	</div>
	
	<!-- Form that sets the source choosed and eventually the text when free text is choosen.
	This is for passing the information when the change language link was hit. -->
	<form name="changelanguage" id="changelanguage" method="post" accept-charset="UTF-8" action="https://www.buergerkarte.at/test-pdf-as/jsp/signupload.jsp" target="_self">
		<% if (german) { %>
			<input type="hidden" name="newlanguage" value="de"/>
		<% } else { %>
			<input type="hidden" name="newlanguage" value="en"/>
		<% } %>
		<% if (source_mode!=null) {
			if (source_mode.contains(FormFields.VALUE_SOURCE_FILE)) { %>
				<input type="hidden" name="source_mode" value="file"/>
				<input type="hidden" name="text" value=""/>
		<% } else { %>
			<input type="hidden" name="source_mode" value="text"/>
			<input type="hidden" name="text" value="<%= sign_freetext %>"/>
		<% }
		} else { %>
			<input type="hidden" name="source_mode" value="file"/>
			<input type="hidden" name="text" value=""/>
		<% } %>
	</form>
	
	<script language="javascript" type="text/javascript">
		initFileUploads();
		checkHeight();
		detectBrowser();
	</script>
	
	<% 
	//After loading the page set all attributes to null
	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);
	
	%>
</body>
</html>