<?php
$month_array = array("January","February","March","April","May","June","July","August","September","October","November","December");
$current_day = date("d");


//$form_url = $protocol . $_SERVER['HTTP_HOST'] . '/amodules/booking_search/iframe.php';
$form_url = 'https://www.booking.com/searchresults.html';

?>
<script type="text/javascript" src="<?php echo $protocol . $_SERVER['HTTP_HOST'] . '/amodules/booking_search/js/booking.com.js';?>"></script>
<!-- start copy sourcecode from here -->
<div id="searchboxInc">
<form id="frm" name="frm" action="<?php echo $form_url; ?>" method="get" target="booking_iframe" autocomplete="off">
	<script type="text/javascript">/*document.forms["frm"].action += 'searchresults.html';*/</script>
	<fieldset>
		<div id="destinationSearch">
			<input type="hidden" name="aid" value="359964" />
			<input type="hidden" name="error_url" value="https://www.booking.com/?aid=359964;" />
			<input type="hidden" name="si" value="ai,co,ci,re,di" />
			<input type="hidden" name="label" value="" />
			<input type="hidden" name="lang" value="en-gb" />
			<input type="hidden" name="nflt" value="" />
			<input type="hidden" name="ifl" value="" />
			<!--h3 class="box-title">Search Hotels</h3-->
		</div>
		<div id="inout">
			<div id="dest">
				<h3>Destination</h3>
				<input class="text" type="text" id="destination" name="ss" value="" title="City, Region, Country, Landmark, Hotel, District"  autocomplete="off" />
			</div>
			<div id="homein">
				<h3>Check-in date</h3>
				<select id="b_checkin_day" name="checkin_monthday" onchange="checkDateOrder('frm', 'b_checkin_day', 'b_checkin_month', 'b_checkout_day', 'b_checkout_month') ; tickCheckBox('b_availcheck');">
					<option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
					<option value="4">4</option>
					<option value="5">5</option>
					<option value="6">6</option>
					<option value="7">7</option>
					<option value="8">8</option>
					<option value="9">9</option>
					<option value="10">10</option>
					<option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option>
				</select>
				<select id="b_checkin_month" name="checkin_year_month" onchange="checkDateOrder('frm', 'b_checkin_day', 'b_checkin_month', 'b_checkout_day', 'b_checkout_month') ; tickCheckBox('b_availcheck');">
					<script language="Javascript"> 
						var monthArray = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
						var today = new Date();
						var month= today.getMonth();
						var year = today.getFullYear()%100;
						var fullYear=today.getFullYear();
						year=new String(year);
						year=addzero(year);
						var countMonth=month;
						for(var i=0;i<12;i++,countMonth++){
							if(countMonth%12==0 && i>0){
								countMonth=0;
								year++;
								year=new String(year);
								year=addzero(year);
								fullYear++;
							}
							document.writeln("<option value=\""+fullYear+"-"+(countMonth+1)+"\">"+monthArray[countMonth]+" '"+year);
						}
					</script>
				</select>
			</div>
			<div id="homeout">
				<h3>Check-out date</h3>
				<select id="b_checkout_day" name="checkout_monthday" onchange="tickCheckBox('b_availcheck');">
				<option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option><option value="6">6</option><option value="7">7</option><option value="8">8</option><option value="9">9</option><option value="10">10</option><option value="11">11</option><option value="12">12</option><option value="13">13</option><option value="14">14</option><option value="15">15</option><option value="16">16</option><option value="17">17</option><option value="18">18</option><option value="19">19</option><option value="20">20</option><option value="21">21</option><option value="22">22</option><option value="23">23</option><option value="24">24</option><option value="25">25</option><option value="26">26</option><option value="27">27</option><option value="28">28</option><option value="29">29</option><option value="30">30</option><option value="31">31</option>
				</select>
				<select id="b_checkout_month" name="checkout_year_month" onchange="tickCheckBox('b_availcheck');">
				<script language="Javascript">
					var monthArray=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
					var today = new Date();
					var month= today.getMonth();
					var year = today.getFullYear()%100;
					var fullYear=today.getFullYear();
					year=new String(year);
					year=addzero(year);
					var countMonth=month;
					for(var i=0;i<12;i++,countMonth++){
						if(countMonth%12==0 && i>0){
							countMonth=0;
							year++;
							year=new String(year);
							year=addzero(year);
							fullYear++;
						}
						document.writeln("<option value=\""+fullYear+"-"+(countMonth+1)+"\">"+monthArray[countMonth]+" '"+year);
					}
				</script>
				</select>
			</div>
			<div id="box-button">
				<button type="submit" id="book-search">Search</button>
			</div>
			
		</div>
		<div class="avail">
			<input id="availcheck" type="checkbox" name="idf" value="on" />
			<label id="labfor" for="availcheck">
			I don't have specific dates yet
			</label>
		</div>
		
	</fieldset>
</form>
<div id="booking-container" style="display: none;">
	<iframe id="booking_iframe" name="booking_iframe" width="990" frameborder="0" scrolling="NO" height="4000"></iframe>
</div>
<script language="Javascript">
var currentDate = new Date(); 
var currentYear = 1900 + currentDate.getYear();
var dailyMS = 24*60*60*1000;
var arrivalDate = new Date(currentDate.getTime());
var departureDate = new Date(currentDate.getTime() + 1*dailyMS);
var arrivalYear = 1900+arrivalDate.getYear();
var arrivalMonth = 1+arrivalDate.getMonth(); var arrivalDay = arrivalDate.getDate();
var departureYear = 1900+departureDate.getYear();
var departureMonth = 1+departureDate.getMonth(); var departureDay = departureDate.getDate();
var a=document.frm;
if ((a.checkin_monthday.selectedIndex == 0) && (a.checkout_monthday.selectedIndex == 0)){
a.checkin_monthday.options[arrivalDay-1].selected = true;
a.checkout_monthday.options[departureDay-1].selected = true;
}
var frm = document.getElementById('frm');
// create date object from checkin values
// set date to 12:00 to avoid problems with one
// date being wintertime and the other summertime
var my = frm['b_checkin_month'].value.split("-");
var ci = new Date (my[0], my[1]-1, frm['b_checkin_day'].value, 12, 0, 0, 0);
// create date object from checkout values
my = frm['b_checkout_month'].value.split("-");
var co = new Date (my[0], my[1]-1, frm['b_checkout_day'].value, 12, 0, 0, 0);
if (ci >= co){
co.setTime(ci.getTime() + 1000 * 60 * 60 * 24);
frm['b_checkout_day'].value = co.getDate();
var com = co.getMonth()+1;
frm['b_checkout_month'].value = co.getFullYear() + "-" + com;
}
</script>
</div>
<div id="calendar"></div>

<script type="text/javascript">
	$(document).ready(function(){
		
		var destination = document.getElementById('destination');
		destination.onblur = function () {
			if (!this.value) {
				this.value = this.getAttribute('title');
				this.className += ' blur';
			}
		}
		destination.onfocus = function () {
			if (this.value == this.getAttribute('title')) {
				this.value = '';
				this.className = this.className.replace(/ blur/, '');
			}
		}
		destination.onblur();
		
		var $diag = $( "#booking-container" );
		$diag.dialog({
			autoOpen: false,
			height: '10',
			width: '10',
			modal: true,
			draggable: false,
			resizable: false,
			close: function( event, ui ) {
				$('#booking_iframe').attr('src', '');
			}
		});
		
		$('#book-search').click(function(ev){
			
			var h = $(window).height() - 60;
			var w = $(window).width() - 60;
			$diag.dialog('option', 'title', 'Search Hotels');
			$diag.dialog('option', 'width', w);
			$diag.dialog('option', 'height', h);
			$diag.dialog('open');
			
		});
		
	});

</script>
<!-- end copy sourcecode until here -->
