/*
 * 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);
	// フォーカス設定
	setFocus(PRM_PLT_REQUEST_YEAR);
	// 項目長設定
	setMaxLength(PRM_TXT_REASON, LEN_REASON);
	// 新規登録、
	if (MODE == 0) {
		setVisibility("btnCancel",false);
	}
	// 更新可能
	if (MODE == 1) {
		setReadOnly(PRM_PLT_REQUEST_YEAR, true);
		setReadOnly(PRM_PLT_REQUEST_MONTH, true);
		setReadOnly(PRM_PLT_REQUEST_DAY, true);
	}
	// 申請中
	if (MODE == 2) {
		setVisibility("btnDraft",false);
		setVisibility("btnRequest",false);
	}
	// 更新不可
	if (MODE == 3) {
		setVisibility("btnDraft",false);
		setVisibility("btnRequest",false);
		setVisibility("btnCancel",false);
	}
	// 差戻更新
	if (MODE == 4) {
		setReadOnly(PRM_PLT_REQUEST_YEAR, true);
		setReadOnly(PRM_PLT_REQUEST_MONTH, true);
		setReadOnly(PRM_PLT_REQUEST_DAY, true);
		setVisibility("btnDraft",false);
	}

}

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

/**
 * 入力チェック
 * @param 無し
 * @return チェック結果(true：OK、false：NG)
 * @throws 実行時例外
 */
function validate() {
	// フィールド背景色設定
	setFieldsBgColor(ARY_FIELDS_ID, COLOR_FIELD_NORMAL);
	// 入力チェック
	var aryMessage = new Array();
	checkDate(PRM_PLT_REQUEST_YEAR, PRM_PLT_REQUEST_MONTH, PRM_PLT_REQUEST_DAY, NAM_WORK_DATE, aryMessage);
	checkTime(PRM_PLT_REQUEST_HOUR, PRM_PLT_REQUEST_MIN, NAM_REQUEST_TIME, aryMessage);
	
	checkRequired(PRM_TXT_REASON, NAM_REASON, aryMessage)
	checkLength(PRM_TXT_REASON, LEN_REASON, NAM_REASON, aryMessage)

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

function checkTime(hourTarget, minuteTarget, rep, aryMessage) {
	var hour = getFormValue(hourTarget);
	var min = getFormValue(minuteTarget);
	var time = eval(hour) *60 + eval(min);
	if (time <= 0) {
		if (aryMessage.length == 0) {
			setFocus(minuteTarget);
			setMessage("WC0007", rep);
		}
		setBgColor(hourTarget, COLOR_FIELD_ERROR);
		setBgColor(minuteTarget, COLOR_FIELD_ERROR);
		aryMessage.push(getMessage("WC0007", rep));
	}
}
