
function getSelectedValue(selectBox) {
  value = '';
  if (selectBox.selectedIndex > -1) {
    value = selectBox.options[selectBox.selectedIndex].value;
  }
  return value;
}

function getSelectedText(selectBox) {
  text = '';
  if (selectBox.selectedIndex > -1) {
    text = selectBox.options[selectBox.selectedIndex].text;
  }
  return text;
}

function setSelectValue(selectBox, value) {
  if (selectBox != null) {
    if (selectBox.options != null) {
      for (var i = 0; i < selectBox.options.length; i++) {
        if (selectBox.options[i] != null && selectBox.options[i].value == value) {
          selectBox.options[i].selected = true; 
        }
        else {
          selectBox.options[i].selected = false; 
        }
      }
    }
  }
}

function updateCounties() {
  var theState = getSelectedValue(document.searchForm.state);    

  document.searchForm.county.selectedIndex = -1;

  if (theState != null && theState != '') {
    document.getElementById("displayCountyLabel").style.display = "";
    document.getElementById("displayCountySelect").style.display = "";

    // send request for counties
    strRequest="getStateCounties.do" + 
               "?state=" + theState + 
               "&destination=search&formName=searchForm&formElem=county";
    sendRequestStateCounties(strRequest);
  }
  else {
    document.getElementById("displayCountyLabel").style.display = "none";
    document.getElementById("displayCountySelect").style.display = "none";
  }
}

