/*                        */
/* メールフォームチェック */
/*                        */
function check_input() {
  var check = 0;
  check += check_kaisha();
  check += check_name();
  check += check_tel();
  check += check_mail();
  check += check_contact();
  if(check>0){
    return false;
  }
  return true;
}

/* （汎用）未入力チェック */
function check_non(val) {
  if(val==''){
    return false;
  }
  return true;
}

/* 会社名チェック */
function check_kaisha() {
  if(!check_non(document.getElementById('kaisha').value)){
    document.getElementById('err_kaisha').style.display = 'block';
    document.getElementById('err_kaisha').innerHTML = '<font class="11pt" color="red"><b>※会社名を入力ください</b></font>';
    return 1;
  }
  document.getElementById('err_kaisha').style.display = 'none';
  return 0;
}

/* 氏名チェック */
function check_name() {
  if(!check_non(document.getElementById('name').value)){
    document.getElementById('err_name').style.display = 'block';
    document.getElementById('err_name').innerHTML = '<font class="11pt" color="red"><b>※ご担当者名を入力ください</b></font>';
    return 1;
  }
  document.getElementById('err_name').style.display = 'none';
  return 0;
}

/* 電話番号チェック */
/* 099-9999-9999 
   099-999-9999 
   0999-99-9999 
   09-9999-9999 */
function check_tel() {
  var str_err = '<font class="11pt" color="red" ><b>※電話番号（固定電話）が正しくありません</b></font>';
  var str = document.getElementById('tel').value;
  var chk1 = str.match(/^\d{3}-\d{4}-\d{4}$|^\d{3}-\d{3}-\d{4}$|^\d{4}-\d{2}-\d{4}$|^\d{2}-\d{4}-\d{4}$/);
  var chk2 = str.match(/^0/);
  if(check_non(str) && chk1 && chk2){
    document.getElementById('err_tel').style.display = 'none';
    return 0;
  }
  document.getElementById("err_tel").innerHTML = str_err;
  document.getElementById('err_tel').style.display = 'block';
  return 1;
}

/* メールチェック */
function check_mail() {
  var str_err = '<font class="11pt" color="red" ><b>※Ｅメールアドレスが正しくありません</b></font>';
  var str = document.getElementById('mail').value;
  var chk1 = str.match(/^.+@[A-Za-z0-9.-]+\.[A-Za-z]+$/);

  if(check_non(str) && chk1){
    document.getElementById('err_mail').style.display = 'none';
    return 0;
  }
  document.getElementById("err_mail").innerHTML = str_err;
  document.getElementById('err_mail').style.display = 'block';
  return 1;
}

function check_contact() {
  if(!check_non(document.getElementById('contents').value)){
    document.getElementById('err_contents').style.display = 'block';
    document.getElementById('err_contents').innerHTML = '<font class="11pt" color="red"><b>※お問い合わせ内容を入力ください</b></font>';
    return 1;
  }
  document.getElementById('err_contents').style.display = 'none';
  return 0;
}
