var reqStateCounties = null;

function sendRequestStateCounties(url, params, HttpMethod) {
  if (!HttpMethod) {
    HttpMethod = "GET";
  }
  reqStateCounties = initXMLHTTPRequest();
  if (reqStateCounties) {
    // this is to ensure that no caching is taking place
    url = url + "&seed=" + (new Date()).getTime();

    reqStateCounties.onreadystatechange = onReadyStateStateCounties;
    reqStateCounties.open(HttpMethod, url, true);
    reqStateCounties.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    reqStateCounties.send(params);
  }
}

function onReadyStateStateCounties() {
  var ready = reqStateCounties.readyState;
  var data = null;
  if (ready == READY_STATE_COMPLETE) {
    data = reqStateCounties.responseText;
    var xmlDoc = reqStateCounties.responseXML.documentElement;
    fillSelect(data, xmlDoc);

    var xSel = xmlDoc.getElementsByTagName('selectElement')[0];
    var destination = xSel.childNodes[3].firstChild.nodeValue;
    if (destination == 'forEdit') {
      toggleLabelText(document.sstoryForm.ff_project_county, "countyLink");
      updateCommunities();
    }
    else if (destination == 'forSearch') {
      toggleLabelText(document.searchForm.ff_project_county, "countyLink"); 
      updateCommunities();
    }
  }
}
