<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */
  require_once "init.php";
  
    $orderby = "CAST(price AS UNSIGNED)"; // default
if(@$_REQUEST['orderby'] == 'price DESC') {
    $orderby = "CAST(price AS UNSIGNED) DESC";
}

    list($listingRecords, $listingMetaData) = getRecords(array(
    'tableName'   => 'listings',
    'joinTable'   => 'homepages',
    'perPage'     => '10',
	'orderBy'     => $orderby,
/*	'orderBy'     => 'price+0', */
/*	'orderBy'     => 'CAST(price AS UNSIGNED)' */
  ));
  
    $orderby = "CAST(price AS UNSIGNED)"; // default
if(@$_REQUEST['orderby'] == 'price DESC') {
    $orderby = "CAST(price AS UNSIGNED) DESC";
}
  
  list($listingRecords, $listingDetails) = getRecords(array(
    'tableName'   => 'listings',
    'joinTable'   => 'homepages',
    'perPage'     => '10',
	'orderBy'     => $orderby,
/*	'orderBy'     => 'price+0', */
/*	'orderBy'     => 'CAST(price AS UNSIGNED)'*/
  ));

?>
<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->  
<!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->  
<!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->  
<head>
    <title>Javea Home Finders - Search Results</title>

    <!-- Meta -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Favicon -->
    <link rel="shortcut icon" href="favicon.ico">

    <!-- CSS Global Compulsory -->
    <link rel="stylesheet" href="../assets/plugins/bootstrap/css/bootstrap.css">
    <link href="../assets/plugins/bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="../assets/css/style.css">

    <!-- CSS Implementing Plugins -->
    <link rel="stylesheet" href="../assets/plugins/line-icons/line-icons.css">
    <link rel="stylesheet" href="../assets/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../assets/plugins/sky-forms/version-2.0.1/css/custom-sky-forms.css">
    <link rel="stylesheet" href="../assets/plugins/image-hover/css/img-hover2.css">

    <!-- CSS Page Style -->    
    <link rel="stylesheet" href="../assets/css/pages/page_search_inner.css">

    <!-- CSS Theme -->    
    <link rel="stylesheet" href="../assets/css/themes/blue.css" id="style_color">

    <!-- CSS Customization -->
    <link rel="stylesheet" href="../assets/css/custom.css">
    
    <!-- CSS Ribbon Wrap -->
	<link href="../assets/css/wrap-ribbon.css" rel="stylesheet" type="text/css">
</head> 

<body>  

<div class="wrapper">  
     <!--=== Header ===-->    
    <div class="header header-v1">
    <!-- Topbar -->
        <div class="topbar">
            <div class="container">
                <!-- Topbar Navigation -->
                <ul class="loginbar pull-right">
                    <li><img src="../assets/img/flags/United-Kingdom.png"></li>
                    <li><img src="../assets/img/flags/France.png"></li>
                    <li><img src="../assets/img/flags/Spain.png"></li>
                    <li><img src="../assets/img/flags/Germany.png"></li>
                    <li><img src="../assets/img/flags/Netherlands.png"></li>  
                </ul>
                <!-- End Topbar Navigation -->
            </div>
        </div>
        <!-- End Topbar -->
    <!--=== jhfbanners ===-->
    <div class="jhfbanners">
        <div class="container">
              <h2 class="pull-left"><div class="jhflogo"><a href="index.html"><img class="img-responsive" src="../assets/img/logo.png"></a></div></h1>
            <ul class="pull-right jhfbanner">
              <li class="hid">Contact Us Today!</li>
                <li><a href="tel:0034966470133">Tel: (+34) 966 470 133</a></li>
                <li><a href="tel:0034600235942">Mob: (+34) 600 235 942</a></li>
            </ul>
        </div>
    </div><!--/breadcrumbs-->
    <!--=== End jhfbanners ===-->
    
        <!-- Navbar -->
        <div class="navbar navbar-default" role="navigation">
            <div class="container">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
                        <span class="sr-only">Toggle navigation</span>
                        <span class="fa fa-bars"></span>
                    </button>
                   <a class="navbar-brand" href="index.html">
                      <h2><i class="fa fa-home"></i></h2>
                    </a>
                </div>

                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse navbar-responsive-collapse">
                  <ul class="nav navbar-nav">
                        <!-- Home -->
                        <li class="active"><a href="index.html">Home</a></li>
                         <li><a href="#">Javea Properties</a></li>
                         <li><a href="#">Buying Your Home</a></li>
                          <li><a href="#">About Javea</a></li>
                         <li><a href="#">Sign Up</a></li>
                         <li><a href="#">Links</a></li>
                         <li><a href="#">Contact Us</a></li>
                         </ul>
                </div><!--/navbar-collapse-->
            </div>    
        </div>            
        <!-- End Navbar -->
    </div>
    <!--=== End Header ===-->   

    <!--=== Breadcrumbs v3 ===-->
    <div class="breadcrumbs-v3">
        <div class="container">
            <h1 class="pull-left">Search Results</h1>
            <ul class="pull-right breadcrumb">
                <li><a href="index.html">Home</a></li>
                <li class="active">Search results</li>
            </ul>
        </div>
    </div>
    <!--=== End Breadcrumbs v3 ===-->
    

    <!--=== Search Results ===-->
    <div class="container s-results margin-bottom-50">
        <div class="row">
            <div class="col-md-3">
                <!-- About Us -->
                <div class="margin-bottom-30">
                
    <!-- Property Search start here -->
		<?php include("../includes/property_search.php"); ?>
	<!-- Property Search end here -->

                   <div class="cleaner"></div>
<form action="" class="sky-form">
            <header><i class="fa fa-envelope"></i> E-Mail Alerts</header>
                    
                    <fieldset>
                    <section>
                            <label class="label"> <h3><span class="color-green">Sign up for our
free email alert</span></h3></label>
                      </section>
                     <section>
                            <label class="label">E-Mail</label>
                            <label class="input">
                                <input type="text">
                            </label>
                      </section>
                      <section>
                            <label class="label">Name</label>
                            <label class="input">
                                <input type="text">
                            </label>
                        </section>  
                        <section>
                        <button type="submit" class="btn-u">Sign up</button>
                        </section> 
                    </fieldset>
                  </form>
                </div>            
            
              
<div class="job-partners jpvis">
<div class="headline"><h3>Our Partners</h3></div>
        <ul class=" list-unstyled our-clients" id="effect-2">
            <li>
                <figure> <a href="http://www.aipp.org.uk/members/javea-home-finders/" target="_blank"><img src="../assets/img/logos/aipp.png" alt=""></a>
                    <div class="img-hover">
                      <h4><a href="http://www.aipp.org.uk/members/javea-home-finders/" target="_blank">More Info</a></h4>
                    </div>
                </figure>
            </li>    
            <li>
                <figure> <a href="#"><img src="../assets/img/logos/safe_purchase.png" alt=""></a>
                    <div class="img-hover">
                      <h4><a href="#">More Info</a></h4> 
                  </div>
                </figure>
            </li>    
            <li>
                <figure> <a href="http://web.mortgagedirectsl.com" target="_blank"><img src="../assets/img/logos/morgage_direct.png" alt=""></a>  
                    <div class="img-hover">
                      <h4><a href="http://web.mortgagedirectsl.com" target="_blank">More Info</a></h4>  
                    </div>
                </figure>
            </li>    
            <li>
                <figure> <a href="http://www.currenciesdirect.com" target="_blank"><img src="../assets/img/logos/currencies_direct.png" alt=""></a>  
                    <div class="img-hover">
                      <h4><a href="http://www.currenciesdirect.com" target="_blank">More Info</a></h4>
                    </div>
                </figure>
            </li>    
                
        </ul>
    </div><!--/container--> 
    <!--=== End Job Partners ===-->
            	
            </div>

            <div class="col-md-9">
            <div class="col-md-6 restit">
            <h4><span class="results-number"><?php echo $listingMetaData['totalRecords']; ?> Properties Found</span></h4>
            </div>
             <div class="col-md-6 respp">
             
              <!--=== debug script to see what is being submitted ===-->
             
      <!--       Town: <?php echo @$_REQUEST['town'];?></br>
             Property Type: <?php echo @$_REQUEST['property_type'];?></br>
             Min beds: <?php echo @$_REQUEST['bedrooms_min'];?></br>
             Price min: <?php echo @$_REQUEST['price_min'];?></br>
             Price max: <?php echo @$_REQUEST['price_max'];?></br>
             Ref No: <?php echo @$_REQUEST['reference_number_keyword'];?></br> -->
             Sort Order Price: <?php echo @$_REQUEST['orderBy'];?></br></br>
            <!-- Results Per Page: <?php echo @$_REQUEST['perPage'];?></br> -->
             
             <!--=== END debug script to see what is being submitted ===-->
             
			<form method="get" class="sky-form sky-formnb" action="http://37.220.93.134/~javeahom/property/listings.php">                   
				<input type = "hidden" name = "town" value = "<?php echo @$_REQUEST['town'];?>" /> 
                <input type = "hidden" name = "property_type" value = "<?php echo @$_REQUEST['property_type'];?>" /> 
                <input type = "hidden" name = "bedrooms_min" value = "<?php echo @$_REQUEST['bedrooms_min'];?>" />                        
				<input type = "hidden" name = "price_min" value = "<?php echo @$_REQUEST['price_min'];?>" />                        
				<input type = "hidden" name = "price_max" value = "<?php echo @$_REQUEST['price_max'] ?>" />                        
				<input type = "hidden" name = "reference_number_keyword" value = "<?php echo @$_REQUEST['reference_number_keyword'];?>" />
           <!-- <input type = "hidden" name = "orderBy" value = "<?php echo @$_REQUEST['orderBy'] ?>" /> -->
                      <div class="row">
                            <section class="col col-6"></section>
                            <section class="col col-6">
                            <label class="select">
                                <select name = "orderBy"  onchange="this.form.submit();">
                                	<option value = "price">Price Order</option>
                                    <option value = "price">Price: Low to High</option>
									<option value = "price DESC">Price: High to Low</option>
								</select>
                            </label>
                            </section>
               <!--               <section class="col col-6">
                           <label class="select">
                                <select name = "perPage">
                                    <option value="10">Results per page</option>	
									<option value="10">10</option>	
									<option value="25">25</option>	
									<option value="50">50</option>	
									<option value="">All</option>	
                      			</select>
                            </label>
                            </section>  -->
                        </div>
                   </form>
            </div>
               
                  <!-- Begin Inner Results -->
                  
   <?php foreach ($listingRecords as $listing): ?>
                
                <div class="inner-results">
                  <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 proptit"><h3><a href="<?php echo $listing['_link'] ?>"><?php echo $listing['property_type'] ?> for sale in <?php echo $listing['town'] ?></a></h3></div>
                  <div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 propprice"><h3><?php echo number_format($listing['price']) ?> &euro; | <a href="<?php echo $listing['_link'] ?>" class="title">Ref: <?php echo $listing['reference_number'] ?></a></h3></div>
                  <div class="cleaner1"></div>
<ul class="list-inline up-ul">
            <li><?php echo $listing['bedrooms'] ?> Beds </li>
                        <li class="reslst-spc">|</li>
                        <li><?php echo $listing['bathrooms'] ?> Baths</li>
                        <li class="reslst-spc">|</li>
                        <li><?php echo $listing['build_size'] ?>m² Build</li>
                      <li class="reslst-spc">|</li>
                        <li><?php echo $listing['plot_size'] ?>m² Plot</li>
                  </ul>
                  <div class="overflow-h">
                    <div class="easy-block-v1">
                    <?php
						if($listing['banner_status'] != "" ){  // Banner Not Blank - Starts
   						echo "<div class=\"easy-block-v1-badge rgba-red\">";
   						echo $listing['banner_status'];
   						echo "</div>";
   						}  // Banner Not Blank - Ends
					?>

						<?php foreach ($listing['uploads'] as $upload): ?>
        					<?php if ($upload['hasThumbnail']): ?>
							<a href="<?php echo $listing['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" border="0" alt="<?php echo $upload['info1'] ?>" /></a>
          					<?php break /* only show one image */ ?>
        					<?php endif; ?>
      					<?php endforeach ?>

      					<?php if (!$listing['uploads']): /* if no uploads show this: */ ?>
     					<img src="../assets/img/photo_not_available_sm.png" alt="Photo Not Available">
     					<?php endif; ?>

                        </div>
                        <div class="overflow-a">
                          <p><?php echo $listing['summary'] ?></p>
                          <div class="cleaner1"></div>
                           <a class="btn-u btn-u-sm" href="<?php echo $listing['_link'] ?>">More Info</a>
                      </div>       
                    </div>     
              </div>
               <div class="cleaner1"></div>
                              <hr>
              
                  <?php endforeach ?> 
                  
  <!-- show errors -->
  <?php if ($listingDetails['invalidPageNum']): ?>
      Results page '<?php echo $listingDetails['page']?>' not found, <a href="<?php echo $listingDetails['firstPageLink'] ?>">start over &gt;&gt;</a><br/><br/>
  <?php elseif (!$listingRecords): ?>
      <h3>Sorry, no listings were found! </h3>
    <p>Please try searching again or <a href="../contact-javea-home-finders-costa-blanca.php">contact us</a> for more help.<br/><br/>
      <?php endif ?>
      <!-- /show errors -->

                <!-- Begin Inner Results -->

                <div class="margin-bottom-30"></div>
                
                <div align="center"><br /><ul class="pagination">
<li>
                    <?php $maxLinks = 7;  ?>
                    <?php  // prev
				    if ($listingMetaData['prevPage']) : ?>
                    <a href="<?php echo $listingMetaData['firstPageLink']; ?>" title=''>First</a>&nbsp; <a href="<?php echo $listingMetaData['prevPageLink']; ?>" title=''>«</a>&nbsp;
                    <?php endif; ?>
                    <?php  // get range of page numbers
				  $selectedPage = $listingMetaData['page'];
				  $minPageNum   = $selectedPage;
				  $maxPageNum   = $selectedPage;
				  while ($maxLinks > 1) {
					$match = false;
					if ($maxPageNum < $listingMetaData['totalPages'] && --$maxLinks) { $maxPageNum++; $match = true; }
					if ($minPageNum > 1 && --$maxLinks)                              { $minPageNum--; $match = true; }
					if (!$match) { break; }
				  }
				 ?>
                    <?php  // display page number links
				  foreach (range($minPageNum, $maxPageNum) as $pageNum) :
				  
					$isSelected = ($pageNum == $selectedPage);
					$pageLink   = thisPageUrl(array('page' => $pageNum));
					$pageLink   = str_replace('&', '&amp;', $pageLink);
				 ?>
                    <?php if ($isSelected): ?>
                    <a href="<?php echo $pageLink; ?>"><span class="active_pagination"><?php echo $pageNum; ?></span></a>
                    <?php else : ?>
                    <a href="<?php echo $pageLink; ?>"><?php echo $pageNum; ?></a>
                    <?php endif; ?>
                    <?php endforeach; ?>
                    <?php  // next
				  	if ($listingMetaData['nextPage']) : ?>
                    <a href="<?php echo $listingMetaData['nextPageLink']; ?>">»</a>&nbsp; <a href="<?php echo $listingMetaData['lastPageLink']; ?>">Last</a>
            <?php endif; ?></li></ul>
                  </p>
                  <p>&nbsp;</p>
              </div>

                
          </div><!--/col-md-9-->
        </div>        
    </div><!--/container-->     
    <!--=== End Search Results ===-->
<!--=== Job Partners ===-->
    <div class="container content job-partners jphid">
        <div class="headline"><h3>Our Partners</h3></div>

        <ul class="list-inline our-clients" id="effect-2">
            <li>
                <figure> <a href="http://www.aipp.org.uk/members/javea-home-finders/" target="_blank"><img src="../assets/img/logos/aipp.png" alt=""></a>
                    <div class="img-hover">
                      <h4><a href="http://www.aipp.org.uk/members/javea-home-finders/" target="_blank">More Info</a></h4>
                    </div>
                </figure>
            </li>    
            <li>
                <figure> <a href="#"><img src="../assets/img/logos/safe_purchase.png" alt=""></a>
                    <div class="img-hover">
                      <h4><a href="#">More Info</a></h4> 
                  </div>
                </figure>
            </li>    
            <li>
                <figure> <a href="http://web.mortgagedirectsl.com" target="_blank"><img src="../assets/img/logos/morgage_direct.png" alt=""></a>  
                    <div class="img-hover">
                      <h4><a href="http://web.mortgagedirectsl.com" target="_blank">More Info</a></h4>  
                    </div>
                </figure>
            </li>    
            <li>
                <figure> <a href="http://www.currenciesdirect.com" target="_blank"><img src="../assets/img/logos/currencies_direct.png" alt=""></a>  
                    <div class="img-hover">
                      <h4><a href="http://www.currenciesdirect.com" target="_blank">More Info</a></h4>
                    </div>
                </figure>
            </li>    
                
        </ul>
    </div><!--/container--> 
    <!--=== End Job Partners ===-->
    <!--=== Footer ===-->
    <div class="footer">
        <div class="container">
            <div class="row">
                <div class="col-md-4 md-margin-bottom-40">
                    <!-- About -->
                    <div class="headline"><h2>Latest News</h2></div>  
                    <p class="margin-bottom-25 md-margin-bottom-40">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse eget velit massa. Vestibulum et enim a nisl tincidunt commodo rhoncus non sem....<br>
                      <a href="#">Read More</a>    
                    <!-- End About -->

                    <!-- Monthly Newsletter -->                    </p>
                  <div class="headline"><h2>Monthly Newsletter</h2></div> 
                    <p>Subscribe to our newsletter and stay up to date with the latest news and deals!</p>
                    <form class="footer-subsribe">
                        <div class="input-group">
                            <input type="text" class="form-control" placeholder="Email Address">                            
                            <span class="input-group-btn">
                                <button class="btn-u" type="button">Subscribe</button>
                            </span>
                        </div>                  
                    </form>                         
                    <!-- End Monthly Newsletter -->
                </div><!--/col-md-4-->  
                
                <div class="col-md-4 md-margin-bottom-40">
                    <!-- Recent Blogs -->
                    <div class="posts">
                        <div class="headline"><h2>Quick Navigation</h2></div>
                        <ul class="nav nav-pills nav-stacked"> 
                            <li class="active"><a href="#">Homepage</a></li>
                            <li><a href="#">Javea Properties</a></li>
                            <li><a href="#">Buying Your Home</a></li>
                            <li><a href="#">About Javea</a></li>
                            <li><a href="#">Contact us</a></li>
                            <li><a href="#">Useful Links</a></li>
                        </ul> 
                    </div>
                    <!-- End Recent Blogs -->                    
                </div><!--/col-md-4-->

                <div class="col-md-4">
                    <!-- Contact Us -->
                    <div class="headline"><h2>Contact Us</h2></div> 
                    <address class="md-margin-bottom-40">
                        Javea Home Finders<br>
                    Avda Libertad 19<br>
                    Javea 03730<br>
                    Alicante Spain<br>
                    Telephone: <a href="#">0034 966 470 133</a><br>
                    Mobile: <a href="#">0034 600 235 942</a><br>
                    Fax: <a href="#">0034 966 468 323</a><br>
                    UK Low Cost: <a href="#">0844 0823 8100</a><br>
                    Email: <a href="mailto:info@javeahomefinders.com" class="">info@javeahomefinders.com</a>
                    </address>
                    <!-- End Contact Us -->

                    <!-- Social Links -->
                    <div class="headline"><h2>Stay Connected</h2></div> 
                    <ul class="social-icons">
                        <li><a href="#" data-original-title="Feed" class="social_rss"></a></li>
                        <li><a href="#" data-original-title="Facebook" class="social_facebook"></a></li>
                        <li><a href="#" data-original-title="Twitter" class="social_twitter"></a></li>
                        <li><a href="#" data-original-title="Goole Plus" class="social_googleplus"></a></li>
                        <li><a href="#" data-original-title="Pinterest" class="social_pintrest"></a></li>
                        <li><a href="#" data-original-title="Linkedin" class="social_linkedin"></a></li>
                        <li><a href="#" data-original-title="Vimeo" class="social_vimeo"></a></li>
                    </ul>
                    <!-- End Social Links -->
                </div><!--/col-md-4-->
            </div>
        </div> 
    </div><!--/footer-->
    <!--=== End Footer ===-->

    <!--=== Copyright ===-->
    <div class="copyright">
        <div class="container">
            <div class="row">
                <div class="col-md-6">                     
                    <p>
                        2014 &copy; ALL Rights Reserved. 
                        <a href="#">Site Map</a> | <a href="#">Terms of Service</a>
                    </p>
                </div>
                <div class="col-md-6">  
                    
                </div>
            </div>
        </div> 
    </div><!--/copyright--> 
    <!--=== End Copyright ===-->
</div><!--/End Wrapepr-->

<!-- JS Global Compulsory -->           
<script type="text/javascript" src="../assets/plugins/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="../assets/plugins/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="../assets/plugins/bootstrap/js/bootstrap.min.js"></script> 
<!-- JS Implementing Plugins -->
<script type="text/javascript" src="../assets/plugins/back-to-top.js"></script>
<!-- JS Page Level -->           
<script type="text/javascript" src="../assets/js/app.js"></script>
<script type="text/javascript" src="../assets/js/retina.js"></script>
<script type="text/javascript" src="../assets/plugins/image-hover/js/modernizr.js"></script>
<script type="text/javascript" src="../assets/plugins/image-hover/js/touch.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function() {
        App.init();
    });
</script>
<!--[if lt IE 9]>
    <script src="../assets/plugins/respond.js"></script>
<![endif]-->

</body>
</html> 