var tree = null;

function myLoad(initialEntry) {
   tree = new dhtmlXTreeObject("treeBox", "100%", "100%", 0);
   tree.setImagePath("imgs/");
   tree.setXMLAutoLoading(cycle + "/");
   document.getElementsByName("entryText")[0].value = initialEntry;
   entryChange();
}

function entryChange() {
   input = document.getElementsByName("entryText")[0].value;
   input = input.replace(/[ ,]+/g, ",");
   lastInput = input;
   tree.deleteChildItems("0");
   var icaos = input.toUpperCase().split(",");
   var invalid = '';
   var nInvalid = 0;
   var visited = {};
   for (var i = 0; i < icaos.length; i++) {
      var icao = icaos[i];
      if (icao.length == 4 && validICAOs[icao] != null) {
        if (visited[icao] == null) {
          tree.insertNewChild("0", icao, icao, 0, 0, 0, 0, 0, 1);
          visited[icao] = 1;
        }
      } else if (icao.length != 0) {
	invalid += ' ' + icao;
	++nInvalid;
      }
   }
   if (invalid != '') {
     var plural = (nInvalid > 1) ? "s" : "";
     alert("ICAO" + plural + " not in Chartfinder:" + invalid + ".\n\n" +
	   "Currently, only charts from the US, UK, Australia, and Canada\n" +
	   "are included.  The Canadian charts are incomplete and out-of-date.\n" +
	   "\n" +
	   "Please see http://charts.vatsim.net for additional charts.");
   }
}

