//This function switches the images on the left hand menu on the mouseover event
function changeImages() {
  if (document.images){
    for (var i=0; i<changeImages.arguments.length; i+=2) {
      document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
    }
  }
}

//Supress the close window dialog
window.opener="top";

//Frame in which to open search results.
var targetFrame = "_self";

//Text used in search results messages:
var noData_txt = "Click <a href='search.xml'>here</a> to return to the search page";
var yourSearch_txt = "Your search for";
var yielded_txt = "yielded";
var closestAnchor_txt = "Closest anchor";
var docInfo_txt = "Document Info";
var context_txt = "Match Context";
var noMatches_txt = "No matches";

//Which elements should be displayed along with the results?
var displayDocInfo = true;
var displayContext = true;
var preferTitleOnly = false;

function writeResults() {
    var estr = document.location.toString();
    var estrtemp = "";
    var index = estr.indexOf("?");
    if (index == -1) {
        document.writeln("<em>" + noData_txt + "</em>");
        return;
    }

    index++;
    estr = estr.substring(index, estr.length);

    index = estr.indexOf(",");
    document.write(yourSearch_txt + " <b>" +
                    unescape(estr.substring(0, index)) + "</b> " + yielded_txt + ":");
    estr = estr.substring(index + 3, estr.length);
    index = -1;
    var numOfMatches = 0;
    var lastindex = 0; //colon
    var clastindex = 0; //comma
    var currdata = "";
    var myUrl = "";
    var myTitle = "";
    var myanchor = "";
    var colonindex = -1;
    var info = "";
    var context = "";
    var anchor = "";
    while ((index = estr.indexOf(",", index + 1)) != -1) {
        document.write("<p>");
        currdata = estr.substring(clastindex, index);
        clastindex = index + 1;
        colonindex = currdata.indexOf(":");
        if (colonindex != -1) {
            numOfMatches++;

            //Get the URL
            myUrl = unescape(currdata.substring(0, colonindex));

            //Get the page's title
            lastindex = colonindex + 1;
            colonindex = currdata.indexOf(":", lastindex);

            myTitle = unescape(currdata.substring(lastindex, colonindex));

            //Get the anchor
            lastindex = colonindex + 1;
            colonindex = currdata.indexOf(":", lastindex);
            anchor = unescape(currdata.substring(lastindex, colonindex));

            if (anchor.length > 0) {
                myUrl += "#" + anchor;
            }
            document.write("<a href=\""+myUrl+"\" target=\"" +
                            targetFrame + "\"><b>" + myTitle + "</b> ");
            if (!preferTitleOnly || myTitle.length == 0) {
                document.write("<b>(" + myUrl + ")</b>");
            }
            document.write("</a>");

            if (anchor.length > 0)
                document.write(" <a href=\""+myUrl+"#"+anchor+"\" target=\"" + targetFrame + "\">[" +     closestAnchor_txt +"]</a>");
            document.writeln("<br>");

            //Get document info
            lastindex = colonindex + 1;
            colonindex = currdata.indexOf(":", lastindex);
            info = unescape(currdata.substring(lastindex, colonindex));
            if (info.length > 0 && displayDocInfo)
                document.write("<b>" + docInfo_txt + "</b>: "+info+"&nbsp;&nbsp;&nbsp;&nbsp;");

            //Get the match context
            lastindex = colonindex+1;
            context = unescape(currdata.substring(lastindex, currdata.length));
            if (context.length > 0 && displayContext)
                document.writeln("<b>" + context_txt + "</b>: \""+context+"\"");
        }
        document.write("</p>");
    }
    if (numOfMatches == 0)
        document.writeln("<em>&lt;" + noMatches_txt + "&gt;</em>");
}