// ----------------------------------------------------------------------------
// Zoom Search Engine 5.1 (30/4/2007)
//
// 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-2007
//
// 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_pageinfo.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, 2, 4);

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

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

// Index format
var PAGEDATA_URL = 0;
var PAGEDATA_TITLE = 1;
var PAGEDATA_DESC = 2;
var PAGEDATA_IMG = 3;
var PAGEINFO_DATETIME = 0;
var PAGEINFO_FILESIZE = 1;
var PAGEINFO_CAT = 2;

// ----------------------------------------------------------------------------
// 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 "";
}

function getParamArray(paramName)
{
    paramStr = document.location.search;

    var retArray = new Array();
    var retCount = 0;

    if (paramStr == "")
        return retArray;

    // 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            
            retArray[retCount] = ret;
            retCount++;            
        }
    }
    return retArray;    
}

// 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 (pageinfo[a[0]][PAGEINFO_DATETIME] < pageinfo[b[0]][PAGEINFO_DATETIME]) return 1;
    else if (pageinfo[a[0]][PAGEINFO_DATETIME] > pageinfo[b[0]][PAGEINFO_DATETIME]) 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 PrintHighlightDescription(line) 
{
    if (Highlighting == 0)
    {
        document.writeln(line);
        return;
    }
        
    res = " " + line + " ";
    for (i = 0; i < numwords; i++) {
        if (RegExpSearchWords[i] == "")
            continue;

        if (SearchAsSubstring == 1)
            res = res.replace(new RegExp("("+RegExpSearchWords[i]+")", "gi"), "[;:]$1[:;]");
        else
            res = res.replace(new RegExp("(\\W|^|\\b)("+RegExpSearchWords[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>");
    document.writeln(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)
            SkippedOutputStr += ", ";
        SkippedOutputStr += "\"<b>" + searchWords[sw] + "</b>\"";
        searchWords[sw] = "";
    }
}

function wordcasecmp(word1, word2) {
    if (word1 == word2)
        return 0;
    else
        return -1;  
}

function htmlspecialchars(query) {
    query = query.replace(/\&/g, "&#38;");
    query = query.replace(/\</g, "&#60;");
    query = query.replace(/\>/g, "&#62;");  
    query = query.replace(/\"/g, "&#34;");
    query = query.replace(/\'/g, "&#39;");
    return query;
}

function QueryEntities(query) { 
    query = query.replace(/\&/g, "&#38;");  
    query = query.replace(/\</g, "&#60;");
    query = query.replace(/\>/g, "&#62;");
    query = query.replace(/\'/g, "&#39;");  
    return query;
}

function FixQueryForAsianWords(query) {
    currCharType = 0;
    lastCharType = 0;   // 0 is normal, 1 is hiragana, 2 is katakana, 3 is "han"
    
    // check for hiragana/katakana splitting required
    newquery = "";
    for (i = 0; i < query.length; i++)
    {
        ch = query.charAt(i);
        chVal = query.charCodeAt(i);
        
        if (chVal >= 12352 && chVal <= 12447)
            currCharType = 1;
        else if (chVal >= 12448 && chVal <= 12543)
            currCharType = 2;
        else if (chVal >= 13312 && chVal <= 44031)
            currCharType = 3;
        else
            currCharType = 0;
                        
        if (lastCharType != currCharType && ch != " ")
            newquery += " ";            
        lastCharType = currCharType;                
        newquery += ch;
    }
    return newquery;
}

// ----------------------------------------------------------------------------
// Parameters initialisation (globals)
// ----------------------------------------------------------------------------

var query = getParam("zoom_query");
query = query.replace(/[\++]/g, " ");  // replace the '+' with spaces
query = query.replace(/[\"+]/g, " ");

var Highlighting = getParam("Highlighting");

//var per_page = parseInt(getParam("zoom_per_page"));
//if (isNaN(per_page)) per_page = 10;
var per_page = 5;

var page = parseInt(getParam("zoom_page"));
if (isNaN(page)) page = 1;

var andq = parseInt(getParam("zoom_and"));
if (isNaN(andq))
{
    if (typeof(DefaultToAnd) != "undefined" && DefaultToAnd == 1)
        andq = 1;
    else
        andq = 0;
}

var cat = getParamArray("zoom_cat[]");
if (cat.length == 0)
{
    cat[0] = parseInt(getParam("zoom_cat"));
    if (isNaN(cat))
        cat[0] = -1;    // search all categories
}
var num_zoom_cats = cat.length; 


// for sorting options. zero is default (relevance)
// 1 is sort by date (if date/time is available)
var sort = parseInt(getParam("zoom_sort"));
if (isNaN(sort)) sort = 0;

var SelfURL = "";
if (typeof(LinkBackURL) == "undefined")
{
    SelfURL = document.location.href;
    // strip off parameters and anchors
    var paramIndex;
    paramIndex = SelfURL.indexOf("?");    
    if (paramIndex > -1)
        SelfURL = SelfURL.substr(0, paramIndex);
    paramIndex = SelfURL.indexOf("#");
    if (paramIndex > -1)
        SelfURL = SelfURL.substr(0, paramIndex);        
}
else
    SelfURL = LinkBackURL;
// encode invalid URL characters
SelfURL = SelfURL.replace(/\</g, "&lt;");
SelfURL = SelfURL.replace(/\"/g, "&quot;");

var data = new Array();
var output = new Array();

target = "";
if (UseLinkTarget == 1)
    target = " target=\"" + LinkTarget + "\" ";

// ----------------------------------------------------------------------------
// Main search function starts here
// ----------------------------------------------------------------------------

function ZoomSearch() 
{
    // give up early if no search words provided
    /*if (query.length == 0)
	{
        document.write("<p>The word(s) you searched for are not in the index.  Use these hints to get better results:</p>");
		document.write("<UL>");
		document.write("<LI>Use a space between multiple words.</LI>");
		document.write("<LI>Common words such as <b>and</b> and <b>the</b> are not in the search index</LI>");
		document.write("<LI>Search is not case sensitive</LI>");
		document.write("<LI>You can include any alphanumeric character and the special characters <b> _ - . ' , $ %</b></LI>");
		document.write("<LI>Add + in front of words that must appear in results. For example, <b>+printer +cartridge +maintenance</b> will find all pages that contain all three words.</LI>");
		document.write("<LI>Add - in front of words that must not appear in results. For example, <b>+printer +cartridge -maintenance</b> will find all pages that have the words \"printer\" and \"cartridge\" but not \"maintenance.\"</LI>");
		document.write("</UL>") 
        return;
    }*/

    if (MapAccents == 1) {
        for (i = 0; i < NormalChars.length; i++) {
            query = query.replace(AccentChars[i], NormalChars[i]);
        }
    }

    // Special query processing required when SearchAsSubstring is enabled
    if (SearchAsSubstring == 1 && UseUTF8 == 1)
        query = FixQueryForAsianWords(query);

    // prepare search query, strip quotes, trim whitespace
    if (WordJoinChars.indexOf(".") == -1)
        query = query.replace(/[\.+]/g, " ");

    if (WordJoinChars.indexOf("-") == -1)
        query = query.replace(/(\S)\-/g, "$1 ");

    if (WordJoinChars.indexOf("_") == -1)
        query = query.replace(/[\_+]/g, " ");

    if (WordJoinChars.indexOf("'") == -1)
        query = query.replace(/[\'+]/g, " ");

    if (WordJoinChars.indexOf("#") == -1)
        query = query.replace(/[\#+]/g, " ");

    if (WordJoinChars.indexOf("$") == -1)
        query = query.replace(/[\$+]/g, " ");

    if (WordJoinChars.indexOf("&") == -1)
        query = query.replace(/[\&+]/g, " ");

    if (WordJoinChars.indexOf(":") == -1)
        query = query.replace(/[\:+]/g, " ");

    if (WordJoinChars.indexOf(",") == -1)
        query = query.replace(/[\,+]/g, " ");

    if (WordJoinChars.indexOf("/") == -1)
        query = query.replace(/[\/+]/g, " ");

    if (WordJoinChars.indexOf("\\") == -1)
        query = query.replace(/[\\+]/g, " ");
        
    // substitute multiple whitespace chars to single character
    // also strip any of the wordjoinchars if followed immediately by a space
    query = query.replace(/[\s\(\)\^\[\]\|\+\{\}\%]+|[\-._',:&\/\\\\](\s|$)/g, " ");   
    
    // trim trailing/leading whitespace
    query = query.replace(/^\s*|\s*$/g,""); 
    
    var queryForHTML = htmlspecialchars(query);
    var queryForSearch;
    if (ToLowerSearchWords == 1)
        queryForSearch = query.toLowerCase();
    else
        queryForSearch = query;    
    queryForSearch = htmlspecialchars(queryForSearch);    

    // split search phrase into words
    searchWords = queryForSearch.split(" "); // split by spaces.
    
    // Sort search words if there are negative signs
    if (queryForSearch.indexOf("-") != -1)
        searchWords.sort(sw_compare);      

    var query_zoom_cats = "";


    numwords = searchWords.length;
    kw_ptr = 0;
    outputline = 0;    
    ipage = 0;
    matches = 0;
    var SWord;
    pagesCount = pageinfo.length;
    
    exclude_count = 0;
    ExcludeTerm = 0;
    
    // Initialise a result table the size of all pages
    res_table = new Array(pagesCount);
    for (i = 0; i < pagesCount; i++)
    {
        res_table[i] = new Array(3);
        res_table[i][0] = 0;
        res_table[i][1] = 0;
        res_table[i][2] = 0;
    }
    
    var UseWildCards = new Array(numwords);    
        
    for (sw = 0; sw < numwords; sw++) {

        UseWildCards[sw] = 0;

        if (skipwords) {
            // check min length
            if (searchWords[sw].length < MinWordLen) {
                SkipSearchWord(sw);
                continue;
            }
            // check skip word list
            for (i = 0; i < skipwords.length; i++) {
                if (searchWords[sw] == skipwords[i]) {
                    SkipSearchWord(sw);
                    break;
                }
            }
        }

        if (searchWords[sw].indexOf("*") == -1 && searchWords[sw].indexOf("?") == -1) {
            UseWildCards[sw] = 0;
        } else {
            UseWildCards[sw] = 1;
            RegExpSearchWords[sw] = pattern2regexp(searchWords[sw]);
        }
        
        if (Highlighting == 1 && UseWildCards[sw] == 0)
            RegExpSearchWords[sw] = searchWords[sw];                    
    }
                   
    // Begin searching...
    for (sw = 0; sw < numwords; sw++) {

        if (searchWords[sw] == "") {
            SkippedWords++;
            continue;
        }

        if (searchWords[sw].charAt(0) == '-')
        {           
            searchWords[sw] = searchWords[sw].substr(1);            
            ExcludeTerm = 1;
            exclude_count++;            
        }
        
        if (UseWildCards[sw] == 1) {            
            if (SearchAsSubstring == 0)
                pattern = "^" + RegExpSearchWords[sw] + "$";
            else
                pattern = RegExpSearchWords[sw];
            re = new RegExp(pattern, "g");
        }

        for (kw_ptr = 0; kw_ptr < dictwords.length; kw_ptr++) {

            data = dictwords[kw_ptr].split(" ");

            if (UseWildCards[sw] == 0) {
                if (SearchAsSubstring == 0)
                    match_result = wordcasecmp(data[0], searchWords[sw]);
                else
                    match_result = data[0].indexOf(searchWords[sw]);
            } else
                match_result = data[0].search(re);


            if (match_result != -1) {
                // keyword found, include it in the output list
                for (kw = 1; kw < data.length; kw += 2) {
                    // check if page is already in output list
                    pageexists = 0;
                    ipage = data[kw];
                    
                    if (ExcludeTerm == 1)
                    {
                        // we clear out the score entry so that it'll be excluded in the filter stage
                        res_table[ipage][0] = 0;
                    }                    
                    else if (res_table[ipage][0] == 0) {
                        matches++;
                        res_table[ipage][0] += parseInt(data[kw+1]);
                    }
                    else {

                        if (res_table[ipage][0] > 10000) {
                            // take it easy if its too big to prevent gigantic scores
                            res_table[ipage][0] += 1;
                        } else {
                            res_table[ipage][0] += parseInt(data[kw+1]); // add in score
                            res_table[ipage][0] *= 2;           // double score as we have two words matching
                        }
                    }
                    res_table[ipage][1] += 1;
                    // store the 'and' user search terms matched' value
                    if (res_table[ipage][2] == sw || res_table[ipage][2] == sw-SkippedWords-exclude_count)
                        res_table[ipage][2] += 1;

                }
                if (UseWildCards[sw] == 0 && SearchAsSubstring == 0)
                    break;    // this search word was found, so skip to next
            }
        }
    }
    
 
    // Count number of output lines that match ALL search terms
    oline = 0;
    fullmatches = 0;    
    output = new Array();
    var full_numwords = numwords - SkippedWords - exclude_count;
    for (i = 0; i < pagesCount; i++) {
        IsFiltered = false;
        if (res_table[i][0] > 0) {
            if (UseCats && cat[0] != -1) {
                // using cats and not doing an "all cats" search
                if (SearchMultiCats) {
                    for (cati = 0; cati < num_zoom_cats; cati++) {                      
                        if (pageinfo[i][PAGEINFO_CAT].charAt(cat[cati]) == "1")
                            break;
                    }
                    if (cati == num_zoom_cats)
                        IsFiltered = true;
                }
                else {                                      
                    if (pageinfo[i][PAGEINFO_CAT].charAt(cat[0]) == "0") {
                        IsFiltered = true;
                    }
                }
            }
            if (IsFiltered == false) {
                if (res_table[i][2] >= full_numwords) {
                    fullmatches++;
                } else {
                    if (andq == 1)
                        IsFiltered = true;
                }
            }
            if (IsFiltered == false) {
                // copy if not filtered out
                output[oline] = new Array(3);
                output[oline][0] = i;
                output[oline][1] = res_table[i][0];
                output[oline][2] = res_table[i][1];
                oline++;
            }
        }
    }
    matches = oline;    

    // Sort results in order of score, use "SortCompare" function
    if (matches > 1)    
    {
        if (sort == 1 && UseDateTime == 1)
            output.sort(SortByDate);    // sort by date
        else
            output.sort(SortCompare);   // sort by relevance
    }
    
    // prepare queryForURL
    var queryForURL = query.replace(/\s/g, "+");
    if (UseUTF8 == 1 && self.encodeURIComponent)
        queryForURL = encodeURIComponent(queryForURL);
    else
        queryForURL = escape(queryForURL);    

    // number of pages of results
    num_pages = Math.ceil(matches / per_page);
	end_result_number = page * per_page;
	start_result_number = end_result_number - 4;
	if (end_result_number > matches)
		end_result_number = matches;
	
	
document.writeln("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" height=\"100%\" class=\"layout\">");
//document.writeln("<tr><td class=\"content\"><div class=\"padder\"><div id=\"SearchResults\">");
document.writeln("<tr><td class=\"content\"><div class=\"padder\"><div id=\"SearchResults\">");
document.writeln("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"result_info\">");
	
	if (matches == 0 || query.length == 0)
		{
        document.write("<div class=\"results\"><p>The word(s) you searched for are not in the index.  Use these hints to get better results:</p>");
		document.write("<UL>");
		document.write("<LI>Use a space between multiple words.</LI>");
		document.write("<LI>Common words such as <b>and</b> and <b>the</b> are not in the search index</LI>");
		document.write("<LI>Search is not case sensitive</LI>");
		document.write("<LI>You can include any alphanumeric character and the special characters <b> _ - . ' , $ %</b></LI>");
		document.write("<LI>Add + in front of words that must appear in results. For example, <b>+printer +cartridge +maintenance</b> will find all pages that contain all three words.</LI>");
		document.write("<LI>Add - in front of words that must not appear in results. For example, <b>+printer +cartridge -maintenance</b> will find all pages that have the words \"printer\" and \"cartridg\" but not \"maintenance.\"</LI>");
		document.write("</UL> </div>") 
        return;
    }
		
    if (num_pages > 1)
        document.writeln("<tr><td class=\"info\"><b>" + start_result_number + " - " + end_result_number + "</b> of <b>" + matches + "</b> Results </td>");

// Display the link to previous page if its not the first page
        if (page > 1)
		{
			if (Highlighting == 1)
			{
			document.writeln("<form id=\"formPrev\" method=\"post\" action=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + (page-1) + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=" + sort + "&amp;Highlighting=1" + "\" ><td class=\"prev\">");
			document.writeln("<input type=\"submit\" value=\"" + " << Previous " + "\"  />");
			document.writeln("</td></form>");
			}
			else
			{document.writeln("<form id=\"formPrev\" method=\"post\" action=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + (page-1) + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=" + sort + "\" ><td class=\"prev\">");
			document.writeln("<input type=\"submit\" value=\"" + " << Previous " + "\"  />");
			document.writeln("</td></form>");
			}
		}

// Display link to the next page if its not the last page
		if (page != num_pages)
		{
			if (Highlighting == 1)
			{
			document.writeln("<form id=\"formNext\" method=\"post\" action=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + (page+1) + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=" + sort + "&amp;Highlighting=1" + "\" ><td class=\"next\">");
			document.writeln("<input type=\"submit\" value=\"" + " Next >> " + "\"  />");
			document.writeln("</td></form>");
			}
			else
			{
			document.writeln("<form id=\"formNext\" method=\"post\" action=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + (page+1) + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=" + sort + "\" ><td class=\"next\">");
			document.writeln("<input type=\"submit\" value=\"" + " Next >> " + "\"  />");
			document.writeln("</td></form>");
			}
		}	
		
		document.writeln("</tr></table>");
//        document.writeln("</div></div>");

document.writeln("<div class=\"results\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"each_result\">");

 			

    // determine current line of result from the output array
    if (page == 1) {
        arrayline = 0;
    } else {
        arrayline = ((page - 1) * per_page);
    }

    // the last result to show on this page
    result_limit = arrayline + per_page;

    // display the results
    while (arrayline < matches && arrayline < result_limit) {
        ipage = output[arrayline][0];
        score = output[arrayline][1];
        
        pgurl = pagedata[ipage][PAGEDATA_URL];
        pgtitle = pagedata[ipage][PAGEDATA_TITLE];
        pgdesc = pagedata[ipage][PAGEDATA_DESC];
        pgimage = pagedata[ipage][PAGEDATA_IMG];        
        pgdate = pageinfo[ipage][PAGEINFO_DATETIME];
        filesize = pageinfo[ipage][PAGEINFO_FILESIZE];
        filesize = Math.ceil(filesize / 1024);
        if (filesize < 1)
            filesize = 1;
        catpage = pageinfo[ipage][PAGEINFO_CAT];
        
        urlLink = pgurl;                                        
        if (GotoHighlight == 1 && Highlighting == 1)             
        {
            if (SearchAsSubstring == 1)
                urlLink = AddParamToURL(urlLink, "zoom_highlightsub=" + queryForURL);
            else
                urlLink = AddParamToURL(urlLink, "zoom_highlight=" + queryForURL);
        }       
        if (PdfHighlight == 1)
        {
            if (urlLink.indexOf(".pdf") != -1)
                urlLink = urlLink+"#search=&quot;"+query+"&quot;";
        } 
                

        document.writeln("<tr>");
                    
        //document.writeln("<div class=\"result_title\">");
        if (DisplayNumber == 1)
            document.writeln("<td class=\"number\">" + (arrayline+1) + ".</td>");
            
        if (DisplayTitle == 1)
        {
            document.writeln("<td> <span class=\"title\"><a href=\"" + "../" + urlLink + "\"" + target + ">");
            PrintHighlightDescription(pgtitle);
            document.writeln("</a></span>");
        }        
        else
            document.writeln("<a href=\"" + urlLink + "\"" + target + ">" + pgurl + "</a>");
                   

        
        if (DisplayMetaDesc == 1)
        {
            // print meta description
            document.writeln("<br><span class=\"description\">");            
            PrintHighlightDescription(pgdesc);
            document.writeln("</span>");
        }
        
        info_str = "";
        
        if (DisplayTerms == 1)
            info_str += STR_RESULT_TERMS_MATCHED + " " + output[arrayline][2];
            
        if (DisplayScore == 1) {
            if (info_str.length > 0)
                info_str += "&nbsp; - &nbsp;";
            info_str += STR_RESULT_SCORE + " " + score;
        }
        
        if (DisplayDate == 1 && pgdate > 0) 
        {
            datetime = new Date(pgdate*1000);
            if (info_str.length > 0)
                info_str += "&nbsp; - &nbsp;";
            info_str += datetime.getDate() + " " + months[datetime.getMonth()] + " " + datetime.getFullYear();
        }
             
        if (DisplayURL == 1) 
		{
			if (info_str.length > 0)
                info_str += "&nbsp; - &nbsp;";
            info_str += "../" + pgurl;
		}
                   
        //document.writeln("<div class=\"infoline\">");
        document.writeln("<br> <span class=\"filename\"><a href=\"" + info_str + "\" >");
		document.writeln(info_str);
        document.writeln("</a></span>");      
       // document.writeln("</div></div>\n");
        
        //if (DisplayFilesize == 1)
		//{
            if (info_str.length > 0)
                info_str += "&nbsp; - &nbsp;";
            info_str += filesize + "k";
        //}        
		document.writeln("<span class=\"filesize\"> &nbsp; - &nbsp;" + filesize + "k</span>");
		
		arrayline++;
    }
document.writeln("</td></tr>");
document.writeln("</table></div>");
    // Show links to other result pages
    if (num_pages > 1) {
        // 10 results to the left of the current page
        start_range = page - 10;
        if (start_range < 1)
            start_range = 1;

        // 10 to the right
        end_range = page + 10;
        if (end_range > num_pages)
            end_range = num_pages;

document.writeln("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" class=\"result_info\">");

// Display the link to previous page if its not the first page
        if (page > 1)
		{
			if (Highlighting == 1)
			{
			document.writeln("<form id=\"formPrev\" method=\"post\" action=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + (page-1) + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=" + sort + "&amp;Highlighting=1" + "\" ><td class=\"prev\">");
			document.writeln("<input type=\"submit\" value=\"" + " << Previous " + "\"  />");
			document.writeln("</td></form>");
			}
			else
			{document.writeln("<form id=\"formPrev\" method=\"post\" action=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + (page-1) + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=" + sort + "\" ><td class=\"prev\">");
			document.writeln("<input type=\"submit\" value=\"" + " << Previous " + "\"  />");
			document.writeln("</td></form>");
			}
		}

// Display link to the next page if its not the last page
		if (page != num_pages)
		{
			if (Highlighting == 1)
			{
			document.writeln("<form id=\"formNext\" method=\"post\" action=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + (page+1) + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=" + sort + "&amp;Highlighting=1" + "\" ><td class=\"next\">");
			document.writeln("<input type=\"submit\" value=\"" + " Next >> " + "\"  />");
			document.writeln("</td></form>");
			}
			else
			{
			document.writeln("<form id=\"formNext\" method=\"post\" action=\"" + SelfURL + "?zoom_query=" + queryForURL + "&amp;zoom_page=" + (page+1) + "&amp;zoom_per_page=" + per_page + query_zoom_cats + "&amp;zoom_and=" + andq + "&amp;zoom_sort=" + sort + "\" ><td class=\"next\">");
			document.writeln("<input type=\"submit\" value=\"" + " Next >> " + "\"  />");
			document.writeln("</td></form>");
			}
		}	
		
		document.writeln("</table>");
        document.writeln("</div></div>");
    }
		document.writeln("</tr></table>");
}

