/*
 * 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_YCODE		, LEN_YCODE		);
	setMaxLength(PRM_TXT_YNAME		, LEN_YNAME		);
	setMaxLength(PRM_TXT_KAIKINTAN	, LEN_KAIKINTAN	);
	setMaxLength(PRM_TXT_SYOKUJITAN , LEN_SYOKUJITAN);
	setMaxLength(PRM_TXT_CYOKU1TAN	, LEN_CYOKU1TAN	);
	setMaxLength(PRM_TXT_CYOKU2TAN	, LEN_CYOKU2TAN	);
	setMaxLength(PRM_TXT_CYOKU3TAN	, LEN_CYOKU3TAN	);
	setMaxLength(PRM_TXT_HOKA1TAN	, LEN_HOKA1TAN	);
	setMaxLength(PRM_TXT_HOKA2TAN	, LEN_HOKA2TAN	);
	setMaxLength(PRM_TXT_HOKA3TAN	, LEN_HOKA3TAN	);
	setMaxLength(PRM_TXT_HOKA4TAN	, LEN_HOKA4TAN	);
	setMaxLength(PRM_TXT_HOKA5TAN	, LEN_HOKA5TAN	);
	// 登録/更新判定
	if (MODE == 0) {
		// フォーカス設定
		setFocus(PRM_TXT_YCODE);
	} else if (MODE == 1 || MODE == 2) {
		// 読取専用設定及びフォーカス設定(UPDATEの場合)
		setReadOnly(PRM_TXT_YCODE  , true);
		setReadOnly(PRM_PLT_TOKYU  , true);
		// フォーカス設定
		setFocus(PRM_TXT_YNAME);
	}
	// 削除ボタン、新規登録ボタン利用可否
	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, 'S2207', 'QC0001', '');
		} else if (MODE == 1 || MODE == 2) {
			doSubmitMessage(objForm, 'S2208', 'QC0001', '');
		}
	}
}

/**
 * 入力チェック
 * @param 無し
 * @return チェック結果(true：OK、false：NG)
 * @throws 実行時例外
 */
function validate() {
	// フィールド背景色設定
	setFieldsBgColor(ARY_FIELDS_ID, COLOR_FIELD_NORMAL);
	// 入力チェック
	var aryMessage = new Array();
	checkRequired(PRM_TXT_YCODE	, NAM_YCODE	, aryMessage);
	checkRequired(PRM_TXT_YNAME	, NAM_YNAME	, aryMessage);
	/*	2008/10/23	m.yoshida	次期Verにて対応 */
/*
	checkRequired(PRM_TXT_KAIKINTAN		, ARY_ALLOWANCE["08"][0]	, aryMessage);
	checkRequired(PRM_TXT_SYOKUJITAN	, ARY_ALLOWANCE["09"][0]	, aryMessage);
	checkRequired(PRM_TXT_CYOKU1TAN		, ARY_ALLOWANCE["10"][0]	, aryMessage);
	checkRequired(PRM_TXT_CYOKU2TAN		, ARY_ALLOWANCE["11"][0]	, aryMessage);
	checkRequired(PRM_TXT_CYOKU3TAN		, ARY_ALLOWANCE["12"][0]	, aryMessage);
	checkRequired(PRM_TXT_HOKA1TAN		, ARY_ALLOWANCE["13"][0]	, aryMessage);
	checkRequired(PRM_TXT_HOKA2TAN		, ARY_ALLOWANCE["14"][0]	, aryMessage);
	checkRequired(PRM_TXT_HOKA3TAN		, ARY_ALLOWANCE["15"][0]	, aryMessage);
	checkRequired(PRM_TXT_HOKA4TAN		, ARY_ALLOWANCE["16"][0]	, aryMessage);
	checkRequired(PRM_TXT_HOKA5TAN		, ARY_ALLOWANCE["17"][0]	, aryMessage);
*/	
	checkCode(PRM_TXT_YCODE	, NAM_YCODE	, aryMessage);
	/*	2008/10/23	m.yoshida	次期Verにて対応 */
/*	
	checkNumber(PRM_TXT_KAIKINTAN		, ARY_ALLOWANCE["08"][0]	, aryMessage);
	checkNumber(PRM_TXT_SYOKUJITAN		, ARY_ALLOWANCE["09"][0]	, aryMessage);
	checkNumber(PRM_TXT_CYOKU1TAN		, ARY_ALLOWANCE["10"][0]	, aryMessage);
	checkNumber(PRM_TXT_CYOKU2TAN		, ARY_ALLOWANCE["11"][0]	, aryMessage);
	checkNumber(PRM_TXT_CYOKU3TAN		, ARY_ALLOWANCE["12"][0]	, aryMessage);
	checkNumber(PRM_TXT_HOKA1TAN		, ARY_ALLOWANCE["13"][0]	, aryMessage);
	checkNumber(PRM_TXT_HOKA2TAN		, ARY_ALLOWANCE["14"][0]	, aryMessage);
	checkNumber(PRM_TXT_HOKA3TAN		, ARY_ALLOWANCE["15"][0]	, aryMessage);
	checkNumber(PRM_TXT_HOKA4TAN		, ARY_ALLOWANCE["16"][0]	, aryMessage);
	checkNumber(PRM_TXT_HOKA5TAN		, ARY_ALLOWANCE["17"][0]	, aryMessage);
*/		
	if (aryMessage.length == 0) {
		return true;
	} else {
		showMessage(aryMessage);
		return false;
	}
}

/**
 * 固定単価チェック
 * @param target1 selectタグid
 * @param target2 inputタグid
 * @return チェック結果(true：読取のみ、false：編集可)
 * @throws 実行時例外
 */
function selectReadOnly(target1,target2) {
	var objTarget1 = getObject(target1);
	var objTarget2 = getObject(target2);
	var n = objTarget1.selectedIndex
	var m = objTarget1.options[n].value;
	var flag = "false";
	if (m != 1) {
		flag = "true";
	}
	objTarget2.disabled = eval(flag);
} 
