//******************************************************************************
// EdgeOfNight / Drowlord - Lookup Functions for dynamic drop-down lists
// File:          inc_lookup.js
// Author:        Joshua Jacobsen
// Email:         drowlord@drowlord.com
// Date:          5/26/2007
//*******************************************************************************

function populate_parent_select(source_select, source_array){
  var source_value = source_select.options[source_select.selectedIndex].value;
  var source_id = 0;
  var loopvar001;
  var loopvar002;

  loopvar002 = 0;
  source_select.options[loopvar002] = new Option();
  source_select.options[loopvar002].text = "";
  source_select.options[loopvar002].value = "0";
  loopvar002++;
  for (loopvar001 = 0; loopvar001 < source_array.length; loopvar001++){
    source_select.options[loopvar002] = new Option();
    source_select.options[loopvar002].text = source_array[loopvar001];
    source_select.options[loopvar002].value = source_array[loopvar001].id;
    loopvar002++;
  }
  source_select.options.length = loopvar002;
}

function populate_child_select(source_select, destination_select, source_array, destination_array){
  var source_value = source_select.options[source_select.selectedIndex].value;
  var destination_value = destination_select.options[destination_select.selectedIndex].value;
  var source_id = 0;
  var loopvar001;
  var loopvar002;
  
  source_id = source_select[source_select.selectedIndex].value;
  loopvar002 = 0;
  destination_select.options[loopvar002] = new Option();
  destination_select.options[loopvar002].text = "";
  destination_select.options[loopvar002].value = "0";
  loopvar002++;
  for(loopvar001=0; loopvar001 < destination_array.length; loopvar001++){
    if (destination_array[loopvar001].ref_id == source_id) {
      destination_select.options[loopvar002] = new Option();
      destination_select.options[loopvar002].text = destination_array[loopvar001];
      destination_select.options[loopvar002].value = destination_array[loopvar001].id;
	  if (destination_value == destination_array[loopvar001]) {
        destination_select.selectedIndex = loopvar002;
      }
      loopvar002++;
    }
  }
  destination_select.options.length = loopvar002;
}

function set_select(select_object, select_value) {
  for (loopvar001 = 0; loopvar001 < select_object.options.length; loopvar001++){
    if (select_object.options[loopvar001].value == select_value) {
      select_object.selectedIndex = loopvar001;
    }
  }
}