/*
 * 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_OVER_TIME_CODE			, LEN_OVER_TIME_CODE);
	setMaxLength(PRM_TXT_WORK_TYPE_NAME			, LEN_WORK_TYPE_NAME);
	setMaxLength(PRM_TXT_CAUSE					, LEN_WORK_TYPE_NAME);
	setMaxLength(PRM_TXT_OVER_TIME_RATE			, LEN_OVER_TIME_RATE);
	setMaxLength(PRM_TXT_CAUTION_MONTH_HOUR		, LEN_CAUTION_MONTH_HOUR);
	setMaxLength(PRM_TXT_CAUTION_MONTH_MIN		, LEN_CAUTION_MONTH_MIN);
	setMaxLength(PRM_TXT_MONTHLY_OVER_TIME_RATE	, LEN_MONTHLY_OVER_TIME_RATE);
	setMaxLength(PRM_TXT_SUB_ACQUIRE_RATE		, LEN_SUB_ACQUIRE_RATE);
	setMaxLength(PRM_TXT_SUB_ACQUIRE_HOLIDAY_RATE	, LEN_SUB_ACQUIRE_HOLIDAY_RATE);
	setMaxLength(PRM_TXT_SUB_QUIT_RATE			, LEN_SUB_QUIT_RATE);
	
	// 登録/更新判定
	if (MODE == 0) {
		// 読取専用設定
		setReadOnly(PRM_PLT_DELETE_FLAG, true);
		// フォーカス設定
		setFocus(PRM_TXT_OVER_TIME_CODE);
	} else if (MODE == 1 || MODE == 2) {
		// 読取専用設定及びフォーカス設定(UPDATEの場合)
		setReadOnly(PRM_TXT_OVER_TIME_CODE  , true);
		// フォーカス設定
		setFocus(PRM_TXT_OVER_TIME_CODE);
	}
	// 削除ボタン、新規登録ボタン利用可否
	if (MODE == 0) {
		setObjectVisibility("btnNewData", false);	
		setWidth("btnNewData", 0);
	} else if(MODE == 1){
		// 読取専用設定
		setReadOnly(PRM_TXT_OVER_TIME_CODE, true);
		// フォーカス設定
		setFocus(PRM_TXT_WORK_TYPE_NAME);
	}
}

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

/**
 * 入力チェック
 * @param 無し
 * @return チェック結果(true：OK、false：NG)
 * @throws 実行時例外
 */
function validate() {
	// フィールド背景色設定
	setFieldsBgColor(ARY_FIELDS_ID, COLOR_FIELD_NORMAL);
	// 入力チェック
	var aryMessage = new Array();
	
	checkRequired(PRM_TXT_OVER_TIME_CODE , NAM_OVER_TIME_CODE , aryMessage); 
	checkRequired(PRM_TXT_WORK_TYPE_NAME , NAM_WORK_TYPE_NAME , aryMessage); 
	checkRequired(PRM_TXT_CAUSE , NAM_CAUSE , aryMessage); 
	checkRequired(PRM_TXT_OVER_TIME_RATE , NAM_OVER_TIME_RATE , aryMessage);
	checkRequired(PRM_PLT_LIMIT_CODE , NAM_LIMIT_CODE , aryMessage);
	checkRequired(PRM_TXT_CAUTION_MONTH_HOUR , NAM_CAUTION_MONTH_HOUR , aryMessage);
	checkRequired(PRM_TXT_CAUTION_MONTH_MIN , NAM_CAUTION_MONTH_MIN , aryMessage);	
	checkRequired(PRM_TXT_MONTHLY_OVER_TIME_RATE , NAM_MONTHLY_OVER_TIME_RATE , aryMessage); 
	checkRequired(PRM_TXT_SUB_ACQUIRE_RATE , NAM_SUB_ACQUIRE_RATE , aryMessage); 
	checkRequired(PRM_TXT_SUB_ACQUIRE_HOLIDAY_RATE , NAM_SUB_ACQUIRE_HOLIDAY_RATE , aryMessage); 
	checkRequired(PRM_TXT_SUB_QUIT_RATE , NAM_SUB_QUIT_RATE , aryMessage); 
	
	checkNumber(PRM_TXT_OVER_TIME_RATE , NAM_OVER_TIME_RATE , aryMessage); 
	checkNumber(PRM_TXT_CAUTION_MONTH_HOUR , NAM_CAUTION_MONTH_HOUR , aryMessage);
	checkNumber(PRM_TXT_CAUTION_MONTH_MIN , NAM_CAUTION_MONTH_MIN , aryMessage);
	checkNumber(PRM_TXT_MONTHLY_OVER_TIME_RATE , NAM_MONTHLY_OVER_TIME_RATE , aryMessage); 
	checkNumber(PRM_TXT_SUB_ACQUIRE_RATE , NAM_SUB_ACQUIRE_RATE , aryMessage); 
	checkNumber(PRM_TXT_SUB_ACQUIRE_HOLIDAY_RATE , NAM_SUB_ACQUIRE_HOLIDAY_RATE , aryMessage); 
	checkNumber(PRM_TXT_SUB_QUIT_RATE , NAM_SUB_QUIT_RATE , aryMessage); 

	checkNumberMinValue(PRM_TXT_OVER_TIME_RATE, 125, NAM_OVER_TIME_RATE, aryMessage);
	checkNumberMinValue(PRM_TXT_MONTHLY_OVER_TIME_RATE, 150, NAM_MONTHLY_OVER_TIME_RATE, aryMessage);
	checkNumberMinValue(PRM_TXT_SUB_ACQUIRE_RATE, 125, NAM_SUB_ACQUIRE_RATE, aryMessage);
	checkNumberMinValue(PRM_TXT_SUB_ACQUIRE_HOLIDAY_RATE, 125, NAM_SUB_ACQUIRE_HOLIDAY_RATE, aryMessage);
	checkNumberMinValue(PRM_TXT_SUB_QUIT_RATE, 150, NAM_SUB_QUIT_RATE, aryMessage);

	checkTimeValue(PRM_TXT_CAUTION_MONTH_HOUR ,PRM_TXT_CAUTION_MONTH_MIN , 60 , NAM_CAUTION_MONTH ,aryMessage); 

	checkDate(PRM_PLT_START_DATE_YEAR, PRM_PLT_START_DATE_MONTH, PRM_PLT_START_DATE_DAY, NAM_START_DATE, aryMessage);


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

/**
 * 最小値確認
 * @param target		確認対象
 * @param minValue		最小値
 * @param rep			変換文字列
 * @param aryMessage	エラーメッセージ格納配列
 * @return
 */
function checkNumberMinValue(target, minValue, rep, aryMessage) {
	if (checkNumberNoMsg(target)) {
		if (getFormValue(target) < minValue) {
			if (aryMessage.length == 0) {
				setFocus(target);
				setMessage("WC2026", rep + "," + minValue);
			}
			setBgColor(target, COLOR_FIELD_ERROR);
			aryMessage.push(getMessage("WC2026", rep + "," + minValue));
		}
	}
}

/**
 * 10進数の整数を返す
 * @param target 対象文字列
 */
function parseIntDecimal(target) {
	return parseInt(target, 10);
}
