/*

   -----------------------------------------------------------------------------------------------
   ** Original Copyright 
   -----------------------------------------------------------------------------------------------
   This Script was created by Satadip Dutta. 
   Email: sat_dutta@post1.com  / satadipd@inf.com 
   URL:http://dutta.home.ml.org
   Version 1.1-IExp 
   
   Please honor my hard work, if you use a variant of this in your page, 
   then please email me :) and keep these comments in the Script.

   This code is Copyright (c) 1997 Satadip Dutta all rights reserved.

   License is granted to user to reuse this code on their own Web site 
   if, and only if, this entire copyright notice is included. The Web Site
   containing this  script   must be a not-for-profit ( non-commercial ) web site. 
   Exclusive written permission must be obtained before using  this version of the search engine

   -----------------------------------------------------------------------------------------------
   ** Supplemental Copyright
   -----------------------------------------------------------------------------------------------
   Modifications to search logic, .js encapsulation, and cross-browser compatibility
   added by John Cokos, iWeb Inc.  May 2002.
      Copyright (x) 2002, iWeb Inc.   http://www.iwebtechnology.com / http://www.iwebtoolkit.com
   -----------------------------------------------------------------------------------------------
*/



    ttl = new Object();
    desc = new Object();
    keys = new Object();
    links= new Object();    
    matched= new Object();    
    kwords= new Object();
    found= new Object();
    temp=0;
    kwords[0]=0;
    found[0]=0;
    output = '';

    function search() {

        temp=0;
        kwords[0]=0;
        found[0]=0;
        output = '';
        do_search();
        

        return false;
    }


    function do_search(){
		var vari=document.motor.expressao.value;
        
		if (vari.length == 0) {
document.getElementById("navega").innerHTML=""		
document.getElementById("navega").innerHTML+="<ul><li><a href='#'>Pesquisa</a></li></u>"
document.getElementById("Resultados").innerHTML="<h1 class='pagetitle'>OSCACER - Pesquisa</h1>"
document.getElementById("Resultados").innerHTML+="<p><br><b>&nbsp;&nbsp;&nbsp;&nbsp;Caractere inválido.</b></p><img src='./img/2.gif' height='223' width='300' style='float:right;margin: 0 45px 25px 0;' />"
document.motor.expressao.value="Pesquisar..."
}
else if (vari == " "){
document.getElementById("navega").innerHTML=""		
document.getElementById("navega").innerHTML+="<ul><li><a href='#'>Pesquisa</a></li></u>"
document.getElementById("Resultados").innerHTML="<h1 class='pagetitle'>FERLITO - Pesquisa</h1>"
document.getElementById("Resultados").innerHTML+="<p><br><b>&nbsp;&nbsp;&nbsp;&nbsp;Caractere inválido.</b></p><img src='./img/2.gif' height='223' width='300' style='float:right;margin: 0 45px 25px 0;' />"
document.motor.expressao.value="Pesquisar..."
}

else
{		
		
		var skeyword=document.motor.expressao.value.toLowerCase();
       
	  
	   
	   var check=1;
        var pos=0;
        var i=0;
        var j=0;
        var itemp=0;
        var config='';

        while (true) {
            if (skeyword.indexOf("+") == -1 ) {
                kwords[check]=skeyword;
                break;
            }
            pos=skeyword.indexOf("+");
            if (skeyword !="+")	 {
                kwords[check]=skeyword.substring(0,pos);
                check++;
            }
            else {
                check--;
                break;
            }
            skeyword=skeyword.substring(pos+1, skeyword.length);	
            if (skeyword.length ==0) {
                check--;
                break;
            }

        }

        // the keywords have been put in keywords object.
        kwords[0]=check;

        // matching and storing the matches in matched
        for ( i=1; i<=kwords[0];i++) {
            for (j=1;j<=num_titles;j++) {
                if ( keys[j].toLowerCase().indexOf(kwords[i]) > -1 || ttl[j].toLowerCase().indexOf(kwords[i]) > -1 || desc[j].toLowerCase().indexOf(kwords[i]) > -1) {
                    matched[j]++;
                }
            }	
        }


        // putting all the indexes of the matched records  in found
        for (i=1;i<=num_titles;i++) {
            if (matched[i] > 0 ) {
                found[0]++;
                // increment the found 	
                found[found[0]]=i;
            }	
        }



        for (i=1;i<=found[0]-1;i++) {
            for(j=i+1;j<=found[0];j++) {
                if ( matched[found[i]]< matched[found[j]] ) {
                    temp= found[j];
                    found[j]=found[i];
                    found[i]=temp;
                }
            }
        }

        // end of sort

        // SEARCH HEADER //
		document.getElementById("navega").innerHTML=""		
document.getElementById("navega").innerHTML+="<ul><li>Pesquisa</li></ul>"
       document.getElementById("Resultados").innerHTML=""	
		document.getElementById("Resultados").innerHTML+="<h1 class='pagetitle'>FERLITO - Pesquisa</h1>"
document.getElementById("Resultados").innerHTML+="<br><p><b>&nbsp;&nbsp;&nbsp;&nbsp;Resultados para a expressão: '"+ vari +"'</b></p><img src='./img/2.gif' height='223' width='300' style='float:right;margin: 0 45px 25px 0;' />"

        

        // No Results //
        if (found[0]==0) {
          document.getElementById("Resultados").innerHTML+="<p><b>&nbsp;&nbsp;&nbsp;&nbsp;Não foram encontrados resultados nesta pesquisa.</b></p><br/>"
        }

        // Results Found //
        else {
            
         

            for (i=1; i<=found[0];i++) {
           
                itemp=found[i];
               
				
				document.getElementById("Resultados").innerHTML+="<p>&nbsp;&nbsp;&nbsp;&nbsp;<a class=res href='" + links[itemp] +"'> • " + ttl[itemp] +"</a></p>"
		
		document.motor.expressao.value="Pesquisar..."
				
				
				
				matched[itemp]=0
            } 
            found[0]=0;
          
        }

    }

   } 
