<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  require_once "/home/luxurychartergroup/luxurychartergroup.com/cms/lib/viewer_functions.php";
 
 

  list($yachtsRecords, $yachtsMetaData) = getRecords(array(
    'tableName'   => 'yachts',
	'where'		  => 'active ="1"' . ' AND hide ="0"',
    'limit'       => '500',
	'allowSearch'	=> true,
	'useSeoUrls'	=> true,
  ));
  
 if(!@$_REQUEST['destinations']){
       $_REQUEST['destinations']=-1;
    }

   if(!@$_REQUEST['type']){
       $_REQUEST['type']=-1;
    }
  list($destinationsRecords, $destinationsMetaData) = getRecords(array(
    'tableName'   => 'destinations',
    'where'		  => "num=".intval(@$_REQUEST['destinations']),
    'limit'       => '1',
    'allowSearch' => false,

  ));
  $destinationsRecord = @$destinationsRecords[0]; // get first record
  
  list($yacht_typeRecords, $yacht_typeMetaData) = getRecords(array(
    'tableName'   => 'yacht_type',
    'where'       => "url ='".mysql_escape(@$_REQUEST['type'])."'",
    'limit'       => '1',
    'allowSearch' => false,

  ));
  $yacht_typeRecord = @$yacht_typeRecords[0]; // get first record
  
  list($settingsRecords, $settingsMetaData) = getRecords(array(
    'tableName'   => 'settings',
    'limit'       => '1',
	'allowSearch'	=> false,
  ));
  $settingsRecord = @$settingsRecords[0]; // get first record


  $banner = $settingsRecord['default_banner'][0];

  if($destinationsRecord['banner_image']){
     $banner=$destinationsRecord['banner_image'][0];
  }
  elseif($yacht_typeRecord['banner_image']){
     $banner=$yacht_typeRecord['banner_image'][0];
  }
  
 $resultsText="";

 if($destinationsRecord){
   $resultsText.=$destinationsRecord['name'];
   
   if($yacht_typeRecord){
     $resultsText.=" and ".$yacht_typeRecord['name_plural'];
   }
 }
 elseif($yacht_typeRecord){
     $resultsText.=$yacht_typeRecord['name_plural'];
   }
 elseif(@$_REQUEST['yacht_name_query']){
     $resultsText.=$_REQUEST['yacht_name_query'];
 }
?>
			
<?php function cutText($string, $setlength) {
$length = $setlength;
if($length<strlen($string)){
while (($string{$length} != " ") AND ($length > 0)) {
$length--;}
if ($length == 0) return substr($string, 0, $setlength);
else return substr($string, 0, $length);}
else return $string; }
?>		
<? include("library/inc/headers.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search Results for <?php echo $resultsText;?> - <?php echo $settingsRecord['title'] ?></title>
<meta name="robots" content="noindex" />
<meta name="description" content="luxury yacht charter search results" />
<link href="/library/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/library/js/scripts.js"></script>
<? include("library/inc/head.php"); ?>
</head>
<body>
<div class="wrapper">
	
	<div class="navbar">
		<? include("library/inc/navbar.php"); ?>
	</div>
	<div class="topbar">
		<div class="banner">
            <img src="<?php echo $banner['urlPath'];?>" height="220" width="649" alt="" />    
			
		</div>
		<div class="logo"><img src="/library/img/logo.png" alt="<?php echo $settingsRecord['title'] ?>" width="300" height="220" /></div>
	</div>
	<div class="content">
		<div class="maincol">
			<h1>Search Results</h1>
            <p>You searched for <b><?php echo $resultsText;?></b></p>
			
				<?php foreach ($yachtsRecords as $record): ?>
                    <table class="searchItem">
                        <tr>
                            <td style="width: 196px;">
                                <a href="/<?php echo strtolower($record['_link']); ?>">
                                <?php foreach ($record['banner_image'] as $upload): ?>
									<?php if ($upload['hasThumbnail']): ?>
                                    <img src="<?php echo $upload['thumbUrlPath'] ?>" width="186" alt="Yacht <?php echo $record['yacht_name'] ?>" />
                                    <?php endif ?>
                                <?php endforeach ?>
                                <?php if (!$record['list_image']): ?>  
                                    <img src="/library/img/default-yacht-thumbnail.jpg" width="186" height="127" alt="Yacht <?php echo $record['yacht_name'] ?>" /><br/>
                                <?php endif ?>
                                </a>
                            </td>
                            <td style="padding-right: 10px;">
                                <p class="title"><a href="/<?php echo strtolower($record['_link']); ?>"><?php echo $record['yacht_name'] ?></a></p>
                                <p class="desc"><?php echo cutText($record['intro'], 150); ?>...</p>
                            </td>
                            <td class="specs">
                            	<p class="length">Length: <?php echo $record['yacht_length'] ?>m, <?php echo round($record['yacht_length'] * 3.2808399); ?>'</p>
                                <p class="guests">Guests: <?php echo $record['guests_night'] ?></p>
                                
								<?php if ($record['rate_low_season'] or $record['rate_high_season']): ?>
                                    <p class="guests">Rate: 
                                        <?php if ($record['rate_low_season'] && $record['rate_low_season'] != $record['rate_high_season']): ?>
                                        
                                            <?php if ($record['rate_currency'] == 'nz'): ?>NZ$<?php elseif ($record['rate_currency'] == 'euro'): ?>&euro;<?php elseif ($record['rate_currency'] == 'au'): ?>AU$<?php else: ?>US$<?php endif ?><?php echo $record['rate_low_season'] ?>
                                        
                                        <?php endif ?>
                                        
                                        <?php if ($record['rate_low_season'] && $record['rate_high_season'] && $record['rate_low_season'] != $record['rate_high_season']): ?> - <?php endif ?>
                                        
                                        <?php if ($record['rate_high_season']): ?>
                                            <?php if ($record['rate_currency'] == 'nz'): ?>NZ$<?php elseif ($record['rate_currency'] == 'euro'): ?>&euro;<?php elseif ($record['rate_currency'] == 'au'): ?>AU$<?php else: ?>US$<?php endif ?><?php echo $record['rate_high_season'] ?>
                                        <?php endif ?>
                                    pw</p>             
                                <?php endif ?>
                                
                                
                                <?php 
                                $values = getListValues('yachts','destinations',$record['destinations']); 
                                $labels = getListLabels('yachts','destinations',$record['destinations']); 
                                $valuesToLabels = array_combine($values, $labels); 
                                ?>
                                <p class="destinations">Destinations: 
                                <?php $count2=0; ?> 
                                <?php foreach ($valuesToLabels as $value => $label): ?><?php echo ($count2==0)? "" : ", " ?><a href="/destination.php/<?php echo  str_replace(" ","-",strtolower($label."-".$value)); ?>/"><?php echo htmlspecialchars($label); ?></a><?php $count2++;?><?php endforeach ?></p>
                                
                            </td>
                        </tr>
                    </table>
				<?php endforeach ?>

			
            	<?php if (!$yachtsRecords): ?>
				<p>No records were found!</p>
				<?php endif ?>
				<div class="clear"></div>
</div>
		<div class="sidecol">
			<? include("library/inc/searchbox.php"); ?>
			<? include("library/inc/usp.php"); ?>
			<div class="enquire">
				<h2>enquire about a yacht charter</h2>
				<? include("library/inc/enquiry_general.php"); ?>
			</div>
		</div>
		<div class="clear"></div>
	</div>
	<div class="footer">
		<? include("library/inc/footer.php"); ?>
	</div>
	<div class="copyright">
		<? include("library/inc/copyright.php"); ?>
	</div>
</div>
</body>
</html>
