function imposeMaxLength(Object, MaxLen) {
  if (Object.value.length >= MaxLen) {
      Object.value = Object.value.substr(0,MaxLen);
  }
  return true;
}

function setDir(box, id) {
  clearBox(box);
  var selectBox = document.getElementById('dir' + box);
  for(var i in dirs) {
    var dir = dirs[i];
    if (dir[1] == id) {
      try {
        // firefox
        selectBox.add(new Option(dir[2], dir[0]), null);
      } catch(ex) {
        // ie
        selectBox.add(new Option(dir[2], dir[0]));
      }
    }
  }
  
  if (selectBox.length > 0) {
    showBox(box);
    openDirs = box;
  } else {
    hideBox(box);
    openDirs = box-1;
  }
}
function clearBox(box) {
  var selectBox = document.getElementById('dir' + box);
  while(selectBox.length > 0) {
    selectBox.remove(0);
  }
}

function showBox(box) {
  var el = document.getElementById('dir' + box);
  if (el) {
    el.className = 'divshow';
  }
}

function hideBox(box) {
  var el = document.getElementById('dir' + box);
  if (el) {
    el.className = 'divhide';
  }
}
function boxChanged(box) {
  var el = document.getElementById('dir' + box);
  setDir(1+box, el.value);
  
  box+=2;
  while (box < 4) {
    clearBox(box);
    hideBox(box);
    box++;
  }
}
function checkdata() {
  var el = document.getElementById('dir' + openDirs);
  if (!el) {
    return false;
  }
  if (el.value > 0) {
    return true;
  }
  return false;
}

