/*************************************************************************

    chm2web Search Library 1.1
    Copyright (c) 2002-2003 A!K Research Labs (http://www.aklabs.com)  
    http://chm2web.aklabs.com - HTML Help Conversion Utility

    Tested with: Internet Explorer 5, Opera 6, Mozilla 1.2, NN6

    ATTENTION! You can use this library only with web help system 
               generated by chm2web software.  
               
**************************************************************************/

function Search(s)
{
if(!s||!ValidateRequest(s))
return false;
document.forms['searchform'].founddocslist.length=0;
request=PrepareRequest(s).split("\x20");
var docs=RecursiveSearch(0,true,[]);
if(!docs.length)
alert("No matches found!");
else
for(var i=0;i<docs.length;i++)
{
var e=document.createElement("OPTION");
e.text=SearchTitles[docs[i]];
e.value=SearchFiles[docs[i]];
document.forms['searchform'].founddocslist[document.forms['searchform'].founddocslist.length]=e;
}
return true;
}
var request=[];
var browser="ie";
var bn=window.navigator.appName;
var ver=navigator.appVersion;
ver=parseFloat(ver.indexOf('MSIE')>0?ver.split(';')[1].split(' ')[2]:ver.split(' ')[0]);
if(navigator.userAgent.indexOf('Opera')!=-1&&ver>=4)
browser="opera";
else
if(bn.indexOf('Netscape')!=-1)
browser="netscape";
function PrepareRequest(req)
{
var regexp=/(\x20\x20)/g;
while(req.match(regexp))
req=req.replace(regexp,"\x20");
regexp=/(^\x20)|(\x20$)/g;
while(req.match(regexp))
req=req.replace(regexp,"");
return req;
}
function ValidateRequest(s)
{
var regexp="/[`~!@#\\$%\\^&\\*\\(\\)\\-\\+=\\{\\}\\[\\]\\|\\\\<\\>,\\.\\?/;:\\'\\\"]/g";
if(s.match(regexp))
{
alert("Invalid character at position "+(regexp.exec(s).index+1)+"!");
return false;
}
return true;
}
function ANDarrays(a,b)
{
var c=[];
for(var i=0;i<a.length;i++)
for(var j=0;j<b.length;j++)
if(a[i]==b[j])
c[c.length]=a[i];
return c;
}
function ORarrays(a,b)
{
var c=b;
var f;
for(var i=0;i<a.length;i++)
{
f=false;
for(var j=0;j<b.length;j++)
{
if(a[i]==b[j])
{
f=true;
break;
}
}
if(!f)
c[c.length]=a[i];
}
return c;
}
function RecursiveSearch(indx,action,resultsarr)
{
if(indx==request.length)
return resultsarr;
if(request[indx]=="OR")
return RecursiveSearch(indx+1,false,resultsarr);
else
if(request[indx]=="AND")
return RecursiveSearch(indx+1,true,resultsarr);
else
for(var i=0;i<SearchIndexes.length;i++)
if(SearchIndexes[i][0]==request[indx].toUpperCase())
{
if(action)
if(indx)
resultsarr=ANDarrays(resultsarr,SearchIndexes[i][1]);
else
resultsarr=SearchIndexes[i][1];
else
resultsarr=ORarrays(resultsarr,SearchIndexes[i][1]);
return RecursiveSearch(indx+1,true,resultsarr);
}
if(action)
if(indx)
return[];
else
return RecursiveSearch(indx+1,true,resultsarr);
else
return resultsarr;
}
var w=null;
function Hilight(){
if((w.document.readyState!='complete')&&(w.document.readyState!='loaded'))
var t=setTimeout('Hilight()',100);
else{
var dbody=w.document.body;
for(var r=0;r<request.length;r++)
if((request[r]!="OR")&&(request[r]!="AND"))
{
var rng=dbody.createTextRange();
if(rng!=null){
for(var i=0;i<100;i++){
rng.moveStart("word",1);
if(!rng.findText(request[r]))break;
rng.pasteHTML("<span style='background-color:#FFFF00'>"+
rng.text+"</span>");
}
}
}
}
}
function OpenFoundDoc()
{
w=open(document.forms['searchform'].founddocslist.options[document.forms['searchform'].founddocslist.selectedIndex].value,'content');
if(browser=='ie')
Hilight();
}
