// ----------------------------------------------------------------------------
// Zoom Search Engine 4.2 (4/4/2006)
//
// This file (search.js) is the JavaScript search front-end for client side
// searches using index files created by the Zoom Search Engine Indexer.
//
// email: zoom@wrensoft.com
// www: http://www.wrensoft.com
//
// Copyright (C) Wrensoft 2000-2005
//
// This script performs client-side searching with the index data file
// (zoom_index.js) generated by the Zoom Search Engine Indexer. It allows you
// to run searches on mediums such as CD-ROMs, or other local data, where a
// web server is not available.
//
// We recommend against using client-side searches for online websites because
// it requires the entire index data file to be downloaded onto the user's
// local machine. This can be very slow for large websites, and our server-side
// search scripts (available for PHP, ASP and CGI) are far better suited for this.
// However, JavaScript is still an option for smaller websites in a limited
// hosting situation (eg: your web host does not support PHP, ASP or CGI).
// ----------------------------------------------------------------------------

// Include required files for index data, settings, etc.
document.write("<script language=\"JavaScript\" src=\"zoom_index.js\" charset=\"" + Charset + "\"><\/script>");
document.write("<script language=\"JavaScript\" src=\"zoom_pages.js\" charset=\"" + Charset + "\"><\/script>");
document.write("<script language=\"JavaScript\" src=\"zoom_titles.js\" charset=\"" + Charset + "\"><\/script>");
document.write("<script language=\"JavaScript\" src=\"zoom_descriptions.js\" charset=\"" + Charset + "\"><\/script>");

document.write("<meta http-equiv=\"content-type\" content=\"text/html; charset=" + Charset + "\">");

// ----------------------------------------------------------------------------
// Settings (change if necessary)
// ----------------------------------------------------------------------------

// The options available in the dropdown menu for number of results
// per page
var PerPageOptions = new Array(10, 20, 50, 100);

// Globals
var SkippedWords = 0;
var searchWords = new Array();
var SkippedOutputStr = "";

var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

// ----------------------------------------------------------------------------
// Helper Functions
// ----------------------------------------------------------------------------

// This function will return the value of a GET parameter
function getParam(paramName)
{
    paramStr = document.location.search;
    if (paramStr == "")
        return "";

    // remove '?' in front of paramStr
    if (paramStr.charAt(0) == "?")
        paramStr = paramStr.substr(1);

    arg = (paramStr.split("&"));
    for (i=0; i < arg.length; i++) {
        arg_values = arg[i].split("=")
        if (unescape(arg_values[0]) == paramName) {
            if (UseUTF8 == 1 && self.decodeURIComponent) // check if decodeURIComponent() is defined
                ret = decodeURIComponent(arg_values[1]);
            else
                ret = unescape(arg_values[1]);  // IE 5.0 and older does not have decodeURI
            return ret;
        }
    }
    return "";
}

// Compares the two values, used for sorting output results
// Results that match all search terms are put first, highest score
function SortCompare (a, b)
{
    if (a[2] < b[2]) return 1;
    else if (a[2] > b[2]) return -1;
    else if (a[1] < b[1]) return 1;
    else if (a[1] > b[1]) return -1;
    else return 0;
}

function SortByDate(a, b)
{
	if (datetime[a[0]] < datetime[b[0]]) return 1;
	else if (datetime[a[0]] > datetime[b[0]]) return -1;
	else return SortCompare(a, b);
}

function sw_compare(a, b)
{
	if (a.charAt(0) == '-') 
		return 1;
	
	if (b.charAt(0) == '-') 
		return -1;
	
	return 0;
}

function pattern2regexp(pattern)
{
    pattern = pattern.replace(/\#/g, "\\#");
    pattern = pattern.replace(/\$/g, "\\$");
    pattern = pattern.replace(/\./g, "\\.");
    pattern = pattern.replace(/\*/g, "[\\d\\S]*");
    pattern = pattern.replace(/\?/g, ".?");
    return pattern;
}

function HighlightDescription(line) {
    res = " " + line + " ";
    for (i = 0; i < numwords; i++) {
        if (searchWords[i] == "")
            continue;

        if (SearchAsSubstring == 1)
            res = res.replace(new RegExp("("+searchWords[i]+")", "gi"), "[;:]$1[:;]");
        else
            res = res.replace(new RegExp("(\\W|^|\\b)("+searchWords[i]+")(\\W|$|\\b)", "gi"), "$1[;:]$2[:;]$3");
    }
    // replace the marker text with the html text
    // this is to avoid finding previous <span>'ed text.
    res = res.replace(/\[;:\]/g, "<span class=\"highlight\">");
    res = res.replace(/\[:;\]/g, "</span>");
    return res;
}

function PrintNumResults(num)
{
    if (num == 0)
        return STR_NO_RESULTS;
    else if (num == 1)
        return num + " " + STR_RESULT;
    else
        return num + " " + STR_RESULTS;
}

function AddParamToURL(url, paramStr)
{
	// add GET parameters to URL depending on 
	// whether there are any existing parameters
	if (url.indexOf("?") > -1)	
		return url + "&amp;" + paramStr;
	else		
		return url + "?" + paramStr;			
}

function SkipSearchWord(sw) {
    if (searchWords[sw] != "") {
        if (SkippedWords > 0)
            SkippedOu