  /*================================================================================================
   * 関数名：trim()
   * 概要  ：" AB " → "AB". (全角スペースも取り除く）
  ================================================================================================*/
  function trim(st){
    var st1;
    st1=st.replace(/^(\s|  )+/g,"");
    //st1=st1.replace(/^\s+|\s　+$/g, "");
    st1=st1.replace(/(\s|　)+$/g,"");
    return st1;
  }

  /*================================================================================================
   * 関数名：checkNum()
   * 概要  ：
  ================================================================================================*/
  function checkNum(s) {
    return !(/[^0-9\s]+/.test(s));
  }

  /*================================================================================================
   * 関数名：checkNum()
   * 概要  ：
  ================================================================================================*/
  function checkFloat(s) {
    if (trim(s) == 0) return true;

    if (!Number(s)){
      return false;
    }
    return true;
  }

  /*================================================================================================
   * 関数名：MM_findObj()
   * 概要  ：
  ================================================================================================*/
  function MM_findObj(n, d) {
    var p,i,x;
    if(!d) d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
      d=parent.frames[n.substring(p+1)].document;
      n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all)
      x=d.all[n];
    for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
  }

  /*================================================================================================
   * 関数名：isValidChar()
   * 概要  ：
  ================================================================================================*/
  function isValidChar(str){
    var strTmp;
    for(i=0; i<str.length; i++){
      strTmp = str.substring(i, i+1);
      if (strTmp == "'" || strTmp == '"' || strTmp == "<" || strTmp == "\\"){
        return false;
      }
    }
    return true;
  }

  /*================================================================================================
   * 関数名：isDigit()
   * 概要  ：
  ================================================================================================*/
  function isDigit(c) { if((c>='0')&&(c<='9')) return true; else return false; }

  /*================================================================================================
   * 関数名：isEmail()
   * 概要  ：メールアドレスチェック。
  ================================================================================================*/
  function isEmail(se)
  {
    var intlen, ctmp;

    se = trim(se);
    if (se == '')
      return false;

    intlen = se.length;
    if (se.indexOf('@') == -1)
      return false;
    if (se.indexOf("@") != se.lastIndexOf("@"))
      return false;
    if (se.indexOf('.') == -1)
      return false;
    if (se.indexOf("..") != -1)
      return false;

    if (se.lastIndexOf(".") <= se.lastIndexOf("@") + 1)
      return false;
    if (intlen -1 == se.lastIndexOf('.'))
      return false;
    if (se.charAt(se.indexOf('@') + 1) == '.')
      return false;

    if ((se.indexOf(" ") != -1) || (se.indexOf("　") != -1))
      return false;

    se = se.toLowerCase();
    for (intcnt = 0; intcnt < intlen; intcnt++)
    {
      ctmp = se.charAt(intcnt)
      if ((!isDigit(ctmp)) && ((ctmp > 'z') || (ctmp < 'a')) && (ctmp != '-') && (ctmp != '.') && (ctmp != '@') && (ctmp != '_'))
        return false;
    }
    ctmp = se.charAt(0);
    if((ctmp=='.') || (ctmp=='-') || (ctmp=='_')) return false;
    return true;
  }

  /*================================================================================================
   * 関数名：checkFormParameter()
   * 概要  ：入力チェック：数字、MaxLenght、得な文字、Email、URL、拡張子の入力、入力必要。
  ================================================================================================*/
  function checkFormParameter() {
    var i,param,name,test,num,min,max,ymd,cond
    var errors='',args=checkFormParameter.arguments;
    for(i=0;i<args.length-2;i+=3) {
      val=MM_findObj(args[i]); name=args[i+1]; test=args[i+2];
      if(val) {
        valueSpace = val.value;
        value=trim(val.value);
        if(value != "") {
          if(value != null) {
            if(test.indexOf('isNum')!=-1) {
              if(!checkNum(value)){
                errors = name + " は数字です。";
                val.focus();
                break;
              }
            }
            else if (test.indexOf('isFloat')!=-1) {
              if(!checkFloat(value)){
                errors = name + " は数字です。";
                val.focus();
                break;
              }
            }
            else if (test.indexOf('maxLength')!=-1) {
              paramater=test.indexOf('maxLength')+9;
              max=new Number(test.substring(paramater));
              if (max<value.length){
                errors = name + " は" + max + "文字までです";
                val.focus();
                break;
              }
            }
            else if (test.indexOf('minLength')!=-1) {
              paramater=test.indexOf('minLength')+9;
              min=new Number(test.substring(paramater));
              if (min>value.length){
                errors = name + " は" + min + "文字以上です";
                val.focus();
                break;
              }
            }
            else if (test.indexOf('minBytes')!=-1) {
              paramater=test.indexOf('minBytes')+8;
              byte=new Number(test.substring(paramater));
              if (!checkNumBytesMin(value, byte)){
                errors = name + " の文字制限は以下の通りです。\n\n・半角"+byte+"文字以上。 \n・全角"+byte/2+"文字以上。";
                val.focus();
                break;
              }
            }
            else if (test.indexOf('maxBytes')!=-1) {
              paramater=test.indexOf('maxBytes')+8;
              byte=new Number(test.substring(paramater));
              if (!checkNumBytesMax(value, byte)){
                errors = name + " の文字制限は以下の通りです。\n\n・半角"+byte+"文字以内。 \n・全角"+byte/2+"文字以内。";
                val.focus();
                break;
              }
            }
            else if (test.indexOf('fixLength')!=-1) {
              paramater=test.indexOf('fixLength')+9;
              max=new Number(test.substring(paramater));
              if (max!=value.length){
                errors = name + " は" + max + "数字です";
                val.focus();
                break;
              }
            }
            else if(test.indexOf('isValidCharV_1')!=-1) {
              if(!isValidCharV_1(value)){
                errors = name + "には使用できない文字[”],[’]が入力されています。";
                val.focus();
                break;
              }
            }
            else if(test.indexOf('isValidChar')!=-1) {
              if(!isValidChar(value)){
                errors = name + "には使用できない文字[”],[’],[<],[\\]が入力されています。";
                val.focus();
                break;
              }
            }
            else if(test.indexOf('isEmail')!=-1) {
              if(!isEmail(value)){
                errors = name + "が不正です。";
                val.focus();
                break;
              }
            }
            else if(test.indexOf('isURL')!=-1) {
              if(!is_URL(value)){
                errors = name + "が不正です。";
                val.focus();
                break;
              }
            }
            else if(test.indexOf('isGif')!=-1) {
              if(value.indexOf(".") == -1){
                errors = "拡張子を入力してください。";
                val.focus();
                break;
              }
              if(value.indexOf(".gif") == -1){
                errors = "[.gif]拡張子のファイルを入力してください。";
                val.focus();
                break;
              }
            }
            else if(test.indexOf('isJpeg')!=-1) {
              if(value.indexOf(".") == -1){
                errors = "拡張子を入力してください。";
                val.focus();
                break;
              }
              value = value.toLowerCase();
              if((value.indexOf(".jpeg") == -1) && (value.indexOf(".jpg") == -1)){
                errors = "[.jpeg],[.jpg]拡張子のファイルを入力してください。";
                val.focus();
                break;
              }
            }
            else if(test.indexOf('is2Byte')!=-1) {
              if(Check2Byte(value)){
                errors = name + "が半角英数字以外は入力不可です。";
                val.focus();
                break;
              }
            }
            else if(test.indexOf('isOneKata')!=-1) {
              if(CheckOneBytesKatakana(value)){
                errors = name + "は、半角カタカナを使用できません。";
                val.focus();
                break;
              }
            }
            else if(test.indexOf('isSpace')!=-1) {
              if(CheckSpace(valueSpace)){
                errors = name + "にスペースは使用できません。";
                val.focus();
                break;
              }
            }
          }
        }
        else if (test.charAt(0)=='R'){
          errors = name + " は必須項目です。";
          val.focus();
          break;
        }
      }
    }
		
    if(errors) alert(errors);
    return (errors == '');
  }
