var reqStateCommunities = null;

function sendRequestStateCommunities(url, params, HttpMethod) {
  if (!HttpMethod) {
    HttpMethod = "GET";
  }
  reqStateCommunities = initXMLHTTPRequest();
  if (reqStateCommunities) {
    // this is to ensure that no caching is taking place
    url = url + "&seed=" + (new Date()).getTime();

    reqStateCommunities.onreadystatechange = onReadyStateStateCommunities;
    reqStateCommunities.open(HttpMethod, url, true);
    reqStateCommunities.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    reqStateCommunities.send(params);
  }
}

function onReadyStateStateCommunities() {
  var ready = reqStateCommunities.readyState;
  var data = null;
  if (ready == READY_STATE_COMPLETE) {
    data = reqStateCommunities.responseText;
    var xmlDoc = reqStateCommunities.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_city, "cityLink");
    }
    else if (destination == 'forSearch') {
      toggleLabelText(document.searchForm.ff_project_city, "communityLink"); 
    }
  }
}
