// JavaScript Document
	
function checkCandle(field,id,mod) {

	var antField = document.getElementById('ch' + id + 'Ant');
	var dioderField = document.getElementById('ch' + id + 'Dioder');
	var errorfield = document.getElementById('msg' + id);
	var wattField = document.getElementById('watt' + id);
	var voltField = document.getElementById('volt' + id);
	if (document.getElementById(mod).value == "2w" ) var watt = .7;
	else var watt = .35;
	
	if (antField.value * dioderField.value < 0 || antField.value * dioderField.value > 12) {	
		errorfield.value = "Max 12 st dioder/kanal!";
		field.bgColor = "#66ffff";
		wattField.value = "";
		voltField.value = "";
		field.focus();
	}
	else {
		errorfield.value = "";
		// calculate watts and voltage use.
		var voltageNeed = antField.value * dioderField.value * 3.4;
		if (voltageNeed < 12) voltField.value = 12;
		if (voltageNeed < 24 && voltageNeed >= 12) voltField.value = 24;
		if (voltageNeed < 48 && voltageNeed >= 24) voltField.value = 48;
		var wattsUsage = Math.round(antField.value * dioderField.value * 34 * watt) /10;
		wattField.value = wattsUsage;
		createSummary();
	}
	
}
function updateModule(nr) {
	var startChannel = 1 + ( (parseInt(nr) - 1) * 3 );
	var mod = 'mod' + nr + 'Type';
	var channel = parseInt(startChannel);
	checkCandle('ch' + channel + 'Ant',channel,mod);
	var channel = parseInt(startChannel) + 1;
	checkCandle('ch' + channel + 'Ant',channel,mod);
	var channel = parseInt(startChannel) + 2;
	checkCandle('ch' + channel + 'Ant',channel,mod);
}		
function createSummary() {
	var sumAnt = document.getElementById('sumAnt');
	var sumWatt = document.getElementById('sumWatt');
	var unitVolt = document.getElementById('unitVolt');
	var volt = 12;
	var watt = 0;
	var ant = 0;
	for (i = 1; i < 13 ; i++) {
		if (document.getElementById('ch'+i+'Ant').value != "") ant = parseInt(ant) + parseInt(document.getElementById('ch'+i+'Ant').value);
		watt = parseFloat(watt) + parseFloat(document.getElementById('watt'+i).value);
		if ( document.getElementById('volt'+i).value > parseInt(volt) ) volt = parseInt(document.getElementById('volt'+i).value);
	}
	sumAnt.value = ant;
	sumWatt.value = Math.round(watt*10) / 10;
	unitVolt.value = volt;
	
}		