
window.addEvent('domready', function() {
  $('record_type_id').onchange = state_id_changed;
  $('state_id').onchange = state_id_changed;
});


function record_type_id_changed()
{

}// end record_type_id_changed()


function state_id_changed()
{
  var county_sel = this.form.county_id;
  county_sel.innerHTML = "";
  
  var type_sel = this.form.record_type_id;
  if( type_sel.options[ type_sel.selectedIndex ].value != 8 )
  {
    county_sel.options[0] = new Option("-- All Counties --", "");
    return;
  }// end if()
  
  var state_id = this.form.state_id.options[this.form.state_id.selectedIndex].value;
  
  // User has selected 'public' records:
  var httpOb = XmlHttp.create();
  httpOb.open("GET", "/handlers/rp.json.counties?state_id=" + state_id, true);
  httpOb.onreadystatechange = function() {
    if( httpOb.readyState == 4 )
    {
      var data = eval( httpOb.responseText );
      county_sel.innerHTML = "";
      for( var i = 0; i < data.length; i++ )
      {
        county_sel.options[i] = new Option( data[i].label, data[i].value );
      }// end for()
    }// end if()
  };
  
  county_sel.options[0] = new Option("[ Loading Data... ]", "");
  httpOb.send( null );
}// end state_id_changed()


