<?php
  require('includes/application_top.php');
  require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ADVANCED_SEARCH);
  $breadcrumb->add(NAVBAR_TITLE_1, tep_href_link(FILENAME_ADVANCED_SEARCH));
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML <?php echo HTML_PARAMS; ?>>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=<?php echo CHARSET; ?>">
<BASE HREF="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<TITLE><?php echo TITLE; ?></TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="stylesheet.css">
<LINK REL="stylesheet" TYPE="text/css" HREF="style.css">
<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 tep_decode_html_entities(ERROR_AT_LEAST_ONE_INPUT); ?>\n";
    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 tep_decode_html_entities(ERROR_INVALID_FROM_DATE); ?>\n";
      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 tep_decode_html_entities(ERROR_INVALID_TO_DATE); ?>\n";
      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)) {
      error_message = error_message + "* <?php echo tep_decode_html_entities(ERROR_TO_DATE_LESS_THAN_FROM_DATE); ?>\n";
      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 tep_decode_html_entities(ERROR_PRICE_FROM_MUST_BE_NUM); ?>\n";
      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 tep_decode_html_entities(ERROR_PRICE_TO_MUST_BE_NUM); ?>\n";
      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 tep_decode_html_entities(ERROR_PRICE_TO_LESS_THAN_PRICE_FROM); ?>\n";
      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="pg">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<div id="bdmain"  class="layout">
<!-- body //-->
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
<div id="bdcenter">
<!-- body_text //-->
<?php echo tep_draw_form('advanced_search', tep_href_link(FILENAME_ADVANCED_SEARCH_RESULT, '', 'NONSSL', false), 'get', 'onSubmit="return check_form(this);"') . tep_hide_session_id(); ?>
 <p CLASS="pageHeading"><?php echo HEADING_TITLE_1; ?></p>

<?php
  if ($messageStack->size('search') > 0) 
 	echo $messageStack->output('search'); 
	?>
	<p style="width:100%;height:22px;text-align:left; text-indent:4px; background-color:#FCAC58; line-height:1.2" class="infoBoxHeading"><?=HEADING_SEARCH_CRITERIA?></p>
	
<?php
  $info_box_contents = array();
  $info_box_contents[] = array('text' => tep_draw_input_field('keywords', '', 'style="width: 100%"'));
  $info_box_contents[] = array('align' => 'right', 'text' => tep_draw_checkbox_field('search_in_description', '1') . ' ' . TEXT_SEARCH_IN_DESCRIPTION);
new infoBox($info_box_contents);
?>
<br>
<br>
<TABLE BORDER="0" WIDTH="100%" CELLSPACING="0" CELLPADDING="2">
          <TR>
            <TD CLASS="smallText"><?php echo '<a href="javascript:popupWindow(\'' . tep_href_link(FILENAME_POPUP_SEARCH_HELP) . '\')">' . TEXT_SEARCH_HELP_LINK . '</a>'; ?></TD>
            <TD CLASS="smallText" ALIGN="right"><?php echo tep_image_submit('button_search.gif', IMAGE_BUTTON_SEARCH); ?></TD>
          </TR>
        </TABLE><TABLE BORDER="0" WIDTH="100%" CELLSPACING="0" CELLPADDING="2">
              <TR>
                <TD CLASS="fieldKey"><?php echo ENTRY_CATEGORIES; ?></TD>
                <TD CLASS="fieldValue"><?php echo tep_draw_pull_down_menu('categories_id', tep_get_categories(array(array('id' => '', 'text' => TEXT_ALL_CATEGORIES)))); ?></TD>
              </TR>
              <TR>
                <TD CLASS="fieldKey">&nbsp;</TD>
                <TD CLASS="smallText"><?php echo tep_draw_checkbox_field('inc_subcat', '1', true) . ' ' . ENTRY_INCLUDE_SUBCATEGORIES; ?></TD>
              </TR>
              <TR>
                <TD COLSPAN="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></TD>
              </TR>
<!--
              <TR>
                <TD CLASS="fieldKey"><?php echo ENTRY_MANUFACTURERS; ?></TD>
                <TD CLASS="fieldValue"><?php echo tep_draw_pull_down_menu('manufacturers_id', tep_get_manufacturers(array(array('id' => '', 'text' => TEXT_ALL_MANUFACTURERS)))); ?></TD>
              </TR>
-->
              <TR>
                <TD COLSPAN="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></TD>
              </TR>
              <TR>
                <TD CLASS="fieldKey"><?php echo ENTRY_PRICE_FROM; ?></TD>
                <TD CLASS="fieldValue"><?php echo tep_draw_input_field('pfrom'); ?></TD>
              </TR>
              <TR>
                <TD CLASS="fieldKey"><?php echo ENTRY_PRICE_TO; ?></TD>
                <TD CLASS="fieldValue"><?php echo tep_draw_input_field('pto'); ?></TD>
              </TR>
              <TR>
                <TD COLSPAN="2"><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></TD>
              </TR>
              <TR>
                <TD CLASS="fieldKey"><?php echo ENTRY_DATE_FROM; ?></TD>
                <TD CLASS="fieldValue"><?php echo tep_draw_input_field('dfrom', DOB_FORMAT_STRING, 'onFocus="RemoveFormatString(this, \'' . DOB_FORMAT_STRING . '\')"'); ?></TD>
              </TR>
              <TR>
                <TD CLASS="fieldKey"><?php echo ENTRY_DATE_TO; ?></TD>
                <TD CLASS="fieldValue"><?php echo tep_draw_input_field('dto', DOB_FORMAT_STRING, 'onFocus="RemoveFormatString(this, \'' . DOB_FORMAT_STRING . '\')"'); ?></TD>
              </TR>
            </TABLE></form>
	</div>
<!-- body_text_eof //-->
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->

<!-- body_eof //-->
</div>
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</div>
</BODY>
</HTML>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
