function mwk_search_widget_adapt() {
	display_mode = $F('search_widget_map_radio'); 
	if (display_mode == 'map') {      
		$('search_widget_closest_to').show();
		$('search_loc_req_map').show();
		$('search_loc_req_distance').hide(); 
		$('search_widget_sort_by').hide();
		$('search_widget_sort_by_map').show();
	 //   $('sort_by').disable();
	   // $('search_locale').enable();
	} else {
	 //   $('sort_by').enable();
		$('search_widget_sort_by').show();
		$('search_widget_sort_by_map').hide();
		$('search_loc_req_map').hide();
    	sort_by = $F('search_widget_distance_radio');
   		if (sort_by == 'distance') {
     		$('search_widget_closest_to').show();
   			$('search_loc_req_distance').show();
     	//	$('search_locale').enable();
   		} else {
     		$('search_widget_closest_to').hide();
   			$('search_loc_req_distance').hide();
    	//	$('search_locale').disable();
   		}  
    }
}            
function mwk_search_widget_submit_ok() {
	display_mode = $F('search_widget_map_radio'); 
    sort_by = $F('search_widget_distance_radio');
    search_locale = "";
    if ($('search_locale')) {
	  	search_locale = $F('search_locale').strip();
  	} else if ($('search_closest_to')) {
	  	search_locale = $F('search_closest_to').strip();
  	}
  	
    alert_text = "";       
    if (($F('search_category_id').strip() == "") && 
        ($F('search_model').strip() == "")) {
	   alert_text += "Either a Category and/or a Model is required. ";
    }
	if ((search_locale == null) || (search_locale.strip() == "")) {
    	if (display_mode == 'map') {
	       alert_text += "City/state or zip is required for the Map view. ";
	    } else if (sort_by == 'distance') {
           alert_text += "City/state or zip is required for sorting by distance. ";
		} 
    }                    
    if (alert_text != "") {
		alert(alert_text);
		return false;
	} else {
    	return true;
    }
}
document.observe('dom:loaded', function() { 
 new Form.Observer('search_widget_form', 0.2, mwk_search_widget_adapt);
// new Field.Observer('vvv', 0.3, mwk_search_widget_adapt); 
// new Field.Observer('sort_by', 0.3, mwk_search_widget_adapt);
 /* Run these once in case the browser cached the form input values... */
 mwk_search_widget_adapt();
});
