// JavaScript Document

/**
*
* @add        2008.08.24    showDate()                    ボタン押時に日付を表示する関数
* @add        2008.08.24    february( 年, 月 )            2月の日付決定関数
* @add        2008.08.24    setDay()                    プルダウン内日付変更関数
* @add        2008.08.24    CreateDays()                日プルダウン作成関数
* @add        2008.08.24    CreateMonths()                月プルダウン作成関数
* @add        2008.08.24    CreateYears()                西暦プルダウン作成関数
* @create    2008.08.24    JS関数ライブラリ作成
*
*/

/*
*
* @add        2008.08.24    CreateYears()                西暦プルダウン作成関数
*
*/
function CreateYears() {
    var i;
    date = new Date();
    var nowYear = date.getFullYear() ;
    var year = nowYear;
    var optionTag;
    
    for( i = 0; i < 20; i++ ) {
        if( year == nowYear ) {
            optionTag = "<option value=\"" + year + "\" selected>" + year + "</option>\n";
        } else {
            optionTag = "<option value=\"" + year + "\">" + year + "</option>\n";
        }
        year++;
        document.write( optionTag );
    }
}

/*
*
* @add        2008.08.24    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 );
    }
}

/*
*
* @add        2008.08.24    CreateDays()                日プルダウン作成関数
*
*/
function CreateDays() {
    var i;
    date = new Date();
    var nowDay = date.getDate()+1;
    var optionTag;
    
    for( i = 1; i <= 31; i++ ) {
        if( i == nowDay ) {
            optionTag = "<option value=\"" + i + "\" selected>" + i + "</option>\n";
        } else {
            optionTag = "<option value=\"" + i + "\">" + i + "</option>\n";
        }
        document.write( optionTag );
    }
}

function CreateDays2() {
    var i;
    date = new Date();
    var nowDay = date.getDate()+2;
    var optionTag;
    
    for( i = 1; i <= 31; i++ ) {
        if( i == nowDay ) {
            optionTag = "<option value=\"" + i + "\" selected>" + i + "</option>\n";
        } else {
            optionTag = "<option value=\"" + i + "\">" + i + "</option>\n";
        }
        document.write( optionTag );
    }
}





/*
*
* @add        2008.08.24    setDay()                    プルダウン内日付変更関数
*
*/
function setDay(){
    var year = document.getElementById( "ciDateY" ).value;
    var month = document.getElementById( "ciDateM" ).value;
    var day = document.getElementById( "ciDateD" );

    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;
    }
}


/*
*
* @add        2008.08.24    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];
}



