function showAdrEntry(acmd, id) {
  var f = document.form1;
  f.cmd.value = 'SHOW_ADDRESSENTRY';
  f.acmd.value = acmd;
  f.id.value = id;
  f.submit();
}

function deleteAdrEntrys() {
  var f = document.form1;
  len = f.length;
  for (i=0; i < len; i++) {
    if (f.elements[i].name == "delete" && f.elements[i].checked) {
      if (!isDelete()) {
        return;
      }
      f.cmd.value="REMOVE_ADDRESSENTRY";
      f.submit();
      return;
    }
  }
  alert("Please select address to delete.");
}

function deleteAdrEntry() {
  var f = document.form1;
  if (!isDelete()) {
    return;
  }
  f.cmd.value="REMOVE_ADDRESSENTRY";
  f.submit();
}

function set(adr) {
  var f = document.form1;
  f.cmd.value = 'SEND_MESSAGE_ENTRY_CREATE';
  f.select_adr.value = adr;
  f.set_adr.value = "TRUE";
  f.submit();
}

function cmdPage(id) {
  var f = document.form1;
  f.cmd.value = 'SHOW_ADDRESSLIST';
  f.top.value = id;
  f.submit();
}

function checkInput() {
  var f = document.form1;
  var val = f.nickname.value;
  if (val.length == 0) {
    alert("Please input nickname.");
    f.nickname.select();
    return;
  }
  if (!checkQuote(val)) {
    f.nickname.select();
    return;
  }
  val = f.kana.value;
  if (!checkQuote(val)) {
    f.kana.select();
    return;
  }
  val = f.mailaddress.value;
  if (val.length == 0) {
    alert("Please input mail address.");
    f.mailaddress.select();
    return;
  }
  if (!checkQuote(val)) {
    f.mailaddress.select();
    return;
  }
  for (n = 0; n < val.length; n++) {
    if (val.charCodeAt(n) >= 0x80) {
      alert("Please input only single-byte character in mail address.");
      f.mailaddress.select();
      return;
    }
  }
  val = f.address.value;
  if (!checkQuote(val)) {
    f.address.select();
    return;
  }
  val = f.phone.value;
  if (!checkQuote(val)) {
    f.phone.select();
    return;
  }
  f.cmd.value = "REGIST_ADDRESSENTRY";
  f.submit();
}

function isDelete() {
  return confirm("Are you sure you want to delete the address from address book?");
}

function jump(start) {
  var f = document.form1;
  f.cmd.value = 'JUMP_ADDRESS'
  f.list.value = start;
  f.submit();
}

function checkQuote(val) {
  for (i=0; i<val.length; i++) {
    if (val.charAt(i).match("\"") != null) {
      alert("Double quotation can not be used.");
      return false;
    }
  }
  return true;
}

function showPublicAddress() {
  var f = document.form1;
  f.cmd.value = 'SHOW_PUBLIC_ADDRESS';
  f.submit();
}

function groupAdrAddItem() {
  var f = document.form1;
  f.cmd.value = 'SHOW_ADDRESSENTRY';
  f.acmd.value = 'ADD';
  f.submit();
}

function groupAdrDelItem(name) {
  var f = document.form1;
  f.cmd.value = 'SHOW_ADDRESSENTRY';
  f.acmd.value = 'DEL';
  f.name.value = name;
  f.submit();
}

function groupAdrSelItem(adr) {
  var f = document.form1;
  f.cmd.value = 'SHOW_ADDRESSENTRY';
  f.acmd.value = 'SEL';
  f.select_adr.value = adr;
  f.set_adr.value = "TRUE";
  f.submit();
}

function groupCmdPage(id) {
  var f = document.form1;
  f.cmd.value = 'SHOW_ADDRESSLIST';
  f.acmd.value = 'GROUP';
  f.top.value = id;
  f.submit();
}


function groupJump(start) {
  var f = document.form1;
  f.cmd.value = 'JUMP_ADDRESS'
  f.acmd.value = 'GROUP';
  f.list.value = start;
  f.submit();
}
