var dataStroom			= new Array();
var dataGas				= new Array();
var dataVerbruik		= new Array();
var verbruikModifier	= 1.2;

// Variabel 1 jaar
dataStroom['Delta']			= {'prijs' : 0.22672, 'vastrecht' : 3.18}
dataStroom['Dong'] 			= {'prijs' : 0.22902, 'vastrecht' : 1.99}
dataStroom['Eneco'] 		= {'prijs' : 0.22972, 'vastrecht' : 1.99}
dataStroom['EON'] 			= {'prijs' : 0.23302, 'vastrecht' : 1.99}
dataStroom['Essent'] 		= {'prijs' : 0.22943, 'vastrecht' : 2.08}
dataStroom['Greenchoice'] 	= {'prijs' : 0.22693, 'vastrecht' : 2.08}
dataStroom['Nuon'] 			= {'prijs' : 0.24071, 'vastrecht' : 1.99}
dataStroom['Oxxio'] 		= {'prijs' : 0.23302, 'vastrecht' : 1.99}
dataStroom['Rendo'] 		= {'prijs' : 0.22792, 'vastrecht' : 2.08}
dataStroom['RWE'] 			= {'prijs' : 0.23455, 'vastrecht' : 1.99}
dataStroom['Westland'] 		= {'prijs' : 0.22943, 'vastrecht' : 2.08}
dataStroom['NEM'] 			= {'prijs' : 0.20965, 'vastrecht' : 6.99}
dataStroom['ED'] 			= {'prijs' : 0.22075, 'vastrecht' : 5.65}

// Variabel 1 jaar
dataGas['Delta'] 		= {'prijs' : 0.54145, 'vastrecht' : 1.49}
dataGas['Dong'] 		= {'prijs' : 0.50512, 'vastrecht' : 1.99}
dataGas['Eneco'] 		= {'prijs' : 0.51601, 'vastrecht' : 1.99}
dataGas['EON'] 			= {'prijs' : 0.52172, 'vastrecht' : 1.99}
dataGas['Essent'] 		= {'prijs' : 0.50527, 'vastrecht' : 2.08}
dataGas['Greenchoice'] 	= {'prijs' : 0.50278, 'vastrecht' : 2.08}
dataGas['Nuon'] 		= {'prijs' : 0.51503, 'vastrecht' : 2.49}
dataGas['Oxxio'] 		= {'prijs' : 0.53586, 'vastrecht' : 1.99}
dataGas['Rendo'] 		= {'prijs' : 0.50572, 'vastrecht' : 5.65}
dataGas['RWE'] 			= {'prijs' : 0.51253, 'vastrecht' : 1.99}
dataGas['Westland'] 	= {'prijs' : 0.50527, 'vastrecht' : 2.08}
dataGas['NEM'] 			= {'prijs' : 0.40459, 'vastrecht' : 6.99}
dataGas['ED'] 			= {'prijs' : 0.47481, 'vastrecht' : 5.65}

// Verbruik
dataVerbruik['2-onder-1-kap'] 	= {'stroom' : 3323, 'gas' : 1733}
dataVerbruik['Flat'] 			= {'stroom' : 3323, 'gas' : 845}
dataVerbruik['Hoekwoning'] 		= {'stroom' : 3323, 'gas' : 2079}
dataVerbruik['Tussenwoning'] 	= {'stroom' : 3323, 'gas' : 1469}
dataVerbruik['Vrijstaand'] 		= {'stroom' : 3323, 'gas' : 2516}

function updateCalc() {
	
	var lev = document.forms.calculator.calcLeverancier.value;
	var typ = document.forms.calculator.calcTypeHuis.value;
	
	//Fix space:
	document.forms.calculator.calcPostcode.value = document.forms.calculator.calcPostcode.value.replace(' ','');
	
	var pc  = document.forms.calculator.calcPostcode.value;
	
	if ( (lev == "0") || (typ == "0") || (pc.length != 6) ) {
		alert("Om uw voordeel te berekenen dient u de gegevens volledig in te vullen");
	} else {
		// Update it
		var obj = document.getElementById("innerCalc");
		var voordeel = round(diff(lev, typ));
		var goedkoper = true;
		
		if (voordeel < 0) {
			goedkoper = false;
			voordeel = round(voordeel * -0.5, 2);
		}
		
		if (obj) {
			
			str  = "<br />Op basis van de door u ingevoerde gegevens hebben wij voor u het voordeel berekend.";
			str += "<br />";
			str += "<ul>";
			str += "<li>Huidige leverancier: " + lev + "</li>";
			str += "<li>Type huis: " + typ + "</li>";
			str += "<li>Postcode: " + pc + "</li>";
			str += "<li>Verbruik stroom: " + round(dataVerbruik[typ]['stroom'] * verbruikModifier,0) + " (kWh)</li>";
			str += "<li>Verbruik gas: " + round(dataVerbruik[typ]['gas']* verbruikModifier,0) + " (m3)</li>";
			str += "</ul><br />";
			str += "Uw voordeel per contractsperiode: <h1>&euro;" + voordeel + "</h1>";
			if (!goedkoper) {
				str += "als u gebruik maakt van onze laagste prijsgarantie.";
			}
			obj.innerHTML = str;
		}
	    	
		// Show it
		$('#basic-modal-content-calc').modal();
	}
}

function diff(a, w) {
	return total(a, w) - total("ED", w);
}

function total(a, w) {
	stroom_vastrecht = dataStroom[a]['vastrecht'] * 36; // 3 jaar
	stroom_verbruik = (dataVerbruik[w]['stroom'] * 3) * verbruikModifier * dataStroom[a]['prijs'];
	
	gas_vastrecht = dataGas[a]['vastrecht'] * 36; // 3 jaar
	gas_verbruik = (dataVerbruik[w]['gas'] * 3) * verbruikModifier * dataGas[a]['prijs'];
	
	return (stroom_vastrecht + stroom_verbruik + gas_vastrecht + gas_verbruik);
}

function round(number,X) {
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
