var g_block = false;
function fsV(s){
	if(fSI(s)<0)return 0;
	var t=fSIT(s);
	return (t.search(/(Preference|\-\-|Countries)/)==-1 && t.length >2);
}
function RunBasicSearch(prefix,fl){
	var vf;
	if(prefix=="ba_")
		vf=fFRM("A");
	else
		vf=fFRM("W");
	var cmd=vf.cmd.value,ea=vf.elements;
	var cbo=ea[cmd+"State"],e=ea[cmd+"City"],z=ea[cmd+"Zip"],s=ea[cmd+"Sort"];
	if(g_block)return (fl)?void(0):false;
	e.value=fTW(e.value);
	z.value=fTW(z.value);
	if(vf.lcid.value !="en-us" || fSI(cbo)>=66 || (fSI(cbo)==1 && ((prefix=="ba_" && ba_d==1 || prefix=="bw_" && bw_d==1)))){
		//foreign
		if(fIE(e.value) && !fsV(cbo)&& fIE(z.value)){
			alert("You did not select any valid parameters for   \nyour search.\n\nSelect valid search parameters and   \ntry again.\n\n");
			e.focus();return (fl)?void(0):false;}
		if(fSIT(s).length < 3 || (fSIT(s)=="Country")){
			alert("Invalid sort option.\n\nSelect a different sort option   \nand try again.\n\n");
			s.focus();return (fl)?void(0):false;}
	}else{
    		if (fIE(e.value) && !fsV(cbo) && fIE(z.value)){
    			alert("You did not select any valid parameters for   \nyour search.\n\nSelect valid search parameters and   \ntry again.\n\n");
    			e.focus();
    			return (fl)?void(0):false;}
    		if(!fIE(z.value)){
    			if(z.value.length >5 || z.value.search(/[^0-9*]/)!=-1){
    				alert("Invalid zip code.\n\nType a 1-5 digit zip code and try again.   \n\nNote: Wildcard character(s) assumed if zip   \nis less than 5 digits.\n\n");
    				z.focus();z.select();
    				return (fl)?void(0):false;}}
    		var st=fSIT(cbo);
    		if(st.search(/(Countries|--)/)!=-1){
    			alert("Invalid state selection.\n\nSelect a state or country and try again.   \n\n");
    			cbo.focus();return (fl)?void(0):false;}
     		var strsort=fSIT(s);
     		if(strsort.length <3){
     			alert("Invalid sort option.\n\nSelect a sort option and try again.   \n\n");
     			s.focus();return (fl)?void(0):false;}
     		if((st.length >3 && st !="District of Columbia") && strsort=="State"){
     			alert("Invalid sort option.\n\nYou cannot sort by State when you have   \nnarrowed your search to a State.\n\nSelect a different sort option and try again.   \n\n");
     			s.focus();return (fl)?void(0):false;}
     		if(st=="District of Columbia" && (strsort !="Zip" && strsort !="Post Date")){
     			alert("Invalid sort option.\n\nThe District of Columbia cannot be sorted   \nby city, state, or county.\n\nSelect a different sort option and try again.   \n\n");
     			s.focus();return (fl)?void(0):false;}}
	g_block=true; 
	if(!fIE(e.value)){
		if(window.frames[prefix+"City_frame"].ih_fLAU){
			window.frames[prefix+"City_frame"].ih_fLAU(new Array(e.value,"all"));}}
	if(!fIE(z.value)){
		if(window.frames[prefix+"Zip_frame"].ih_fLAU){
		window.frames[prefix+"Zip_frame"].ih_fLAU(new Array(z.value,"all"));}}
	vf.submit();g_block=false;return void(0);
}

function ResetForm(p,fl){
	var msg;
	if(p=='bw_'){
		p='bwclear';msg="Reset assistants wanted basic search?  \n\n";
	}else{
		p='baclear';msg="Reset assistants available basic search?  \n\n";}
	if(!confirm(msg))return (fl)?void(0):false;
	document.location.href="index.php?cmd="+p; 
	return true; 
}
function bs_OptRename(id,f,t){
	var cbo=fID(id); 
	for(var i=0;i<cbo.options.length;i++){if(cbo.options[i].text==f){cbo.options[i].text=t;}}
	return 1;
}
function bs_OptRemove(id,t){
	var cbo=fID(id);
	for(var i=0;i<cbo.options.length;i++){
		if(cbo.options[i].text==t){cbo.remove(i);}}
	return 1; 
}
function bs_OptAdd(id,t){
	var cbo=fID(id);
	for(var i=0;i<cbo.options.length;i++){
		if(cbo.options[i].text==t){return 1;}}
	var n=fCE("OPTION");n.text=t;
	if(g_b=='ms')
		cbo.add(n);
	else
		cbo.add(n,null);return 1;
}
function bs_OptSel(id,t){
	var cbo=fID(id);
	for(var i=0;i<cbo.options.length;i++){
		if(cbo.options[i].text==t){cbo.options[i].selected=true;break;}}
	return 1; 
}
function bs_OptClean(id){
	var cbo=fID(id);
	for(var i=0;i<cbo.options.length;i++){
		if(cbo.options[i].text.search(/\S+/)==-1){
			cbo.remove(i);}}
	return 1; 
}
function bs_View(p){
	var cbo=fID(p+"State"),a,ud=0;
	if(p=="ba_" && ba_d>0){
		ud=1;
	}else if(p=="bw_" && bw_d>0){
		ud=1;}
	var isdc=(fSIT(cbo).toLowerCase()=="district of columbia");
	if(fSI(cbo) >=66 || (fSI(cbo)==1 && ud==1)){
		a=((g_b=="ms")?"block":"table-row");
		a=new Array("none","block","none","block","none","Zip","Postal Code",a);
		bs_OptRemove(p+"Sort","County");
	}else{
		if(isdc){
			a="none";
		}else{
			a=((g_b=="ms")?"block":"table-row");}
		a=new Array("block","none","block","none","block","Postal Code","Zip",a);
		bs_OptAdd(p+"Sort","County");}
	fIS(p+"StateLabel").display=a[0];
	fIS(p+"StateLabelCountry").display=a[1];
	fIS(p+"ZipLabel").display=a[2];
	fIS(p+"ZipLabelCountry").display=a[3];
	bs_OptRename(p+"Sort",a[5],a[6]);
	fIS(p+"CityTD").display=a[7];
	var s=fSIT(cbo);
	if(s.search(/\S+/)==-1){
		bs_OptAdd(p+"Sort","State");
	}else{
		bs_OptRemove(p+"Sort","State");}
	cbo=fID(p+"Sort");
	if(fSIT(cbo).length < 3){bs_OptSel(p+"Sort","City");}
	if(isdc){if(fSIT(cbo)!="Zip" && fSIT(cbo)!="Date"){bs_OptSel(p+"Sort","Zip");}}
	h_fHP("ba_Zip");h_fHP("bw_Zip");
	return 1;
}
function bs_Viewf(p){
	var cbo=fID(p+"State");
	var s=fSIT(cbo);
	if(s.search(/\S+/)==-1){
		bs_OptAdd(p+"Sort","Country");bs_OptRemove(p+"Sort","State");
	}else{
		bs_OptRemove(p+"Sort","Country");}
	cbo=fID(p+"Sort");
	if(s=="United States"){
		bs_OptAdd(p+"Sort","State");
		if(fSIT(cbo).length<3){bs_OptSel(p+"Sort","State");}
	}else{
		bs_OptRemove(p+"Sort","State");
		if(fSIT(cbo).length<3){bs_OptSel(p+"Sort","City");}}
	fIS(p+"CityTD").display=((g_b=="ms")?"block":"table-row");
	return 1;
}
function ShowRecord(id,db){
	g_ol+=12;g_ol=(g_ol>48)?-48:g_ol;
	var cx=((g_scr.width-625)/2)+g_ol,cy=((g_scr.height-475)/2-25)+g_ol;
	g_win_viewer=window.open("view.php?db="+db+"&record="+id+"&v="+fGC('PHPSESSID'),"","toolbar=0,height=475,width=625,left="+cx+",top="+cy+",screenX="+cx+",screenY="+cy+",scrollbars=1,resizable=1,status=1");
	if(!g_win_viewer){
		alert("The Viewer window failed to open.\n\nUpdate your browser settings to allow \npopups for this Site.\n\nYou may also search to locate the record and\ndisplay it manually.\n");
	}else{g_win_viewer.focus();}			
}
