   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();
        show_output();
        return false;
    }
    function do_search(){
        var skeyword=document.searchengine.keywords.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 //



output = output + "<html><head><title>KARNATAKA POWER CORPORATION LTD</title><link href='theme/set.css' rel='stylesheet' type='text/css'>";

output = output + " <script language='JavaScript' type='text/JavaScript'> "
output = output + " <!-- "
output = output + " function MM_reloadPage(init) {   "
output = output + "   if (init==true) with (navigator) {if ((appName=='Netscape')&&(parseInt(appVersion)==4)) { "
output = output + "     document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }} "
output = output + "   else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload(); "
output = output + " } "
output = output + " MM_reloadPage(true); "
output = output + " //--> "
output = output + " </script> "
output = output + "    <script language='javascript' src='search.js'></script>"
output = output + "     <script language='javascript' src='data.js'></script> "
output = output + "     <!-- This is for netscape, don't mess with it.... -->"
output = output + "     <style>#SEARCHOUT { visibility:show; position:relative;}</style> "

output = output + "</head><body topmargin='2'>";
output = output + "<table width='800' border='0' cellspacing='0' cellpadding='0' style='border-collapse: collapse'  bordercolor='#111111' height='90'><tr><td colspan='2' width='724' height='19'>";
output = output + "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='789' id='AutoNumber11'>";
output = output + "<tr><td width='27' rowspan='2'>&nbsp;</td>";
output = output + "<td width='449' rowspan='2'><a href='index.htm'>";
output = output + "<img border='0' src='images/banner.gif' width='766' height='96'></a></td>";
output = output + "<td width='323'>&nbsp;</td></tr><tr>";

output = output + "<table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='110%' id='AutoNumber13' height='63'>";
output = output + "<tr><td width='100%' colspan='3' height='19'>&nbsp;</td></tr><tr>";
output = output + "<td width='100%' colspan='3' height='25'>&nbsp;</td></tr><tr>";
output = output + "<td width='10%' height='19'>&nbsp;</td><td width='6%' height='19'>&nbsp;</td>";
output = output + "<td width='84%' height='19'><b><font face='Verdana' style='font-size: 9pt'>";

output = output + "</table></td></tr><tr><td colspan='2' width='724' height='1'><b>";
output = output + "<font size='2' face='Arial' color='#000080'>";

output = output + "</tr><tr><td width='173' height='1'></td><td width='632' height='1'>";

output = output + "</tr></table>";
output = output + " <td width='328'> <FORM  NAME='searchengine' onSubmit='return search()'>"
output = output + " <p align='right'><font face='Arial' style='font-size: 9pt'>&nbsp;&nbsp;&nbsp;&nbsp; Search "
output = output + " </font><font size='1' face='Arial'> "
output = output + " <INPUT TYPE='text'  NAME='keywords' VALUE=''  MAXLENGTH=40 size='10'>"
output = output + " <INPUT TYPE='submit' NAME='go' VALUE='go'></FORM> </font></td></p>"



	
        output = output + "<font face='Verdana' style='font-size: 9pt'>Search Results for: <B>";    
        for (i=1;  i<=kwords[0]; i++) {
            output = output +  kwords[i].bold() + "   ";
        }
        output = output + '</B>';
        // No Results //
        if (found[0]==0) {
            output = output + "<HR><BR><BR><b>No matches resulted in this search </b> <br>";
            output = output + "You may close the results and reduce the length/number  of the keywords  <br>";
        }
        // Results Found //
        else {
           
           output = output + "[" + found[0] + "  Matches  " . italics();
            output = output + "]<hr color='#000000' align='left' width='400'><BR><OL>";
            for (i=1; i<=found[0];i++) {
                output = output + "<LI>";
                itemp=found[i];
                output = output + ttl[itemp].bold() + "<br>";
                output = output + desc[itemp] + "<br>";
                output = output + links[itemp].link(links[itemp])+"<br>";
                temp= (matched[itemp]/kwords[0])*100
                output = output + "<i>" +temp+" %  </i><P>" ;
                matched[itemp]=0
            } 
            found[0]=0;
            output = output + "</OL>";
        }
    }
    function show_output() {
            var NS4 = (document.layers) ? 1 : 0;
            var IE = (document.all) ? 1 : 0;
            var DOM = 0; 
            var Opera = 0;
            if (parseInt(navigator.appVersion) >=5) {DOM=1};
            if ( (navigator.userAgent.indexOf("Opera 6")!=-1) || (navigator.userAgent.indexOf("Opera/6")!=-1) ) {
                 DOM = 0;
                 IE = 0;
                 Opera = 1;
            }
            target=('SEARCHOUT');
               
                if (DOM || IE) {
 
    config='toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1'
                    win = window.open ("searchresult.htm","outputwindow",config)
                    
                    win.document.write(output);
                    win.document.close();
		
                }
                    
                else if (NS4 || Opera) {
                    config='height=400,width=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes'
                    win = window.open ("","outputwindow",config)
                    win.document.open();
                    win.document.write(output);
                    win.document.close();
                }
                    
                // && (version >=4)
                else {
                    alert("get a real browser");
                }
            }