/*************************************
 *【共通】値を１項目セット後、submit
 *    引数
 *      frmname : フォーム名
 *      valname : element名
 *      val     : 値
 *************************************/
function SetVal_Submit1(frmname,valname,val) {
	document.forms[frmname].elements[valname].value = val;
	document.forms[frmname].submit();
}

/*************************************
 *【共通】値を２項目セット後、submit
 *    引数
 *      frmname  : フォーム名
 *      valname  : element名1
 *      val      : 値1
 *      valname2 : element名2
 *      val2     : 値2
 *************************************/
function SetVal_Submit2(frmname,valname,val,valname2,val2) {
	document.forms[frmname].elements[valname].value = val;
	document.forms[frmname].elements[valname2].value = val2;
	document.forms[frmname].submit();
}

/*************************************
 *【共通】ボタン押下時、確認アラート表示からsubmit
 *    引数
 *      ConfMsg : 処理メッセージ ※「登録」「変更」「削除」
 *      FormNm  : はい選択時にsubmitするform名
 *************************************/
function btnConfirmSubmit(ConfMsg, FormNm){
	if(window.confirm('' + ConfMsg + 'しても宜しいでしょうか？')){
		document.forms[FormNm].submit();
	}
}

/*************************************
 *【共通】ボタン押下時、確認アラート表示後、値を１項目セットしsubmit
 *    引数
 *      frmname : フォーム名
 *      valname : element名
 *      val     : 値
 *      ConfMsg : 確認メッセージ    ※「登録」「更新」・・・
 *************************************/
function btnConfirmSubmit1(frmname,valname,val,ConfMsg) {
	if(window.confirm(ConfMsg + "しても宜しいでしょうか？")){
		document.forms[frmname].elements[valname].value = val;
		document.forms[frmname].submit();
	}
}

/*************************************
 *【共通】確認アラート表示後、値を２項目セットしsubmit
 *    引数
 *      frmname  : フォーム名
 *      valname  : element名1
 *      val      : 値1
 *      valname2 : element名2
 *      val2     : 値2
 *      ConfMsg  : 確認メッセージ    ※「登録」「更新」・・・
 *************************************/
function btnConfirmSubmit2(frmname,valname,val,valname2,val2,ConfMsg) {
	if(window.confirm(ConfMsg + "しても宜しいでしょうか？")){
		document.forms[frmname].elements[valname].value = val;
		document.forms[frmname].elements[valname2].value = val2;
		document.forms[frmname].submit();
	}
}

/*************************************
 *【共通】フォームのコントロールを初期化する
 *    引数
 *      frmNm : フォーム名
 *************************************/
function formClear(frmNm){
	var ctrlCnt = document.forms[frmNm].elements.length;
	//全コントロールを確認
	for(i=0;i<ctrlCnt;i++){
		switch (document.forms[frmNm].elements[i].type){
			//テキストボックス
			case "text":
				document.forms[frmNm].elements[i].value = "";
				break;
			//ラジオボタン
			case "radio":
				document.forms[frmNm].elements[i].checked = false;
				break;
			//セレクトボックス
			case "select-one":
				document.forms[frmNm].elements[i].selectedIndex = 0;
				break;
			//チェックボックス
			case "checkbox":
				document.forms[frmNm].elements[i].checked = false;
				break;
		}
	}
}

/*************************************
 *【サプリ管理画面】日付変更
 *    引数
 *      periodkind  : 今日　昨日　今月
 *      year  		: 年
 *      month      	: 月
 *      day 		: 日
 *      formnm    	: フォーム名
 *      date_flg	: 0⇒時分まで　1⇒時分なし
 *************************************/
var periodkind = "";
var formnm = "";
var date_flg = "";
function periodChange(periodkind,year,month,day,formnm,date_flg){

	var year_min = 2006;
	var month_min = 1;
	var day_min = 1;
	var year_cnt = 0;
	var month_cnt = 0;
	var day_cnt = 0;

	while (year_min <= year){
		year_cnt++;
		year_min++;
	}

	while (month_min <= month){
		month_cnt++;
		month_min++;
	}

	while (day_min <= day){
		day_cnt++;
		day_min++;
	}

	if(date_flg == "1"){
		if(periodkind == "thismonth"){

			document.forms[formnm].from_year.options.selectedIndex = year_cnt;
			document.forms[formnm].from_month.options.selectedIndex = month_cnt;
			document.forms[formnm].from_day.options.selectedIndex = 1;

			document.forms[formnm].to_year.options.selectedIndex = year_cnt;
			document.forms[formnm].to_month.options.selectedIndex = month_cnt;
			document.forms[formnm].to_day.options.selectedIndex = day_cnt;
		}else{

			document.forms[formnm].from_year.options.selectedIndex = year_cnt;
			document.forms[formnm].from_month.options.selectedIndex = month_cnt;
			document.forms[formnm].from_day.options.selectedIndex = day_cnt;

			document.forms[formnm].to_year.options.selectedIndex = year_cnt;
			document.forms[formnm].to_month.options.selectedIndex = month_cnt;
			document.forms[formnm].to_day.options.selectedIndex = day_cnt;
		}
	}else{
		if(periodkind == "thismonth"){

			document.forms[formnm].from_year.options.selectedIndex = year_cnt;
			document.forms[formnm].from_month.options.selectedIndex = month_cnt;
			document.forms[formnm].from_day.options.selectedIndex = 1;
			document.forms[formnm].from_hour.options.selectedIndex = 0;
			document.forms[formnm].from_minutes.options.selectedIndex = 0;

			document.forms[formnm].to_year.options.selectedIndex = year_cnt;
			document.forms[formnm].to_month.options.selectedIndex = month_cnt;
			document.forms[formnm].to_day.options.selectedIndex = day_cnt;
			document.forms[formnm].to_hour.options.selectedIndex = 0;
			document.forms[formnm].to_minutes.options.selectedIndex = 0;
		}else{

			document.forms[formnm].from_year.options.selectedIndex = year_cnt;
			document.forms[formnm].from_month.options.selectedIndex = month_cnt;
			document.forms[formnm].from_day.options.selectedIndex = day_cnt;
			document.forms[formnm].from_hour.options.selectedIndex = 0;
			document.forms[formnm].from_minutes.options.selectedIndex = 0;

			document.forms[formnm].to_year.options.selectedIndex = year_cnt;
			document.forms[formnm].to_month.options.selectedIndex = month_cnt;
			document.forms[formnm].to_day.options.selectedIndex = day_cnt;
			document.forms[formnm].to_hour.options.selectedIndex = 0;
			document.forms[formnm].to_minutes.options.selectedIndex = 0;
		}
	}

}

/*************************************
 *【サプリ管理画面】チェックボックスの全チェック
 *    引数
 *      check  		: true　false
 *      list_cnt  	: チェック数
 *      formnm     	: フォーム名
 *************************************/
var chk_cnt;
var list_cnt;
function BoxChecked(check, list_cnt, formnm){
	if(list_cnt != 0){
		for (chk_cnt = 1; chk_cnt <= list_cnt; chk_cnt++){
			document.forms[formnm].elements["list_chk"+chk_cnt].checked = check;
		}
	}

/*
	for (chk_cnt = 0; chk_cnt < document.search_frm.elements['list_chk[]'].length; chk_cnt++){
		document.search_frm.elements['list_chk[]'][chk_cnt].checked = check;
	}
*/
}

/*************************************
 *【サプリ管理画面】改ページ処理
 *    引数
 *      gotopage  	: next　back　jump
 *      nowpage  	: 今のページ
 *      formnm     	: フォーム名
 *************************************/
var gotopage;
var nowpage;
function gotoPage(gotopage, formnm){
	if(gotopage == "next"){
		document.forms[formnm].pageselect.value = parseInt(document.forms[formnm].pageselect.options[document.forms[formnm].pageselect.selectedIndex].value) + 1;
	}else if(gotopage == "back"){
		document.forms[formnm].pageselect.value = parseInt(document.forms[formnm].pageselect.options[document.forms[formnm].pageselect.selectedIndex].value) - 1;
	}else if(gotopage == "jump"){
		document.forms[formnm].pageselect.value = document.forms[formnm].pageselect.selectedIndex + 1;
	}else{
		document.forms[formnm].pageselect.value = "1";
	}
	//document.forms[formnm].submit();
}