/*
 * 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.
 */
date = new Date();
year = date.getFullYear();
month = date.getMonth()+1;
/**
 * 画面読込時追加処理
 * @param 無し
 * @return 無し
 * @throws 実行時例外
 */
function onLoadExtra() {
	// 項目背景色設定
	setFieldsBgColor(ARY_FIELDS_ID    , COLOR_FIELD_NORMAL);
	setFieldsBgColor(ARY_ERR_FIELDS_ID, COLOR_FIELD_ERROR );
	// 項目長設定
	setMaxLength(PRM_TXT_K_CODE	, LEN_K_CODE	);
	// 初期設定
	if (year >= 2010 && month >= 4) {
		setOption(PRM_PLT_START_YEAR, ARY_NEW_YEAR);
		setOption(PRM_PLT_START_MONTH, ARY_NEW_MONTH);
		setOption(PRM_PLT_END_YEAR, ARY_NEW_YEAR);
		setOption(PRM_PLT_END_MONTH, ARY_NEW_MONTH);
		setFormValue(PRM_PLT_START_YEAR, year);
		setFormValue(PRM_PLT_START_MONTH, month);
		setFormValue(PRM_PLT_END_YEAR, year);
		setFormValue(PRM_PLT_END_MONTH, month);
	} else {
		setOption(PRM_PLT_START_YEAR, ARY_OLD_YEAR);
		setOption(PRM_PLT_START_MONTH, ARY_OLD_MONTH);
		setOption(PRM_PLT_END_YEAR, ARY_OLD_YEAR);
		setOption(PRM_PLT_END_MONTH, ARY_OLD_MONTH);
		setFormValue(PRM_PLT_START_YEAR, year);
		setFormValue(PRM_PLT_START_MONTH, month);
		setFormValue(PRM_PLT_END_YEAR, year);
		setFormValue(PRM_PLT_END_MONTH, month);
	}
}




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

/**
 * 入力チェック
 * @param 無し
 * @return チェック結果(true：OK、false：NG)
 * @throws 実行時例外
 */
function validate() {
	// フィールド背景色設定
	setFieldsBgColor(ARY_FIELDS_ID, COLOR_FIELD_NORMAL);
	// 入力チェック
	var aryMessage = new Array();
	
	checkLength(PRM_TXT_K_CODE, LEN_K_CODE, NAM_K_CODE, aryMessage);

	var startDate = new Date(getFormValue(PRM_PLT_START_YEAR), getFormValue(PRM_PLT_START_MONTH) -1);
	var endDate = new Date(getFormValue(PRM_PLT_END_YEAR), getFormValue(PRM_PLT_END_MONTH) -1);
	if (startDate > endDate) {
		if (aryMessage.length == 0) {
			setFocus(PRM_PLT_START_YEAR);
			setMessage("WC0006", NAM_START_DATE);
		}
		setBgColor(PRM_PLT_START_YEAR, COLOR_FIELD_ERROR);
		setBgColor(PRM_PLT_START_MONTH, COLOR_FIELD_ERROR);
		aryMessage.push(getMessage("WC0006", NAM_START_DATE));
	}
	
	if (aryMessage.length == 0) {
		return true;
	} else {
		showMessage(aryMessage);
		return false;
	}
}

function setYMPlt() {
	var tableType = getFormValue(PRM_PLT_WORK_TABLE);
	var startYear = getFormValue(PRM_PLT_START_YEAR);
	var startMonth = getFormValue(PRM_PLT_START_MONTH);
	var endYear = getFormValue(PRM_PLT_END_YEAR);
	var endMonth = getFormValue(PRM_PLT_END_MONTH);
	if (tableType == "0") {
		if (startYear >= 2010 || endYear >= 2010) {
			if (startYear >= 2010) {
				setOption(PRM_PLT_START_YEAR, ARY_OLD_YEAR);
				setOption(PRM_PLT_START_MONTH, ARY_OLD_MONTH);
				setFormValue(PRM_PLT_START_YEAR, "2010");
				setFormValue(PRM_PLT_START_MONTH, "3");
			}
			if (endYear >= 2010) {
				setOption(PRM_PLT_END_YEAR, ARY_OLD_YEAR);
				setOption(PRM_PLT_END_MONTH, ARY_OLD_MONTH);
				setFormValue(PRM_PLT_END_YEAR, "2010");
				setFormValue(PRM_PLT_END_MONTH, "3");
			}
		}
	} else if (tableType == "1") {
		if (startYear <= 2010 || endYear <= 2010) {
			if (startYear <= 2010) {
				setOption(PRM_PLT_START_YEAR, ARY_NEW_YEAR);
				setOption(PRM_PLT_START_MONTH, ARY_NEW_MONTH);
				setFormValue(PRM_PLT_START_YEAR, "2010");
				setFormValue(PRM_PLT_START_MONTH, "4");
			}
			if (endYear <= 2010) {
				setOption(PRM_PLT_END_YEAR, ARY_NEW_YEAR);
				setOption(PRM_PLT_END_MONTH, ARY_NEW_MONTH);
				setFormValue(PRM_PLT_END_YEAR, "2010");
				setFormValue(PRM_PLT_END_MONTH, "4");
			}
		}
	}
}

function setPltStartMonth() {
	var tableType = getFormValue(PRM_PLT_WORK_TABLE);
	var startYear = getFormValue(PRM_PLT_START_YEAR);
	var startMonth = getFormValue(PRM_PLT_START_MONTH);
	var endYear = getFormValue(PRM_PLT_END_YEAR);
	var endMonth = getFormValue(PRM_PLT_END_MONTH);
	if (tableType == "0" && startYear == "2010") {
		setOption(PRM_PLT_START_MONTH, ARY_OLD_MONTH);
		if (startMonth > 3) {
			setFormValue(PRM_PLT_START_MONTH, "3");
		} else {
			setFormValue(PRM_PLT_START_MONTH, startMonth);
		}
	} else if (tableType == "1" && startYear == "2010") {
		setOption(PRM_PLT_START_MONTH, ARY_NEW_MONTH);
		if (startMonth > 3) {
			setFormValue(PRM_PLT_START_MONTH, startMonth);
		} else {
			setFormValue(PRM_PLT_START_MONTH, "4");
		}
	} else if (startYear != "2010") {
		setOption(PRM_PLT_START_MONTH, ARY_PLT_MONTH);
		setFormValue(PRM_PLT_START_MONTH, startMonth);
	}
}

function setPltEndMonth() {
	var tableType = getFormValue(PRM_PLT_WORK_TABLE);
	var startYear = getFormValue(PRM_PLT_START_YEAR);
	var startMonth = getFormValue(PRM_PLT_START_MONTH);
	var endYear = getFormValue(PRM_PLT_END_YEAR);
	var endMonth = getFormValue(PRM_PLT_END_MONTH);
	if (tableType == "0" && endYear == "2010") {
		setOption(PRM_PLT_END_MONTH, ARY_OLD_MONTH);
		if (endMonth > 3) {
			setFormValue(PRM_PLT_END_MONTH, "3");
		} else {
			setFormValue(PRM_PLT_END_MONTH, endMonth);
		}
	} else if (tableType == "1" && endYear == "2010") {
		setOption(PRM_PLT_END_MONTH, ARY_NEW_MONTH);
		if (endMonth > 3) {
			setFormValue(PRM_PLT_END_MONTH, endMonth);
		} else {
			setFormValue(PRM_PLT_END_MONTH, "4");
		}
	} else if (endYear != "2010") {
		setOption(PRM_PLT_END_MONTH, ARY_PLT_MONTH);
		setFormValue(PRM_PLT_END_MONTH, endMonth);
	}
}
