function num_sel ( fld ) {
	var ct = 0;
	for( x = 0; x < fld.length; x++ ){ if( fld[x].selected ) { ct++ } }
	return ct;
}

function is_ok( fld, maxnum, imgid ){
	var count = num_sel( fld );

	if( imgid != "" ) { document.images[imgid].src = ( ( ( count <= maxnum ) && ( count >= 0 ) ) ? "/img/blank.gif" : "/img/icon-invalid.gif" ); }

// if( count > maxnum ) { alert( imgid + ' = ' + document.images[imgid].src ); }

	return ( ( count <= maxnum ) && ( count >=0 ) );
}

function validate_form( searchform ) {
	var errtxt = '';
	if( searchform.f && ! is_ok( searchform.f, 4, '' ) ) { errtxt += "You can only select up to 4 functions!\n"; }
	if( searchform.s && ! is_ok( searchform.s, 4, '' ) ) { errtxt += "You can only select up to 4 sectors!\n";       }
	if( searchform.l && ! is_ok( searchform.l, 4, '' ) ) { errtxt += "You can only select up to 4 locations!\n";     }
	if( errtxt != '' ) { alert( errtxt ); }
	return ( errtxt == "" );
}
