<!--
// new version updated 8/16/06 by pHonstein; numbers by RHuntley
// note: fg_calculator template file must also be updated to alter defaults in the interface

 function round2d(n) {

	var tem = new String(Math.round(100*n)/100);
	var pos = tem.lastIndexOf(".");
	if (pos >= 0) {
		tem1 = tem.substring(0, pos);
		tem2 = tem.substring(pos+1, tem.length);
		//alert("tem1 " + tem1 + ", tem2 " + tem2);
		if (tem2.length == 0) {
			tem2 = "";
		}
		else if (tem2.length == 1) {
			tem2  += "";
		}
		tem = tem1 + "." + tem2;
	}
	else {
		tem = tem + ".";
	}
	return(tem);
}


function resetForm() {

	document.forma.num_people.value = 1;
	document.forma.electricity.value = 4401;
	document.forma.oil.value = 0;
	document.forma.gas.value = 311;
	document.forma.lpg.value = 0;	
	document.forma.veh1_mpy.value = 13785;
	document.forma.veh2_mpy.value = 13785;
	document.forma.veh1_mpg.value = document.forma.veh2_mpg.value = 25.2;
	document.forma.air_mpy.value = 10000;
	
	calcForm();
}

function oldNumPersons() {

	num_people_old = parseFloat(document.forma.num_people.value);
}

function multForm() {
	
	persons = (document.forma.num_people.value>0) ? parseFloat(document.forma.num_people.value) : 1;
	//alert("multForm: " + num_people_old);

	electricity_per_1 = document.forma.electricity.value/num_people_old;
	oil_per_1 = document.forma.oil.value/num_people_old;
	gas_per_1 = document.forma.gas.value/num_people_old;
	lpg_per_1 = document.forma.lpg.value/num_people_old;
	
	document.forma.electricity.value = electricity_per_1*persons;
	document.forma.oil.value = oil_per_1*persons;
	document.forma.gas.value = gas_per_1*persons;
	document.forma.lpg.value = lpg_per_1*persons;

	oldNumPersons();

	calcForm();
}

function work() {

	if (parent.frames[0] && parent.frames['gornji'].Go) {parent.frames['gornji'].Go();}
	resetForm();
}

function calcForm() {

    var el_mul, gas_mul, oil_mul, lpg_mul, veh_mul, air_mul, ton_mul, co2_tpy, z_mul, persons, energy, transport;
    el_mul = 0.000606;
	gas_mul = 0.0059138;	// 120.593/2205 //old 0.054697
	oil_mul = 0.01015;      // old was 0.011806
	lpg_mul = 0.005807;
	veh_mul = 0.00887;	// 8.87/1000
	// below was 0.00028975, which is 0.63889/2205
	air_mul = 0.0002704;
	air_mul = 0.0001900;
	ton_mul = 5.50;
	z_mul = 2.5;

	num_people_def = 1;
	electricity_def = 4401;
	oil_def = 284;
	gas_def = 311;
	lpg_def = 164;	
	veh1_mpy_def = 13785;
	veh2_mpy_def = 13785;
	veh1_mpg_def = veh2_mpg_def = 25.2;
	air_mpy_def = 10000;

	document.forma.co2_py.value = '';
	document.forma.dol_py.value = '';
	document.forma.dol_pm.value = '';
	document.forma.z_co2.value = '';
	document.forma.z_py.value = '';
	document.forma.z_pm.value = '';	

	//document.forma.electricity.value = (document.forma.electricity.value>0) ? document.forma.electricity.value : 0.00;
	//document.forma.oil.value = (document.forma.oil.value>0) ? document.forma.oil.value : 0.00;
	//document.forma.gas.value = (document.forma.gas.value>0) ? document.forma.gas.value : 0.0;
	//document.forma.lpg.value = (document.forma.lpg.value>0) ? document.forma.lpg.value : 0.00;
	//document.forma.veh1_mpy.value = (document.forma.veh1_mpy.value>0) ? document.forma.veh1_mpy.value : 0.00;
	//document.forma.veh2_mpy.value = (document.forma.veh2_mpy.value>0) ? document.forma.veh2_mpy.value : 0.00;
	//document.forma.veh1_mpg.value = (document.forma.veh1_mpg.value>0) ? document.forma.veh1_mpg.value : 25;
	//document.forma.veh2_mpg.value = (document.forma.veh2_mpg.value>0) ? document.forma.veh2_mpg.value : 25;
	//document.forma.air_mpy.value = (document.forma.air_mpy.value>0) ? document.forma.air_mpy.value : 0.00;
	//document.forma.num_people.value = (document.forma.num_people.value>0) ? document.forma.num_people.value : 1;
    
	persons = parseFloat(document.forma.num_people.value);
	//document.forma.gas.value = round2d(document.forma.gas.value);
	
    el = (document.forma.electricity.value>0) ? parseFloat(document.forma.electricity.value) : 0;
    gas = (document.forma.gas.value>0) ? parseFloat(document.forma.gas.value) : 0;
	oil = (document.forma.oil.value>0) ? parseFloat(document.forma.oil.value) : 0;
	lpg = (document.forma.lpg.value>0) ? parseFloat(document.forma.lpg.value) : 0;
	veh1_mpy = (document.forma.veh1_mpy.value>0) ? parseFloat(document.forma.veh1_mpy.value) : 0;
	veh1_mpg = (document.forma.veh1_mpg.value>0) ? parseFloat(document.forma.veh1_mpg.value) : 25;
	veh2_mpy = (document.forma.veh2_mpy.value>0) ? parseFloat(document.forma.veh2_mpy.value) : 0;
	veh2_mpg = (document.forma.veh2_mpg.value>0) ? parseFloat(document.forma.veh2_mpg.value) : 25;
	air = (document.forma.air_mpy.value>0) ? parseFloat(document.forma.air_mpy.value) : 0;	
		
	energy = el*el_mul + gas*gas_mul + oil*oil_mul + lpg*lpg_mul;
	transport = (veh1_mpy/veh1_mpg+veh2_mpy/veh2_mpg)*veh_mul + air*air_mul;

	co2_tpy = energy + transport;

	document.forma.co2_py.value = round2d(co2_tpy);
	document.forma.dol_py.value = '$' + round2d(co2_tpy*ton_mul);
	document.forma.dol_pm.value = '$' + round2d(co2_tpy*ton_mul/12);
	
	document.forma.z_co2.value = round2d(co2_tpy*z_mul);
	document.forma.z_py.value = '$' + round2d(co2_tpy*ton_mul*z_mul);
	document.forma.z_pm.value = '$' + round2d(co2_tpy*ton_mul/12*z_mul);
}
-->