/**
 * 画面読込時追加処理
 * @param 無し
 * @return 無し
 * @throws 実行時例外
 */
function onLoadExtra() {
	// 項目背景色設定
	setFieldsBgColor(ARY_FIELDS_ID    , COLOR_FIELD_NORMAL);
	setFieldsBgColor(ARY_ERR_FIELDS_ID, COLOR_FIELD_ERROR );
	// 項目長設定
	setMaxLength(PRM_TXT_SHIFT_CODE 		, LEN_SHIFT_CODE);
	setMaxLength(PRM_TXT_SHIFT_NAME 		, LEN_SHIFT_NAME);
	setMaxLength(PRM_TXT_START_HOUR 		, LEN_TIME);
	setMaxLength(PRM_TXT_START_MIN 			, LEN_TIME);
	setMaxLength(PRM_TXT_QUIT_HOUR 			, LEN_TIME);
	setMaxLength(PRM_TXT_QUIT_MIN 			, LEN_TIME);
	setMaxLength(PRM_TXT_WORK_HOUR 			, LEN_TIME);
	setMaxLength(PRM_TXT_WORK_MIN 			, LEN_TIME);
	setMaxLength(PRM_TXT_BREAK_HOUR 		, LEN_TIME);
	setMaxLength(PRM_TXT_BREAK_MIN 			, LEN_TIME);
	setMaxLength(PRM_TXT_OVER_START_HOUR 	, LEN_TIME);
	setMaxLength(PRM_TXT_OVER_START_MIN 	, LEN_TIME);
	setMaxLength(PRM_TXT_OVER_BREAK_HOUR 	, LEN_TIME);
	setMaxLength(PRM_TXT_OVER_BREAK_MIN 	, LEN_TIME);
	// 登録/更新判定
	if (MODE == 0) {
		// 読取専用設定
		setReadOnly(PRM_PLT_DELETE  	, true);
		setReadOnly(PRM_TXT_WORK_HOUR  	, true);
		setReadOnly(PRM_TXT_WORK_MIN  	, true);
		// フォーカス設定
		setFocus(PRM_TXT_SHIFT_CODE);
	} else if (MODE == 1) {
		// 読取専用設定
		setReadOnly(PRM_TXT_SHIFT_CODE  , true);
		setReadOnly(PRM_TXT_WORK_HOUR  	, true);
		setReadOnly(PRM_TXT_WORK_MIN  	, true);
		// フォーカス設定
		setFocus(PRM_TXT_SHIFT_NAME);
	}
	// 新規登録ボタン利用可否
	if (MODE != 1){
		setObjectVisibility("btnNewData", false);	
		setWidth("btnNewData", 0);
	}
}

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

/**
 * 入力チェック
 * @param 無し
 * @return チェック結果(true：OK、false：NG)
 * @throws 実行時例外
 */
function validate() {
	// フィールド背景色設定
	setFieldsBgColor(ARY_FIELDS_ID, COLOR_FIELD_NORMAL);
	// 入力チェック
	var aryMessage = new Array();
	checkRequired(PRM_TXT_SHIFT_CODE		, NAM_SHIFT_CODE			, aryMessage);
	checkRequired(PRM_TXT_SHIFT_NAME		, NAM_SHIFT_NAME			, aryMessage);
	checkRequired(PRM_TXT_START_HOUR		, NAM_START_TIME_HOUR		, aryMessage);
	checkRequired(PRM_TXT_START_MIN			, NAM_START_TIME_MIN		, aryMessage);
	checkRequired(PRM_TXT_QUIT_HOUR			, NAM_QUIT_TIME_HOUR		, aryMessage);
	checkRequired(PRM_TXT_QUIT_MIN			, NAM_QUIT_TIME_MIN			, aryMessage);
	checkRequired(PRM_TXT_WORK_HOUR			, NAM_WORKING_HOURS_HOUR	, aryMessage);
	checkRequired(PRM_TXT_WORK_MIN			, NAM_WORKING_HOURS_MIN		, aryMessage);
	checkRequired(PRM_TXT_BREAK_HOUR		, NAM_BREAK_TIME_HOUR		, aryMessage);
	checkRequired(PRM_TXT_BREAK_MIN			, NAM_BREAK_TIME_MIN		, aryMessage);
	checkRequired(PRM_TXT_OVER_START_HOUR	, NAM_OVERTIME_START_HOUR	, aryMessage);
	checkRequired(PRM_TXT_OVER_START_MIN	, NAM_OVERTIME_START_MIN	, aryMessage);
	checkRequired(PRM_TXT_OVER_BREAK_HOUR	, NAM_OVERTIME_BREAK_HOUR	, aryMessage);
	checkRequired(PRM_TXT_OVER_BREAK_MIN	, NAM_OVERTIME_BREAK_MIN	, aryMessage);
	
	checkCode    (PRM_TXT_SHIFT_CODE , NAM_SHIFT_CODE, aryMessage);
	
	checkNumber  (PRM_TXT_START_HOUR		, NAM_START_TIME_HOUR		, aryMessage);
	checkNumber  (PRM_TXT_START_MIN			, NAM_START_TIME_MIN		, aryMessage);
	checkNumber  (PRM_TXT_QUIT_HOUR			, NAM_QUIT_TIME_HOUR		, aryMessage);
	checkNumber  (PRM_TXT_QUIT_MIN			, NAM_QUIT_TIME_MIN			, aryMessage);
	checkNumber  (PRM_TXT_BREAK_HOUR		, NAM_BREAK_TIME_HOUR		, aryMessage);
	checkNumber  (PRM_TXT_BREAK_MIN			, NAM_BREAK_TIME_MIN		, aryMessage);
	checkNumber  (PRM_TXT_OVER_START_HOUR	, NAM_OVERTIME_START_HOUR	, aryMessage);
	checkNumber  (PRM_TXT_OVER_START_MIN	, NAM_OVERTIME_START_MIN	, aryMessage);
	checkNumber  (PRM_TXT_OVER_BREAK_HOUR	, NAM_OVERTIME_BREAK_HOUR	, aryMessage);
	checkNumber  (PRM_TXT_OVER_BREAK_MIN	, NAM_OVERTIME_BREAK_MIN	, aryMessage);

	checkLength(PRM_TXT_SHIFT_CODE 		, LEN_SHIFT_CODE 	, NAM_SHIFT_CODE			, aryMessage);
	checkLength(PRM_TXT_SHIFT_NAME 		, LEN_SHIFT_NAME 	, NAM_SHIFT_NAME			, aryMessage);
	checkLength(PRM_TXT_START_HOUR 		, LEN_TIME 			, NAM_START_TIME_HOUR		, aryMessage);
	checkLength(PRM_TXT_START_MIN 		, LEN_TIME 			, NAM_START_TIME_MIN		, aryMessage);
	checkLength(PRM_TXT_QUIT_HOUR 		, LEN_TIME 			, NAM_QUIT_TIME_HOUR		, aryMessage);
	checkLength(PRM_TXT_QUIT_MIN 		, LEN_TIME 			, NAM_QUIT_TIME_MIN			, aryMessage);
	checkLength(PRM_TXT_WORK_HOUR 		, LEN_TIME 			, NAM_WORKING_HOURS_HOUR	, aryMessage);
	checkLength(PRM_TXT_WORK_MIN 		, LEN_TIME 			, NAM_WORKING_HOURS_MIN		, aryMessage);
	checkLength(PRM_TXT_BREAK_HOUR 		, LEN_TIME 			, NAM_BREAK_TIME_HOUR		, aryMessage);
	checkLength(PRM_TXT_BREAK_MIN 		, LEN_TIME 			, NAM_BREAK_TIME_MIN		, aryMessage);
	checkLength(PRM_TXT_OVER_START_HOUR , LEN_TIME 			, NAM_OVERTIME_START_HOUR	, aryMessage);
	checkLength(PRM_TXT_OVER_START_MIN 	, LEN_TIME 			, NAM_OVERTIME_START_MIN	, aryMessage);
	checkLength(PRM_TXT_OVER_BREAK_HOUR , LEN_TIME 			, NAM_OVERTIME_BREAK_HOUR	, aryMessage);
	checkLength(PRM_TXT_OVER_BREAK_MIN 	, LEN_TIME 			, NAM_OVERTIME_BREAK_MIN	, aryMessage);
	//時間、分の合計値チェック
	checkTimeValue(PRM_TXT_START_HOUR		,PRM_TXT_START_MIN		, 24 , NAM_START_TIME		,aryMessage);
	checkTimeValue(PRM_TXT_QUIT_HOUR		,PRM_TXT_QUIT_MIN		, 48 , NAM_QUIT_TIME		,aryMessage);
	checkTimeValue(PRM_TXT_BREAK_HOUR		,PRM_TXT_BREAK_MIN		, 24 , NAM_BREAK_TIME		,aryMessage);
	checkTimeValue(PRM_TXT_OVER_START_HOUR	,PRM_TXT_OVER_START_MIN	, 48 , NAM_OVERTIME_START	,aryMessage);
	checkTimeValue(PRM_TXT_OVER_BREAK_HOUR	,PRM_TXT_OVER_BREAK_MIN	, 24 , NAM_OVERTIME_BREAK	,aryMessage);

	var start 	= getFormValue(PRM_TXT_START_HOUR) * 60 + eval(getFormValue(PRM_TXT_START_MIN));
	var quit 	= getFormValue(PRM_TXT_QUIT_HOUR)  * 60 + eval(getFormValue(PRM_TXT_QUIT_MIN));
	if (quit < start) {
		setBgColor(PRM_TXT_START_HOUR, COLOR_FIELD_ERROR);
		setBgColor(PRM_TXT_START_MIN, COLOR_FIELD_ERROR);
		setBgColor(PRM_TXT_QUIT_HOUR, COLOR_FIELD_ERROR);
		setBgColor(PRM_TXT_QUIT_MIN, COLOR_FIELD_ERROR);
		aryMessage.push(getMessage("WC2028", NAM_START_TIME + "," + NAM_QUIT_TIME));
	}
	
	setFormValue(PRM_TXT_WORK_HOUR, Math.floor(eval((quit - start) / 60)));
	setFormValue(PRM_TXT_WORK_MIN, eval((quit - start) % 60));

	var breakHour = getFormValue(PRM_TXT_BREAK_HOUR);
	var breakMin  = getFormValue(PRM_TXT_BREAK_MIN);
	if ((quit - start) < (breakHour * 60 + eval(breakMin))) {
		setBgColor(PRM_TXT_BREAK_HOUR, COLOR_FIELD_ERROR);
		setBgColor(PRM_TXT_BREAK_MIN, COLOR_FIELD_ERROR);
		aryMessage.push(getMessage("WC2028", NAM_BREAK_TIME + "," + NAM_WORKING_HOURS));
	}
	
	if (aryMessage.length == 0) {
		return true;
	} else {
		showMessage(aryMessage);
		return false;
	}
}
