// This function populates a list with data returned by AJAX ...
function populate_list(list_id,data_object_array,text_field,value_field,empty_text,empty_value)
{
  var select = jQuery('select#' + list_id);
  
  if(select.length > 0)
  {
    // clear the list ...
    
    select.empty();
    
    // Add empty value if defined ..
    
    if(empty_text.length > 0)
    {
      if(!empty_value)
      {
        empty_value = '';
      }
      
      // Append the empty value ...
      select.append('<option value="'+ empty_value +'">' + empty_text + '</option>');
    }
    
    if(data_object_array.length > 0)
    {
      // check for text field ..
      
      if(!data_object_array[0][text_field])
      {
        alert('Text field "' + text_field + '" not found in data object array!');
      }
      
      // Check for value field ...
      
      if(!data_object_array[0][value_field])
      {
        alert('Value field "' + value_field + '" not found in data object array!');
      }
      
      for(var i=0;i<data_object_array.length;i++)
      {
        // Append each row of data ...
      select.append('<option value="'+ data_object_array[i][value_field] +'">' + data_object_array[i][text_field] + '</option>');
      }
    }
  }
  else
  {
    alert('select#' + list_id + ' not found in dom tree!');
  }
}