<%@page import="java.util.*, javax.sql.*, java.sql.*, javax.naming.*, java.text.*,
m05bClasses.m05bConexion, java.io.BufferedOutputStream, java.io.OutputStream,
sun.misc.BASE64Decoder"%>

<%@include file="/mantenimientosJSP/includes/m05b.inc"%>
<!-- Para poder mostrar los caracteres especiales en los mensajes javascript -->
<%@page contentType="text/html; charset=UTF-8" %>

<!-- Fecha de creacion: (11/12/03) -->
<%	// _______________________________XLNETs______________________________________
	// Evaluar variable de session que indica si esta conectado a XLNets
	if (session.getAttribute("objetoSeguridad") == null) {
		// Verificar que no ha transcurrido el tiempo de sesion (web.xml) %>
			<%@ include file="/m05bControlAcceso.inc"%>
<%	}%>

<%@ include file="/m05bIdioma.inc"%>

<HTML>

<head>
	<title><%= res.getString("etTituloFirmarDocumento")%></title>
	<link rel="stylesheet" href="<%=m05bConstantesPaginas.PATH_ESTILOS%>/m05bestilos.css" type="text/css">
	<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
	<META http-equiv="Pragma" content="no-cache">
	<META http-equiv="Control" content="no-cache">
	<META http-equiv="Expires" content="0">
</head>

<BODY style="cursor: wait;" onLoad="javascript:document.body.style.cursor='default';return false;" onunload="document.body.style.cursor='wait';">

<%
	//Mostrar o descargar el PDF
	String tipoFirma = (String)request.getParameter("TipoFirma");
	String mostrarPDF = request.getParameter("MostrarPDF");

	if (mostrarPDF != null && mostrarPDF.equals("1")) {
		%>
		<form action="m05bFirmarDocumentoJsp.jsp?TipoFirma=<%=tipoFirma%>&MostrarPDF=1" method="post">
		    <input type="hidden" name="hiddenDocumentoBase64" id="hiddenDocumentoBase64">
	    	<input type="hidden" name="isSubmit" id="isSubmit">
		</form>
		<script type="text/javascript">
			document.getElementById("hiddenDocumentoBase64").value = window.parent.opener.document.formAsignaciones.pdfFicheroEntDev.value;
		</script>
		<%
		Object objDocumentoBase64 = request.getParameter("hiddenDocumentoBase64");
		if (objDocumentoBase64 != null && objDocumentoBase64.toString().length() > 0) {
			byte[] decData;
			BASE64Decoder decoder;
			decoder = new BASE64Decoder();
			decData = decoder.decodeBuffer(objDocumentoBase64.toString());

			response.reset();
			OutputStream oOut=response.getOutputStream();
			BufferedOutputStream bOut=new BufferedOutputStream(oOut);

			response.setContentLength(decData.length);
			response.setContentType("application/pdf");

			bOut.write(decData);
			bOut.flush();
			bOut.close();
			response.flushBuffer();
		} else {
			String isSubmit = request.getParameter("isSubmit");
			if (isSubmit != null && isSubmit.equals("S")) {
				%><script>alert('Ha ocurrido un error al obtener el documento a firmar.');</script><%
			} else {
				%>
				<script>
				document.getElementById("isSubmit").value = 'S';
				document.forms[0].submit();
				</script>
				<%
			}
		}
	} else {

%>
		<TABLE style="width: 100%">
			<tr>
				<td align="center">
				<input type="button" class="botonAsig" name="firmar" value="<%= res.getString("etBOT_FIRMAR")%>" ONCLICK="JavaScript:firmar();" onMouseOver="top.status='<%= res.getString("etBOT_STATUSFIRMAR")%>'; return false" onMouseOut="top.status=''; return false" />
				<label style="width: 40px;"></label>
				<input type="button" class="botonAsig" name="cerrar" value="<%= res.getString("etBOT_CERRAR")%>" ONCLICK="JavaScript:self.close();" onMouseOver="top.status='<%= res.getString("etBOT_STATUSCERRAR")%>'; return false" onMouseOut="top.status=''; return false" />
				</td>
			</tr>
			<tr><td></td></tr>
		    <tr>
		    	<td>
			    	<div id="visorDocumento" class="r01gClsVisorDocumento" style="height: 594px;">
						<iframe class="r01gClsDocumento"
							type="application/pdf"
							src="m05bFirmarDocumentoJsp.jsp?TipoFirma=<%=tipoFirma%>&MostrarPDF=1"
							width="100%"
							height="100%">
						</iframe>
					</div>
				</td>
			</tr>
		</TABLE>

		<script type="text/javascript">
			function firmar() {
				//self.close();
				<%if (tipoFirma.equals(m05bConstantes.FIRMAENTREGA)) {%>
				window.opener.fncFirmarEntregaFIN();
				<%} else {%>
				window.opener.fncFirmarDevolucionFIN();
				<%}%>
			}
		</script>
<%}%>

</BODY>
</HTML>