window.onload = function (){
    var myData;
    var referrer = location.href.split("?");
    if(referrer[1] != null){
        myData = referrer[1];
    }else{
        var nowdate = new Date();
        var nowmonth = nowdate.getMonth() + 1;
        var nowday = nowdate.getDate();
        nowday = "" + nowday;
        if(nowday.toString().length == 1) {
            nowday = "0" + nowday;
        }
        var get_today = nowmonth + nowday;
        var getdir = location.href.split("/");
        for(i=0;i<getdir.length;i++){
            if(getdir[i] == "today_breakfast" 
               || getdir[i] == "breakfast.html"){
                myData = menu_array[get_today]["ID"]+"1";
            }else if(getdir[i] == "today_lunch" 
                     || getdir[i] == "lunch.html"){
                myData = menu_array[get_today]["ID"]+"2";
            }else if(getdir[i] == "today_dinner" 
                     || getdir[i] == "dinner.html"){
                myData = menu_array[get_today]["ID"]+"3";
            }
        }
    }
    
    var meal;
    if(myData.substr(3,1)==1){
        meal = "朝食";
    }else if(myData.substr(3,1)==2){
        meal = "昼食";
    }else if(myData.substr(3,1)==3){
        meal = "夕食";
    }
    
    var now = myData.substr(0,3);

    var head;
    head = '<table cellspacing="0" cellpadding="0" width="601" border="0"><tr>';
    head += '<td class="bgSectionHeading" valign="center" height="20">';
    head += '<span class="sectionHeading">' + recipe_Array[myData]['recipe'] + '</span>';
    head += '</td></tr><tr><td height="10">';
    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"><tr><td width="330" valign="top">';
    head += '<img src="/images/content/patients/content_area/dietary_menu/'+myData+'_l.jpg" alt="写真" align="left" valign="top" width="285" height="237" vspace="0" hspace="0">';
    head += '</td>';

    var nourishment = recipe_Array[myData]['nourishment'].split(',');

    var head_cal;
    head_cal = '<td valign="top">';
    head_cal += '<table border="1" cellspacing="0" cellpadding="1" width="240">';
    head_cal += '<caption>'+meal+'の栄養量</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>';
    head_cal += '</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" />'+nourishment[0]+'</td>';
    head_cal += '<td width="75" nowrap>'+nourishment[1]+'</td>';
    head_cal += '<td width="75" nowrap>'+nourishment[2]+'</td>';
    head_cal += '</tr>';
    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>';
    head_cal += '</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" />'+nourishment[3]+'</td>';
    head_cal += '<td width="75" nowrap>'+nourishment[4]+'</td>';
    head_cal += '<td width="75" nowrap>'+nourishment[5]+'</td>';
    head_cal += '</tr>';
    head_cal += '</table>';

    if(recipe_Array[myData]['substitution'] == 1){
        var sub;
        sub = '<h3>【'+substitution_Array[now]['takes']+'】</h3>';
        sub += '<p><a href="substitute.html?'+myData+'" >';
        sub += '<img src="/images/content/patients/content_area/dietary_menu/'+substitution_Array[now]['img']+'.jpg" alt="写真" valign="top" width="180" height="150" border="0"></a></p>';
        sub += '<strong><a href=substitute.html?'+myData+' >'+substitution_Array[now]['menu']+'</a></strong>';
        var substitution_nutritive = substitution_Array[now]['nutritive'].split('.');
        if(substitution_nutritive[1] != null){
            sub +='<img src="/images/content/patients/content_area/dietary_menu/icn_calorie.gif" width="24" height="18" alt="icon-kcal" />'+substitution_nutritive[0];
            sub +='&nbsp;<img src="/images/content/patients/content_area/dietary_menu/icn_cholesterol.gif" width="24" height="18" alt="icon-mg" />'+substitution_nutritive[1]+'<br>';
        }else{
            sub += '<img src="/images/content/patients/content_area/dietary_menu/icn_calorie.gif" width="24" height="18" alt="icon-kcal" />'+substitution_Array[now]['nutritive']+'<br>';
        }
        if(substitution_Array[now]['message'] != 0){
            sub += messeage_Array[substitution_Array[now]['message']];
        }

        head_cal += sub;
    }

    var dot;
    dot = '</td></tr></table>';
    dot += '<table border="0" width="610" cellpadding="3" cellspacing="0"><tr>';
    dot += '<td height="7"><img src="/site_images/s.gif" width="1" height="1" alt="" ></td>';
    dot += '</tr><tr><td height="3" colspan="2">';
    dot += '<img src="/images/content/patients/content_area/dietary_menu/hr_dot.gif" border="0" height="1" width="598" alt="" >';
    dot += '</td></tr><tr>';
    dot += '<td height="7"><img src="/site_images/s.gif" width="1" height="1" alt="" ></td>';
    dot += '</tr></table>';

    var dot_2="";

    dot_2 += '<table border="0" width="610" cellpadding="3" cellspacing="0"><tr>';
    dot_2 += '<td height="7"><img src="/site_images/s.gif" width="1" height="1" alt="" ></td>';
    dot_2 += '</tr><tr><td height="3" colspan="2">';
    dot_2 += '<img src="/images/content/patients/content_area/dietary_menu/hr_dot.gif" border="0" height="1" width="598" alt="" >';
    dot_2 += '</td></tr><tr>';
    dot_2 += '<td height="7"><img src="/site_images/s.gif" width="1" height="1" alt="" ></td>';
    dot_2 += '</tr></table>';

    head += head_cal+dot;

    var nutritive_list = recipe_Array[myData]['nutritive'].split(',');
    var dish_menu = recipe_Array[myData]['dish'].split(',');
    var material = '';
    material += '<h3>■材料</h3>';
    var test ="";
    material += '<table cellspacing="3" cellpadding="3" width="601" border="0"><tr>';
    material += '<td width="315" valign="top">';
    for(i=0;i<dish_menu.length;i++){
        if(i%2 == 0){
            if(i != 0){
                material += '</tr><tr><td width="315" valign="top">';
            }
        }else if(i != 0){
            material += '<td width="295" valign="top">';
        }
        if(nutritive_list[i] != null){
            var nutritive = nutritive_list[i].split('.');
            var nutritive_img;    
            if(nutritive[1] != null){
                nutritive_img = '<img src="/images/content/patients/content_area/dietary_menu/icn_calorie.gif" width="24" height="18" alt="icon-kcal" />&nbsp;'+nutritive[0]+'&nbsp;';
                nutritive_img += '<img src="/images/content/patients/content_area/dietary_menu/icn_cholesterol.gif" width="24" height="18" alt="icon-mg" />&nbsp;'+nutritive[1];
            }else{
                if(nutritive_list[i] != null){
                    nutritive_img = '<img src="/images/content/patients/content_area/dietary_menu/icn_calorie.gif" width="24" height="18" alt="icon-kcal" />&nbsp;'+nutritive_list[i];
                }
            }
        }

        material += '<strong>・'+dish_menu[i]+'</strong>'+nutritive_img+'<br />';
        var material_list = recipe_Array[myData]['material'][i].split(',');
        var amount_list = recipe_Array[myData]['amount'][i].split(',');
        for(j=0;j<material_list.length;j++){
            if(material_list[j]!=""){
                material += material_list[j]+'---'+amount_list[j]+'<br />';
            }
        }
        if(recipe_Array[myData]['spice'][i] != null){
            var spice;
            var source = "";
            spice = recipe_Array[myData]['spice'][i].split('@');
            if(spice[1] != null){
                for(k=0;k<spice.length;k++){
                    if(k!=0){
                        source += "<br />";
                    }
                    source += '<font color="red">'+spice[k].split(",").join("<br />")+'</font>';
                }
            }else{
                source += '<font color="red">'+spice[0].split(",").join("<br />")+'</font>';
            }
            material += source;
        }
        material += '</td>';
    }

    material += '</tr></table>'+dot_2;

    var makes;
    makes = '<h3>■作り方</h3>';
    for(i=0;i<recipe_Array[myData]['make'].length;i++){
        var make_list = recipe_Array[myData]['make'][i].split(',');
        makes += '<strong>・'+make_list[0]+'</strong><ol>';
        for(j=1;j<make_list.length;j++){
            makes += '<li>'+make_list[j]+'</li>';
        }
        makes += '</ol>';
        if(i!=recipe_Array[myData]['make'].length-1){
            makes += '<table border="0" width="610" cellpadding="3" cellspacing="3">';
            makes += '<tr>';
            makes += '<td height="7"><img src="/site_images/s.gif" width="1" height="1" alt="" ></td>';
            makes += '</tr>';
            makes += '</table>';
        }
    }
    var recipe = head+material+makes;
    var menu = document.getElementById('AreaDietaryMenu');
    menu.innerHTML = recipe;
}
