// 開始日付と終了日付の妥当性チェック
function dateRangeCheck(form) {
	
	var startYear = form.startYear.value;
	var startMonth = form.startMonth.value;
	var startDay = form.startDay.value;	
	var endYear = form.endYear.value;
	var endMonth = form.endMonth.value;
	var endDay = form.endDay.value;
	
	// 開始日付の入力有無チェック
	var blankStartDate = isBlankDate(startYear, startMonth, startDay);
	var notBlankStartDate = isNotBlankDate(startYear, startMonth, startDay);
	// 終了日付の入力有無チェック
	var blankEndDate = isBlankDate(endYear, endMonth, endDay);
	var notBlankEndDate = isNotBlankDate(endYear, endMonth, endDay);
	
	// 開始日付
	var startDate = new Date(startYear + "/" + startMonth + "/" + startDay);
	// 終了日付
	var endDate = new Date(endYear + "/" +  endMonth + "/" + endDay);

	var checkFlg = true;

	// 開始日付と終了日付のどちらも入力されていない場合はＮＧ
	if( (blankStartDate == true) && (blankEndDate == true)  ) {
		checkFlg = false;
	}

	// 開始日付の妥当性チェック
	if((startYear != "" || startMonth != "" || startDay!="") && checkFlg){
		// 年・月・日のいづれかが入力されていない場合
		if(startYear == "" || startMonth == "" || startDay == ""){
			checkFlg = false;
		}else{
			// ２月の場合
			if( startMonth == "2") {
				checkFlg = dayOfLeapYearCheck(startYear, startDay);
			}
			// ２月以外の場合
			else {
				checkFlg = dayOfMonthCheck(startMonth, startDay);
			}
		}
	}

	// 終了日付の妥当性チェック
	if((endYear != "" || endMonth != "" || endDay !="") && checkFlg){
		// 年・月・日のいづれかが入力されていない場合
		if(endYear == "" || endMonth == "" || endDay == ""){
			checkFlg = false;
		}else{
			// ２月の場合
			if( endMonth == "2") {
				checkFlg = dayOfLeapYearCheck(endYear, endDay);
			}
			// ２月以外の場合
			else {
				checkFlg = dayOfMonthCheck(endMonth, endDay);
			}
		}
	}

	
	
	// 開始日付と終了日付の関連チェック 
	if((notBlankStartDate == true) && (notBlankEndDate == true) && checkFlg) {
		// 開始年＞終了年の場合
		if( parseInt(startYear) > parseInt(endYear) ) {
	
			checkFlg = false;
		}
		// 開始年＝終了年で、開始月＞終了月の場合
		else if((startYear == endYear)  && ( parseInt(startMonth) > parseInt(endMonth)) ) {
	
			checkFlg = false;
		}
		// 開始年＝終了年で、開始月＝終了月で、開始日＞終了日の場合
		else if((startYear == endYear) && (startMonth == endMonth) && ( parseInt(startDay) > parseInt(endDay)) ) {
	
			checkFlg = false;
		}
	}
	
	
	
	// チェックＯＫであれば、PDFダウンロード中画面を表示
	if(checkFlg){
		
		if( typeof( form.elements[ "autoFocus" ] ) != "undefined" ) { 
			//オートフォーカスを無効にする。
			form.elements[ "autoFocus" ].value = false;
		}
		pdfWindowOpen(form);
	}
	
}

// 改正経過印刷画面のポップアップ画面を表示する
// エラーチェックはサーバー側で実施する
function openPrintProcessRevision(form) {
	
	// 実行中の子ウィンドウがなければ、改正経過印刷画面のポップアップ画面を表示
	if (isChildWindowProcessing=="FALSE") {
		pdfAsyncWindowOpen(form,"printProcessRevision.do?action=doShow");
	}
	
}

// 年・月・日が全て未入力のチェック
function isBlankDate(year, month, day) {
	if( year == "" && month == "" && day == "") {
		return true;
	}
	return false;
}

// 年・月・日が全て入力済のチェック
function isNotBlankDate(year, month, day) {
	if( year != "" && month != "" && day != "") {
		return true;
	}
	return false;
} 	

// ２月の日付の妥当性チェック
function dayOfLeapYearCheck(inYear, inDay) {
	var year = Number(inYear);
	if (((year%4)==0 && (year%100)!=0) || (year%400)==0) {
		if( (inDay == "30") || (inDay == "31")) {
			return false;
		}
	}
	else {
		if((inDay == "29") || (inDay == "30") || (inDay == "31")) {
			return false;
		}
	}
	return true;
}

// ２月以外の月の日付の妥当性チェック
function dayOfMonthCheck(month, day) {
	if((month == "4") || (month == "6") || (month == "9") || (month == "11")) {
		if(day == "31") {
			return false;
		}
	}
	return true;
}

// ボタンの２度押し制御
function disableDownload(form) {
	for(i = 0; i < form.elements.length; i++ ) {
    	if(form.elements[i].type == 'submit') {
	    	form.elements[i].disabled = true;
	    }
    }	
}


