/*
 * 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_COMPANY_CODE   , LEN_COMPANY_CODE   );
	setMaxLength(PRM_TXT_COMPANY_NAME   , LEN_COMPANY_NAME   );
	setMaxLength(PRM_TXT_COMPANY_KANA   , LEN_COMPANY_KANA   );
	setMaxLength(PRM_TXT_ENTERPRENEUR   , LEN_ENTERPRENEUR   );
	setMaxLength(PRM_TXT_COMPANY_POSTAL , LEN_COMPANY_POSTAL );
	setMaxLength(PRM_TXT_COMPANY_ADDRESS, LEN_COMPANY_ADDRESS);
	setMaxLength(PRM_TXT_COMPANY_PHONE  , LEN_COMPANY_PHONE  );
	setMaxLength(PRM_TXT_COM_HEALTH_PREMIUM_RATE  , LEN_INS_RATIO_INT + LEN_INS_RATIO_DEC + 1);
	setMaxLength(PRM_TXT_COM_NURSING_PREMIUM_RATE , LEN_INS_RATIO_INT + LEN_INS_RATIO_DEC + 1);
	setMaxLength(PRM_TXT_COM_PENSION_PREMIUM_RATE , LEN_INS_RATIO_INT + LEN_INS_RATIO_DEC + 1);
	setMaxLength(PRM_TXT_COM_FUND_PREMIUM_RATE    , LEN_INS_RATIO_INT + LEN_INS_RATIO_DEC + 1);
	setMaxLength(PRM_TXT_COM_UNEMPLOY_PREMIUM_RATE, LEN_INS_RATIO_INT + LEN_INS_RATIO_DEC + 1);
	setMaxLength(PRM_TXT_HEALTH_PREMIUM_RATE  , LEN_INS_RATIO_INT + LEN_INS_RATIO_DEC + 1);
	setMaxLength(PRM_TXT_NURSING_PREMIUM_RATE , LEN_INS_RATIO_INT + LEN_INS_RATIO_DEC + 1);
	setMaxLength(PRM_TXT_PENSION_PREMIUM_RATE , LEN_INS_RATIO_INT + LEN_INS_RATIO_DEC + 1);
	setMaxLength(PRM_TXT_FUND_PREMIUM_RATE    , LEN_INS_RATIO_INT + LEN_INS_RATIO_DEC + 1);
	setMaxLength(PRM_TXT_UNEMPLOY_PREMIUM_RATE, LEN_INS_RATIO_INT + LEN_INS_RATIO_DEC + 1);
	setMaxLength(PRM_TXT_STATION_NO  , LEN_STATION_NO  );
	setMaxLength(PRM_TXT_DISPOSE_NO  , LEN_DISPOSE_NO  );
	// 登録/更新判定
	if (MODE == 0) {
		// フォーカス設定
		setFocus(PRM_TXT_COMPANY_CODE);
		// ボタン非表示
		setVisibility("btnNext", false);
	} else if (MODE == 1) {
		// 読取専用設定
		setReadOnly(PRM_TXT_COMPANY_CODE  , true);
		// フォーカス設定
		setFocus(PRM_TXT_COMPANY_NAME);
	}
}

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


/**
 * 入力チェック
 * @param 無し
 * @return チェック結果(true：OK、false：NG)
 * @throws 実行時例外
 */
function validate() {
	// フィールド背景色設定
	setFieldsBgColor(ARY_FIELDS_ID, COLOR_FIELD_NORMAL);
	// 半角カナ変換
	convSbKana (PRM_TXT_COMPANY_KANA);
	// 入力チェック
	var aryMessage = new Array();
	// 必須確認
	checkRequired(PRM_TXT_COMPANY_CODE, NAM_COMPANY_CODE, aryMessage);
	// コード確認
	checkCode (PRM_TXT_COMPANY_CODE  , NAM_COMPANY_CODE  , aryMessage);
	checkPhone(PRM_TXT_COMPANY_PHONE , NAM_COMPANY_PHONE , aryMessage);
	checkPhone(PRM_TXT_COMPANY_POSTAL, NAM_COMPANY_POSTAL, aryMessage);
	// 数値確認
	checkDecimal(PRM_TXT_COM_HEALTH_PREMIUM_RATE  , LEN_INS_RATIO_INT, LEN_INS_RATIO_DEC, NAM_COM_HEALTH_PREMIUM_RATE  , aryMessage);
	checkDecimal(PRM_TXT_COM_NURSING_PREMIUM_RATE , LEN_INS_RATIO_INT, LEN_INS_RATIO_DEC, NAM_COM_NURSING_PREMIUM_RATE , aryMessage);
	checkDecimal(PRM_TXT_COM_PENSION_PREMIUM_RATE , LEN_INS_RATIO_INT, LEN_INS_RATIO_DEC, NAM_COM_PENSION_PREMIUM_RATE , aryMessage);
	checkDecimal(PRM_TXT_COM_FUND_PREMIUM_RATE    , LEN_INS_RATIO_INT, LEN_INS_RATIO_DEC, NAM_COM_FUND_PREMIUM_RATE    , aryMessage);
	checkDecimal(PRM_TXT_COM_UNEMPLOY_PREMIUM_RATE, LEN_INS_RATIO_INT, LEN_INS_RATIO_DEC, NAM_COM_UNEMPLOY_PREMIUM_RATE, aryMessage);
	checkDecimal(PRM_TXT_HEALTH_PREMIUM_RATE      , LEN_INS_RATIO_INT, LEN_INS_RATIO_DEC, NAM_HEALTH_PREMIUM_RATE      , aryMessage);
	checkDecimal(PRM_TXT_NURSING_PREMIUM_RATE     , LEN_INS_RATIO_INT, LEN_INS_RATIO_DEC, NAM_NURSING_PREMIUM_RATE     , aryMessage);
	checkDecimal(PRM_TXT_PENSION_PREMIUM_RATE     , LEN_INS_RATIO_INT, LEN_INS_RATIO_DEC, NAM_PENSION_PREMIUM_RATE     , aryMessage);
	checkDecimal(PRM_TXT_FUND_PREMIUM_RATE        , LEN_INS_RATIO_INT, LEN_INS_RATIO_DEC, NAM_FUND_PREMIUM_RATE        , aryMessage);
	checkDecimal(PRM_TXT_UNEMPLOY_PREMIUM_RATE    , LEN_INS_RATIO_INT, LEN_INS_RATIO_DEC, NAM_UNEMPLOY_PREMIUM_RATE    , aryMessage);

	
	if (aryMessage.length == 0) {
		return true;
	} else {
		showMessage(aryMessage);
		return false;
	}
}
