
/**
*
* showDate()                  ボタン押時に日付を表示する関数
* february( 年, 月 )          2月の日付決定関数
* setDay()                    プルダウン内日付変更関数
* CreateDays()                日プルダウン作成関数
* CreateMonths()              月プルダウン作成関数
* CreateYears()               西暦プルダウン作成関数
*
*/

/*
*
* CreateYears()　西暦プルダウン作成関数
*
*/
function CreateYears() {
    var i;
    date = new Date();
	var nowYear = date.getYear();
	if (nowYear < 2000) { nowYear += 1900; } 
    var year = nowYear;
    var optionTag;
   
    for( i = 0; i < 2; i++ ) {
        if( year == nowYear ) {
            optionTag = "<option value=\"" + year + "\" selected>" + year + "</option>\n";
        } else {
            optionTag = "<option value=\"" + year + "\">" + year + "</option>\n";
        }
        year++;
        document.write( optionTag );
    }
}

/*
*
* CreateMonths()　月プルダウン作成関数
*
*/
function CreateMonths() {
    var i;
    date = new Date();
    var nowMonth = date.getMonth() + 1;
    var optionTag;
   
    for( i = 1; i <= 12; i++ ) {
        if( i == nowMonth ) {
            optionTag = "<option value=\"" + i + "\" selected>" + i + "</option>\n";
        } else {
            optionTag = "<option value=\"" + i + "\">" + i + "</option>\n";
        }
        document.write( optionTag );
    }
}
/*
*
* CreateYearsMonths()　年月プルダウン作成関数
*
*/
function _add_date( y, m, d ){
	with ( this ){ return new Date( getFullYear() + y, getMonth() + m-1, getDate() + d, getHours(), getMinutes(), getSeconds() ); }
}

function CreateYearsMonths() {
//2011-01-29
//システムアイ:チー作
	var i;
	var count = 4;
	var date = new Date();
	ThisMonth = date.getMonth()+1;
	ThisYear = date.getFullYear()
	for( i = 0; i <= count-1; i++ ) {
		YYYY = ThisYear + Math.floor((ThisMonth+i-1)/12);
		Mo = (ThisMonth+i)%12;
		if( Mo==0 ){
			M = 12;
			MM = 12;
		} else {
			M = Mo;
			MM = String(Mo+100).substring(1);
		}
		optionTag = YYYY + "年"+ M +"月"+MM +"t";
		optionTag = "<option value='" + YYYY + "/" + M + "'>" + YYYY + "年" + M + "月</option>";
		document.write(optionTag);
	}
}



function CreateYearsMonths_old() {
    var i;
	var count = 3;
	var d = new Date;
	var year;
	var month;

	Date.prototype.addDate = _add_date;
    for( i = 1; i <= count; i++ ) {
		optionTag = "<option value=" + d.addDate(0,i,0).getFullYear() + "/" + (d.addDate(0,i,0).getMonth() + 1) + ">" + d.addDate(0,i,0).getFullYear() + "年" + (d.addDate(0,i,0).getMonth() + 1) + "月</option>\n";
		document.write( optionTag );
	}
}
/*
*
* CreateDays()  日プルダウン作成関数
*
*/
function CreateDays() {

    var i;
    var s;
    var y;
    var m;
    date = new Date();
    var nowDay = date.getDate();
    var optionTag;

	y = parseInt(date.getYear());
	m = parseInt(date.getMonth() + 1);

    var lastday = february( y, m );

	s = 1;
    for( i = s; i <= lastday; i++ ) {
        if( i == nowDay ) {
            optionTag = "<option value=\"" + i + "\" selected>" + i + "</option>\n";
        } else {
            optionTag = "<option value=\"" + i + "\">" + i + "</option>\n";
        }
        document.write( optionTag );
    }
}

/*
*
* setDay()　プルダウン内日付変更関数
*
*/
function setDay(){

	var yearmonth = document.getElementById( "ym" ).value;
	var year;
	var month;
    date = new Date();
    var m = parseInt(date.getMonth() + 1);
    var nowDay = date.getDate();
    var day = document.getElementById( "day" );
    
	yearmonth = yearmonth.split("/");
	year = yearmonth[0];
	month = yearmonth[1];
	
    var lastday = february( year, month );
    var itemnum = day.length;
    if ( lastday - 1 < day.selectedIndex ) {
        day.selectedIndex = lastday - 1;
    }

    day.length = lastday;
    for ( cnt = ( itemnum + 1 ); cnt <= lastday; cnt++ ) {
        day.options[cnt - 1].text = cnt;
    }

	if (m == month) {
		if ( day.selectedIndex < nowDay - 1 ) {
			day.selectedIndex = nowDay - 1;
		}
	}
}

/*
*
* february( 年, 月 )　2月の日付決定関数
*
*/
function february( year, month ){
    var lastday = new Array( 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
    if ( ( (year % 4 == 0) && (year % 100 != 0) ) || ( year % 400 == 0 ) ) {
        lastday[1] = 29;
    }
    return lastday[month - 1];
}

/**
*
* showDate()　ボタン押時に日付を表示する関数
*
*/
function showDate() {
    var year = document.getElementById( "year" ).value;
    var month = document.getElementById( "month" ).value;
    var day = document.getElementById( "day" ).value;
    return false;
}


