//週間メニューリスト
window.onload = function (){
    var nowdate = new Date();
    var nowmonth = nowdate.getMonth() + 1;
    var nowday = nowdate.getDate();
    var nowyear = nowdate.getYear();
    var date = nowdate.getDay();
    nowday = "" + nowday;
    if(nowday.toString().length == 1){
        nowday = "0" + nowday;
    }
    if(date == 0){
        date = 6;
    }else{
        date = date-1;
    }
    if(nowyear < 2000){
        nowyear += 1900;
    }
    var get_today = nowmonth + nowday;
    var date_array = new Array();
    date_array[0] = '月曜日のメニュー';
    date_array[1] = '火曜日のメニュー';
    date_array[2] = '水曜日のメニュー';
    date_array[3] = '木曜日のメニュー';
    date_array[4] = '金曜日のメニュー';
    date_array[5] = '土曜日のメニュー';
    date_array[6] = '日曜日のメニュー';
    var week_day = nowday - date;
    var month_lastday;
    if(week_day<1){
        nowmonth = nowmonth-1;
        if(nowmonth < 1){
            nowmonth = 12;
        }
    }
    if(nowmonth == 1 
       || nowmonth == 3 
       || nowmonth == 5 
       || nowmonth == 7 
       || nowmonth == 8 
       || nowmonth == 10 
       || nowmonth == 12){
        month_lastday = 31;
    }else if(nowmonth == 4 
             ||nowmonth == 6 
             ||nowmonth == 9 
             ||nowmonth ==11){
        month_lastday = 30;
    }else if(nowmonth == 2){
        month_lastday = 28;
        if((nowyear%4 == 0 
            && nowyear%100 != 0)
            || nowyear%400 == 0){
            month_lastday = 29;
        }
    }
    if(week_day<1){
         week_day = week_day+month_lastday;
    }   
    var this_week_array = new Array()
    for(i=0;i<date_array.length;i++){
        if(month_lastday<week_day){
            nowmonth = nowmonth + 1;
            week_day = 1;
            if(nowmonth > 12){
                nowmonth = 1;
            }
        }
        if(week_day<10){
            week_day = "0" + week_day;
        }
        var week_date =  nowmonth + "" +week_day;
        this_week_array[i] = new Array();
        this_week_array[i]["season"] = nowmonth;
        this_week_array[i]["date"] = week_date;
        this_week_array[i]["ID"] = menu_array[week_date]["ID"];
        this_week_array[i]["morning_menu"] = menu_array[week_date]["morning_menu"];
        this_week_array[i]["lunch_menu"] = menu_array[week_date]["lunch_menu"];
        this_week_array[i]["dinner_menu"] = menu_array[week_date]["dinner_menu"];
        week_day++;
    }
    var weekly_table="";
    weekly_table = '<table cellspacing="3" cellpadding="3" width="601" border="0">';
    for(i=0;i<date_array.length;i++){
        weekly_table += '<tr><td width="120" valign="top" align="left"><strong>';
        weekly_table += '<a href="day.html?'+this_week_array[i]['date']+'#'+i+'='+this_week_array[i]['season']+'">';
        weekly_table += date_array[i]+"</a>";
        weekly_table += '</strong></td><td valign="top" align="left">';
        weekly_table += '<ul class="ul-dietary">';
        weekly_table += '<li><a href="breakfast.html?'+this_week_array[i]['ID']+'1" >';
        weekly_table += this_week_array[i]['morning_menu']+'</a></li>';
        weekly_table += '<li><a href="lunch.html?'+this_week_array[i]['ID']+'2" >';
        weekly_table += this_week_array[i]['lunch_menu']+'</a></li>';
        weekly_table += '<li><a href="dinner.html?'+this_week_array[i]['ID']+'3" >';
        weekly_table += this_week_array[i]['dinner_menu']+'</a></li>';
        weekly_table += '</ul></td></tr>';
    }
    weekly_table += "</table>";
    var menu = document.getElementById("AreaDietaryMenu");
    menu.innerHTML = weekly_table;
}
