//###########################################################region 年-月-日联动相关方法

//当dropMyYear发生onchanged事件时，触发该函数
function MyYearOnchanged(){
	var myyear = document.getElementById("dropMyYear");
	var mymonth = document.getElementById("dropMyMonth");
	var myday = document.getElementById("dropMyDay");

	if(myyear.value == "-1"){
		mymonth.disabled = true;
		myday.disabled = true;
	}
	else{
		//初始化dropMyMonth
		mymonth.disabled = false;
		myday.disabled = false;
		mymonth.options[0].selected = true;
		//初始化dropMyDay
		myday.length = 0;
		var myoption = new Option("选择...","-1");
		myday.add(myoption);
	}
}

function MyMonthOnchange(){
	var bigMonths = getBigMonth();
	var smallMonths = getSmallMonth();
	var month = document.getElementById("dropMyMonth");
	var isGone = true;

	//初始化dropMyDay为31天
	if(isGone){
		for(var i=0; i<bigMonths.length; i++){
			if(month.value.toString() == bigMonths[i].toString()){
				initDayDrop("big",false);
				isGone = false;
				break;
			}
		}
	}

	//初始化dropMyDay为30天
	if(isGone){
		for(var i=0; i<smallMonths.length; i++){
			if(month.value.toString() == smallMonths[i].toString()){
				initDayDrop("small",false);
				isGone = false;
				break;
			}
		}
	}
	
	//初始化dropMyDay为28天或29天
	if(isGone){
		initDayDrop("flat",true);
	}

	var myday = document.getElementById("dropMyDay");
	myday.options[0].selected = true;
}

//初始化dropMyDay，根据月份判断天数
function initDayDrop(monthType, isBigYear){
	var dayArray = new Array();

	if(isBigYear){
		dayArray = getflatDay()
	}
	else{
		if(monthType == "big"){
			dayArray = getBigDay();
		}
		else{
			dayArray = getSmallDay();
		}
	}

	loadDropDays(dayArray);
}

//返回天数为31天的大月份
function getBigMonth(){
	var bigMonths = new Array();
	bigMonths[0] = "1";
	bigMonths[1] = "3";
	bigMonths[2] = "5";
	bigMonths[3] = "7";
	bigMonths[4] = "8";
	bigMonths[5] = "10";
	bigMonths[6] = "12";

	return bigMonths;
}

//返回天数为30天的小月份
function getSmallMonth(){
	var smallMonths = new Array();
	smallMonths[0] = "4";
	smallMonths[1] = "6";
	smallMonths[2] = "9";
	smallMonths[3] = "11";

	return smallMonths;
}

//返回2月平月的天数
function getflatDay(){
	var year = getYear();
	var flatDays = new Array();
	//year如果能被4除尽，返回29天的dropMyDays
	if((year%4) == 0){
		for(var i=0; i<29; i++){
			flatDays[i] = i+1;
		}
	}
	//year如果不能被4除尽，返回28天的dropMyDays
	else{
		for(var i=0; i<28; i++){
			flatDays[i] = i+1;
		}
	}

	return flatDays;
}

//返回31天
function getBigDay(){
	var bigDays = new Array();
	for(var i=0; i<31; i++){
		bigDays[i] = i+1;
	}

	return bigDays;
}

//返回30天
function getSmallDay(){
	var smallDays = new Array();
	for(var i=0; i<30; i++){
		smallDays[i] = i+1;
	}

	return smallDays;
}

//返回dropMyYear中的年
function getYear(){
	var year = document.getElementById("dropMyYear");
	var selectedyear = year.value;
	return selectedyear;
}

//将返回的数组装载到dropMyDays
function loadDropDays(dayarray){
	var dropday = document.getElementById("dropMyDay");
	
	dropday.length = 1;

	//alert(dayarray.length);
	for(var i=0; i<dayarray.length; i++){
		var myoption = new Option(dayarray[i], dayarray[i]);
		dropday.add(myoption);
	}
}

//###########################################################endregion 年-月-日联动相关方法