<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%
      java.util.List offers = (java.util.List)request.getSession().getAttribute("offers");
      java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
 %>

<html>
<head>
  <title>PDA-Application Book a leisureoffer</title>
  <script type="text/javascript">
    function makeBooking(index)
    {
       selectorName = "CarSelect" + index;
       carValue = document.getElementsByName(selectorName)[0].value;
       document.forms[0].elements[1].value = carValue;
       document.forms[0].elements[0].value = index;
       document.forms[0].submit();
    }
   
    function cancel()
    {
       location.href="Menu.jsp";
    }
  </script>
</head>
<body>
 <center>
  <h1>Make a Booking</h1>
  <html:errors/><p>
  <table border="1">  
    <tr><th><b>Leisure Offer:</b></th><th><b>Price:</b></th><th><b>From:</b></th><th><b>To:</b></th><th><b>Car:</b></th><th><b>Make Booking:</b></th></tr>
    <% 
         java.util.Iterator itor = offers.iterator();
         int i = 0;
         while (itor.hasNext())
         {
            com.ferienclub.leisure.LeisureOffer offer = (com.ferienclub.leisure.LeisureOffer)itor.next();
            java.lang.String name = offer.getName();
            double price = offer.getPrice();
            String from = sdf.format(offer.getStartTime());
            String to = sdf.format(offer.getEndTime());
            %>
            <tr>
              <td><%= name %></td>
              <td><%= price %></td>
              <td><%= from %></td>
              <td><%= to %></td>
              <td>
                <select name="CarSelect<%= i %>">
                  <option value="true">Yes</option>
                  <option value="false">No</option>
                </select>
              </td>
              <td><input type="button" value="Make Booking" onclick="makeBooking(<%= i %>)"/></td>
            </tr>
           <%
           i++;
         }
     %>
  </table>
  <p>
  <input type="button" value="Cancel" onclick="cancel()"/>
 </center>

 <html:form action="makeBooking.do">
   <html:hidden name="bookingForm" property="bookingIndex"/>
   <html:hidden name="bookingForm" property="withCar"/>
 </html:form>  

</body>
</html>
