function inputCheck(element, name){
   if(!element.value){
    window.alert(name + "が未入力です");
    return false;
  }
  return true;
}

function inputCheckLength(element, name, maxlength){
  if(getByteCount(element.value) > maxlength){
    window.alert(name + " が " + maxlength + " バイトを超えています");
    return false;
  }
  return true;
}

function checkIsZenkaku(value) {
  for (var i = 0; i < value.length; ++i) {
    var c = value.charCodeAt(i);
    if (c < 256) {
      return false;
    }
  }
  return true;
}

function getByteCount(value) {
  var count = 0;

  for ( var i = 0; i < value.length; ++i ) {
    var sub = value.substring(i, i + 1);
    //全角の場合２バイト追加。
    if( checkIsZenkaku(sub) ){
      count += 2;
    } else {
      count += 1;
    }
  }
  return count;
}

function inputCheckHanNum(element, name){
  if(!checkIsHanNum(element.value)){
    window.alert(name + " に半角数字以外は入力できません");
    return false;
  }
  return true;
}

function checkIsHanNum(value) {
  for (var i = 0; i < value.length; ++i) {
    var c = value.charCodeAt(i);
    //半角数字以外は不許可
    if (48 > c || c > 57) {
      return false;
    }
  }
  return true;
}

function inputCheckAlphaNumericSign(element, name){
  if(!checkAlphaNumericSign(element.value)){
    window.alert(name + " に半角英数字記号以外は入力できません");
    return false;
  }
  return true;
}

function checkAlphaNumericSign(value){
  var iCount;
  var iCode;
  for (iCount=0 ; iCount<value.length ; iCount++){
    iCode = value.charCodeAt(iCount);
    //半角英文字数字記号以外が含まれる場合は不許可
    if(0<=iCode && iCode <=255){
    }else{
      return false;
    }
  }
  return true;
}

function checkUploadfile(value){
  if (value == "") return true;
  if (!value.match(".pdf","i")){
    alert("PDFファイル以外はアップロードできません");
    return false;
  }
  return true;
}

function inputCheckHankana(element, name){
  if(!checkHankana(element.value)){
    window.alert(name + " に半角カタカナ以外は入力できません");
    return false;
  }
  return true;
}

function checkHankana(value) {
  for (var i = 0; i < value.length; ++i) {
    var c = value.charCodeAt(i);
    //半角カタカナ以外は不許可
    if (c >= 65382 && c <= 65439) {
    } else {
      return false;
    }
  }
  return true;
}

function inputCheckFurigana(element, name){
  if(element.value.match( /[^ぁ-ん　\sー・]+/ ) ) {
    window.alert(name + "にひらがな以外は入力できません");
    return false;
  }
  return true;
}

function isEmail(element, name){
  if(element.value.match("^[0-9A-Za-z._]+@[0-9A-Za-z.]+$")){
    return true;
  }
  window.alert(name + "は正しい形式で入力してください");
  return false;
}
