/*
 (c)1999-2000 Open Objects Software
 Search scripts

 There are 2 types of search pages:
 1.Search Index Pages - these are the pages that the users first see when they hit a 'search' hyperlink etc.  They 
   only contain a search form.
 2.Search Results Pages - these are the pages that the users see after they've entered a search from a Search Index 
   page.  They contain both a search form, as well as navigation bars for sorting the results, hiding summaries, 
   going to the next results page etc.
 */



/*---------------------------------------------------
 * Search Index pages
 * 
 * For the 'Site' style
 ---------------------------------------------------*/


function writeSearchForm(setParametersFnName, doc){
  doc.writeln("<SCRIPT language='JavaScript'>var thisDoc = this.document;</SCRIPT>");
  doc.writeln("<DIV class='webromForm'>");
  doc.writeln("<form name='simpleform' onSubmit='"
             + setParametersFnName 
             + "(thisDoc); top.performSearch();return false;'>");
  doc.writeln("<TABLE WIDTH='100%'cellspacing='0' border='0'>");
  doc.writeln("<TR class='abslogo'><TD colspan='4'><div class='abslogo'><IMG border='0' src='abslogo.gif' align='left'></TD></div></TR>");
  doc.writeln("<TR class='title'><TD WIDTH='11%'> &nbsp; <MAP NAME='nF5E.$Body.0.1DE4'> <AREA SHAPE='rect' COORDS='1,0,36,32' ID='HotspotRectangle13_1_1' HREF='../index.html' ALT='CD Home Page'></MAP> <IMG SRC='home.gif' WIDTH=36 HEIGHT=32 ALT='CD Home Page' USEMAP='#nF5E.$Body.0.1DE4' BORDER=0></TD> <TD WIDTH='12%'><MAP NAME='nF5E.$Body.0.2272'> <AREA SHAPE='rect' COORDS='0,1,32,32' ID='HotspotRectangle13_2_1' ALT='Help' HREF='help.html'></MAP> <IMG SRC='help.gif' WIDTH='31' HEIGHT='29' ALT='Help' USEMAP='#nF5E.$Body.0.2272' BORDER='0'></TD> <TD colspan='2'><P class='title'>Search</P></TD>")
  doc.writeln("</TABLE>")
  doc.writeln("<TABLE WIDTH='100%' cellspacing='0' border='0'>");
  doc.writeln("<TR><TD colspan='4'>&nbsp;</TD></TR>");
  doc.writeln("<TR><TD width='23%'>&nbsp;<SELECT name='match_style'><OPTION>Match All Terms</OPTION><OPTION>Match Any Terms</OPTION></SELECT></TD> <TD colspan='2'><INPUT type='text' name='query' size='60' value=''></TD> <TD>&nbsp;<INPUT type='submit' name='submit' value='Search'></TD></TR>");
  doc.writeln("<TR><TD>&nbsp;</TD><TD><BR><SELECT name='maxhits'><OPTION value='1000'>1000</OPTION><OPTION value='500'>500</OPTION><OPTION value='100'>100</OPTION><OPTION SELECTED value='50'>50</OPTION><OPTION value='25'>25</OPTION></SELECT></TD><TD><BR><P>Maximum number of search results</P></TD><TD>&nbsp;</TD></TR>");
  doc.writeln("<TR ><TD>&nbsp;</TD><TD WIDTH='10%'><INPUT type='checkbox' name='show_highlighted' onClick='top.setShowingHighlights(this.checked);'></TD><TD><P>Highlighting</P></TD><TD>&nbsp;</TD></TR>");
  doc.writeln("<TR><TD colspan='4'><hr></TD></TR>");
  doc.writeln("</TABLE>")
  doc.writeln("<TABLE WIDTH='100%' cellspacing='0' border='0'>");
  doc.writeln("<TR VALIGN='top'> <TD><span class='helpLink'> &nbsp;&nbsp;&nbsp;<A href='help.html'>Help</A></span></TD> <TD><div class='abshome'><A href='../index.html'>Home</A>&nbsp;&nbsp;&nbsp;</div></TD></TR>");
  doc.writeln("</TABLE></FORM></DIV>");
}


function writeSearchIndexHeader(doc){
  doc.writeln("<html>");
  doc.writeln("<head><title>Search</title><link rel='stylesheet' type='text/css' href='webrom.css'>");
  handleNetscape4Resize(doc);
  doc.writeln("</head>");
}


function writeSearchIndexBody(doc){
  doc.writeln("<body "
             + "onLoad='top.zeroPageID();top.initializeSearchIndexPage(this.document);'>");
}

function writeSearchIndexGui(doc){ 
 writeSearchForm("top.setQueryParametersFromSearchIndexPage", doc);
}
 
 
function writeSearchIndexFooter(doc){
  doc.writeln("<DIV class='webromForm'>");  
  doc.writeln("<TABLE WIDTH='100%'cellspacing='0' border='0'>");
  doc.writeln("<TR> <TD><DIV class='copyright'>Webrom CD Toolkit &copy; 2000 &nbsp &nbsp;<A href='http://www.openobjects.com/'>Open Objects Software</A></DIV></TD></TR>");
  doc.writeln("</TABLE></DIV>")
  doc.write("</body></html>\n");
}



/*
 * You may need to customize this function if you customize the 
 * SearchIndex page or the SearchResults page.
 */
function initializeSearchIndexPage(doc){
  var form = doc.simpleform;

  form.query.value = getQueryText();
  form.show_highlighted.checked = isShowingHighlights();

  var maxHits = getMaxNumberOfHits();
  if(maxHits == 25) {
    form.maxhits.selectedIndex = 4;
  } else if (maxHits == 50) {
    form.maxhits.selectedIndex = 3;
  } else if (maxHits == 100) {
    form.maxhits.selectedIndex = 2;
  } else if (maxHits == 500) {
    form.maxhits.selectedIndex = 1;
  } else {
    form.maxhits.selectedIndex = 0;
  }

  if(isMatchingAllSearchTerms()){
    form.match_style.selectedIndex = 0;
  } else {
    form.match_style.selectedIndex = 1;
  }
}



/*
 * You may need to customize this function if you customize the 
 * SearchIndex page or the SearchResults page.
 */
function setQueryParametersFromSearchIndexPage(doc){
  var qform = doc.simpleform;

  setQueryText(qform.query.value);
  setShowingHighlights(qform.show_highlighted.checked);
  setShowingNavigationLinks(isShowingHighlights());
  setMatchingAllSearchTerms(qform.match_style.selectedIndex == 0);

  //Set up the maximum number of hits
  var maxhits = qform.maxhits;
  setMaxNumberOfHits(Number(maxhits.options[maxhits.selectedIndex].value));
}





/*---------------------------------------------------
 * Search Results pages
 * 
 * For the 'Site' style
 ---------------------------------------------------*/
function writeNavbar(doc, pageNumber, startResult, endResult, totalResults, formName){
  //Write the navigation 'arrows' for the top of the search results list
  doc.writeln("<div class='navbar'>");
  doc.writeln("<form name='" + formName + "'>");
  doc.writeln("<table width='100%' border='0' cellspacing='0'>");
  doc.writeln("<tr><td width='2%'>&nbsp;</td><td width='24%'><div class='totalSearchResults'>" 
               + totalResults 
               + " result(s)</div></td>");
  if (formName == "navbarTop"){
	  doc.writeln("<td width='28%'><select name='sortby' "
	               + "onChange='top.setSortOrder(Number(this.options[this.selectedIndex].value));"
	               + "top.performSearch();'>");
	  doc.writeln("<option value='0'>Sort by Relevance</option>");
	  doc.writeln("<option  value='1'>Sort by Title</option>");
	  doc.writeln("</select></td>");
 }
//  doc.writeln("<td width='30%'><input type='button' name='showSummaries' value='Hide Summaries' ");
//  doc.writeln("onClick='top.setShowingSummaries(!top.isShowingSummaries());top.loadResultsPage("
//              + pageNumber
  //            + ");'></td>");

  //Write the 'back' gif if necessary
  if (isFirstSearchResultsPage(startResult)) {
    doc.writeln("<td width='2%'>&nbsp;</td>");
  } else {
    doc.writeln("<td width='2%'><a href='javascript:top.loadResultsPage(" 
                + (pageNumber - 1)
                + ")'><img src='back.gif' border='0' alt='Previous'></a></td>");
  }

  //Write the document count
  doc.writeln("<td width='10%'><div class='hitsOnThisPage'>" 
                + (1 + startResult) 
                + " - " 
                + (1 + endResult) 
                + "</div></td>");

  //Write the 'next' gif if necessary
  if (isLastSearchResultsPage(endResult, totalResults)) {
    doc.writeln("<td width='2%'>&nbsp;</td>");
  } else {
    doc.writeln("<td width='2%'><a href='javascript:top.loadResultsPage("
                 + (pageNumber + 1) 
                 + ")'><img src='next.gif' border='0' alt='Next'></a></td>");
  }

  doc.writeln("<td width='2%'>&nbsp;</td></tr></table></form></div>");
}



function writeSearchResultsHeader(doc, numberOfSearchHits, isShowingSearchGui){
  doc.writeln("<html>");
  doc.writeln("<head><title>Search Results</title><link rel='stylesheet' type='text/css' href='webrom.css'>");
  handleNetscape4Resize(doc);
  doc.writeln("</head>");
  if (isShowingSearchGui) {
    doc.writeln("<body"
                 + " onLoad='top.zeroPageID();top.initializeSearchResultsPage(this.document, " 
                 + numberOfSearchHits
                 + ", "
                 + isShowingSearchGui
                 + ");'>");
  } else {
    doc.writeln("<body>");
  }
}



function writeSearchResultsGui(doc){
  writeSearchForm("top.setQueryParametersFromSearchResultsPage", doc);
}


function writeNoResultsPage(doc){
  doc.write("<h4>No Results</h4>Please refine query and try again.\n");    
}


function writeNavbarTop(doc, pageNumber, startResult, endResult, totalResults){
  writeNavbar(doc, pageNumber, startResult, endResult, totalResults, "navbarTop");
}


function writeSearchHit(doc, hitNumber, resultRecord){
  var description = resultRecord.description;

  doc.writeln("<div class='searchResult'>");
  doc.writeln("<table width='100%' border='0'>");
  doc.writeln("<tr><td width='3%'><div class='hitNumber'>" + (hitNumber + 1) + ".</div></td><td width='90%'><div  class='hitLink'>");

  writeResultAnchor(doc, resultRecord);

  doc.writeln("</div></td><td width='7%'><div  class='hitRelevance'>(" + resultRecord.relevance + "%)</div></td></tr>");
  if(isShowingSummaries() && (description != null)){
  doc.writeln("<tr><td>&nbsp;</td><td><div class='hitDescription'>" 
  //           + description 
               + "</div></td><td>&nbsp;</td></tr>");
  }

  doc.writeln("</table><hr>");
}


function writeNavbarBottom(doc, pageNumber, startResult, endResult, totalResults){
  writeNavbar(doc, pageNumber, startResult, endResult, totalResults, "navbarBottom");
}


function writeSearchResultsFooter(doc){
  doc.writeln("<DIV class='webromForm'>");
  doc.writeln("<DIV class='logo' align='right'><A href='http://www.openobjects.com/'><IMG border='0' src='webrom.gif'></A></DIV>");
  doc.writeln("<DIV class='copyright' align='right'>Webrom CD Toolkit &copy; 2000 <A href='http://www.openobjects.com/'>Open Objects Software</A></DIV>");
  doc.write("</DIV></body></html>\n");
}


/*
 * You may need to customize this function if you customize the 
 * SearchIndex page or the SearchResults page.
 */
function initializeSearchResultsPage(document, numberOfHits, isShowingSearchForm){
  if (isShowingSearchForm){
    initializeSearchIndexPage(document);
  }

  if (numberOfHits > 0) {
    var topNavbarForm = document.navbarTop;
    var bottomNavbarForm = document.navbarBottom;

    initializeNavbar(topNavbarForm);
   // initializeNavbar(bottomNavbarForm);
  }
}



function initializeNavbar(form){
  form.sortby.selectedIndex = getSortOrder();

//  if(isShowingSummaries()){
//    form.showSummaries.value = "Hide Summaries";
//  } else {
//    form.showSummaries.value = "Show Summaries";
//  }
}



/*
 * You may need to customize this function if you customize the 
 * SearchIndex page or the SearchResults page.
 */
function setQueryParametersFromSearchResultsPage(document){
  setQueryParametersFromSearchIndexPage(document);
}



// Eof
