<?php
$optres ['css'][] = $module_css_path . "amodules/booking_search/css/find_hotels_large.css";
$optres ['css'][] = $path . "amodules/booking_search/js/find_hotels_large.css";

$book_title = '';
$book_btext = '';
$aff_code = 'BOOKING000000002';
$hotel_aff_location = 'Limassol';

$book_destinations = array();
$book_regions = array();

$q = "SELECT * FROM `booking_cities` where 1=1 order by full_name asc;";
$r = @mysql_query($q);
if($r && mysql_num_rows($r) > 0) {
	while ($row = mysql_fetch_assoc($r)) {
		$book_destinations [] = array_map('stripslashes', $row);
	}
}

$q = "SELECT * FROM `booking_regions` where country_code='cy' order by region_name asc;";
$r = @mysql_query($q);
if($r && mysql_num_rows($r) > 0) {
	while ($row = mysql_fetch_assoc($r)) {
		$book_regions [] = array_map('stripslashes', $row);
	}
}

?>
<div id="bbooking-form">
	<div id="booking-search-header">
		<?php
		$small = trim($module_title_small) != "" ? ' <small>' . trim(stripslashes($module_title_small)) . '<small>' : '';
		?>
		<<?php echo $module_title_tag;?> class="booking-title-tag"><?php echo stripslashes($module_title);?><?php echo $small;?></<?php echo $module_title_tag;?>>
		<img src="<?php echo $protocol . $_SERVER['HTTP_HOST'];?>/amodules/booking_search/aff/bestprices-20.png" alt="Best Prices Guaranteed" onclick="window.open('https://www.booking.com/general.en.html?;tmpl=doc/rate_guarantee','RateGuarantee','status=1,toolbar=0,menubar=0,width=450,height=550,scrollbars=1');"/>
	</div>
	<div id="booking-search-container">
		<form id="booking-search" action="<?php echo $protocol . $_SERVER['HTTP_HOST'];?>/amodules/booking_search/aff/aff_jump.php" target="_blank" method="get">
			<?php
			$def_checkin = date("d/m/Y", strtotime("+1 day"));
			$def_checkout = date("d/m/Y", strtotime("+2 day"));
			$def_rooms = 1;
			$def_adults = 2;
			$def_children = 0;
			$min_checkout_date = date("d/m/Y", strtotime("+2 day"));
			$max_checkout_date = date("d/m/Y", strtotime("+29 day"));
			if(isset($_SESSION['hotel_search']) && isset($_SESSION['hotel_search']['checkin']) && trim($_SESSION['hotel_search']['checkin']) != ""){
				$def_checkin = $_SESSION['hotel_search']['checkin'];
				$dt = DateTime::createFromFormat('d/m/Y', $def_checkin);
				$dt_reg = strtotime($dt->format('Y-m-d'));
				$min_checkout_date = date("d/m/Y", strtotime('+1 day', $dt_reg));
				$max_checkout_date = date("d/m/Y", strtotime('+28 day', $dt_reg));
				
			}
			if(isset($_SESSION['hotel_search']) && isset($_SESSION['hotel_search']['checkout']) && trim($_SESSION['hotel_search']['checkout']) != ""){
				$def_checkout = $_SESSION['hotel_search']['checkout'];
			}
			if(isset($_SESSION['hotel_search']['adults']) && intval($_SESSION['hotel_search']['adults']) >0){
				$def_adults = intval($_SESSION['hotel_search']['adults']);
			}
			?>
			
	
			<div class="booking-checkinout">
				<span class="bfldst bfirst blast">
					<label for="ck-dest">Resort Area</label>
					<select id="ck-dest" class="btext ck-dest" name="ck_dest">
						<option value="" selected="selected">All Cyprus</option>
						<optgroup label="Regions">
							<?php
							foreach ($book_regions as $i=>$region_data) {
								echo '<option value="r|', $region_data['id'], '">', $region_data['region_name'], '</option>';
							}
							?>
						</optgroup>
						<optgroup label="Areas">
							<?php
							foreach ($book_destinations as $i=>$city_data) {
								echo '<option value="c|', $city_data['ufi'], '">', $city_data['full_name'], '</option>';
							}
							?>
						</optgroup>
					</select>
				</span>
				<span class="bfldst bfirst blast">
					<label for="bcheckin">Check In</label>
					<input type="btext" id="bcheckin" value="<?php echo $def_checkin;?>" class="bsprite-calendar-ylw btext datepicker checkin" name="checkin"/>
				</span>
				<span class="bfldst blast chk-out cal ">
					<label for="bcheckout">Check Out</label>
					<input type="btext" id="bcheckout" value="<?php echo $def_checkout;?>" class="bsprite-calendar-ylw btext datepicker checkout" name="checkout"/>
				</span>
				<div style="float : left;" class="apart_form_other_container">
					<div style="float : left; margin-left : 0px;">
						<label class="small">Rooms</label>
						<select id="main_rooms" name="rooms">
							<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>
						</select>
					</div>
					<div style="float : left; margin-left : 10px;">
						<label class="small">Adults</label>
						<select id="main_adults" name="adults">
							<option value="1">1</option>
							<option selected="" 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>
						</select>
					</div>
					<div style="float : left; margin-left : 10px;">
						<label class="small">Children</label>
						<select id="main_children" name="children">
							<option value="0">0</option>
							<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>
		
						</select>
					</div>
				</div>
			
				<div class="baff_providers_container">
					<div class="baff-partner-button">
						<div class="bfind-hotels" rel="<?php echo $aff_code;?>">
							Search
						</div>
					</div>
				</div>
			</div>
			<div class="extra" id="hotel_form_rooms_infos_container">
				<table id="hotel_form_rooms_infos" border="0" cellpadding="0" cellspacing="0" width="100%">
					<thead>
						<tr>
							<th>&nbsp;</th>
							<th>Adults</th>
							<th>Children</th>
							<th class="childrenAge">Children Age <small>(0-17 years old)</small></th>
						</tr>
					</thead>
				</table>
			</div>
			
			<div style="clear: both;"></div>
		</form>
	</div>
</div>
<script type="text/javascript">
    var mindate_hotel_search_checkin = '<?php echo (isset($_SESSION['hotel_search']['checkin'])) ? $_SESSION['hotel_search']['checkin'] : date("d/m/Y", strtotime("+1 day"));?>';
    var min_checkout_date = '<?php echo (isset($_SESSION['hotel_search']['checkin'])) ? $min_checkout_date : date("d/m/Y", strtotime("+2 day"));?>';
    var max_checkout_date = '<?php echo (isset($_SESSION['hotel_search']['checkin'])) ? $max_checkout_date : date("d/m/Y", strtotime("+29 day"));?>';
</script>