/*=============================================================================================
 * 関数名：chkDate
 * 概要  ：日付のチェック
=============================================================================================*/
/*function chkDate( label, sYear, sMonth, sDay ){
	var year, month, day;
	year = parseInt(sYear.options[sYear.selectedIndex].text, 10);
	month = parseInt(sMonth.options[sMonth.selectedIndex].text, 10);
	day = parseInt(sDay.options[sDay.selectedIndex].text, 10);

	//閏年のチェック
	if( month == '2' ) {
		if( ( (year % 4 == 0) && (year % 100 != 0) ) || (year % 400 == 0) ){
			if( day > 29 ){
				alert("["+label+"] 2月は29日までです。");
				return false;
			}
		} else {
			if( day > 28 ){
				alert("["+label+"] 2月は28日までです。");
				return false;
			}
		}
	} else {
		switch( month ){
			case 4:
			case 6:
			case 9:
			case 11:
				if( day > 30 ){
					alert("["+label+"] "+month+"月は30日までです。");
					return false;
				}
				break;
			default:
				break;
		}
	}

	//日付制限
	var dt = new Date( year, month - 1, day );
	var today = new Date();
	if( dt.getTime() > today.getTime() ) {
		alert("["+label+"] は今日までです。");
		return false;
	}

	return true;

}*/

/*=============================================================================================
 * 関数名：chkDate
 * 概要  ：日付のチェック
=============================================================================================*/
function chkDate(sLabel, sYear, sMonth, sDay){
	iYear = parseInt(sYear.options[sYear.selectedIndex].text, 10);
	iMonth = parseInt(sMonth.options[sMonth.selectedIndex].text, 10);
	iDay = parseInt(sDay.options[sDay.selectedIndex].text, 10);

	return ShowMsgDateErr(sLabel, iYear, iMonth, iDay);
}//end function

/*=============================================================================================
 * 関数名：chkDateTextInput
 * 概要  ：日付のチェック
=============================================================================================*/
function chkDateTextInput(sLabel, oYear, oMonth, oDay){
	iYear = parseInt(oYear.value, 10);
	iMonth = parseInt(oMonth.value, 10);
	iDay = parseInt(oDay.value, 10);

	return ShowMsgDateErr(sLabel, iYear, iMonth, iDay);
}//end function

/*=============================================================================================
 * 関数名：ShowMsgDateErr
 * 概要  ：日付のチェック
=============================================================================================*/
function ShowMsgDateErr(label, year, month, day){
	var bDate = chkDateInput(year, month, day);
	switch (bDate){
		case 0:
			return true;
			break;
		case 1:
			alert("["+label+"] 2月は29日までです。");
			break;
		case 2:
			alert("["+label+"] 2月は28日までです。");
			break;
		case 3:
			alert("["+label+"]月の設定範囲は、01～12までです。");
			break;
		case 4:
			alert("["+label+"]"+month+"月は、30日までです。");
			break;
		case 5:
			alert("["+label+"]"+month+"月は、31日までです。");
			break;
		case 6:
			alert("["+label+"]の設定範囲は、本日までです。");
			break;
		case 7:
			alert("["+label+"]の設定範囲は、1900年以降です。");
			break;
		case 8:
			alert("["+label+"]日の設定範囲は、01～31までです。");
			break;
		case 9:
			alert("["+label+"]年の設定範囲は、1900～本日までです。");
			break;
	}
	return false;
}//end function

/*=============================================================================================
 * 関数名：chkDateInput
 * 概要  ：日付のチェック
=============================================================================================*/
function chkDateInput(iYear, iMonth, iDay){
	if (iYear <= 0) return 9;
	if ((iMonth <= 0) || (iMonth > 12)) return 3;
	if (iDay <= 0) return 8;

	//閏年のチェック
	if (iMonth == '2'){
		if( ( (iYear % 4 == 0) && (iYear % 100 != 0) ) || (iYear % 400 == 0) ){
			if( iDay > 29 ) return 1;
		}else if( iDay > 28 ) return 2;

//		return 0;
	}
	
	switch(iMonth){
		case 4:
		case 6:
		case 9:
		case 11:
			if(iDay > 30) return 4;
			break;
		default:
			if(iDay > 31) return 5;
			break;
	}

	//日付制限
	if ( iYear < 1900 ) {
		return 7;
	}
	
	var dBirthday = new Date(iYear, iMonth - 1, iDay);

	var today = new Date();
	if( dBirthday.getTime() > today.getTime()) return 6;

//	var d1900 = new Date(1900, 0, 1);
//	if( dBirthday.getTime() < d1900.getTime()) return 7;

	return 0;
}
