/*
 * 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.
 */
var KEY_SEPARATOR      = ",";

/**
 * 画面読込時追加処理
 * @param 無し
 * @return 無し
 * @throws 実行時例外
 */
function onLoadExtra() {
	// 項目背景色設定
	setFieldsBgColor(ARY_FIELDS_ID,     COLOR_FIELD_NORMAL);
	setFieldsBgColor(ARY_ERR_FIELDS_ID, COLOR_FIELD_ERROR);
	// フォーカス設定(EDITの場合)
	setFocus(PRM_PLT_YEAR);
	/*	2008/11/14	m.yoshida	登録方法追加	*/
	changeVisibility(PRM_CKB_SELECT_WORK_TYPE	, "divWorkType"	, "divRotation"	);
	changeVisibility(PRM_CKB_SELECT_PERIOD		, "divMonthly"	, "divDaily"	);
	
}

/**
 * サーバー通信処理
 * @param 無し
 * @return 無し
 * @throws 実行時例外
 */
function submitForm(objForm) {
	// 入力チェック
	if (validate()) {
		doSubmitMessage(objForm, 'K1223', 'QC0001', "");
	}
}

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

	/*	2008/11/14	m.yoshida	登録方法追加	*/	
	var check = document.getElementsByName(PRM_CKB_SELECT_PERIOD);
	for(var i = 0; i < check.length ;i++){
		if(check[i].checked) {
			checkDate(PRM_PLT_YEAR, PRM_PLT_MONTH, PRM_PLT_SCHEDULE_DAY, NAM_SCHEDULE_START, aryMessage);
		}
	}
	check = document.getElementsByName(PRM_CKB_SELECT_WORK_TYPE);
	for(var i = 0; i < check.length ;i++){
		if(check[i].checked) {
			checkRequired(PRM_PLT_ROTATION_CODE	, NAM_ROTATION_TYPE	, aryMessage);
		}
	}

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

/**
 * 表示対象変更
 *	2008/11/14	m.yoshida	登録方法追加
 * @param ckb		対象チェックボックスID
 * @param target1	対象箇所１
 * @param target2	対象箇所２
 */
function changeVisibility(ckb, target1, target2) {
	var check = document.getElementsByName(ckb);
	for(var i = 0; i < check.length ;i++){
		if(check[i].checked) {
			setDivVisibility(target1, false);
			setDivVisibility(target2, true);			
		} else {
			setDivVisibility(target1, true);
			setDivVisibility(target2, false);
		}
	}
}

/**
 * 表示対象可視変更
 *	2008/11/14	m.yoshida	登録方法追加
 * @param target	対象箇所
 * @param isVisible	可視判定
 */
function setDivVisibility(target, isVisible) {
	var objTarget = getObject(target);
	if (isVisible) {
		objTarget.style.display = "block";
	} else {
		objTarget.style.display = "none";
	}
}
