/**
 * @author Tamada
 */

$(function(){
	// 年変更時
	$("select[name='checkIn_year']").change(function(){
		setDaySel( $(this).val(), $("select[name='checkIn_month']").val(), $("select[name='checkIn_day']").val() );
	});
	
	// 月変更時
	$("select[name='checkIn_month']").change(function(){
		setDaySel( $("select[name='checkIn_year']").val(), $(this).val(), $("select[name='checkIn_day']").val() );
	});
});

// 日数変更
function setDaySel( sYear, sMonth, sDay )
{
	obDay = $('select[name="checkIn_day"]');
	SelDate = new Date(sYear, sMonth, 0);
	// 日の削除
	obDay.children().remove();
	// 日の挿入
	for( nCnt = 1; nCnt < SelDate.getDate()+1; nCnt++ )
	{
		obDay.append($('<option>').val(nCnt).text(nCnt));
	}
	obDay.val(sDay);
}

// フォーム値チェック
function checkVal( form ){
	// 日付チェック
	tmpDate = new Date();
	sYear = form.checkIn_year.value;
	sMonth = form.checkIn_month.value;
	sDay = form.checkIn_day.value;
	SelDate = new Date(sYear, sMonth-1, sDay);
	NowDate = new Date(tmpDate.getFullYear(), tmpDate.getMonth(), tmpDate.getDate());
	if( SelDate.getTime() < NowDate.getTime() )
	{
		alert("宿泊日の指定が不正です。再度入力しなおしてください。");
		return false;
	}
	
	// 都道府県選択チェック
	if( form.prefecture.value == "" )
	{
		alert( "都道府県を選択してください。" );
		return false;
	}
	form.submit();
	return false;
}

function checkName( form ){
	if( form.inn_name.value == "" )
	{
		alert( "宿泊施設名を入力してください。" );
		return false;
	}
	form.submit();
	return false;
}

