function $(i)
{
 return document.getElementById(i);
}

function $$(x)
{
 z = parseFloat(document.getElementById(x).value);
 if(isNaN(z)) return 0; else return z;
}

function calc(val, factor, putin) 
{ 
 if(val == "") val = "0";
 val = val.replace(/[\,]/, '.');
 
 if(!parseFloat(val)) val = 0;
 $(putin).value = parseFloat(val * factor).toFixed(2);
 
 var totalgas = $$('ans1') + $$('ans2') + $$('ans3') + $$('ans4') + $$('ans5') + $$('ans6') + $$('ans7') + $$('ans8') + $$('ans9') + $$('ans10');
 totalgas = parseFloat(totalgas).toFixed(2);
 var carbon = Math.round(totalgas * 2.73) / 10; // 0.273 is the CO2 to C conversion factor (12/44th)
  
 $('totalgas').value = totalgas;
 $('carbon').value = carbon;
 return;
}