﻿function popup(panel,amount){
    /*if(amount==""){
        alert("請輸入份數");
        return;
    }*/
    window.open("calories_main2.aspx?panel="+panel+"&amount="+amount,"","resizable=yes,menubar=no,scrollbars=yes,statusbar=no,toolbar=no,top=0,left=0,width=600,height=500");
}

function popup2(panel,amount,amount2){
    /*if(amount=="" || amount2==""){
        alert("請輸入份數");
        return;
    }*/
    window.open("calories_main2.aspx?panel="+panel+"&amount="+amount+"&amount2="+amount2,"","resizable=yes,menubar=no,scrollbars=yes,statusbar=no,toolbar=no,top=0,left=0,width=600,height=500");
}

function popup3(panel,amount,amount2,amount3){
    /*if(amount=="" || amount2=="" || amount3==""){
        alert("請輸入份數");
        return;
    }*/
    window.open("calories_main2.aspx?panel="+panel+"&amount="+amount+"&amount2="+amount2+"&amount3="+amount3,"","resizable=yes,menubar=no,scrollbars=yes,statusbar=no,toolbar=no,top=0,left=0,width=600,height=500");
}

function popup4(panel,amount,amount2,amount3,amount4){
    /*if(amount=="" || amount2=="" || amount3=="" || amount4==""){
        alert("請輸入份數");
        return;
    }*/
    window.open("calories_main2.aspx?panel="+panel+"&amount="+amount+"&amount2="+amount2+"&amount3="+amount3+"&amount4="+amount4,"","resizable=yes,menubar=no,scrollbars=yes,statusbar=no,toolbar=no,top=0,left=0,width=600,height=500");
}

function counttotal(){
    var amount;
    var protein=new Array(13);
    var carbohydrate=new Array(13);
    var fat=new Array(13);
    var calory=new Array(13);
    
    var protein_total=0;
    var carbohydrate_total=0;
    var fat_total=0;
    var calorty_total=0;

    amount=parseInt(document.getElementById("amount1").value);
    if(isNaN(amount)){
        alert("請輸入五穀根莖類食物的份數");
        return;
    }
    protein[1]=amount*2;
    carbohydrate[1]=amount*15;
    fat[1]=0;
    calory[1]=amount*70;
    
    amount=parseInt(document.getElementById("amount2").value);
    if(isNaN(amount)){
        alert("請輸入蔬菜類食物的份數");
        return;
    }
    protein[2]=amount*1;
    carbohydrate[2]=amount*5;
    fat[2]=0;
    calory[2]=amount*25;
    
    amount=parseInt(document.getElementById("amount3").value);
    if(isNaN(amount)){
        alert("請輸入低熱量豆類食物的份數");
        return;
    }
    protein[3]=amount*7;
    carbohydrate[3]=0;
    fat[3]=amount*3;
    calory[3]=amount*55;
    
    amount=parseInt(document.getElementById("amount3_2").value);
    if(isNaN(amount)){
        alert("請輸入高熱量豆類食物的份數");
        return;
    }
    protein[4]=amount*7;
    carbohydrate[4]=0;
    fat[4]=amount*3;
    calory[4]=amount*75;
    
    amount=parseInt(document.getElementById("amount4").value);
    if(isNaN(amount)){
        alert("請輸入水果類食物的份數");
        return;
    }
    protein[5]=0;
    carbohydrate[5]=amount*15;
    fat[5]=0;
    calory[5]=amount*60;
    
    amount=parseInt(document.getElementById("amount5").value);
    if(isNaN(amount)){
        alert("請輸入全脂奶類食物的份數");
        return;
    }
    protein[6]=amount*8;
    carbohydrate[6]=amount*12;
    fat[6]=amount*8;
    calory[6]=amount*150;
    
    amount=parseInt(document.getElementById("amount5_2").value);
    if(isNaN(amount)){
        alert("請輸入低脂奶類食物的份數");
        return;
    }
    protein[7]=amount*8;
    carbohydrate[7]=amount*12;
    fat[7]=amount*4;
    calory[7]=amount*120;
    
    amount=parseInt(document.getElementById("amount5_3").value);
    if(isNaN(amount)){
        alert("請輸入脫脂奶類食物的份數");
        return;
    }
    protein[8]=amount*8;
    carbohydrate[8]=amount*12;
    fat[8]=0;
    calory[8]=amount*80;
    
    amount=parseInt(document.getElementById("amount6").value);
    if(isNaN(amount)){
        alert("請輸入低脂肉、魚類食物的份數");
        return;
    }
    protein[9]=amount*7;
    carbohydrate[9]=0;
    fat[9]=amount*3;
    calory[9]=amount*55;
    
    amount=parseInt(document.getElementById("amount6_2").value);
    if(isNaN(amount)){
        alert("請輸入中脂肉、魚類食物的份數");
        return;
    }
    protein[10]=amount*7;
    carbohydrate[10]=0;
    fat[10]=amount*5;
    calory[10]=amount*75;
    
    amount=parseInt(document.getElementById("amount6_3").value);
    if(isNaN(amount)){
        alert("請輸入偏高脂肉、魚類食物的份數");
        return;
    }
    protein[11]=amount*7;
    carbohydrate[11]=0;
    fat[11]=amount*10;
    calory[11]=amount*120;
    
    amount=parseInt(document.getElementById("amount6_4").value);
    if(isNaN(amount)){
        alert("請輸入高脂肉、魚類食物的份數");
        return;
    }
    protein[12]=amount*7;
    carbohydrate[12]=0;
    fat[12]=amount*10;
    calory[12]=amount*135;
    
    amount=parseInt(document.getElementById("amount7").value);
    if(isNaN(amount)){
        alert("請輸入油脂類類食物的份數");
        return;
    }
    protein[13]=0;
    carbohydrate[13]=0;
    fat[13]=amount*5;
    calory[13]=amount*45;            
    
    
    for(var i=1;i<=13;i++){
        protein_total+=protein[i];
        carbohydrate_total+=carbohydrate[i];
        fat_total+=fat[i];
        calorty_total+=calory[i];
    }
    
    document.getElementById("TextBox_total").value="蛋白質"+protein_total+"g, ";
    document.getElementById("TextBox_total").value+="醣類"+carbohydrate_total+"g, ";
    document.getElementById("TextBox_total").value+="脂肪"+fat_total+"g, ";
    document.getElementById("TextBox_total").value+="熱量"+calorty_total+"卡";
}