$(document).ready(function() {
	$('a[href="#start"]').click(function(){
		scrollToStart();
		return false;
	});

	$('form#calendarForm').submit(function(){
		return validate(this);
	});
});


function initialize() {
	$('a.date').click(
			function() {
				clickDate(this);
				return false;
			}
	);

	$('a.prev').click(
			function() {
				changeMonth(this,-1);
				return false;
			}
	);

	$('a.next').click(
			function() {
				changeMonth(this,1);
				return false;
			}
	);
}
function scrollToStart() {
	scrollTo("start");
}



function validate(form) {
	year = $("select[name='year']").val();
	month = $("select[name='month']").val();
	day = $("select[name='day']").val();

	if(!checkDate(year,month,day)){
		alert('正しい日付を選択してください。');
		return false;
	}
	
	wk = new Date();
	tomorrow = new Date(wk.getFullYear(),wk.getMonth(),wk.getDate()+1);
	begin = new Date(year,month-1,day);
	
	if(tomorrow>begin){
		alert('明日以降の日付を指定してください。');
		return false;
	}
	return true;
}

function checkDate(selY, selM, selD){
	var year, month, day;
	year = parseInt(selY);
	month = parseInt(selM);
	day = parseInt(selD);
	if(month == '2'){
		if( ( (year % 4 == 0) && (year % 100 != 0) ) || (year % 400 == 0) ){
			if(day > 29){
				return false;
			}
		} else {
			if(day > 28){
				return false;
			}
		}
	} else {
		switch(month){
			case 4:
			case 6:
			case 9:
			case 11:
				if(day > 30){
					return false;
				}
				break;
			default:
				break;
		}
	}
	return true;
}

