//*****************************************************
//Property of Herrick Filter Manufacturing Corporation
//Author: Harren Chua
//Copyright @ HFMC2002
//All materials are property of HFMC
//*****************************************************
//                  SEARCH PROGRAM
//*****************************************************

sid="HFMC";

 function makeArray(n) {
                this.length = n;
                for (var k = 1; k <= n; k++) {
                                this[k] = "";
                }
                return this;
        } 

//these are the search specific functions
function stripInput(key) {

var chr = "ok";


//strip any leading commas,spaces or quotes
        while(key.substring(0,1) == ","  || key.substring(0,1) == " " || key.substring(0,1) == '"' ) { 
                key = key.substring(1,key.length);}

//strip any trailing commas,spaces or quotes
        while(key.substring(key.length-1,key.length) == "," || key.substring(key.length-1,key.length) == " " || key.substring(key.length-1,key.length) == '"') {
                key = key.substring(0,key.length-1);}
 
        return key;
}

function parseIt(key) {
        key = stripInput(key);
        key+=",";
        var y = 1;
while(key.indexOf(",") > 0) {
        var pos = key.indexOf(",");
        keywords[y]=key.substring(0,pos);
        keywords[y] = stripInput(keywords[y]);//take off any spaces after the ","
        //alert(keywords[y]);
        y++;

        if(y > 11) {
                writeOutput("Too many search words");
		    writeOutput("Please re-enter key words.");
                return -1;}
        key=key.substring(pos+1,key.length);}
        return y-1;
}

var keywords = new makeArray(11);

//initialize search keyword array
function clearSearch(form) {
 
        for(var x=1;x <= 11; x++) {
                keywords[x]=""; }
 
}

function writeOutput(outString) {
        parent.output.document.open(); 
        parent.output.document.write(outString);
        parent.output.document.close();
}

        function dataEntry (){
                this.v1= "";
                this.v2="";
                this.v3 = "";
                this.v4 = "";
                this.v5 = "";
                this.v6 = "";
                this.v7 = ""; 
                return this;
        }


function makeRecordLinks(size) {
        this.length = size;
                for (var r=1; r<= size; r++) {
                this[r] = new dataEntry();
                this[r].v1= v1[r];
                this[r].v2 = v2[r];
                this[r].v3 = v3[r];
                this[r].v4 = v4[r];
                this[r].v5 = v5[r];
                this[r].v6 = v6[r];
                this[r].v7 = v7[r]; }
                return this;
                        }

function searchAll(keyword) {

var nw=1;
        clearSearch(document.searchform);
        var x = parseIt(keyword);

        if(x == -1) {   //abort on failed parse
                return;}

        if(keyword =="" || keyword.length < 2) {
                writeOutput("<body background='' body bgcolor=white text=black><center><img src='images/logo_koji.gif'></center><br><br><font face='Tahoma' size='-1'><B>Please enter a valid search string and retry your search.<P>Possible reasons for an invalid string are:<p><ul><li>Null Entry<li>Less than two characters</ul></b></font> <p align='center'><hr><br> </p>");
                return; }

        parent.output.document.open();
        parent.output.document.clear();
        parent.document.close();
        while(keywords[nw].length > 1) {
                search(new  makeRecordLinks(records_count),keywords[nw]);
                nw++;} 

//done to placate MSIE
                if (navigator.appName != "Netscape"){
                        parent.output.document.close();}
}

function printRecords(records,q) {
        while(sid!="HFMC") {};
        parent.output.document.write("<tr><td><font face='Tahoma' size='-1'>" + records[q].v1 +"</font></td>");
        parent.output.document.write("<td><font face='Tahoma' size='-1'>" + records[q].v2 +"</font></td>");
        parent.output.document.write("<td><font face='Tahoma' size='-1'>" + records[q].v3 +"</font></td>");
        parent.output.document.write("<td><font face='Tahoma' size='-1'>" + records[q].v4 + "</font></td>");
        parent.output.document.write("<td><font face='Tahoma' size='-1'>" + records[q].v5 + "</font></td>");
        parent.output.document.write("<td><font face='Tahoma' size='-1'>" + records[q].v6 + "</font></td>");
        parent.output.document.write("<td><font face='Tahoma' size='-1'>" + records[q].v7 + "</font></td></tr>");
 
}


