/*
 (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.
 */

//NB: the *location* for this page is actually the 'index.html' page at the root of the VCD
var isExpiredPageLocation = this.location + '/../cd/isExpired.html';
var isUnauthorizedPageLocation = this.location + '/../cd/isUnauthorized.html';


/*---------------------------------------------------
 * Skeleton for search index pages
 ---------------------------------------------------*/
function writeSearchIndexPage(doc){
  //Open the document
  doc.open();

  //Write the standard HTML header info
  writeSearchIndexHeader(doc);

  //Write the search form
  writeSearchIndexGui(doc);

  //Write the standard HTML footer
  writeSearchIndexFooter(doc);

  //Close the document
  doc.close();
}


function writeSearchIndexHeader(doc){
  //stub
}


function writeSearchIndexGui(doc){
  //stub
}


function writeSearchIndexFooter(doc){
  //stub
}



/*---------------------------------------------------
 * Skeleton for search results pages
 ---------------------------------------------------*/

//This fn is called from the SEARCH INDEX page, to display the search results.
//This is done in the following manner:
//  1.Load in the file 'result.html'
//  2.The file 'result.html' contains JavaScript that is executed when it loads.  This JavaScript calls the fn 
//    'writeSearchResultsPage()' to dynamically write the search results page.
function loadResultsPage(pageNumber){
  currentPage = pageNumber;
  var win = getSearchResultsWindow();

  setSearchResultsWindow(open("result.html", win.name));
}


function writeSearchResultsPage(pageNumber, isShowingSearchGui){
  var win = getSearchResultsWindow();
  var doc = win.document;
  var numberOfSearchHits = getNumberOfHits();
  var resultsPerPage = getHitsPerPage();
  var startResult = getFirstHitForPage(pageNumber, resultsPerPage);
  var endResult = getLastHitForPage(pageNumber, startResult, resultsPerPage, numberOfSearchHits); 

  //Open the document
  doc.open();

  //Write the standard HTML header info
  writeSearchResultsHeader(doc, numberOfSearchHits, isShowingSearchGui);

  //Write the search form
  if (isShowingSearchGui) {
    writeSearchResultsGui(doc);
  }

  //Write the search hit information
  if (numberOfSearchHits > 0) {
    var hitsPerPage = getHitsPerPage();
    writeNavbarTop(doc, pageNumber, startResult, endResult, numberOfSearchHits);
    writeSearchHitsInfo(doc, pageNumber, startResult, endResult, numberOfSearchHits);
    writeNavbarBottom(doc, pageNumber, startResult, endResult, numberOfSearchHits);
  } else {
    writeNoResultsPage(doc);
  }

  //Write the stardard HTML footer
  writeSearchResultsFooter(doc);

  //Close the document
  doc.close();
}



function writeSearchResultsHeader(doc, numberOfSearchHits, isShowingSearchGui){
  //stub
}


function writeSearchResultsGui(doc){
  //stub
}


function writeNavbarTop(doc, pageNumber, startResult, endResult, numberOfSearchHits){
  //stub
}


//Default implementation for writing the list of search hits on the search-results page.
function writeSearchHitsInfo(doc, pageNumber, startResult, endResult, numberOfSearchHits){
  var resultRecord;
  for (hitNumber = startResult; hitNumber <= endResult; hitNumber++){
    resultRecord = parent.resultsArray[hitNumber];
    writeSearchHit(doc, hitNumber, resultRecord);
  }
}


function writeSearchHit(doc, hitNumber, resultRecord){
  //stub
}


function writeNavbarBottom(doc, pageNumber, startResult, endResult, numberOfSearchHits){
  //stub
}


function writeNoResultsPage(doc){
  //stub
}


function writeSearchResultsFooter(doc){
  //stub
}



function showIsUnauthorizedPage(){
  var searchHitWindow = findNamedWindow(top, getSearchHitWindowName());

  searchHitWindow.location = isUnauthorizedPageLocation;
}



function showIsExpiredPage(){
  var searchHitWindow = findNamedWindow(top, getSearchHitWindowName());

  searchHitWindow.location = isExpiredPageLocation;
}






/*----------------------------------------------------------------------------
 * Utility fns for writing common parts of the search- and search-results
 * pages
 -----------------------------------------------------------------------------*/

//Utitlity fn for fixing a bug that occurs when you resize a dynamically created HTML 
//page under Netscape 4
function handleNetscape4Resize(doc){
  doc.writeln("<script language='JavaScript'>");
  doc.writeln("var ns4 = document.layers;");
  doc.writeln("if (ns4) {");
  doc.writeln("  var origWidth = innerWidth;");
  doc.writeln("  var origHeight = innerHeight;");
  doc.writeln("}");
  doc.writeln("function reDo() {");
  doc.writeln("  if (innerWidth != origWidth || innerHeight != origHeight)");
  doc.writeln("    location.reload();");
  doc.writeln("}");
  doc.writeln("if (ns4) onresize = reDo;");
  doc.writeln("</script>");
}


//Fns for producing the hyperlinks to documents that are in the search results pages.
function writeResultAnchor(doc, resultRecord){
  var title = resultRecord.title;
  var location = resultRecord.location;

  doc.writeln("<a href=\"javascript:top.loadWebromSearchHit('" 
                 + location
                 + "')\">"
                 + title
                 + "</a>");
}


// Eof
