<?php
  /**
   * Search
   *
   * @package Digital Downloads Pro
   * @author wojoscripts.com
   * @copyright 2010
   * @version $Id: search.php, v2.00 2011-07-10 10:12:05 gewa Exp $
   */
  define("_VALID_PHP", true);
  require_once("../init.php");
?>
<?php
  if (isset($_POST['liveSearch']))
      : $string = sanitize($_POST['liveSearch'],20,false);
  
  if (strlen($string) > 3)
      : $sql = $db->query("SELECT id, title, slug" 
	  . " \n FROM products WHERE MATCH (title, description) AGAINST ('" . $db->escape($string) . "*' IN BOOLEAN MODE)"
	  . " \n ORDER BY id LIMIT 10");
  $display = '';	  
  $display .= '<div id="searchresults">';
  $i = 0;
  while ($row = $db->fetch($sql)): 
  $i++;
  
  if ($core->seo == 1) :
	$link = $core->site_url . '/view-item/' . intval($row['id']) . '/' . $row['slug'] . '.html';
  else:
	$link = $core->site_url . '/item.php?pid=' . intval($row['id']);
  endif;
  
  $title = $row['title'];
  if (strlen($title) > 65)
      $title = sanitize($title,50);
  $display .= '<div><a href="'.$link.'">'.$i.'. '.$title.'</a></div>';
  endwhile;
  $display .= '</div>';
  print $display;
  endif;
  endif;
?>