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

/**
 * 画面読込時追加処理
 * @param 無し
 * @return 無し
 * @throws 実行時例外
 */
function onLoadExtra() {
	// 項目背景色設定
	setFieldsBgColor(ARY_FIELDS_ID,     COLOR_FIELD_NORMAL);
	setFieldsBgColor(ARY_ERR_FIELDS_ID, COLOR_FIELD_ERROR);
	// フォーカス設定(EDITの場合)
	/*	2008/11/14	m.yoshida	選択情報表示	*/
	//setFocus(PRM_PLT_SCHEDULE_YEAR);
	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, 'K1221', 'QC0001', "");
	}
}

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

	//checkDate(PRM_PLT_SCHEDULE_YEAR, PRM_PLT_SCHEDULE_MONTH, PRM_PLT_SCHEDULE_DAY, NAM_SCHEDULE_START, aryMessage);
	//checkRequired(PRM_PLT_ROTATION_CODE	, NAM_ROTATION_TYPE	, aryMessage);
	/*	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;
	}
}

function checkDate(yyyy, mm, dd,msg,aryMsg) {
	//年月日チェック
	dayMonth = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
	ValidFlag = true;
	yyyy2 = getFormValue(yyyy);
	mm2 = getFormValue(mm);
	dd2 = getFormValue(dd);
	if ((mm2 < 1) || (mm2 > 12)){
		setBgColor(yyyy, COLOR_FIELD_ERROR);
		aryMsg.push(msg + "の月は1--12を入力してください。");
	}
	if ((dd2 < 1) || (dd2 > dayMonth[mm2 - 1])){
		setBgColor(dd, COLOR_FIELD_ERROR);
		aryMsg.push(getMessage("WC0006", msg));
	}
	if (!chkUrudosi(yyyy2) && (mm2 == 2) && (dd2 == 29)){
		setBgColor(dd, COLOR_FIELD_ERROR);
		aryMsg.push(getMessage("WC0006", msg));
	}
}

function chkUrudosi(y) {
	if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {
		return true;
	}
	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";
	}
}
