jQuery(document).ready(function() {

  // specialty
  var specialty_type = jQuery('#specialty_type');
  specialty_type.bind("change", function(event){
    var t = jQuery(event.target);
    var gp = jQuery('#specialty-gp');
    var specialist = jQuery('#specialty-specialist');
    var selected_type = t.val(); 
    if (selected_type == '1')
    {
      jQuery("#search_practice_type").removeAttr("disabled");
      jQuery("#search_specialty_id").attr("disabled", "disabled");
      specialist.hide();
      gp.show();
    }
    else if (selected_type == '2')
    {
      jQuery("#search_practice_type").attr("disabled", "disabled");
      jQuery("#search_specialty_id").removeAttr("disabled");
      gp.hide();
      specialist.show();
    }
    else
    {
      jQuery("#search_practice_type").attr("disabled", "disabled");
      jQuery("#search_specialty_id").attr("disabled", "disabled");
      gp.hide();
      specialist.hide();    	
    }
  });
  specialty_type.change(); // simulate a change event to update specialty section

  jQuery('#adv_search_button').bind("click", function(event){

    jQuery('#adv_search_fields').toggle();

    var adv_search_activated = jQuery('#search_adv_search_activated').val();

    var new_value = 0;
    if (adv_search_activated == 0)
    {
      new_value = 1;
    }
    jQuery('#search_adv_search_activated').val(new_value);
  });

  if (jQuery('#search_adv_search_activated').val())
  {
	  jQuery('#adv_search_fields').show();
  }
});