// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults


function filter_html_elements(search_id, src_tag, src_class, dest_tag)
{
	q = $(search_id).getValue();
	reg = new RegExp(".*" + q, "i")

	els = $$(src_tag + "." + src_class);

	els.each(function(e)
	{
		str = e.innerHTML;
		id = e.id.replace(src_tag + "_", dest_tag + "_");

		if (q)
		{
			if (str.match(reg))
				$(id).show();
			else
				$(id).hide();
		}
		else
			$(id).show();
	});
}


function set_control_value(el_id, val)
{
  $(el_id).setValue(val);
}

function toggle_by_switch(switch_id, first_id, sec_id)
{
   is_on = $(switch_id).checked;
   
   if (is_on)
   {
     $(first_id).show();
     $(sec_id).hide();
   }
   else
   {
     $(first_id).hide();
     $(sec_id).show();
   }
}

function $RF(el, radioGroup) 
{
  if($(el).type && $(el).type.toLowerCase() == 'radio') 
  {
    var radioGroup = $(el).name;
    var el = $(el).form;
  }
  else if ($(el).tagName.toLowerCase() != 'form')
  {
    return false;
  }

  var checked = $(el).getInputs('radio', radioGroup).find(
    function(re) {return re.checked;}
  );
  return (checked) ? $F(checked) : null;
}