/*
 * MosP - Mind Open Source Project         http://www.mosp.jp/
 * Copyright (C) 1987-2009 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_CODE, LEN_CODE);
	setMaxLength(PRM_TXT_NAME, LEN_NAME);
	setMaxLength(PRM_TXT_ABBR, LEN_ABBR);
	// モード毎設定
	switch (MODE) {
		case 0:
			setFocus(PRM_TXT_CODE);
			break;
		case 1:
			setReadOnly(PRM_PLT_TYPE, true);
			setReadOnly(PRM_TXT_CODE, true);
			setFocus(PRM_TXT_NAME);
			break;
		case 2:
			setReadOnly(PRM_PLT_TYPE  , true);
			setReadOnly(PRM_TXT_CODE  , true);
			setReadOnly(PRM_PLT_DELETE, true);
			setFocus(PRM_TXT_NAME);
			break;
		default:
	}
}

/**
 * サーバー通信時処理
 * @param objForm フォームオブジェクト
 * @param cmd     コマンド
 * @return 無し
 * @throws 実行時例外
 */
function submitForm(objForm, cmd) {
	if (validate()) {
		setFormValue(PRM_HID_TYPE  , getFormValue(PRM_PLT_TYPE  ));
		setFormValue(PRM_HID_DELETE, getFormValue(PRM_PLT_DELETE));
		doSubmitMessage(objForm, cmd, 'QC0001', '');
	}
}

/**
 * 入力チェック
 * @param 無し
 * @return チェック結果(true：OK、false：NG)
 * @throws 実行時例外
 */
function validate() {
	// フィールド背景色設定
	setFieldsBgColor(ARY_FIELDS_ID, COLOR_FIELD_NORMAL);
	// 入力チェック準備
	var aryMessage = new Array();
	// 入力チェック
	checkRequired(PRM_TXT_CODE, NAM_CODE, aryMessage);
	checkRequired(PRM_TXT_NAME, NAM_NAME, aryMessage);
	checkRequired(PRM_TXT_ABBR, NAM_ABBR, aryMessage);
	checkCode    (PRM_TXT_CODE, NAM_CODE, aryMessage);
	// チェック内容確認
	if (aryMessage.length == 0) {
		return true;
	} else {
		showMessage(aryMessage);
		return false;
	}
}

