{{script}}
import travel
from datetime import date, timedelta
from rlextra.radxml.xmlutils import xml2doctree
params = request.params
oYMD = params['oYMD']
rYMD = params['rYMD']
orig = params['orig']
dest = params['dest']
ticket_id = params['ticket_id']
numOfAdults = params['numOfAdults']
step2XML = travel.getStep2XML(orig, dest, oYMD, rYMD, ticket_id) 
open('step2xml.xml','w').write(step2XML)
step2Tree = xml2doctree(step2XML,0)
ticket = step2Tree.tickets.airTicket
outJDays = 0
for trip in ticket.getNamedChildren('trip'):
	if trip.id=='outbound':
		for flight in trip.getNamedChildren('flight'):
			if str(flight.isOverNight)=='True':
				outJDays+=1
hotels = step2Tree.hotels
iL=oYMD.split('-')
checkinDate=date(int(iL[0]),int(iL[1]),int(iL[2]))+timedelta(days=outJDays)
inYMD=str(checkinDate)
if rYMD!='0000-00-00':
	oL=rYMD.split('-')
	checkoutDate=date(int(oL[0]),int(oL[1]),int(oL[2]))
else:
	checkoutDate=checkinDate+timedelta(days=1)
outYMD=str(checkoutDate)
{{endscript}}
{{app.doHeader(onload="javascript:genMonYearOptions('checkinMonYear','%s', '%s','l');setDayOptions('checkinDay', '%s','l');genMonYearOptions('checkoutMonYear','%s', '%s', 'u');setDayOptions2('checkoutDay', '%s', 'u');"  % (inYMD, outYMD, inYMD, inYMD, outYMD, outYMD))}}
	<div id="main">
		<div id="main2">
<h2>Choose Hotel</h2>
<p>Please specify your check in details</p>
<p>Checkin:</p>
<select name="checkinDay" size="1" id="checkinDay">
</select>
{{script}}
{{endscript}}
<!--{{oYMD}}, {{rYMD}}-->
<select name="checkinMonYear" size="1" id="checkinMonYear" onChange="genDayOptions(this.value, 'checkinDay', '{{inYMD}}', '{{outYMD}}','l')" >
</select>
<br/>
<p>Checkout:</p>
<select name="checkoutDay" size="1" id="checkoutDay">
</select>
<select name="checkoutMonYear" size="1" id="checkoutMonYear" onChange="genDayOptions(this.value, 'checkoutDay', '{{inYMD}}', '{{outYMD}}','u')" >
</select>

<form name="hotels" method="get">
<input type="hidden" name="action" value="step3"/>
<input type="hidden" name="ticket_id" value="{{ticket_id}}"/>
<input type="hidden" name="tripTitle" value="{{tripTitle}}"/>				
<input type="hidden" name="subtitle" value="{{subtitle}}"/>				
<input type="hidden" name="customerName" value="{{customerName}}"/>				
<input type="hidden" name="chosenHotel" value=""/>
<input type="hidden" name="oYMD" value="{{oYMD}}"/>
<input type="hidden" name="rYMD" value="{{rYMD}}"/>
<input type="hidden" name="orig" value="{{orig}}"/>
<input type="hidden" name="dest" value="{{dest}}"/>
<input type="hidden" name="numOfAdults" value="{{numOfAdults}}"/>
<input type="hidden" name="checkinYMD" value=""/>
<input type="hidden" name="checkoutYMD" value=""/>
{{include('views/hotelbooking.prep', dictionary=dictionary, hotels=hotels, step='2')}}
</form>
		</div>
	</div>
	<div id="sidebar">	<!-- Begin .box -->
		<div class="box">
			<div class="box2">
				<div class="box3"><h2 class="sidebar-title">Step 2 - Hotel Selection</h2>
                <p>As before, you can either choose a specific hotel with the links
                in the bottom right of each one; or you can leave things open to include
                all options in the brochure.</p>

                <p>If we were building a pre-sale solution for a hotel company, they would 
                generally have all destinations richly described on their site, and might
                implement a criteria-search or shopping basket metaphor. This could then
                create very rich brochures with all the rooms, restaurants and facilities
                (as with the <a href="http://www.reportlab.com/case_hilton_ebro.html">
                        eBrochures we built for Hilton</a>).</p>

                <p>For a large-scale booking site with very wide coverage, we would generally
                have content similar in detail to what's on the left.  BUT we can augment this
                later with info about the location.
                </p>

				</div>
			</div>
		</div>	<!-- End .box -->
	</div>
{{app.doFooter()}}
