/*
 * MosP - Mind Open Source Project    http://www.mosp.jp/
 * Copyright (C) MIND Co., Ltd.       http://www.e-mind.co.jp/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
/**
 * 画面読込時追加処理
 * @param 無し
 * @return 無し
 * @throws 実行時例外
 */
function onLoadExtra() {
	// 項目背景色設定
	setFieldsBgColor(ARY_FIELDS_ID    , COLOR_FIELD_NORMAL);
	setFieldsBgColor(ARY_ERR_FIELDS_ID, COLOR_FIELD_ERROR );
	// 項目長設定
	setMaxLength(PRM_TXT_JCODE		, LEN_JCODE		);
	setMaxLength(PRM_TXT_KAIMEI		, LEN_KAIMEI	);
	setMaxLength(PRM_TXT_KAIFURI	, LEN_KAIFURI	);
	setMaxLength(PRM_TXT_KJIGYONUSI , LEN_KJIGYONUSI);
	setMaxLength(PRM_TXT_KAIYUBIN1	, LEN_KAIYUBIN1	);
	setMaxLength(PRM_TXT_KAIYUBIN2	, LEN_KAIYUBIN2	);
	setMaxLength(PRM_TXT_KAIJYUSYO	, LEN_KAIJYUSYO	);
	setMaxLength(PRM_TXT_KAITEL1	, LEN_KAITEL	);
	setMaxLength(PRM_TXT_KAITEL2	, LEN_KAITEL	);
	setMaxLength(PRM_TXT_KAITEL3	, LEN_KAITEL	);
	setMaxLength(PRM_TXT_KAIFAX1	, LEN_KAIFAX	);
	setMaxLength(PRM_TXT_KAIFAX2	, LEN_KAIFAX	);
	setMaxLength(PRM_TXT_KAIFAX3	, LEN_KAIFAX	);
	setMaxLength(PRM_TXT_RITKOYOU	, LEN_RITKOYOU	);
	setMaxLength(PRM_TXT_RITKKOYOU	, LEN_RITKKOYOU	);
	setMaxLength(PRM_TXT_RITKENPO	, LEN_RITKENPO	);
	setMaxLength(PRM_TXT_RITKKENPO	, LEN_RITKKENPO	);
	setMaxLength(PRM_TXT_RITKAIGO	, LEN_RITKAIGO	);
	setMaxLength(PRM_TXT_RITKKAIGO	, LEN_RITKKAIGO	);
	setMaxLength(PRM_TXT_RITKOSEI	, LEN_RITKOSEI	);
	setMaxLength(PRM_TXT_RITKKOSEI	, LEN_RITKKOSEI	);
	setMaxLength(PRM_TXT_RITKIKIN	, LEN_RITKIKIN	);
	setMaxLength(PRM_TXT_RITKKIKIN	, LEN_RITKKIKIN	);
	setMaxLength(PRM_TXT_SYAHOFUGO	, LEN_SYAHOFUGO	);
	setMaxLength(PRM_TXT_SYAHOKIGO	, LEN_SYAHOKIGO	);
	setMaxLength(PRM_TXT_SYAHOBANGO	, LEN_SYAHOBANGO);
	setMaxLength(PRM_TXT_KENPOJINO	, LEN_KENPOJINO	);
	setMaxLength(PRM_TXT_KIKINJINO1	, LEN_KIKINJINO1);
	setMaxLength(PRM_TXT_KIKINJINO2	, LEN_KIKINJINO2);
	
	// 登録/更新判定
	if (MODE == 0) {
		// フォーカス設定
		setFocus(PRM_TXT_JCODE);
	} else if (MODE == 1 || MODE == 2) {
		// 読取専用設定及びフォーカス設定(UPDATEの場合)
		setReadOnly(PRM_TXT_JCODE  , true);
		// フォーカス設定
		setFocus(PRM_TXT_KAIMEI);
	}
	// 削除ボタン、新規登録ボタン利用可否
	if (MODE != 2) {
		setObjectVisibility("btnDelete", false);
		setObjectVisibility("btnNewData", false);	
		setWidth("btnDelete", 0);
		setWidth("btnNewData", 0);
	}
}

/**
 * サーバー通信処理
 * @param 無し
 * @return 無し
 * @throws 実行時例外
 */
function submitForm(objForm) {
	// 入力チェック
	if (validate()) {
		// サーバー通信(入力エラー無の場合)
		if (MODE == 0) {
			doSubmitMessage(objForm, 'S2017', 'QC0001', '');
		} else if (MODE == 1 || MODE == 2) {
			doSubmitMessage(objForm, 'S2018', 'QC0001', '');
		}
	}
}

/**
 * 入力チェック
 * @param 無し
 * @return チェック結果(true：OK、false：NG)
 * @throws 実行時例外
 */
function validate() {
	// フィールド背景色設定
	setFieldsBgColor(ARY_FIELDS_ID, COLOR_FIELD_NORMAL);
	// 入力チェック
	var aryMessage = new Array();
	convSbKana(PRM_TXT_KAIFURI);
	
	checkRequired(PRM_TXT_JCODE		, NAM_JCODE		, aryMessage);
	checkRequired(PRM_TXT_KAIMEI	, NAM_KAIMEI	, aryMessage);
	checkRequired(PRM_TXT_KAIFURI	, NAM_KAIFURI	, aryMessage);
	checkRequired(PRM_TXT_KJIGYONUSI, NAM_KJIGYONUSI, aryMessage);
	checkRequired(PRM_TXT_KAIYUBIN1	, NAM_KAIYUBIN1	, aryMessage);
	checkRequired(PRM_TXT_KAIYUBIN2	, NAM_KAIYUBIN2	, aryMessage);
	checkRequired(PRM_TXT_KAIJYUSYO	, NAM_KAIJYUSYO	, aryMessage);

	checkCode(PRM_TXT_JCODE	, NAM_JCODE	, aryMessage);
	
	checkNumber(PRM_TXT_KAIYUBIN1	, NAM_KAIYUBIN1	, aryMessage);
	checkNumber(PRM_TXT_KAIYUBIN2	, NAM_KAIYUBIN2	, aryMessage);
	checkNumber(PRM_TXT_KIKINJINO1	, NAM_KIKINJINO1, aryMessage);
	checkNumber(PRM_TXT_KIKINJINO2	, NAM_KIKINJINO2, aryMessage);
	checkNumber(PRM_TXT_KENPOJINO	, NAM_KENPOJINO	, aryMessage);
	
	checkNumeric(PRM_TXT_RITKOYOU	, NAM_RITKOYOU	, aryMessage);
	checkNumeric(PRM_TXT_RITKKOYOU	, NAM_RITKKOYOU	, aryMessage);
	checkNumeric(PRM_TXT_RITKENPO	, NAM_RITKENPO	, aryMessage);
	checkNumeric(PRM_TXT_RITKKENPO	, NAM_RITKKENPO	, aryMessage);
	checkNumeric(PRM_TXT_RITKAIGO	, NAM_RITKAIGO	, aryMessage);
	checkNumeric(PRM_TXT_RITKKAIGO	, NAM_RITKKAIGO	, aryMessage);
	checkNumeric(PRM_TXT_RITKOSEI	, NAM_RITKOSEI	, aryMessage);
	checkNumeric(PRM_TXT_RITKKOSEI	, NAM_RITKKOSEI	, aryMessage);
	checkNumeric(PRM_TXT_RITKIKIN	, NAM_RITKIKIN	, aryMessage);
	checkNumeric(PRM_TXT_RITKKIKIN	, NAM_RITKKIKIN	, aryMessage);
	
	checkNumber(PRM_TXT_KAITEL1	, NAM_KAITEL1	, aryMessage);
	checkNumber(PRM_TXT_KAITEL2	, NAM_KAITEL2	, aryMessage);
	checkNumber(PRM_TXT_KAITEL3	, NAM_KAITEL3	, aryMessage);
	checkNumber(PRM_TXT_KAIFAX1	, NAM_KAIFAX1	, aryMessage);
	checkNumber(PRM_TXT_KAIFAX2	, NAM_KAIFAX2	, aryMessage);
	checkNumber(PRM_TXT_KAIFAX3	, NAM_KAIFAX3	, aryMessage);
	
	checkRegLength(PRM_TXT_KAIYUBIN1, LEN_KAIYUBIN1, NAM_KAIYUBIN1, aryMessage);
	checkRegLength(PRM_TXT_KAIYUBIN2, LEN_KAIYUBIN2, NAM_KAIYUBIN2, aryMessage);
	
	checkLength(PRM_TXT_KAIFURI, LEN_KAIFURI, NAM_KAIFURI, aryMessage);
	
	if (aryMessage.length == 0) {
		return true;
	} else {
		showMessage(aryMessage);
		return false;
	}
}
