<%@ page import="at.knowcenter.wag.egov.egiz.web.FormFields" %>
<%@ page import="at.knowcenter.wag.egov.egiz.web.SessionAttributes" %>
<%@ page import="at.gv.egiz.pdfas.api.commons.Constants" %>
<%@ page import="at.gv.egiz.pdfas.web.i18n.LanguageDecoratorMapper"%>
<%@ page import="at.knowcenter.wag.egov.egiz.web.servlets.UpdateFormServlet"%>

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

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

<html>
<head>
	<%
   boolean testMode = request.getContextPath().startsWith("/test-");
	boolean forceTextualForMocca = true;
	%>
	<title>
	<%
		if (testMode) {
	%>
		<fmt:message key="test.common.title"/>
	<% } else { %>
		<fmt:message key="common.title"/>
	<% } // end if %>		   
	</title>
  <% session.removeAttribute(SessionAttributes.SIGNED_PDF_DOCUMENT); %>
	<script language="javascript" type="text/javascript">
		<!--
			function updateForm() {
				var updateform = document.getElementById('updateform');
				var submitform = document.getElementById('submitform');
				
				updateform.<%= FormFields.FIELD_SIGNATURE_TYPE %>.value = submitform.<%= FormFields.FIELD_SIGNATURE_TYPE %>.value; 
				updateform.<%= FormFields.FIELD_MODE %>.value = submitform.<%= FormFields.FIELD_MODE %>.value; 
				updateform.<%= FormFields.FIELD_CONNECTOR %>.value = submitform.<%= FormFields.FIELD_CONNECTOR %>.value; 
				updateform.submit();
				return(false);
			}
			function submitForm(preview) {
				var submitform = document.getElementById('submitform');
				if (!submitform.fileupload.value) {
					if (preview) {
						alert('<fmt:message key="signupload.documentnotselected.preview"/>');
					} else {
						alert('<fmt:message key="signupload.documentnotselected"/>');
					}
					return(false);
				}
				if (preview) {
					submitform.<%= FormFields.FIELD_PREVIEW %>.value='true';
				} else {
					submitform.<%= FormFields.FIELD_PREVIEW %>.value='false';
				}
				return(true);
			}
		-->
	</script>
	<%
		// PRESETS
		// signature device
	   String device = (String) session.getAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_DEVICE_KEY);
	   if (device == null) {
	      device = Constants.SIGNATURE_DEVICE_BKU;
	      session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_DEVICE_KEY, device);
	   }
	   // signature mode
	   String mode = (String) session.getAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_MODE_KEY);
		if (forceTextualForMocca && Constants.SIGNATURE_DEVICE_MOC.equals(device)) {
		   mode = FormFields.VALUE_MODE_TEXTUAL;
		   session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_MODE_KEY, mode);
		}
	   if (mode == null) {
		   mode = FormFields.VALUE_MODE_BINARY;
		   session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_MODE_KEY, mode);
		}
	   // signature type
	   String type = (String) session.getAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_TYPE_KEY);
	   if (type == null) {
	      Locale locale = (Locale) session.getAttribute(LocaleParamFilter.LOCALE_SESSION_KEY);
	      if (locale == null) {
	         locale = request.getLocale();
	      }
	      type = Locale.GERMAN.getLanguage().equals(locale.getLanguage()) ? "SIGNATURBLOCK_DE" : "SIGNATURBLOCK_EN";
	      session.setAttribute(UpdateFormServlet.UPLOADFORM_SIGNATURE_TYPE_KEY, type);
	   }

	   %>
</head>
<body>
<h1>
	<%
		if (testMode) {
	%>
		<fmt:message key="test.common.title"/>
	<% } else { %>
		<fmt:message key="common.title"/>
	<% } // end if %>		   
</h1>
<h2 align="left"><fmt:message key="signupload.heading2"/></h2>
<div class="pdfasnote"><fmt:message key="signupload.selectfilenote"/></div>
<form name="updateform" id="updateform" method="post" action="<%= request.getContextPath() %>/UpdateForm">
	<input type="hidden" name="<%= FormFields.FIELD_SIGNATURE_TYPE %>" value=""/>
	<input type="hidden" name="<%= FormFields.FIELD_MODE %>" value=""/>
	<input type="hidden" name="<%= FormFields.FIELD_CONNECTOR %>" value=""/>
</form>
<form name="submitform" id="submitform"
      enctype="multipart/form-data"
      accept-charset="UTF-8"
      method="post"
      action="<%= request.getContextPath() %>/Sign">
	<table border="0" cellspacing="0" cellpadding="4" id="pdfasupperformtable">
		<tr>
			<td align="left" nowrap="nowrap"><label><fmt:message key="signupload.signaturetype"/>:</label></td>
			<td align="left">
				<select class="field" name="<%= FormFields.FIELD_SIGNATURE_TYPE %>" onchange="return updateForm();">
					<option value="SIGNATURBLOCK_DE" <%= "SIGNATURBLOCK_DE".equals(type) ? "selected=\"selected\"" : "" %>><fmt:message key="signupload.signaturetype.signaturblock.de"/></option>
					<option value="SIGNATURBLOCK_EN" <%= "SIGNATURBLOCK_EN".equals(type) ? "selected=\"selected\"" : "" %>><fmt:message key="signupload.signaturetype.signaturblock.en"/></option>
				</select>			
				<!-- %= // FormFields.generateTypeSelectBox() % -->
			</td>
		</tr>
		<tr>
			<td align="left" nowrap="nowrap"><label><fmt:message key="signupload.signaturemode"/>:</label></td>
			<td align="left">
				<% if (forceTextualForMocca && Constants.SIGNATURE_DEVICE_MOC.equals(device)) {%>
					<fmt:message key="common.textual"/>
					<input type="hidden" name="<%= FormFields.FIELD_MODE %>" value="<%= FormFields.VALUE_MODE_TEXTUAL %>"/>
				<% } else { %>
					<select name="<%= FormFields.FIELD_MODE %>" onchange="return updateForm();">
					<option value="<%= FormFields.VALUE_MODE_BINARY %>" <%= FormFields.VALUE_MODE_BINARY.equals(mode) ? "selected=\"selected\"" : "" %>><fmt:message key="common.binary"/></option>
					<option value="<%= FormFields.VALUE_MODE_TEXTUAL %>" <%= FormFields.VALUE_MODE_TEXTUAL.equals(mode) ? "selected=\"selected\"" : "" %>><fmt:message key="common.textual"/></option>
						<!--
							<option value="<%= FormFields.VALUE_MODE_DETACHED %>">detached</option>
						-->
					</select>
				<% } %>
			</td>
		</tr>
		<tr>
			<td align="left" nowrap="nowrap"><label><fmt:message key="signupload.signaturedevice"/>:</label></td>
			<td align="left">
				<select name="<%= FormFields.FIELD_CONNECTOR %>" onchange="return updateForm();">
					<option value="<%= Constants.SIGNATURE_DEVICE_BKU %>" <%= Constants.SIGNATURE_DEVICE_BKU.equals(device) ? "selected=\"selected\"" : "" %>><fmt:message key="common.bku"/></option>
					<option value="<%= Constants.SIGNATURE_DEVICE_MOC %>" <%= Constants.SIGNATURE_DEVICE_MOC.equals(device) ? "selected=\"selected\"" : "" %>><fmt:message key="common.mocca"/></option>
				</select>
			</td>
		</tr>
		<tr>
			<td align="left" nowrap="nowrap"><label><fmt:message key="signupload.file"/>:</label></td>
			<td align="left"><input size="50" type="file" id="fileupload" name="<%= FormFields.FIELD_UPLOAD %>" accept="application/pdf"/></td>
		</tr>
	</table>
	<div class="pdfasnote"><span class="pdfasemphasis"><fmt:message key="signupload.note.prefix"/>:</span> <fmt:message key="signupload.note"/></div>

	<input type="hidden" name="<%= FormFields.FIELD_DOWNLOAD %>" value="<%= FormFields.VALUE_DOWNLOAD_ATTACHMENT %>"/>
	<input type="hidden" name="<%= FormFields.FIELD_PREVIEW %>" value="false" />

	<div class="pdfasverticalspace"></div>
	
	<jsp:include page="SIGNATURBLOCK.jsp"/>
	
	<div class="pdfasnote"><fmt:message key="signupload.noteonsigmark"/></div>
	<% if (Constants.SIGNATURE_DEVICE_BKU.equals(device)) { %>
		<div>
			<!-- =============================================== Start BKU-Erkennung -->
			<iframe src="<%= request.getContextPath() %>/bku-erkennung/bku-erkennung_iframe.html" width="152" height="57" id="sep_iframe" scrolling="no" marginheight="0" marginwidth="0" frameborder="0" allowtransparency="true"></iframe>
			<!-- ================================================ Stop BKU-Erkennung -->
		</div>
	<% } else if (Constants.SIGNATURE_DEVICE_MOC.equals(device)) { %>
		<div>
			<img src="images/chiperling.jpg" width="57" height="57" alt="<fmt:message key="common.mocca"/>"/>
		</div>
	<% } else { %>
		<div class="pdfasverticalspace"></div>
	<% } // end if %>
		<div>
			<input type="submit" value="<fmt:message key="signupload.button.sign"/>" onclick="return submitForm(false);"/>
			<input type="submit" value="<fmt:message key="signupload.button.preview"/>" onclick="return submitForm(true);"/>
		</div>
	
</form>

</body>
</html>