<%@page import="com.rms.tfc.entity.Pedido"%>
<%@page import="com.rms.tfc.util.DateUtil"%>
<%@page import="com.rms.tfc.util.StringUtil"%>
<%@page import="com.rms.tfc.mapper.MapperBBDD"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.List"%>
<%@page import="com.rms.tfc.util.SessionUtil"%>
<%
	List<Pedido> listaPedidos =  (List<Pedido>) request.getAttribute("objetoJSP");
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Gesti&oacute;n de tienda</title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<link href="../css/tienda.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
var submitDone = false;

function recibirPedido(idPedido){
	if (!submitDone){
		var formulario = document.getElementById("pedido");
		formulario.idPedido.value = idPedido;
		submitDone = true;
		formulario.submit();
	}
}

function verDetallePedido(idPedido){
	window.open('DetallePedido.html?idPedido=' + idPedido,'Detalle_Pedido_' + idPedido,'scrollbars=1,toolbar=0,location=0,directories=0,resizable=1,width=900,height=300');
}
</script>
</head>
<body>
<table width="945" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td bgcolor="#272e96" width="945" height="75" align="center"><span style="color: #FFFFFF; font-weight:bold; font-size: 35px;">Aplicaci&oacute;n de gesti&oacute;n de tienda</span></td>
  </tr>
  <tr>
    <td><%@ include file="cabecera.jsp" %>
		<table width="912" border="0" align="center" cellpadding="0" cellspacing="0">
		  <tr>
		    <td class="texto">Usuario: <strong><%=SessionUtil.getUserSession()%></strong></td>
		    <td class="volver">&nbsp;</td>
		  </tr>
		  <tr>
		    <td class="texto"><a href="admin.html">Administraci&oacute;n</a> &gt; <strong>Pedidos pendientes</strong></td>
            <td class="volver"><div align="right" class="volver"></div></td>
		  </tr>
		  <tr>
		    <td colspan="2" class="texto"><img src="../img/sp.gif" width="2" height="5"></td>
		  </tr>
		  <tr>
		    <td colspan="2" class="texto"><img src="../img/sp-gris.gif" width="912" height="1"></td>
		  </tr>
		</table>
	</td>
  </tr>
  <tr>
        <td height="20">&nbsp;</td>
  </tr>
  <tr>
    <td>
    <table width="775"  border="0" align="center" cellpadding="2" cellspacing="0">
      <tr>
        <td width="130" bgcolor="#F0F0F0"> &nbsp;<img src="../img/bulet5.gif" width="15" height="16" align="absmiddle"> <span class="titulos">Id del Pedido</span></td>
        <td width="240" bgcolor="#E1E1E1" class="titulos">Descripci&oacute;n del pedido</td>
        <td width="120" bgcolor="#F0F0F0" class="titulos"><div align="center">Fecha del pedido</div></td>
        <td width="120" bgcolor="#E1E1E1" class="titulos"><div align="center">Estado</div></td>
        <td width="165">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="5" class="texto_titulos">
<% 
	Iterator<Pedido> itPedidos = listaPedidos.iterator();
	Pedido pedido = null;
	String nombreTienda = null;
	while(itPedidos.hasNext()){
		pedido = itPedidos.next();
%>          
		 <table width="100%" border="0" >
          <tr>
          	<td width="130" bgcolor="#F0F0F0"><span class="texto"><%=pedido.getIdPedido()%></span></td>
	        <td width="240" bgcolor="#E1E1E1"><span class="texto"><%=pedido.getDescripcion()%></span></td>
	        <td width="120" bgcolor="#F0F0F0"><span class="texto"><%=DateUtil.getStringFromDate(pedido.getFechaPedido(), "dd/MM/yyyy")%></span></td>
	        <td width="120" bgcolor="#E1E1E1"><span class="texto"><%=pedido.getEstado()%></span></td>
	        <td width="165" align="center" nowrap>
	        	<%
	        		if (MapperBBDD.estadoExpedido.equals(pedido.getEstado())){
	        	%>
	        	<a href="javascript:recibirPedido(<%=pedido.getIdPedido()%>);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Recibir_<%=pedido.getIdPedido()%>','','../img/recibir2.gif',1)"><img src="../img/recibir.gif" name="Recibir_<%=pedido.getIdPedido()%>" width="123" height="25" border="0"></a>
	        	<%
	        		} else {
	        	%>
	        	&nbsp;
	        	<%
	        		}
	        	%>
	        </td>
	      </tr>
          <tr>
			<td bgcolor="#F9F9F9" class="texto_titulos" nowrap><a href="javascript:verDetallePedido(<%=pedido.getIdPedido()%>)" style="color:#004b96; text-decoration:none;"><span style="font-weight:bold;">Ver Detalle&nbsp;</span></a>
			<td colspan="4"></td>
          </tr>
        </table> 
<% } %>    
        </td>
      </tr>              
    </table>
	<form action="RecibirPedido.html" method="post" name="pedido" id="pedido">
		<input type="hidden" name="idPedido" id="idPedido" value="" />
	</form>
	</td>
  </tr>  
  <tr>
      <td>
      	<table width="934" border="0" align="center" cellpadding="0" cellspacing="0">
      		<tr>
		    	<td>&nbsp;</td>
		    </tr>
		    <tr>
		    	<td><div align="center">
		          <p><img src="../img/line.gif" width="913" height="10"></p>
		        </div></td>
		    </tr>
		    <tr>
        <td><div align="center"><span class="pie">2015 TFC Roberto Mart&iacute;nez Sierra</span></div></td>
		    </tr>
      </table>
    </td>
  </tr>
</table>
</body>
</html>