//WVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWV  JSSE's BRAIN  WVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWVWV

stopw=["the","and","for","with","I","is","it"];
srchtype=0;//----------------- 1=exact match   0=by keyword
dresults="";
matchcount=0;
matchs=0;

function triggersrch(eee,toserfo){
	if(window.event){//-----------for different browser thing.
		kikod=window.event.keyCode;
	}else if(eee){
		kikod=eee.which;
	}
	if(kikod==13){
		coresearch(toserfo);
	}
}


//(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)   START SEARCH!   (+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)(+)
function coresearch(tofilter){

	totop();//--------------------call this function just in case it got disabled by to many results
	if(tofilter.charAt(0)=='\"' && tofilter.charAt(tofilter.length-1)=='\"'){//-----------see if exact match is wanted
		srchtype=1;
		tofilter=tofilter.substring(1,tofilter.length-1);//---------understood that exact match is searched for
														 //---------so can remove quotes
	}

	if(tofilter.length<3){//>-------------------check if the search is too short (less than 3 characters)
						  //-------------------if too short, alert
		parent.document.getElementById("resher").style.borderLeft="0px solid";
		parent.document.getElementById("resher").innerHTML="<b>Your search term is too vague.  Please be more specific.</b>";
		
	}else{//-----------------------------------do further formating
		while(tofilter.charAt(0)==" "){//----------------strip off the spaces at the ends of the input
			tofilter=tofilter.substring(1,tofilter.length);
		}
		while(tofilter.charAt(tofilter.length-1)==" "){
			tofilter=tofilter.substring(0,tofilter.length-1);
		}
		//parent.document.getElementById("resher").innerHTML=tofilter+"   "+srchtype;

		if(srchtype==0){//-------------------------------------split string into array
						//-------------------------------------if not quoted, split() and filter
			tofilter=tofilter.split(" ");

			//--------------------------------------filter out stop words
			filtered=new Array();
			gotstopw=0;
			for(p=0; p<tofilter.length; p++){
				for(q=0; q<stopw.length; q++){
					if(tofilter[p].toLowerCase()==stopw[q].toLowerCase()){
						gotstopw=1;
						break;
					}
				}
				if(!gotstopw){
					filtered[filtered.length]=tofilter[p];
				}else{
					gotstopw=0;
				}
			}
		}else{
			filtered=new Array();
			filtered[filtered.length]=tofilter;
		}

		//----------------------->---------------start checking and matching and displaying
		thescanner(wholehelp,filtered);

		//--------------------------------------return all the globals to normal
		dresults="";
		srchtype=0;
	}
}


function thescanner(rsar,tomatch){//----------------------look for matches for top-most level
							  //----------------------the top-most level has all the root topics and do not follow the
						 	  //----------------------record pattern - means that can have more then 3 elements
				//------------------------------------this is going to have 3 elements where the third one is the sub
				//------------------------------------which will always be an array

	for(r=0; r<rsar.length; r++){
		//------------------------>--------------------put the description together with the title
		tocompare=rsar[r][1].toLowerCase()+" "+rsar[r][2].toLowerCase();

		for(s=0; s<tomatch.length; s++){//------->-----matching....
			insearch=tomatch[s].toLowerCase();
			if(tocompare.indexOf(insearch)!=-1){
				//------------------------------------don't break.  See if matches other words too.
				matchcount++;
			}
		}

		if(matchcount==tomatch.length){//-------------if there are matches for all keywords, insert into display string
			
			matchs++;//-------------------------------count the number of matches
			oc="";
			marginl=0;
			for(t=1; t<=rsar[r][0].length; t++){
				//--->---------------------------------format open functions
				oc+="topen('t"+rsar[r][0].substring(0,t)+"','box"+rsar[r][0].substring(0,t)+"');";
				marginl+=10;
			}

			if(rsar[r][2].length>30){//-----------------------------------cut long descriptions
				rsar[r][2]=rsar[r][2].substring(0,50)+"...";
			}

			//----------------------------------->----display the results
			dresults+="<div style='margin-left: "+marginl+"px;'><b><a href='#t"+rsar[r][0]+"' onclick="+oc+"document.getElementById('t"+rsar[r][0]+"').focus();glower(10,'g"+rsar[r][0]+"',0);>"+rsar[r][1]+"</a></b><br><span>"+rsar[r][2]+"</span></div>";
		}

		matchcount=0;
	}
	if(matchs>15){
		window.onscroll=function(){
			parent.document.getElementById("hetop").style.bottom=(100-document.documentElement.scrollTop)+"px";
		}
	}
	matchs=0;

	if(dresults!=""){
		parent.document.getElementById("resher").innerHTML=dresults;
		parent.document.getElementById("resher").style.borderLeft="1px solid #99deff";
	}else{
		parent.document.getElementById("resher").style.borderLeft="0px solid";
		parent.document.getElementById("resher").innerHTML="<center><b>No results found</b></center>";
	}
}



