﻿var qqq='';
var TabMeasuresCalorific=new Array();


function CalculateCalorific(DDLMeasureId, TBCountId, ProductCalorific, LblCalorific, LblCalorificSum, TBCalorificId, Type)
{
    var wsk=document.getElementById(DDLMeasureId);
    if (wsk!=null)
    {
    var IdMeasure = wsk.value;
    var Count = document.getElementById(TBCountId).value;
    Count = Count.replace(',','.');
    var ItemCalorific=0;
    if (!isNaN(IdMeasure) && !isNaN(Count) && IdMeasure!=0)
        ItemCalorific=Math.round(parseInt(Count) * TabMeasuresCalorific[Type+'_'+IdMeasure]);
    document.getElementById(LblCalorific).value=ItemCalorific+'kcal';
    //document.getElementById(LblCalorific).innerHTML=ItemCalorific+'kcal';
    document.getElementById(TBCalorificId).value=ItemCalorific;
    CalculateCalorificSum();
    }
}

function pageLoaded(sender, args)
{
    if (args.get_dataItems()["ScriptStr"]!=null)
    {
        var Tab=args.get_dataItems()["ScriptStr"].split('&');
        for(var i=0; i<Tab.length-1; i++)
            eval(Tab[i]);
    }
    CalculateCalorificSum();
    //update view
    if (document.getElementById("ScrolledPanel1"))
        ScrollPanel_OnLoadV("ScrolledPanel1");
    if (document.getElementById("ScrolledPanel2"))    
        ScrollPanel_OnLoadV("ScrolledPanel2");
}

function CalculateCalorificSum()
{
    var sum=0;
    for(var i=0; i<document.getElementsByName('DivTBCount').length; i++)
        if (!isNaN(document.getElementsByName('DivTBCount')[i].getElementsByTagName('input')[0].value))
            sum+=parseFloat(document.getElementsByName('DivTBCount')[i].getElementsByTagName('input')[0].value);
    if (document.getElementById('CalorificSum')) 
        document.getElementById('CalorificSum').value=sum+'kcal';
}


