/**
 * 初期化処理
 * 作成期間指定の初期表示設定する
 */
function init() {
	dselChange(document.SearchForm.dsel);
}

/**
 * 作成期間指定の表示設定する
 *
 * @param obj 作成期間指定オブジェクト
 */
function dselChange(obj) {
	if ( obj.value == "98" ) {
		document.getElementById("singledata").style.display = "";
		document.getElementById("datespan").style.display = "none";
	} else if( obj.value == "99" ) {
		document.getElementById("singledata").style.display = "none";
		document.getElementById("datespan").style.display = "";
	} else {
		document.getElementById("singledata").style.display = "none";
		document.getElementById("datespan").style.display = "none";
	}
}

/**
 * 作成期間指定の表示設定する
 *
 * @param obj 日付オブジェクト
 * @param len 日付文字列の最大文字数
 * @param next 次に遷移するオブジェクト
 */
function changeDate(obj, len, next) {
	if ( obj.value.length >= len ) {
		eval("document.SearchForm." + next).focus();
	}
}

/**
 * Submit時のチェック処理
 */
function submitFunc() {
	// 日付指定入力時チェック
	if ( document.SearchForm.dsel.value == "98" ) {
		var syear  = document.SearchForm.syear.value;
		var smonth = document.SearchForm.smonth.value;
		var sdate  = document.SearchForm.sdate.value;

		if ( isBrank(syear) ) {
			alert("日付を入力してください。");
			return false;
		}
		if ( isBrank(smonth) && !isBrank(sdate) ) {
			alert("日付は年月日形式で入力してください。");
			return false;
		}
		if ( !isNumber(syear) ||
			 !isNumber(smonth) ||
			 !isNumber(sdate) ) {
			alert("日付は年月日形式で入力してください。");
			return false;
		}

		if ( syear.length != 4 ) {
			alert("日付は年月日形式で入力してください。");
			return false;
		}

		if ( isBrank(smonth) ) {
			smonth = "01";
		}
		if ( isBrank(sdate) ) {
			sdate = "01";
		}
		var singleDate = syear + "/" + smonth + "/" + sdate;
		if ( !checkDate(singleDate) ) {
			alert("日付は年月日形式で入力してください。");
			return false;
		}
	}

	// 日付範囲入力時チェック
	if ( document.SearchForm.dsel.value == "99" ) {
		var fyear  = document.SearchForm.fyear.value;
		var fmonth = document.SearchForm.fmonth.value;
		var fdate  = document.SearchForm.fdate.value;
		var tyear  = document.SearchForm.tyear.value;
		var tmonth = document.SearchForm.tmonth.value;
		var tdate  = document.SearchForm.tdate.value;

		if ( isBrank(fyear) && isBrank(tyear) ) {
			alert("日付を入力してください。");
			return false;
		}

		if ( isBrank(fyear) && !isBrank(fmonth) ) {
			alert("日付は年月日形式で入力してください。");
			return false;
		}
		if ( isBrank(fmonth) && !isBrank(fdate) ) {
			alert("日付は年月日形式で入力してください。");
			return false;
		}
		if ( isBrank(tyear) && !isBrank(tmonth) ) {
			alert("日付は年月日形式で入力してください。");
			return false;
		}
		if ( isBrank(tmonth) && !isBrank(tdate) ) {
			alert("日付は年月日形式で入力してください。");
			return false;
		}

		if ( !isNumber(fyear) ||
			 !isNumber(fmonth) ||
			 !isNumber(fdate) ||
			 !isNumber(tyear) ||
			 !isNumber(tmonth) ||
			 !isNumber(tdate) ) {
			alert("日付は年月日形式で入力してください。");
			return false;
		}

		if ( !isBrank(fyear) && fyear.length != 4 ) {
			alert("日付は年月日形式で入力してください。");
			return false;
		}
		if ( !isBrank(tyear) && tyear.length != 4 ) {
			alert("日付は年月日形式で入力してください。");
			return false;
		}

		if ( isBrank(fyear) ) {
			fyear = "1970";
		}
		if ( isBrank(fmonth) ) {
			fmonth = "01";
		}
		if ( isBrank(fdate) ) {
			fdate = "01";
		}

		if ( isBrank(tyear) ) {
			tyear = "9999";
		}
		if ( isBrank(tmonth) ) {
			tmonth = "12";
		}
		if ( isBrank(tdate) ) {
			tdate = "28";
		}

		var fromDate = fyear + "/" + fmonth + "/" + fdate;
		var toDate = tyear + "/" + tmonth + "/" + tdate;
		if ( !checkDate(fromDate) || !checkDate(toDate)  ) {
			alert("日付は年月日形式で入力してください。");
			return false;
		}

		if ( !compare(fromDate, toDate) ) {
			alert("期間の前後を正しく入力してください。");
			return false;
		}
	}

	// カテゴリーチェック状況設定
	var ccheckVal = "";
	for ( i = 0; i < document.SearchForm.check.length; i++ ) {
		if ( document.SearchForm.check[i].checked ) {
			ccheckVal += document.SearchForm.check[i].value + " ";
		}
	}
	if ( ccheckVal == "" ) {
		alert("カテゴリーを1つ以上選択してください。");
		return false;
	}

	document.SearchForm.ccheck.value = ccheckVal;
	document.SearchForm.ssel.value = "0";
	document.SearchForm.nowPage.value = "1";

	return true;
}

