<?php
/**
  @licence GPL 2005-2011  The osCSS developers - osCSS Open Source E-commerce
  @portion code Copyright (c) 2002 osCommerce
  @package osCSS-2 <www http://www.oscss.org>
  @version 2.1.0
  @date  27/01/11, 15:00
  @author oscim <mail aurelien@oscim.fr> <www http://www.oscim.fr>
  @encode UTF-8
 *\file search_suggest.php
 *\brief box input search, and return ajax list product
 *
 *		Cette boite affiche un champs de recherche et affiche une liste de resutat via ajax
 *		Le javascript est contenu dans la boite , et chargé a travers le constructeur page_javascript
*/
  global $page;

  $s='';
  $s.='<script type="text/javascript"><!--//'."\n";
  $s.='function searchSuggest() {'."\n";
    $s.='keySend = document.getElementById(\'quick_find\').keywords.value;'."\n";
    $s.='divOutput = document.getElementById(\'search_suggest\');'."\n";
    $s.='divOutput.innerHTML = \'\';'."\n";
    $s.='divOutput.style.visibility="hidden";'."\n";
    $s.='if ( keySend.length > 1 ) {'."\n";
        $s.='if ( text = file(\''.tep_href_link('ajax_exe.php', 'action=search_suggest').'&'.'search=\'+escape(keySend)) ) {'."\n";
            $s.='divOutput.style.visibility="visible";'."\n";
            $s.='searchResult = text.split("\n");'."\n";
            $s.='suggest = \'<ul>\';'."\n";

            $s.='for(i=0; i < searchResult.length-1; i++) {'."\n";
              $s.=' suggest += \'<li onmouseover="javascript:suggestOver(this);" onmouseout="javascript:suggestOut(this);" \';'."\n";
              $s.=' suggest += \'onclick="javascript:setSearch(this.innerHTML);" class="suggest_link">\' + searchResult[i] + \'</li>\';'."\n";
            $s.='}'."\n";
            $s.='suggest += \'</ul>\';'."\n";
            $s.='divOutput.innerHTML = suggest;'."\n";
      $s.=' }'."\n";
    $s.='}'."\n";
  $s.='}'."\n";

  //Mouse over function
  $s.='function suggestOver(div_value) {'."\n";
    $s.='div_value.className = \'suggest_link_over\';'."\n";
  $s.='}'."\n";
  //Mouse out function
  $s.='function suggestOut(div_value) {'."\n";
    $s.='div_value.className = \'suggest_link\';'."\n";
  $s.='}'."\n";
  //Click function
  $s.='function setSearch(selectedValue) {'."\n";
    $s.='document.getElementById(\'quick_find\').keywords.value = selectedValue;'."\n";
    $s.='document.getElementById(\'search_suggest\').innerHTML = \'\';'."\n";
    $s.='document.getElementById(\'search_suggest\').style.visibility="hidden";'."\n";
  $s.='}'."\n";
  $s.='//--></script>'."\n";

  $page->javascript->add_script_src(array('file'=>'search_suggest','script'=>tep_output_string_protected($s,false,true)) );

  $array= array('title'=>__('box heading search'),'content'=>tep_output_string_protected(tep_get_include_contents('box.search_suggest'),false,true));
?>