window.onload = function (){
    var nowdate = new Date();
    var now_month = nowdate.getMonth() + 1;
    var nowday = nowdate.getDate();
    nowday = "" + nowday;
    if(nowday.toString().length == 1) {
        nowday = "0" + nowday;
    }

    var get_today = now_month + nowday;
    var now_season=season[now_month].split(",");
    now_month = "" + now_month;
    if(now_month.toString().length == 1) {
        now_month = "0" + now_month;
    }
    
    var data_list = menu_array[get_today]["ID"];
    var morning_list = menu_array[get_today]["ID"]+"1";
    var lunch_list = menu_array[get_today]["ID"]+"2";
    var dinner_list = menu_array[get_today]["ID"]+"3";

    var dir_array = new Array("breakfast","lunch","dinner");
    var cook_array = new Array("朝食.morning_menu.morning_list","昼食.lunch_menu.lunch_list","夕食.dinner_menu.dinner_list");
    var pic_array = new Array(morning_list,lunch_list,dinner_list);
    
    var head;
    head = '<table cellspacing="0" cellpadding="0" width="601" border="0">';
    head += '<tr><td width="310" valign="top">';
    head += '<img src="/images/content/patients/content_area/dietary_menu/banner_'+now_season[0]+'.jpg" border="0" width="287" height="60" alt="'+now_season[1]+'のメニュー">';
    head += '</td><td valign="top">';
    head += '脂質異常症（高脂血症）の食事メニューはデイリー更新。<br />毎週月曜日に今週のメニューがアップされます。</td>';
    head += '</tr><tr><td height="20" colspan="2">';
    head += '<img src="/site_images/s.gif" width="1" height="1" alt="" >';
    head += '</td></tr></table>';
    
    head += '<table cellspacing="0" cellpadding="0" width="601" border="0">';
    head += '<tr><td class="bgSectionHeading" valign="center" height="20">';
    head += '<span class="sectionHeading">'+ now_month + '月' + nowday + '日 のメニュー</span>';
    head += '</td></tr>';
    head += '<tr><td height="3">';
    head += '<img src="/site_images/s.gif" width="" height="" alt="" >';
    head += '</td></tr></table>';

    var menu_list;
    menu_list = '<table cellspacing="0" cellpadding="0" width="601" border="0"><tr><td width="330">';
    menu_list += '朝食<br>■<a href ="/content/patients/dietary_menu/today_menu/today_'+dir_array[0]+'/index.html?'+morning_list +'" >';
    menu_list += menu_array[get_today]['morning_menu']+'</a><br />';
    menu_list += '昼食<br>■<a href ="/content/patients/dietary_menu/today_menu/today_'+dir_array[1]+'/index.html?'+lunch_list +'" >';
    menu_list += menu_array[get_today]['lunch_menu']+'</a><br />';
    menu_list += '夕食<br>■<a href ="/content/patients/dietary_menu/today_menu/today_'+dir_array[2]+'/index.html?'+dinner_list+'" >';
    menu_list += menu_array[get_today]['dinner_menu']+'</a>';
    menu_list += '</td><td>';

    var head_cal;
    head_cal = '<table border="1" cellspacing="0" cellpadding="1" width="240">';
    head_cal += '<caption>一日の栄養量</caption>';
    head_cal += '<tr align="center">';
    head_cal += '<td width="90" nowrap><font size="1">エネルギー</font></td>';
    head_cal += '<td width="75" nowrap><font size="1">蛋白質</font></td>';
    head_cal += '<td width="75" nowrap><font size="1">塩　分</font></td></tr>';
    head_cal += '<tr align="right" valign="bottom">';
    head_cal += '<td width="90" nowrap><img src="/images/content/patients/content_area/dietary_menu/icn_calorie.gif" width="24" height="18" alt="icon-kcal" />'+list_array[data_list]['calorie']+'kcal</td>';
    head_cal += '<td width="75" nowrap>'+list_array[data_list]['protein']+'g</td>';
    head_cal += '<td width="75" nowrap>'+list_array[data_list]['solt']+'g</td>';
    head_cal += '</tr><tr align="center">';
    head_cal += '<td width="90" nowrap><font size="1">コレステロール</font></td>';
    head_cal += '<td width="75" nowrap><font size="1">炭水化物</font></td>';
    head_cal += '<td width="75" nowrap><font size="1">食物繊維</font></td></tr>';
    head_cal += '<tr align=right valign=bottom>';
    head_cal += '<td width="90" nowrap><img src="/images/content/patients/content_area/dietary_menu/icn_cholesterol.gif" width="24" height="18" alt="icon-mg" />'+list_array[data_list]['cholesterol']+'mg</td>';
    head_cal += '<td width="75" nowrap>'+list_array[data_list]['carbohydrate']+'g</td>';
    head_cal += '<td width="75" nowrap>'+list_array[data_list]['fiber']+'g</td>';
    head_cal += '</tr></table></td></tr></table>';
    menu_list += head_cal;
       
    var details;
    details = '<table cellspacing="0" cellpadding="0" width="601" border="0"><tr>';
    details += '<td height="15"><img src="/site_images/s.gif" width="1" height="1" alt="" ></td>';
    details += '</tr><tr>';
    details += '<td class="bgSectionHeading" valign="center" height="20">';
    details += '<span class="sectionHeading">'+now_month + '月' + nowday + '日 のメニュー詳細</span>';
    details += '</td></tr><tr>';
    details += '<td height="3"><img src="/site_images/s.gif" width="1" height="1" alt="" ></td>';
    details += '</tr></table>';

    var detailslist = '<table border="0" width="610" cellpadding="3" cellspacing="3">';
    for(i=0;i<pic_array.length;i++){
        var cook = cook_array[i].split('.');
        if(i != 0){
            detailslist += '<tr>';
            detailslist += '<td height="3" colspan="2"><img src="/images/content/patients/content_area/dietary_menu/hr_dot.gif" alt="" border=0 height=1 width=598></td>';
            detailslist += '</tr>';
        }
        detailslist += '<tr><td width="180" align="center" valign="top">';
        detailslist += '<a href ="/content/patients/dietary_menu/today_menu/today_'+dir_array[i]+'/index.html?'+pic_array[i]+'" >';
        detailslist += '<img src="/images/content/patients/content_area/dietary_menu/'+pic_array[i]+'_s.jpg"'+' "alt='+ menu_array[get_today][cook[1]] + '" border="0" height="150" width="180">';
        detailslist += '</a></td><td>';
        detailslist += '<h3>'+cook[0]+'<br>■'+menu_array[get_today][cook[1]]+'</h3><p>';
        
        var dish_list = list_array[data_list][cook[2]].split(',');
        for(j=0;j<dish_list.length;j++){
            if(j == dish_list.length-1){
                detailslist += '・'+dish_list[j]+'</p>';
            }else{
                detailslist += '・'+dish_list[j]+'<br />';
            }
        }
        detailslist += '<p align="right"><img src="/images/content/patients/content_area/dietary_menu/icn_'+dir_array[i]+'.gif" width="15" height="14" alt="icon-'+dir_array[i]+'" />&nbsp;';
        detailslist += '<a href ="/content/patients/dietary_menu/today_menu/today_'+dir_array[i]+'/index.html?'+pic_array[i]+'" >';
        detailslist += cook[0]+'のレシピ</a></p></td></tr>';
    }
    detailslist += '</table>';
    var today_menu = head+menu_list+details+detailslist;
    var menu = document.getElementById('AreaDietaryMenu');
    menu.innerHTML = today_menu;
}
