<?php
/*
  $Id: advanced_search.php,v 1.8 2009/04/14 23:51:23 ryu Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
  
  modified for Koshoten.net2
  http://www.koshoten.net/
*/

  require('includes/application_top.php');

  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ADVANCED_SEARCH);

  $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_ADVANCED_SEARCH));
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>" /> 
<meta http-equiv="content-style-type" content="text/css" />
<title><?php echo TITLE; ?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>" />
<link rel="stylesheet" type="text/css" href="general.css" media="screen,print" />
<?php 
  $customCSS = substr(FILENAME_ADVANCED_SEARCH, 0, strrpos(FILENAME_ADVANCED_SEARCH, '.')). ".css";
  if (file_exists($customCSS)){
    echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$customCSS\" media=\"screen,print\" />";
  }
?>
<script language="javascript" src="includes/general.js"></script>
<script language="javascript"><!--
function check_form() {
  var error_message = "<?php echo JS_ERROR; ?>";
  var error_found = false;
  var error_field;
  var keywords = document.advanced_search.keywords.value;
  var dfrom = document.advanced_search.dfrom.value;
  var dto = document.advanced_search.dto.value;
  var pfrom = document.advanced_search.pfrom.value;
  var pto = document.advanced_search.pto.value;
  var pfrom_float;
  var pto_float;

  if ( ((keywords == '') || (keywords.length < 1)) && ((dfrom == '') || (dfrom == '<?php echo DOB_FORMAT_STRING; ?>') || (dfrom.length < 1)) && ((dto == '') || (dto == '<?php echo DOB_FORMAT_STRING; ?>') || (dto.length < 1)) && ((pfrom == '') || (pfrom.length < 1)) && ((pto == '') || (pto.length < 1)) ) {
    error_message = error_message + "<?php echo JS_AT_LEAST_ONE_INPUT; ?>";
    error_field = document.advanced_search.keywords;
    error_found = true;
  }

  if ((dfrom.length > 0) && (dfrom != '<?php echo DOB_FORMAT_STRING; ?>')) {
    if (!IsValidDate(dfrom, '<?php echo DOB_FORMAT_STRING; ?>')) {
      error_message = error_message + "<?php echo JS_INVALID_FROM_DATE; ?>";
      error_field = document.advanced_search.dfrom;
      error_found = true;
    }
  }

  if ((dto.length > 0) && (dto != '<?php echo DOB_FORMAT_STRING; ?>')) {
    if (!IsValidDate(dto, '<?php echo DOB_FORMAT_STRING; ?>')) {
      error_message = error_message + "<?php echo JS_INVALID_TO_DATE; ?>";
      error_field = document.advanced_search.dto;
      error_found = true;
    }
  }

  if ((dfrom.length > 0) && (dfrom != '<?php echo DOB_FORMAT_STRING; ?>') && (IsValidDate(dfrom, '<?php echo DOB_FORMAT_STRING; ?>')) && (dto.length > 0) && (dto != '<?php echo DOB_FORMAT_STRING; ?>') && (IsValidDate(dto, '<?php echo DOB_FORMAT_STRING; ?>'))) {
// if (!CheckDateRange(document.advanced_search.dfrom, document.advanced_search.dto)) {
    var df = dfrom.replace(/-/g,"/");
    var dt = dto.replace(/-/g,"/");
    if (Date.parse(df) > Date.parse(dt)) {
      error_message = error_message + "<?php echo JS_TO_DATE_LESS_THAN_FROM_DATE; ?>";
      error_field = document.advanced_search.dto;
      error_found = true;
    }
  }

  if (pfrom.length > 0) {
    pfrom_float = parseFloat(pfrom);
    if (isNaN(pfrom_float)) {
      error_message = error_message + "<?php echo JS_PRICE_FROM_MUST_BE_NUM; ?>";
      error_field = document.advanced_search.pfrom;
      error_found = true;
    }
  } else {
    pfrom_float = 0;
  }

  if (pto.length > 0) {
    pto_float = parseFloat(pto);
    if (isNaN(pto_float)) {
      error_message = error_message + "<?php echo JS_PRICE_TO_MUST_BE_NUM; ?>";
      error_field = document.advanced_search.pto;
      error_found = true;
    }
  } else {
    pto_float = 0;
  }

  if ( (pfrom.length > 0) && (pto.length > 0) ) {
    if ( (!isNaN(pfrom_float)) && (!isNaN(pto_float)) && (pto_float < pfrom_float) ) {
      error_message = error_message + "<?php echo JS_PRICE_TO_LESS_THAN_PRICE_FROM; ?>";
      error_field = document.advanced_search.pto;
      error_found = true;
    }
  }

  if (error_found == true) {
    alert(error_message);
    error_field.focus();
    return false;
  } else {
    RemoveFormatString(document.advanced_search.dfrom, "<?php echo DOB_FORMAT_STRING; ?>");
    RemoveFormatString(document.advanced_search.dto, "<?php echo DOB_FORMAT_STRING; ?>");
    return true;
  }
}

function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=280,screenX=150,screenY=150,top=150,left=150')
}
//--></script>
</head>
<body>
<div id="container">
<!-- header -->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- /header -->
<hr />
<!-- contents -->
<div id="contents">
<!-- left_contents -->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- /left_contents -->
<hr />
<!-- right_contents -->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- /right_contents -->
<hr />
<!-- main_contents -->
<div id="mainContents">
<p class="hide"><a id="skipped" name="skipped" title="<?php echo TEXT_NAVISKIPPED; ?>"><?php echo TEXT_NAVISKIPPED; ?></a></p> 
<h2 class="pageHeading"><?php echo HEADING_TITLE; ?></h2>
<div id="advancedSearch">
<div id="contentsBox">
<?php
  if ((KN_CFG_GETA_ENABLED == 'true') && (KN_CFG_GETA_SEARCH_ENABLED == 'true')) {
    $cssid = 'leftBox';
    $contentbox_header = BOX_HEADING_GETA_SEARCH;

    $contentbox_contents = array();
    $contentbox_contents[] = array('form' => tep_draw_form('geta_search', tep_href_link(FILENAME_GETA_SEARCH_RESULT, '', 'NONSSL', false)),
                                 'text' => '<p>' . BOX_GETA_SEARCH_TEXT2 . "</p>\n<p>" . tep_draw_textarea_field('search_text', 'soft', '', '12') . "</p>\n" . '<p class="buttonArea"><input type="submit" value="' . BOX_GETA_SEARCH_SUBMIT . '" /><input type="reset" value="' . BOX_GETA_SEARCH_RESET . '" />' . "</p>\n");


    $contentbox_footer = '<p><a href="http://geta.ex.nii.ac.jp/" target="_blank">' . tep_image(DIR_WS_IMAGES . 'geta.gif', TEXT_GETA_LOGO, '115' , '38', 'id="getaImage"') . '</a></p>';

    new contentBox($cssid, $contentbox_contents, $contentbox_header, $contentbox_footer);
  }

  $cssid = 'rightBox';
  $contentbox_header = HEADING_SEARCH_CRITERIA;
  
  $criteria_box = '';
  if (isset($_GET['errorno'])) {
    $criteria_box .= '<p class="infoLine"><span class="infoMessage">';
    if (($_GET['errorno'] & 1) == 1) {
      $criteria_box .= str_replace('\n', '<br />', JS_AT_LEAST_ONE_INPUT);
    }
    if (($_GET['errorno'] & 10) == 10) {
      $criteria_box .= str_replace('\n', '<br />', JS_INVALID_FROM_DATE);
    }
    if (($_GET['errorno'] & 100) == 100) {
      $criteria_box .= str_replace('\n', '<br />', JS_INVALID_TO_DATE);
    }
    if (($_GET['errorno'] & 1000) == 1000) {
      $criteria_box .= str_replace('\n', '<br />', JS_TO_DATE_LESS_THAN_FROM_DATE);
    }
    if (($_GET['errorno'] & 10000) == 10000) {
      $criteria_box .= str_replace('\n', '<br />', JS_PRICE_FROM_MUST_BE_NUM);
    }
    if (($_GET['errorno'] & 100000) == 100000) {
      $criteria_box .= str_replace('\n', '<br />', JS_PRICE_TO_MUST_BE_NUM);
    }
    if (($_GET['errorno'] & 1000000) == 1000000) {
      $criteria_box .= str_replace('\n', '<br />', JS_PRICE_TO_LESS_THAN_PRICE_FROM);
    }
    if (($_GET['errorno'] & 10000000) == 10000000) {
      $criteria_box .= str_replace('\n', '<br />', JS_INVALID_KEYWORDS);
    }
    $criteria_box .= "</span></p>\n";
  }
  $criteria_box .= '<table>' . "\n" .
                 '<tr>' . "\n" .
                 '<th>' . ENTRY_PRODUCTS_NAME . '</th>' . "\n" .
                 '<td>' . tep_draw_input_field('keywords_p_name', '', 'class="advancedSearchInput"') . '</td>' . "\n" .
                 '</tr>' . "\n";
  if ((KN_CFG_USE_SUBTITLE == 'true') && (KN_CFG_USE_SERIES_TITLE == 'true')) {
    $criteria_box .= '<tr>' . "\n" .
                 '<th>&nbsp;</th>' . "\n" .
                 '<td class="searchInSubtitle">' . tep_draw_checkbox_field('search_in_subtitle', '1') . "\n" . '<label for="subtitle">' . TEXT_SEARCH_IN_SUBTITLE_SERIES_TITLE . '</label></td>' . "\n" .
                 '</tr>' . "\n";
  } else {
    if (KN_CFG_USE_SUBTITLE == 'true') {
      $criteria_box .= '<tr>' . "\n" .
                 '<th>&nbsp;</th>' . "\n" .
                 '<td class="searchInSubtitle">' . tep_draw_checkbox_field('search_in_subtitle', '1') . "\n" . '<label for="subtitle">' . TEXT_SEARCH_IN_SUBTITLE . '</label></td>' . "\n" .
                 '</tr>' . "\n";
    }
    if (KN_CFG_USE_SERIES_TITLE == 'true') {
      $criteria_box .= '<tr>' . "\n" .
                 '<th>&nbsp;</th>' . "\n" .
                 '<td class="searchInSubtitle">' . tep_draw_checkbox_field('search_in_subtitle', '1') . "\n" . '<label for="subtitle">' . TEXT_SEARCH_IN_SERIES_TITLE . '</label></td>' . "\n" .
                 '</tr>' . "\n";
    }
  }
  if (KN_CFG_USE_AUTHOR == 'true') {
    $criteria_box .= '<tr>' . "\n" .
                 '<th>' . ENTRY_PRODUCTS_AUTHOR . '</th>' . "\n" .
                 '<td>' . tep_draw_input_field('keywords_p_author', '', 'class="advancedSearchInput"') . '</td>' . "\n" .
                 '</tr>' . "\n";
  }
  if (KN_CFG_USE_PUBLISHERS == 'true') {
    $criteria_box .= '<tr>' . "\n" .
                 '<th>' . ENTRY_PRODUCTS_PUBLISHERS . '</th>' . "\n" .
                 '<td>' . tep_draw_input_field('keywords_p_publishers', '', 'class="advancedSearchInput"') . '</td>' . "\n" .
                 '</tr>' . "\n";
  }
  if (KN_CFG_USE_ISBN == 'true') {
    $criteria_box .= '<tr>' . "\n" .
                 '<th>' . ENTRY_PRODUCTS_ISBN . '</th>' . "\n" .
                 '<td>' . tep_draw_input_field('keywords_p_isbn', '', 'class="advancedSearchInput"') . '</td>' . "\n" .
                 '</tr>' . "\n";
  }
  $criteria_box .= "</table>\n";
  $criteria_box .= '<div class="box">' . "\n" .
                 '<p class="leftBox"><a href="javascript:popupWindow(\'' . tep_href_link(FILENAME_POPUP_SEARCH_HELP) . '\')">' . TEXT_SEARCH_HELP_LINK . "</a></p>\n" .
                 '<p class="rightBox">' . tep_image_submit('button_search.gif', IMAGE_BUTTON_SEARCH) . "</p>\n" .
                 "</div>\n";
  $criteria_box .= '<table>' . "\n" .
                 '<tr>' . "\n" .
                 '<th>' . ENTRY_CATEGORIES . '</th>' . "\n" .
                 '<td>' . tep_draw_pull_down_menu('categories_id', tep_get_categories(array(array('id' => '', 'text' => TEXT_ALL_CATEGORIES))), '', 'class="advancedSearchInput"') . '</td>' . "\n" .
                 '</tr>' . "\n" .
                 '<tr>' . "\n" .
                 '<th>&nbsp;</th>' . "\n" .
                 '<td class="includeSubcategories">' . tep_draw_checkbox_field('inc_subcat', '1', true) . "\n" . '<label for="subtitle">' . ENTRY_INCLUDE_SUBCATEGORIES . '</label></td>' . "\n" .
                 '</tr>' . "\n";
  if (KN_CFG_USE_MANUFACTURERS) {
    $criteria_box .= '<tr>' . "\n" .
                 '<th>' . ENTRY_MANUFACTURERS . '</th>' . "\n" .
                 '<td>' . tep_draw_pull_down_menu('manufacturers_id', tep_get_manufacturers(array(array('id' => '', 'text' => TEXT_ALL_MANUFACTURERS))), '', 'class="advancedSearchInput"') . '</td>' . "\n" .
                 '</tr>' . "\n";
  }
  if (KN_CFG_USE_PRICE_SEARCH == 'true') {
    $criteria_box .= '<tr>' . "\n" .
                 '<th>' . ENTRY_PRICE_FROM . '</th>' . "\n" .
                 '<td>' . tep_draw_input_field('pfrom', '', 'class="advancedSearchInput"') . '</td>' . "\n" .
                 '</tr>' . "\n" .
                 '<tr>' . "\n" .
                 '<th>' . ENTRY_PRICE_TO . '</th>' . "\n" .
                 '<td>' . tep_draw_input_field('pto', '', 'class="advancedSearchInput"') . '</td>' . "\n" .
                 '</tr>' . "\n";
  }
  if (KN_CFG_USE_DATE_SEARCH == 'true') {
    $criteria_box .= '<tr>' . "\n" .
                 '<th>' . ENTRY_DATE_FROM . '</th>' . "\n" .
                 '<td>' . tep_draw_input_field('dfrom', DOB_FORMAT_STRING, 'class="advancedSearchInput" onFocus="RemoveFormatString(this, \'' . DOB_FORMAT_STRING . '\')"') . '</td>' . "\n" .
                 '</tr>' . "\n" .
                 '<tr>' . "\n" .
                 '<th>' . ENTRY_DATE_TO . '</th>' . "\n" .
                 '<td>' . tep_draw_input_field('dto', DOB_FORMAT_STRING, 'class="advancedSearchInput" onFocus="RemoveFormatString(this, \'' . DOB_FORMAT_STRING . '\')"') . '</td>' . "\n" .
                 '</tr>' . "\n";
  }
  $criteria_box .= '</table>';

  $contentbox_contents = array();
  $contentbox_contents[] = array('form' => tep_draw_form('advanced_search', tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT, '', 'NONSSL', false), 'get', 'onSubmit="return check_form(this);"') . tep_hide_session_id(),
                                             'text' => $criteria_box);

  new contentBox($cssid, $contentbox_contents, $contentbox_header);
?>
</div>
</div>
</div>
<!-- /main_contents -->
</div>
<!-- /contents -->
<hr />
<!-- footer -->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- /footer -->
</div>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
