// Used by search page
function load_populater(){
  set_selected();
  populate_cat1('searchby1',0);
  populate_search('searchby2');
  set_selected();
}



var all=""; if (document.all) all=".all";
var style=".style"; if (navigator.appName.indexOf('ape')!=-1) style="";
var ape=navigator.appName.indexOf('ape');
var ie=navigator.appName.indexOf('icrosoft');



function populate_search(data){
	mobj=eval('document.aform.'+data);
	var current_value="";
	for(var index=0; index<mobj.length; index++){
		if(mobj.options[index].selected==true) current_value=mobj.options[index].value;
	}
	if((current_value=="zipcode")||(current_value=="company")||(current_value=="keyword")){
		if(navigator.appName.indexOf('ape')!=-1){
			var temp=prompt('Please enter the keyword to search for','');
			if(temp){
				eval('document.aform.'+data+'_r.length=0;');
				eval('document.aform.'+data+'_r.options[document.aform.'+data+'_r.options.length]=new Option(temp,temp);');
				eval('document.aform.'+data+'_r.options[0].selected=1;');
				eval('document.aform.'+data+'_t.value=temp;');
				return;
			}
			else{
				eval('document.aform.'+data+'.options[1].selected=1;');
				populate_search(data);
				return;
			}
		}
		eval('document'+all+'.aform.'+data+'_t'+style+'.visibility="visible";');
		eval('document'+all+'.aform.'+data+'_r'+style+'.visibility="hidden";');
		return;
	}
	else{
		eval('document'+all+'.aform.'+data+'_t'+style+'.visibility="hidden";');
		eval('document'+all+'.aform.'+data+'_r'+style+'.visibility="visible";');
	}
	eval('document.aform.'+data+'_r.length=0;');
	eval('document.aform.'+data+'_r.options[document.aform.'+data+'_r.options.length]=new Option("Select One","");');
	var rec=eval(current_value+'src');
	for (var i=0; i<rec.length-1; i++){
		mtext=rec[i];	mval=rec[i];
		eval('document.aform.'+data+'_r.options[document.aform.'+data+'_r.options.length]=new Option(mtext,mval);');
	}
	eval('document.aform.'+data+'_r.options[0].selected=1;');
}







function populate_cat1(data,whocalledme){
	var rec=categorysrc;
	if(whocalledme<1){
		document.aform.searchby1_r.length=0;	
		eval('document'+all+'.aform.searchby1_r'+style+'.visibility="hidden";');
		document.aform.searchby1_r.options[document.aform.searchby1_r.options.length]=new Option("Select One","");
		document.aform.searchby1_r.options[0].selected=1;
	
		document.aform.searchby3.length=0;	
		eval('document'+all+'.aform.searchby3'+style+'.visibility="hidden";');
		document.aform.searchby3.options[document.aform.searchby3.options.length]=new Option("Not Applicable","");
		document.aform.searchby3.options[0].selected=1;

		document.aform.searchby4.length=0;	
		eval('document'+all+'.aform.searchby4'+style+'.visibility="hidden";');
		document.aform.searchby4.options[document.aform.searchby4.options.length]=new Option("Not Applicable","");
		document.aform.searchby4.options[0].selected=1;
	}




	mobj=eval('document.aform.searchby1');
	var current_value="";
	var current_text="";
	for(var index=0; index<mobj.length; index++){
		if(mobj.options[index].selected==true){
			current_value=mobj.options[index].value;
			current_text=mobj.options[index].text;
		}
	}

	if((current_value=="zipcode")||(current_value=="company")||(current_value=="keyword")){
		if(navigator.appName.indexOf('ape')!=-1){
			var temp=prompt('Please enter the keyword to search for','');
			if(temp){
				eval('document.aform.'+data+'_r.length=0;');
				eval('document.aform.'+data+'_r.options[document.aform.'+data+'_r.options.length]=new Option(temp,temp);');
				eval('document.aform.'+data+'_r.options[0].selected=1;');
				eval('document.aform.'+data+'_t.value=temp;');
				return;
			}
			else{
				eval('document.aform.'+data+'.options[1].selected=1;');
				populate_cat1(data);
				return;
			}
		}
		eval('document'+all+'.aform.'+data+'_t'+style+'.visibility="visible";');
		eval('document'+all+'.aform.'+data+'_r'+style+'.visibility="hidden";');
		return;
	}
	else{
		eval('document'+all+'.aform.'+data+'_t'+style+'.visibility="hidden";');
		eval('document'+all+'.aform.'+data+'_r'+style+'.visibility="visible";');
	}



	for (var i=0; i<rec.length-1; i++){
		if(rec[i].indexOf('0000')!=-1){			
			mtext=rec[i].substr(7,rec[i].length);mval=rec[i].substr(0,6);
			document.aform.searchby1_r.options[document.aform.searchby1_r.options.length]=new Option(mtext,mval);
		}
	}
	document.aform.searchby1_r.options[0].selected=1;
}









function populate_cat2(){
	var rec=categorysrc;
	document.aform.searchby4.length=0;
	eval('document'+all+'.aform.searchby4'+style+'.visibility="hidden";');
	document.aform.searchby4.options[document.aform.searchby4.options.length]=new Option("Not Applicable","");
	document.aform.searchby4.options[0].selected=1;

	document.aform.searchby3.length=0;
	eval('document'+all+'.aform.searchby3'+style+'.visibility="visible";');
	document.aform.searchby3.options[document.aform.searchby3.options.length]=new Option("Not Applicable","");
	document.aform.searchby3.options[0].selected=1;

	//determine the value of the currently select item... Netscape making this difficult. Internet Explorer -way- better!
	mobj=eval('document.aform.searchby1_r');
	var current_value="";
	var current_text="";
	for(var index=0; index<mobj.length; index++){
		if(mobj.options[index].selected==true){
			current_value=mobj.options[index].value;
			current_text=mobj.options[index].text;
		}
	}



	var first_item="";
	if((current_text=="Select One")||(current_text.length<1)) return;
	else first_item="All "+current_text;



	var rec=categorysrc;
	document.aform.searchby4.length=0;
	eval('document'+all+'.aform.searchby4'+style+'.visibility="hidden";');
	document.aform.searchby4.options[document.aform.searchby4.options.length]=new Option("Not Applicable","");
	document.aform.searchby4.options[0].selected=1;


	document.aform.searchby3.length=0;
	eval('document'+all+'.aform.searchby3'+style+'.visibility="visible";');
	document.aform.searchby3.options[document.aform.searchby3.options.length]=new Option(first_item,"");
	document.aform.searchby3.options[0].selected=1;


	var parent_left=current_value.substr(0,2);
	var parent_right=current_value.substr(4,6);


	for (var i=0; i<rec.length-1; i++){
		var test_left=rec[i].substr(0,2);
		var test_right=rec[i].substr(4,2);
		if((parent_left==test_left)&&(parent_right==test_right)&&(current_value!=rec[i].substr(0,6))){
			mtext=rec[i].substr(7,rec[i].length);
			mval=rec[i].substr(0,6);
			document.aform.searchby3.options[document.aform.searchby3.options.length]=new Option(mtext,mval);
		}
	}
	if(document.aform.searchby3.length>0) eval('document'+all+'.aform.searchby3'+style+'.visibility="visible";');
	else eval('document'+all+'.aform.searchby3'+style+'.visibility="hidden";');
}






function populate_cat3(){
	var rec=categorysrc;
	document.aform.searchby4.length=0;
	eval('document'+all+'.aform.searchby4'+style+'.visibility="hidden";');
	document.aform.searchby4.options[document.aform.searchby4.options.length]=new Option("Not Applicable","");
	document.aform.searchby4.options[0].selected=1;


	mobj=eval('document.aform.searchby3');
	var current_value="";
	var current_text="";
	for(var index=0; index<mobj.length; index++){
		if(mobj.options[index].selected==true){
			current_value=mobj.options[index].value;
			current_text=mobj.options[index].text;
		}
	}


	var first_item="";
	if((current_text=="Select One")||(current_text.length<1)||(current_text.substr(0,3)=="All")) return;
	else first_item="All "+current_text;


	var rec=categorysrc;
	document.aform.searchby4.length=0;
	eval('document'+all+'.aform.searchby4'+style+'.visibility="hidden";');
	document.aform.searchby4.options[document.aform.searchby4.options.length]=new Option(first_item,"");
	document.aform.searchby4.options[0].selected=1;

	var parent_left=current_value.substr(0,4);
	for (var i=0; i<rec.length-1; i++){
		var test_left=rec[i].substr(0,4);
		if((parent_left==test_left)&&(current_value!=rec[i].substr(0,6))){
			mtext=rec[i].substr(7,rec[i].length);
			mval=rec[i].substr(0,6);
			document.aform.searchby4.options[document.aform.searchby4.options.length]=new Option(mtext,mval);
		}
	}
	if(document.aform.searchby4.length>0) eval('document'+all+'.aform.searchby4'+style+'.visibility="visible";');
	else eval('document'+all+'.aform.searchby4'+style+'.visibility="hidden";');
}







