/*
 * MosP - Mind Open Source Project         http://www.mosp.jp/
 * Copyright (C) 1987-2009 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_THIS_GET_TY		, LEN_PAID_HOLIDAY	);
	setMaxLength(PRM_TXT_THIS_GET_LY		, LEN_PAID_HOLIDAY	);
	setMaxLength(PRM_TXT_THIS_DISPOSE_TY	, LEN_PAID_HOLIDAY	);
	setMaxLength(PRM_TXT_THIS_DISPOSE_LY	, LEN_PAID_HOLIDAY	);
	setReadOnly(PRM_TXT_THIS_REST_TOTAL , true);
	setReadOnly(PRM_TXT_THIS_REST_TY  	, true);
	setReadOnly(PRM_TXT_THIS_REST_LY  	, true);
	// 一覧背景色設定
	setTableColor("list");
	// 登録/更新判定
	if (MODE == 0) {
		setVisibility("btnRegist", false);
	}
}

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

/**
 * フィールド変更
 * @param 無し
 * @return 
 * @throws 実行時例外
 */
function makeValue(target1,target2,target3,target4){

	// フィールド背景色設定
	setFieldsBgColor(ARY_FIELDS_ID, COLOR_FIELD_NORMAL);
	// 入力チェック
	var aryMessage = new Array();
	checkNumber(PRM_TXT_THIS_GET_TY	, NAM_THIS_GET_THIS		, aryMessage);
	checkNumber(PRM_TXT_THIS_GET_LY	, NAM_THIS_GET_FORMER	, aryMessage);
	checkDecimal(PRM_TXT_THIS_DISPOSE_TY , LEN_INTEGER , LEN_DECIMAL , NAM_THIS_DISPOSE_THIS 	, aryMessage);
	checkDecimal(PRM_TXT_THIS_DISPOSE_LY , LEN_INTEGER , LEN_DECIMAL , NAM_THIS_DISPOSE_FORMER 	, aryMessage);
	
	if (aryMessage.length != 0) {
	showMessage(aryMessage);
	return false;
	} 
	
	var targetA = eval(document.getElementById(target1).value);	
	var targetB	= eval(document.getElementById(target2).value);	
	var targetC = eval(document.getElementById(target3).value);	
	var targetD;
	targetD = targetA + targetB - targetC;
		if(targetD < 0)	{
		targetD = 0;
		 alert("破棄数が有休保有数を超えました。有休保有数は0になります。");
		}
	
	document.getElementById(target4).value = targetD;
	
	var targetLY = eval(document.getElementById(PRM_TXT_THIS_REST_LY).value);	
	var targetTY = eval(document.getElementById(PRM_TXT_THIS_REST_TY).value);	
	
	document.getElementById(PRM_TXT_THIS_REST_TOTAL).value = targetLY + targetTY ;	 
}

/**
 * 入力チェック
 * @param 無し
 * @return チェック結果(true：OK、false：NG)
 * @throws 実行時例外
 */
function validate() {
	// フィールド背景色設定
	setFieldsBgColor(ARY_FIELDS_ID, COLOR_FIELD_NORMAL);
	// 入力チェック
	var aryMessage = new Array();
	//必須確認
	checkRequired(PRM_TXT_THIS_GET_TY		, NAM_THIS_GET_THIS			, aryMessage);
	checkRequired(PRM_TXT_THIS_GET_LY		, NAM_THIS_GET_FORMER		, aryMessage);
	checkRequired(PRM_TXT_THIS_DISPOSE_TY	, NAM_THIS_DISPOSE_THIS		, aryMessage);
	checkRequired(PRM_TXT_THIS_DISPOSE_LY	, NAM_THIS_DISPOSE_FORMER	, aryMessage);
	// 数値チェック
	checkNumber(PRM_TXT_THIS_GET_TY			, NAM_THIS_GET_THIS				, aryMessage);
	checkNumber(PRM_TXT_THIS_GET_LY			, NAM_THIS_GET_FORMER			, aryMessage);
	checkDecimal(PRM_TXT_THIS_DISPOSE_TY , LEN_INTEGER , LEN_DECIMAL , NAM_THIS_DISPOSE_THIS , aryMessage);
	checkDecimal(PRM_TXT_THIS_DISPOSE_LY , LEN_INTEGER , LEN_DECIMAL , NAM_THIS_DISPOSE_FORMER , aryMessage);
		
	if (aryMessage.length == 0) {
		return true;
	} else {
		showMessage(aryMessage);
		return false;
	}
	
}
