// ご予約用年月日表示JS
window.onload = function (){
    setEvent_to_OBJ("document.getElementById('year')" ,"change","iniD") 
    ini();
}
function setEvent_to_OBJ(objNameStr,eventTypeNameStr,fncNameStr){
    eval(objNameStr+".on"+eventTypeNameStr+"="+ fncNameStr);
}

arrM = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
var dayT = new Date;
var strY = dayT.getYear();
var strM = dayT.getMonth();
var strD = dayT.getDate();
if(strY < 1900){strY += 1900;}//NN系対策

function ini(){
    iniY();
    iniM();
    iniD();
}
function iniY(){
    strM++;
    var yr = document.getElementById("year");
    yr.options.length = 6;
    yr.options[0].text  = '';

    for(var i=0;i<6;i++){
        yr.options[i].text  = strY + '年' + strM + '月';
        if(strM==12){
            strY++;
            strM=1;
        } else {
            strM++;
        }
    }
    yr.options[0].selected = "selected";

    strY = dayT.getYear();
    strM = dayT.getMonth();
    if(strY < 1900){strY += 1900;}//NN系対策
    strM++;
    yr.options[0].value = '';

    for(var i=0;i<6;i++){
        yr.options[i].value = strY * 100 + strM;
        if(strM==12){
            strY++;
            strM=1;
        } else {
            strM++;
        }
    }

    yr.options[0].selected = "selected";

    strY = dayT.getYear();
    strM = dayT.getMonth();
    if(strY < 1900){strY += 1900;}//NN系対策

    var yr2 = document.getElementById("year2");
    yr2.options.length = 1;
    yr2.options[0].text  = strY;
    yr2.options[0].selected = "selected";

}

function iniM(){
    var mt = document.getElementById("month");
    mt.options.length = 12;
    for(var i=0;i<12;i++){
        mt.options[i].text  = i + 1;
        mt.options[i].value = i + 1;
        if(i == strM){mt.options[i].selected = "selected";}
    }
}

function iniD(){
    var yr2    = document.getElementById("year");
    var dt    = document.getElementById("date");
    var mt    = document.getElementById("month");
    var u_flg = 0;//うるう年か否か
    var d_flg = 0;//年月が現在と同じか否か
    //月末の日数
    var lngD  = arrM[mt.options[mt.selectedIndex].value];
    if(mt.options[mt.selectedIndex].value == 2){
        u_flg = uruu(strY);
    }

    if(strY < 1900){strY += 1900;}//NN系対策

    if(u_flg != 0){lngD ++;}
    if(mt.options[mt.selectedIndex].value == strM + 1 &&
        yr2.options[yr2.selectedIndex].value == strY){d_flg = 1;}

		lngD = 31; // うるう年判定中止（必ず31日まで表示）

    dt.options.length = lngD;
    for(var i=0;i<lngD;i++){
        dt.options[i].text  = i + 1;
        dt.options[i].value = i + 1;
        if(i == strD - 1 && d_flg == 1){
            dt.options[i].selected = "selected";
        }
    }
    if(d_flg == 0){

        for(var i=0;i<lngD;i++){
            dt.options[i].text  = i + 1;
            dt.options[i].value = i + 1;
            if(i == strD){dt.options[i-1].selected = "selected";}
        }

    }
}

function uruu(strY){
// window.alert(strY);
    if((strY % 4 == 0 && strY % 100 != 0) || strY % 400 == 0){
        return 1;
    }else{
        return 0;
    }
}





