function fsV(s){
	if(fSI(s)<0)return 0;
	var t=fSIT(s);
	return (t.search(/(Preference|\-\-|Countries)/)==-1 && t.length >1);}
var g_block=false;
function fV(f){
	var srt,srt2,strstate,cbo;
	strstate=fSIT(f.aa_State);
	cbo=fID("aa_State");
	f.aa_City.value=fTW(f.aa_City.value);f.aa_Zip.value=fTW(f.aa_Zip.value);
	if(fSI(cbo)>=66 || (fSI(cbo)==1 && aa_d>0) || f.lcid.value!="en-us"){
		//foreign
		if(!fsV(f.aa_IsAgency) && !fsV(f.aa_CreationDate ) && !fsV(f.aa_State) && !fsV(f.aa_Car) && !fsV(f.aa_Salary) && !fsV(f.aa_Shifts) && !fsV(f.aa_HrWrk) && !fsV(f.aa_Education) && !fsV(f.aa_Screened) && !fsV(f.aa_WorksWith) && !fsV(f.aa_ADLs) &&  !fsV(f.aa_IADLs) && !fsV(f.aa_OADLs) && fIE(f.aa_City.value) && fIE(f.aa_Zip.value)  && !fsV(f.aa_Days) && !fsV(f.aa_ReferencesAvailable) && fIE(f.aa_AgencyName.value) && fIE(f.aa_ScreenName.value) && fIE(f.aa_FirstName.value) && fIE(f.aa_LastName.value) && fIE(f.aa_Email.value) && fIE(f.aa_Phone.value) && fIE(f.aa_ONotes.value)  ){
			alert("Missing or invalid search parameters.\n\nSelect search parameters and try again.   \n\n");
			f.aa_City.focus();return false;}
		if(fSIT(f.aa_State).length >4){
			if(!fsV(f.aa_State)){
				alert("Invalid country selection.\n\nSelect a country and try again.   \n\n");
				f.aa_State.focus();return false;}}
	}else{
		f.aa_County.value=fTW(f.aa_County.value); 
		if(!fsV(f.aa_IsAgency) && !fsV(f.aa_CreationDate ) && !fsV(f.aa_State) && !fsV(f.aa_Car) && !fsV(f.aa_Salary) && !fsV(f.aa_Shifts) && !fsV(f.aa_HrWrk) && !fsV(f.aa_Education) && !fsV(f.aa_Screened) && !fsV(f.aa_WorksWith) && !fsV(f.aa_ADLs) &&  !fsV(f.aa_IADLs) && !fsV(f.aa_OADLs) && fIE(f.aa_City.value) && fIE(f.aa_County.value) && fIE(f.aa_Zip.value) && !fsV(f.aa_Days) && !fsV(f.aa_ReferencesAvailable) && fIE(f.aa_AgencyName.value) && fIE(f.aa_ScreenName.value) && fIE(f.aa_FirstName.value) && fIE(f.aa_LastName.value) && fIE(f.aa_Email.value) && fIE(f.aa_Phone.value) && fIE(f.aa_ONotes.value) ){
			alert("Missing or invalid search parameters.\n\nSelect search parameters and try again.   \n\n");
			f.aa_City.focus();return false;}
		if(fSIT(f.aa_State).length >4){
			if(!fsV(f.aa_State)){
				alert("Invalid state selection.\n\nSelect a state and try again.   \n\n");
				f.aa_State.focus();return false;}}
		if(!fIE(f.aa_Zip.value)){
			if(f.aa_Zip.value.length >5 || f.aa_Zip.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");
				f.aa_Zip.focus();
				return false;}}}

	var isdc=(fSIT(cbo).toLowerCase()=="district of columbia");
	if(isdc){
		if(fSIT(f.aa_Sort)=="County" || fSIT(f.aa_Sort)=="City"){
			as_OptSel("aa_Sort","Zip");}			
		if(fSIT(f.aa_Sort2)=="County" || fSIT(f.aa_Sort2)=="City"){
			if(fSIT(f.aa_Sort2)=="Zip")
				as_OptSel("aa_Sort2","Post Date");
			else
				as_OptSel("aa_Sort2","Zip");
		}			
		if(fSIT(f.aa_Sort)==fSIT(f.aa_Sort2)){
			if(fSIT(f.aa_Sort)=="Zip")
				as_OptSel("aa_Sort2","Post Date");
			else if(fSIT(f.aa_Sort)=="Post Date"){
				as_OptSel("aa_Sort2","Zip");}}}
	srt=fSIT(f.aa_Sort);
	srt2=fSIT(f.aa_Sort2);
	if(srt.length < 3 || srt2.length < 3){
		alert("Invalid sort option.\n\nOne or both sort options is missing.   \n\nSelect sort options and try again.   \n\n");
		f.aa_Sort.focus();return false;}
	if((strstate.length > 3 && strstate !="District of Columbia") && srt=="State"){
		alert("Invalid first 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");
		f.aa_Sort.focus();return false;}
	if((strstate.length >3 && strstate !="District of Columbia") && srt2=="State"){
		alert("Invalid second 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");
		f.aa_Sort2.focus();return false;}
	if(strstate=="District of Columbia" && (srt=="City" || srt=="State" || srt=="County")){
		alert("Invalid first 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");
		f.aa_Sort.focus();return false;}
	if(strstate=="District of Columbia" && (srt2=="City" || srt2=="State" || srt2=="County") ){
		alert("Invalid second 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");
		f.aa_Sort2.focus();return false;}
	if(srt===srt2){
		alert("Invalid sort option.\n\nThe first and second sort options   \ncannot be the same.\n\nSelect different sort options and try again.   \n\n");
		f.aa_Sort.focus();return false;}
	if(!fsV(f.aa_ResultsPerPage)){
		alert("Invalid results per page selection.\n\nSelect the number of results to display per page  \nand try again.\n\n");
		f.aa_ResultsPerPage.focus();return false;}
	return true;}
function ClearFields(fl){
	if(!confirm("Reset advanced assistant available   \nsearch session?"))return (fl)?void(0):false;
	document.location.href='advsearcha.php?cmd=new';return true;}
function fSubmit(fl){
	if(g_block)return (fl)?void(0):false;
	var frm=fID('frmmain');
	if(fV(frm)){
		g_block=true;
		var a=new Array("City","Zip","County","ScreenName","FirstName","LastName","Email","Phone","AgencyName","ONotes"),e;
		for(var i=0;i<a.length;i++){
			e=fID("aa_"+a[i]);
			if(e){
				if(!fIE(e.value)){
					if(window.frames["aa_"+a[i]+"_frame"].ih_fLAU){
						window.frames["aa_"+a[i]+"_frame"].ih_fLAU(new Array(e.value,"all"));}}}}
		frm.submit();
		g_block=false;return void(0)
		g_block=false;return true;}
	return (fl)?void(0):false;}
function as_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 as_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);break;}}
	return 1;}
function as_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 as_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 as_View(p){
	var cbo=fID(p+"State"),a,isdc=0;
	if(fSI(cbo)>=66 || (fSI(cbo)==1 && aa_d>0)){
		a=((g_b=="ms")?"block":"table-row");
		a=new Array("none","block","none","block","none","Zip","Postal Code",a);
		as_OptRemove(p+"Sort","County");as_OptRemove(p+"Sort2","County");
		a[8]="none";
	}else{
		isdc=(fSIT(cbo).toLowerCase()=="district of columbia");
		if(isdc){
			a="none";
		}else{
			a=((g_b=="ms")?"block":"table-row");}
		a=new Array("block","none","block","none","block","Postal Code","Zip",a);
		a[8]=a[7];
		as_OptAdd(p+"Sort","County");as_OptAdd(p+"Sort2","County");}
	fIS(p+"CityTD").display=a[7];fIS(p+"CountyTD").display=a[8];fIS(p+"StateLabel").display=a[0];
	fIS(p+"StateLabelCountry").display=a[1];fIS(p+"ZipLabel").display=a[2];fIS(p+"ZipLabelCountry").display=a[3];
	if(a[3]=="block"){
		fID(p+"Zip").title=fID(p+"ZipLabelCountry").title; 
	}else{
		fID(p+"Zip").title=fID(p+"ZipLabel").title;}
	fIS(p+"CountyLabel").display=a[4];
	as_OptRename(p+"Sort",a[5],a[6]);as_OptRename(p+"Sort2",a[5],a[6]);
	var s=fSIT(cbo);
	if(s.search(/\w+/)==-1){
		as_OptAdd(p+"Sort","State");as_OptAdd(p+"Sort2","State");
	}else{
		as_OptRemove(p+"Sort","State");as_OptRemove(p+"Sort2","State");}
	cbo=fID(p+"Sort");
	if(fSIT(cbo).length < 3){as_OptSel(p+"Sort","City");}
	if(fSIT(fID(p+"Sort2")).length < 3){as_OptSel(p+"Sort2","City");}
	if(a[7]!="none"){
		h_fHP(p+"City");
	}else{
		h_fHG2(p+"City_");}
	h_fHP(p+"Zip");
	if(a[8]!="none"){
		h_fHP(p+"County");
	}else{
		h_fHG2(p+"County_");}
	return 1;
	 
}
function as_Viewf(p){
	var cbo=fID(p+"State"); 
	var s=fSIT(cbo);
	if(s.search(/\w+/)==-1){
		as_OptAdd(p+"Sort","Country");as_OptRemove(p+"Sort","State");as_OptAdd(p+"Sort2","Country");as_OptRemove(p+"Sort2","State");
	}else{
		as_OptRemove(p+"Sort","Country");as_OptRemove(p+"Sort2","Country");}
	cbo=fID(p+"Sort");
	if(s=="United States"){
		as_OptAdd(p+"Sort","State");as_OptAdd(p+"Sort2","State");
		if(fSIT(cbo).length <3){as_OptSel(p+"Sort","State");}
		if(fSIT(fID(p+"Sort2")).length <3){as_OptSel(p+"Sort2","State");}
	}else{
		as_OptRemove(p+"Sort","State");as_OptRemove(p+"Sort2","State");
		if(fSIT(cbo).length < 3){as_OptSel(p+"Sort","City");}
		if(fSIT(fID(p+"Sort2")).length < 3){as_OptSel(p+"Sort2","City");}}
	return 1;}
function as_Clear(e){
	fID(e).selectedIndex=-1;
	return 1;}
function as_ViewA(p){
	var cbo=fID(p+'IsAgency');
	var e=fIS(p+'AgencyNameTD');
	if(fSIT(cbo)=='Individuals Only'){
		e.display='none';
	}else{
		e.display='block';
	}

}